[Python-checkins] cpython (merge 3.5 -> default): Issue #25913: Leading <~ is optional now in base64.a85decode() with adobe=True.

serhiy.storchaka python-checkins at python.org
Wed Feb 24 05:08:26 EST 2016


https://hg.python.org/cpython/rev/90d5473b8673
changeset:   100313:90d5473b8673
parent:      100311:113e9c6fd64d
parent:      100312:ce5bf3290621
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Wed Feb 24 12:08:11 2016 +0200
summary:
  Issue #25913: Leading <~ is optional now in base64.a85decode() with adobe=True.
Patch by Swati Jaiswal.

files:
  Lib/base64.py           |  13 +++++++++----
  Lib/test/test_base64.py |   3 +--
  Misc/NEWS               |   5 ++++-
  3 files changed, 14 insertions(+), 7 deletions(-)


diff --git a/Lib/base64.py b/Lib/base64.py
--- a/Lib/base64.py
+++ b/Lib/base64.py
@@ -366,10 +366,15 @@
     """
     b = _bytes_from_decode_data(b)
     if adobe:
-        if not (b.startswith(_A85START) and b.endswith(_A85END)):
-            raise ValueError("Ascii85 encoded byte sequences must be bracketed "
-                             "by {!r} and {!r}".format(_A85START, _A85END))
-        b = b[2:-2] # Strip off start/end markers
+        if not b.endswith(_A85END):
+            raise ValueError(
+                "Ascii85 encoded byte sequences must end "
+                "with {!r}".format(_A85END)
+                )
+        if b.startswith(_A85START):
+            b = b[2:-2]  # Strip off start/end markers
+        else:
+            b = b[:-2]
     #
     # We have to go through this stepwise, so as to ignore spaces and handle
     # special short sequences
diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py
--- a/Lib/test/test_base64.py
+++ b/Lib/test/test_base64.py
@@ -494,6 +494,7 @@
             eq(base64.a85decode(data, adobe=False), res, data)
             eq(base64.a85decode(data.decode("ascii"), adobe=False), res, data)
             eq(base64.a85decode(b'<~' + data + b'~>', adobe=True), res, data)
+            eq(base64.a85decode(data + b'~>', adobe=True), res, data)
             eq(base64.a85decode('<~%s~>' % data.decode("ascii"), adobe=True),
                res, data)
 
@@ -584,8 +585,6 @@
                                       b"malformed", adobe=True)
         self.assertRaises(ValueError, base64.a85decode,
                                       b"<~still malformed", adobe=True)
-        self.assertRaises(ValueError, base64.a85decode,
-                                      b"also malformed~>", adobe=True)
 
         # With adobe=False (the default), Adobe framing markers are disallowed
         self.assertRaises(ValueError, base64.a85decode,
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -186,7 +186,10 @@
 Library
 -------
 
-Issue #26186: Remove an invalid type check in importlib.util.LazyLoader.
+- Issue #25913: Leading ``<~`` is optional now in base64.a85decode() with
+  adobe=True.  Patch by Swati Jaiswal.
+
+- Issue #26186: Remove an invalid type check in importlib.util.LazyLoader.
 
 - Issue #26367: importlib.__import__() raises ImportError like
   builtins.__import__() when ``level`` is specified but without an accompanying

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list