[#3127|Blocklist] Fix importing blocklist with encoded lines

There are some blocklists with encoded names that break upon importing
so decode lines to unicode.

Need to use decode_bytes as not all encoded lines are utf8!
This commit is contained in:
Calum Lind 2017-11-05 20:52:43 +00:00
parent 9bcda41700
commit 95d826b77c
1 changed files with 3 additions and 0 deletions

View File

@ -12,6 +12,7 @@ from __future__ import unicode_literals
import logging
import re
from deluge.common import decode_bytes
from .common import IP, BadIP, raises_errors_as
log = logging.getLogger(__name__)
@ -54,6 +55,7 @@ class BaseReader(object):
blocklist = self.open()
valid = True
for line in blocklist:
line = decode_bytes(line)
if not self.is_ignored(line):
try:
(start, end) = self.parse(line)
@ -71,6 +73,7 @@ class BaseReader(object):
"""Yields each ip range from the file"""
blocklist = self.open()
for line in blocklist:
line = decode_bytes(line)
if not self.is_ignored(line):
yield self.parse(line)
blocklist.close()