summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorEmilio Pozuelo Monfort <pochu@debian.org>2020-07-17 11:57:54 +0200
committerEmilio Pozuelo Monfort <pochu@debian.org>2020-07-29 10:20:41 +0200
commit8ae68d88163932449cf8a31d9ee722f2e5732ff8 (patch)
treedc703d85eb89600b4a33c17c49684f9a60988de7 /lib
parentc92e30105faa521767a6ca38bd04c9fc22c955d2 (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.py14
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:

© 2014-2024 Faster IT GmbH | imprint | privacy policy