[Piuparts-devel] [Git][debian/piuparts][develop] 2 commits: avoid "input" as variable name

Holger Levsen gitlab at salsa.debian.org
Fri Dec 27 11:53:21 GMT 2019



Holger Levsen pushed to branch develop at Debian / piuparts


Commits:
82709f47 by Nis Martensen at 2019-12-27T11:52:51Z
avoid "input" as variable name

It is better to avoid using names of builtin functions as variable
names.

Signed-off-by: Holger Levsen <holger at layer-acht.org>

- - - - -
e526f8a1 by Nis Martensen at 2019-12-27T11:53:02Z
piupartslib/__init__: fix byte stream decoding

When trying to decode a byte sequence into a string, it is possible that
the sequence ends in the middle of a multibyte character. In this case
the decoding fails.

This hack assumes that the input byte sequence is always encoded in
UTF-8, and that the original data stream never ends in the middle of a
multibyte character.

Signed-off-by: Holger Levsen <holger at layer-acht.org>

- - - - -


4 changed files:

- piuparts-master-backend.py
- piupartslib/__init__.py
- piupartslib/dependencyparser.py
- piupartslib/packagesdb.py


Changes:

=====================================
piuparts-master-backend.py
=====================================
@@ -96,8 +96,8 @@ class ProtocolError(Exception):
 
 class Protocol:
 
-    def __init__(self, input, output):
-        self._input = input
+    def __init__(self, myinput, output):
+        self._input = myinput
         self._output = output
 
     def _readline(self):
@@ -129,8 +129,8 @@ class Protocol:
 
 class Master(Protocol):
 
-    def __init__(self, input, output):
-        Protocol.__init__(self, input, output)
+    def __init__(self, myinput, output):
+        Protocol.__init__(self, myinput, output)
         self._commands = {
             "section": self._switch_section,
             "recycle": self._recycle,


=====================================
piupartslib/__init__.py
=====================================
@@ -33,6 +33,17 @@ class DecompressedStream():
         self._line_buffer = []
         self._i = 0
         self._end = 0
+        self._undecbuf = b''
+
+    def _split_decode(self, myb):
+        lmyb = len(myb)
+        for end in range(lmyb, max(lmyb-6, -1), -1):
+            try:
+                return myb[:end].decode(), myb[end:]
+            except UnicodeDecodeError:
+                pass
+        # not returned yet? We have a problem
+        raise UnicodeDecodeError
 
     def _refill(self):
         if self._input is None:
@@ -46,7 +57,8 @@ class DecompressedStream():
             if self._decompressor:
                 chunk = self._decompressor.decompress(chunk)
             if isinstance(chunk, bytes):
-                chunk = chunk.decode()
+                chunk = self._undecbuf + chunk
+                chunk, self._undecbuf = self._split_decode(chunk)
             self._buffer = self._buffer + chunk
             if chunk:
                 return True


=====================================
piupartslib/dependencyparser.py
=====================================
@@ -51,8 +51,8 @@ class _Cursor:
 
     """Store an input string and a movable location in it"""
 
-    def __init__(self, input):
-        self._input = input
+    def __init__(self, myinput):
+        self._input = myinput
         self._len = len(self._input)
         self._pos = 0
 


=====================================
piupartslib/packagesdb.py
=====================================
@@ -47,10 +47,10 @@ import six
 apt_pkg.init_system()
 
 
-def rfc822_like_header_parse(input):
+def rfc822_like_header_parse(myinput):
     headers = []
     while True:
-        line = input.readline()
+        line = myinput.readline()
         if not line or line in ["\r\n", "\n"]:
             break
         if headers and line and line[0].isspace():
@@ -184,10 +184,10 @@ class PackagesFile(UserDict):
             stream.close()
             self._urllist.append(url)
 
-    def _read_file(self, input, restrict_packages=None):
+    def _read_file(self, myinput, restrict_packages=None):
         """Parse a Packages file and add its packages to us-the-dict"""
         while True:
-            headers = rfc822_like_header_parse(input)
+            headers = rfc822_like_header_parse(myinput)
             if not headers:
                 break
             p = Package(headers)



View it on GitLab: https://salsa.debian.org/debian/piuparts/compare/a065bef3ec0e558b39067a59de372ada82494677...e526f8a15505344da15595e1c1b092e0535159de

-- 
View it on GitLab: https://salsa.debian.org/debian/piuparts/compare/a065bef3ec0e558b39067a59de372ada82494677...e526f8a15505344da15595e1c1b092e0535159de
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/piuparts-devel/attachments/20191227/099d558e/attachment-0001.html>


More information about the Piuparts-devel mailing list