From 9ec7434f703e896addff57b410ec0addcf224391 Mon Sep 17 00:00:00 2001 From: Emilio Pozuelo Monfort Date: Fri, 17 Jul 2020 11:57:54 +0200 Subject: debian_support: decode lines when necessary We sometimes get passed lines as bytes, which we need to decode under python3. We should probably add an argument to PackageFile's constructor for when we get a fileObj argument, but let's do that when we no longer have to worry about py2 and py3 compatibility. --- lib/python/debian_support.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/python/debian_support.py b/lib/python/debian_support.py index ba824775ab..65caf95554 100644 --- a/lib/python/debian_support.py +++ b/lib/python/debian_support.py @@ -150,8 +150,16 @@ class PackageFile: self.file = fileObj self.lineno = 0 + def readline(self): + line = self.file.readline() + + if line != None and not isstring(line): + line = line.decode('utf-8') + + return line + def __iter__(self): - line = self.file.readline().decode('utf-8') + line = self.readline() self.lineno += 1 pkg = [] while line: @@ -160,7 +168,7 @@ class PackageFile: self.raiseSyntaxError('expected package record') yield pkg pkg = [] - line = self.file.readline().decode('utf-8') + line = self.readline() self.lineno += 1 continue @@ -171,7 +179,7 @@ class PackageFile: contents = contents or '' while True: - line = self.file.readline().decode('utf-8') + line = self.readline() self.lineno += 1 match = self.re_continuation.match(line) if match: -- cgit v1.2.3