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
commit590a1fbff263047de706f9e8e01e93f3b66f3bd9 (patch)
treeeec5f686feea0f312f1c38895f83f71624e0fc18 /lib
parent751b43a80330bafa2a17cb8135c68ba33c13802d (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