From 40bea495dab92cde18bf41acea83b8e76f55bcf9 Mon Sep 17 00:00:00 2001 From: Emilio Pozuelo Monfort Date: Thu, 16 Jul 2020 17:47:49 +0200 Subject: debian_support.py: add py3 compatibility for apt-update-file --- lib/python/debian_support.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/python/debian_support.py b/lib/python/debian_support.py index a51435caf3..ba824775ab 100644 --- a/lib/python/debian_support.py +++ b/lib/python/debian_support.py @@ -19,6 +19,7 @@ from __future__ import print_function """This module implements facilities to deal with Debian-specific metadata.""" import gzip +import io import json import os.path import re @@ -150,7 +151,7 @@ class PackageFile: self.lineno = 0 def __iter__(self): - line = self.file.readline() + line = self.file.readline().decode('utf-8') self.lineno += 1 pkg = [] while line: @@ -159,7 +160,7 @@ class PackageFile: self.raiseSyntaxError('expected package record') yield pkg pkg = [] - line = self.file.readline() + line = self.file.readline().decode('utf-8') self.lineno += 1 continue @@ -170,7 +171,7 @@ class PackageFile: contents = contents or '' while True: - line = self.file.readline() + line = self.file.readline().decode('utf-8') self.lineno += 1 match = self.re_continuation.match(line) if match: @@ -222,6 +223,8 @@ del listReleases def readLinesSHA1(lines): m = sha1() for l in lines: + if sys.version_info.major == 3: + l = l.encode('utf-8') m.update(l) return m.hexdigest() @@ -306,7 +309,10 @@ def downloadGunzipLines(remote): try: gfile = gzip.GzipFile(fileobj=streamIO(data.read())) try: - return gfile.readlines() + if sys.version_info.major == 3: + return io.TextIOWrapper(gfile).readlines() + else: + return gfile.readlines() finally: gfile.close() finally: -- cgit v1.2.3