mirror of
https://github.com/chibicitiberiu/ytsm.git
synced 2024-02-24 05:43:31 +00:00
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:
parent
59a766b0fe
commit
9d8b023560
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user