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.
This commit is contained in:
Tiberiu Chibici 2018-11-03 14:56:16 +02:00
parent 59a766b0fe
commit 9d8b023560

View File

@ -38,8 +38,10 @@ class SubscriptionListFileParser(SubFileParser):
def probe(self, file_handle): def probe(self, file_handle):
file_handle.seek(0) file_handle.seek(0)
for line in file_handle: for line in file_handle:
if isinstance(line, bytes) or isinstance(line, bytearray):
line = line.decode()
# Trim comments and spaces # Trim comments and spaces
line = re.sub('#.*', '', line).strip() line = re.sub('(^|\s)#.*', '', line).strip()
if len(line) > 0: if len(line) > 0:
return self.__is_url(line) return self.__is_url(line)
return False return False
@ -47,8 +49,10 @@ class SubscriptionListFileParser(SubFileParser):
def parse(self, file_handle): def parse(self, file_handle):
file_handle.seek(0) file_handle.seek(0)
for line in file_handle: for line in file_handle:
if isinstance(line, bytes) or isinstance(line, bytearray):
line = line.decode()
# Trim comments and spaces # Trim comments and spaces
line = re.sub('#.*', '', line).strip() line = re.sub('(^|\s)#.*', '', line).strip()
if len(line) > 0: if len(line) > 0:
yield line yield line