diff options
author | Emilio Pozuelo Monfort <pochu@debian.org> | 2020-07-17 11:57:54 +0200 |
---|---|---|
committer | Emilio Pozuelo Monfort <pochu@debian.org> | 2020-07-29 10:20:41 +0200 |
commit | 9ec7434f703e896addff57b410ec0addcf224391 (patch) | |
tree | 3ca473d21512c469f05318709ed3c8edf936db39 /lib | |
parent | 5bb67bfaf06d456c4c46ea7575e496d2443960bf (diff) |
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/python/debian_support.py | 14 |
1 files changed, 11 insertions, 3 deletions
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: |