From 9d8b023560012acb4491006ba7e7497412ab994d Mon Sep 17 00:00:00 2001 From: Tiberiu Chibici Date: Sat, 3 Nov 2018 14:56:16 +0200 Subject: [PATCH] Improved handling of comments in 'subscription list' files (basically a text file containing subscriptions, and optionally comments with #). Properly handled case where file is opened in binary mode. --- app/YtManagerApp/utils/subscription_file_parser.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/YtManagerApp/utils/subscription_file_parser.py b/app/YtManagerApp/utils/subscription_file_parser.py index 6860b9e..225c3bd 100644 --- a/app/YtManagerApp/utils/subscription_file_parser.py +++ b/app/YtManagerApp/utils/subscription_file_parser.py @@ -38,8 +38,10 @@ class SubscriptionListFileParser(SubFileParser): def probe(self, file_handle): file_handle.seek(0) for line in file_handle: + if isinstance(line, bytes) or isinstance(line, bytearray): + line = line.decode() # Trim comments and spaces - line = re.sub('#.*', '', line).strip() + line = re.sub('(^|\s)#.*', '', line).strip() if len(line) > 0: return self.__is_url(line) return False @@ -47,8 +49,10 @@ class SubscriptionListFileParser(SubFileParser): def parse(self, file_handle): file_handle.seek(0) for line in file_handle: + if isinstance(line, bytes) or isinstance(line, bytearray): + line = line.decode() # Trim comments and spaces - line = re.sub('#.*', '', line).strip() + line = re.sub('(^|\s)#.*', '', line).strip() if len(line) > 0: yield line