Ticket #6917: port_python_zippath_py3_comparable_decorator.patch

File port_python_zippath_py3_comparable_decorator.patch, 32.8 KB (added by cpdean, 3 years ago)

removed my own implementation of eq in favor of the old cmp with the comparable decorator for python3 compatibility

  • twisted/python/dist3.py

    From 242cc5f75f26f596c16999b8f3e8f3d93a986cc6 Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Tue, 15 Apr 2014 17:14:17 -0400
    Subject: [PATCH 01/18] add python3 future imports and add zippath to py3 test
     suite
    
    ---
     twisted/python/dist3.py   | 1 +
     twisted/python/zippath.py | 1 +
     2 files changed, 2 insertions(+)
    
    diff --git a/twisted/python/dist3.py b/twisted/python/dist3.py
    index eee4f44..613646f 100644
    a b modules = [ 
    100100    "twisted.python.test",
    101101    "twisted.python.test.deprecatedattributes",
    102102    "twisted.python.test.modules_helpers",
     103    "twisted.python.test.test_zippath",
    103104    "twisted.python.threadable",
    104105    "twisted.python.threadpool",
    105106    "twisted.python.usage",
  • twisted/python/zippath.py

    diff --git a/twisted/python/zippath.py b/twisted/python/zippath.py
    index c29addd..f6bd4e7 100644
    a b This module contains implementations of IFilePath for zip files. 
    77
    88See the constructor for ZipArchive for use.
    99"""
     10from __future__ import print_function, division, absolute_import
    1011
    1112__metaclass__ = type
    1213
  • twisted/python/test/test_zippath.py

    -- 
    1.7.12.4 (Apple Git-37)
    
    
    From 0d451dc03c3874473135e64e5bd738ff1317139c Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Tue, 15 Apr 2014 17:49:11 -0400
    Subject: [PATCH 02/18] WIP: getting around bytes + str error, still broken
     with ZipArchive(b'..'). see twisted.test.test_paths
     for workaround?
    
    ---
     twisted/python/test/test_zippath.py | 6 +++---
     1 file changed, 3 insertions(+), 3 deletions(-)
    
    diff --git a/twisted/python/test/test_zippath.py b/twisted/python/test/test_zippath.py
    index 863e2f3..6f40e4a 100644
    a b class ZipFilePathTestCase(AbstractFilePathTestCase): 
    3333    """
    3434    def setUp(self):
    3535        AbstractFilePathTestCase.setUp(self)
    36         zipit(self.cmn, self.cmn + '.zip')
    37         self.path = ZipArchive(self.cmn + '.zip')
     36        zipit(self.cmn, self.cmn + b'.zip')
     37        self.path = ZipArchive(self.cmn + b'.zip')
    3838        self.root = self.path
    39         self.all = [x.replace(self.cmn, self.cmn + '.zip') for x in self.all]
     39        self.all = [x.replace(self.cmn, self.cmn + b'.zip') for x in self.all]
    4040
    4141
    4242    def test_zipPathRepr(self):
  • twisted/python/test/test_zippath.py

    -- 
    1.7.12.4 (Apple Git-37)
    
    
    From e094de2dc288f6fd65d73d51aba1a998267725df Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Thu, 17 Apr 2014 08:18:34 -0400
    Subject: [PATCH 03/18] fix bugs using zipfile.  it only works if you pass it
     strings, not bytestrings
    
    ---
     twisted/python/test/test_zippath.py | 10 +++++++---
     1 file changed, 7 insertions(+), 3 deletions(-)
    
    diff --git a/twisted/python/test/test_zippath.py b/twisted/python/test/test_zippath.py
    index 6f40e4a..98ca9b5 100644
    a b import os, zipfile 
    1010from twisted.test.test_paths import AbstractFilePathTestCase
    1111from twisted.python.zippath import ZipArchive
    1212
     13import sys
     14
     15encoding = sys.getfilesystemencoding()
     16
    1317
    1418def zipit(dirname, zfname):
    1519    """
    1620    Create a zipfile on zfname, containing the contents of dirname'
    1721    """
    18     zf = zipfile.ZipFile(zfname, "w")
     22    zf = zipfile.ZipFile(zfname.decode(encoding), "w")
    1923    for root, ignored, files, in os.walk(dirname):
    2024        for fname in files:
    2125            fspath = os.path.join(root, fname)
    2226            arcpath = os.path.join(root, fname)[len(dirname)+1:]
    2327            # print fspath, '=>', arcpath
    24             zf.write(fspath, arcpath)
     28            zf.write(fspath.decode(encoding), arcpath.decode(encoding))
    2529    zf.close()
    2630
    2731
    class ZipFilePathTestCase(AbstractFilePathTestCase): 
    3438    def setUp(self):
    3539        AbstractFilePathTestCase.setUp(self)
    3640        zipit(self.cmn, self.cmn + b'.zip')
    37         self.path = ZipArchive(self.cmn + b'.zip')
     41        self.path = ZipArchive((self.cmn + b'.zip').decode(encoding))
    3842        self.root = self.path
    3943        self.all = [x.replace(self.cmn, self.cmn + b'.zip') for x in self.all]
    4044
  • twisted/python/zippath.py

    -- 
    1.7.12.4 (Apple Git-37)
    
    
    From b9db7e93dd9ee6efc72f03d545fee0a82890d219 Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Thu, 17 Apr 2014 08:31:26 -0400
    Subject: [PATCH 04/18] fix tests in python2, strings are now unicode
    
    ---
     twisted/python/zippath.py | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/twisted/python/zippath.py b/twisted/python/zippath.py
    index f6bd4e7..0f02ff7 100644
    a b class ZipPath(AbstractFilePath): 
    7171        parts = [os.path.abspath(self.archive.path)]
    7272        parts.extend(self.pathInArchive.split(ZIP_PATH_SEP))
    7373        path = os.sep.join(parts)
    74         return "ZipPath('%s')" % (path.encode('string-escape'),)
     74        return "ZipPath('%s')" % (path.encode('unicode-escape'),)
    7575
    7676
    7777    def parent(self):
  • twisted/python/test/test_zippath.py

    -- 
    1.7.12.4 (Apple Git-37)
    
    
    From eac43c8b8d543226f33f898858496c001972ce7b Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Thu, 17 Apr 2014 10:37:24 -0400
    Subject: [PATCH 05/18] converting strings to bytes, since that's how the
     test_paths suite looks
    
    ---
     twisted/python/test/test_zippath.py | 11 ++++++-----
     twisted/python/zippath.py           |  2 +-
     2 files changed, 7 insertions(+), 6 deletions(-)
    
    diff --git a/twisted/python/test/test_zippath.py b/twisted/python/test/test_zippath.py
    index 98ca9b5..6134237 100644
    a b class ZipFilePathTestCase(AbstractFilePathTestCase): 
    5050        """
    5151        child = self.path.child("foo")
    5252        pathRepr = "ZipPath(%r)" % (
    53             os.path.abspath(self.cmn + ".zip" + os.sep + 'foo'),)
     53            os.path.abspath(self.cmn + b".zip" + os.sep.encode() + b'foo'),)
    5454
    5555        # Check for an absolute path
    5656        self.assertEqual(repr(child), pathRepr)
    class ZipFilePathTestCase(AbstractFilePathTestCase): 
    7272        """
    7373        child = self.path.child("foo").child("..").child("bar")
    7474        pathRepr = "ZipPath(%r)" % (
    75             self.cmn + ".zip" + os.sep.join(["", "foo", "..", "bar"]))
     75            self.cmn +
     76            (".zip" + os.sep.join(["", "foo", "..", "bar"])).encode("utf-8"))
    7677        self.assertEqual(repr(child), pathRepr)
    7778
    7879
    class ZipFilePathTestCase(AbstractFilePathTestCase): 
    8283        string literals are escaped in the ZipPath repr.
    8384        """
    8485        child = self.path.child("'")
    85         path = self.cmn + ".zip" + os.sep.join(["", "'"])
    86         pathRepr = "ZipPath('%s')" % (path.encode('string-escape'),)
     86        path = self.cmn + (".zip" + os.sep.join(["", "'"])).encode("utf-8")
     87        pathRepr = "ZipPath('%s')" % (path,)
    8788        self.assertEqual(repr(child), pathRepr)
    8889
    8990
    class ZipFilePathTestCase(AbstractFilePathTestCase): 
    9293        Make sure that invoking ZipArchive's repr prints the correct class
    9394        name and an absolute path to the zip file.
    9495        """
    95         pathRepr = 'ZipArchive(%r)' % (os.path.abspath(self.cmn + '.zip'),)
     96        pathRepr = 'ZipArchive(%r)' % (os.path.abspath(self.cmn + b'.zip'),)
    9697
    9798        # Check for an absolute path
    9899        self.assertEqual(repr(self.path), pathRepr)
  • twisted/python/zippath.py

    diff --git a/twisted/python/zippath.py b/twisted/python/zippath.py
    index 0f02ff7..dfbc641 100644
    a b class ZipPath(AbstractFilePath): 
    7171        parts = [os.path.abspath(self.archive.path)]
    7272        parts.extend(self.pathInArchive.split(ZIP_PATH_SEP))
    7373        path = os.sep.join(parts)
    74         return "ZipPath('%s')" % (path.encode('unicode-escape'),)
     74        return "ZipPath('%s')" % (path,)
    7575
    7676
    7777    def parent(self):
  • twisted/python/zippath.py

    -- 
    1.7.12.4 (Apple Git-37)
    
    
    From aa8620ee01d5e089cda77e55a9b65d8daefbbb7d Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Thu, 17 Apr 2014 11:51:27 -0400
    Subject: [PATCH 06/18] convert stray strings to bytes
    
    ---
     twisted/python/zippath.py | 16 ++++++++++------
     1 file changed, 10 insertions(+), 6 deletions(-)
    
    diff --git a/twisted/python/zippath.py b/twisted/python/zippath.py
    index dfbc641..6a25db4 100644
    a b from zope.interface import implementer 
    3333# using FilePath here exclusively rather than os to make sure that we don't do
    3434# anything OS-path-specific here.
    3535
    36 ZIP_PATH_SEP = '/'              # In zipfiles, "/" is universally used as the
     36ZIP_PATH_SEP = b'/'             # In zipfiles, "/" is universally used as the
    3737                                # path separator, regardless of platform.
    3838
    3939
    class ZipPath(AbstractFilePath): 
    5757        self.pathInArchive = pathInArchive
    5858        # self.path pretends to be os-specific because that's the way the
    5959        # 'zipimport' module does it.
    60         self.path = os.path.join(archive.zipfile.filename,
     60        self.path = os.path.join(archive.zipfile.filename.encode(),
    6161                                 *(self.pathInArchive.split(ZIP_PATH_SEP)))
    6262
    6363    def __cmp__(self, other):
    class ZipArchive(ZipPath): 
    208208            self.zipfile = ZipFile(archivePathname)
    209209        else:
    210210            self.zipfile = ChunkingZipFile(archivePathname)
    211         self.path = archivePathname
    212         self.pathInArchive = ''
     211        try:
     212            self.path = archivePathname.encode("utf-8")
     213        except AttributeError:
     214            self.path = archivePathname
     215
     216        self.pathInArchive = b''
    213217        # zipfile is already wasting O(N) memory on cached ZipInfo instances,
    214218        # so there's no sense in trying to do this lazily or intelligently
    215219        self.childmap = {}      # map parent: list of children
    216220
    217221        for name in self.zipfile.namelist():
    218             name = name.split(ZIP_PATH_SEP)
     222            name = name.split(ZIP_PATH_SEP.decode())
    219223            for x in range(len(name)):
    220224                child = name[-x]
    221                 parent = ZIP_PATH_SEP.join(name[:-x])
     225                parent = ZIP_PATH_SEP.decode().join(name[:-x])
    222226                if parent not in self.childmap:
    223227                    self.childmap[parent] = {}
    224228                self.childmap[parent][child] = 1
  • twisted/python/zippath.py

    -- 
    1.7.12.4 (Apple Git-37)
    
    
    From fa8909ae5ac234ab2c8541a72cb9ba11e716ab99 Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Thu, 17 Apr 2014 12:02:57 -0400
    Subject: [PATCH 07/18] convert more stray strings to bytes
    
    ---
     twisted/python/zippath.py | 6 +++---
     1 file changed, 3 insertions(+), 3 deletions(-)
    
    diff --git a/twisted/python/zippath.py b/twisted/python/zippath.py
    index 6a25db4..4ac984a 100644
    a b class ZipPath(AbstractFilePath): 
    5858        # self.path pretends to be os-specific because that's the way the
    5959        # 'zipimport' module does it.
    6060        self.path = os.path.join(archive.zipfile.filename.encode(),
    61                                  *(self.pathInArchive.split(ZIP_PATH_SEP)))
     61                                 *(self.pathInArchive.encode().split(ZIP_PATH_SEP)))
    6262
    6363    def __cmp__(self, other):
    6464        if not isinstance(other, ZipPath):
    class ZipPath(AbstractFilePath): 
    6969
    7070    def __repr__(self):
    7171        parts = [os.path.abspath(self.archive.path)]
    72         parts.extend(self.pathInArchive.split(ZIP_PATH_SEP))
     72        parts.extend(self.pathInArchive.encode().split(ZIP_PATH_SEP))
    7373        path = os.sep.join(parts)
    7474        return "ZipPath('%s')" % (path,)
    7575
    7676
    7777    def parent(self):
    78         splitup = self.pathInArchive.split(ZIP_PATH_SEP)
     78        splitup = self.pathInArchive.encode.split(ZIP_PATH_SEP)
    7979        if len(splitup) == 1:
    8080            return self.archive
    8181        return ZipPath(self.archive, ZIP_PATH_SEP.join(splitup[:-1]))
  • twisted/python/test/test_zippath.py

    -- 
    1.7.12.4 (Apple Git-37)
    
    
    From 82dfacfb8a74155e9d835caf4345a9d971f66dea Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Thu, 17 Apr 2014 15:21:37 -0400
    Subject: [PATCH 08/18] wip: confused with these repr tests breaking in py2
    
    ---
     twisted/python/test/test_zippath.py | 2 +-
     twisted/python/zippath.py           | 6 +++---
     2 files changed, 4 insertions(+), 4 deletions(-)
    
    diff --git a/twisted/python/test/test_zippath.py b/twisted/python/test/test_zippath.py
    index 6134237..c79325b 100644
    a b class ZipFilePathTestCase(AbstractFilePathTestCase): 
    8484        """
    8585        child = self.path.child("'")
    8686        path = self.cmn + (".zip" + os.sep.join(["", "'"])).encode("utf-8")
    87         pathRepr = "ZipPath('%s')" % (path,)
     87        pathRepr = "ZipPath(%s)" % (path,)
    8888        self.assertEqual(repr(child), pathRepr)
    8989
    9090
  • twisted/python/zippath.py

    diff --git a/twisted/python/zippath.py b/twisted/python/zippath.py
    index 4ac984a..16166c7 100644
    a b class ZipPath(AbstractFilePath): 
    7070    def __repr__(self):
    7171        parts = [os.path.abspath(self.archive.path)]
    7272        parts.extend(self.pathInArchive.encode().split(ZIP_PATH_SEP))
    73         path = os.sep.join(parts)
    74         return "ZipPath('%s')" % (path,)
     73        path = os.sep.encode().join(parts)
     74        return "ZipPath(%s)" % (path,)
    7575
    7676
    7777    def parent(self):
    78         splitup = self.pathInArchive.encode.split(ZIP_PATH_SEP)
     78        splitup = self.pathInArchive.encode().split(ZIP_PATH_SEP)
    7979        if len(splitup) == 1:
    8080            return self.archive
    8181        return ZipPath(self.archive, ZIP_PATH_SEP.join(splitup[:-1]))
  • twisted/python/test/test_zippath.py

    -- 
    1.7.12.4 (Apple Git-37)
    
    
    From f728abf2d4e0ce3e2653d26f35eac26c17fedd12 Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Thu, 17 Apr 2014 16:40:12 -0400
    Subject: [PATCH 09/18] fix escaping test between py2 and 3
    
    ---
     twisted/python/test/test_zippath.py | 6 +++++-
     twisted/python/zippath.py           | 2 +-
     2 files changed, 6 insertions(+), 2 deletions(-)
    
    diff --git a/twisted/python/test/test_zippath.py b/twisted/python/test/test_zippath.py
    index c79325b..b61beff 100644
    a b import os, zipfile 
    99
    1010from twisted.test.test_paths import AbstractFilePathTestCase
    1111from twisted.python.zippath import ZipArchive
     12import twisted.python.compat as compat
    1213
    1314import sys
    1415
    class ZipFilePathTestCase(AbstractFilePathTestCase): 
    8485        """
    8586        child = self.path.child("'")
    8687        path = self.cmn + (".zip" + os.sep.join(["", "'"])).encode("utf-8")
    87         pathRepr = "ZipPath(%s)" % (path,)
     88        if compat._PY3:
     89            pathRepr = "ZipPath(%s)" % (path,)
     90        else:
     91            pathRepr = "ZipPath(%r)" % (path,)
    8892        self.assertEqual(repr(child), pathRepr)
    8993
    9094
  • twisted/python/zippath.py

    diff --git a/twisted/python/zippath.py b/twisted/python/zippath.py
    index 16166c7..edbb63f 100644
    a b class ZipPath(AbstractFilePath): 
    7171        parts = [os.path.abspath(self.archive.path)]
    7272        parts.extend(self.pathInArchive.encode().split(ZIP_PATH_SEP))
    7373        path = os.sep.encode().join(parts)
    74         return "ZipPath(%s)" % (path,)
     74        return "ZipPath(%r)" % (path,)
    7575
    7676
    7777    def parent(self):
  • twisted/python/test/test_zippath.py

    -- 
    1.7.12.4 (Apple Git-37)
    
    
    From e9e0dd727f59c76ffb4a0d3fb84ddaf9a968e354 Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Thu, 17 Apr 2014 17:08:07 -0400
    Subject: [PATCH 10/18] fix error adding bytes to strings, fix ZipArchive to
     allow taking bytes, since ZipFile breaks if you pass
     it bytes
    
    ---
     twisted/python/test/test_zippath.py | 4 +++-
     twisted/python/zippath.py           | 7 +++++++
     2 files changed, 10 insertions(+), 1 deletion(-)
    
    diff --git a/twisted/python/test/test_zippath.py b/twisted/python/test/test_zippath.py
    index b61beff..8c71a8d 100644
    a b class ZipFilePathTestCase(AbstractFilePathTestCase): 
    5757        self.assertEqual(repr(child), pathRepr)
    5858
    5959        # Create a path to the file rooted in the current working directory
    60         relativeCommon = self.cmn.replace(os.getcwd() + os.sep, "", 1) + ".zip"
     60        relativeCommon = self.cmn.replace(
     61            os.getcwd().encode(encoding) + os.sep.encode(encoding), b"", 1)
     62        relativeCommon += b".zip"
    6163        relpath = ZipArchive(relativeCommon)
    6264        child = relpath.child("foo")
    6365
  • twisted/python/zippath.py

    diff --git a/twisted/python/zippath.py b/twisted/python/zippath.py
    index edbb63f..c8ddd39 100644
    a b from zope.interface import implementer 
    3636ZIP_PATH_SEP = b'/'             # In zipfiles, "/" is universally used as the
    3737                                # path separator, regardless of platform.
    3838
     39ENCODING = sys.getfilesystemencoding()
     40
    3941
    4042@implementer(IFilePath)
    4143class ZipPath(AbstractFilePath):
    class ZipArchive(ZipPath): 
    204206
    205207        @param archivePathname: a str, naming a path in the filesystem.
    206208        """
     209
     210        # convert to string because python3 ZipFile doesn't take bytes
     211        if isinstance(archivePathname, bytes):
     212            archivePathname = archivePathname.decode(ENCODING)
     213
    207214        if _USE_ZIPFILE:
    208215            self.zipfile = ZipFile(archivePathname)
    209216        else:
  • twisted/python/zippath.py

    -- 
    1.7.12.4 (Apple Git-37)
    
    
    From 43f072be68e7ef99cbd10ceca540873337592849 Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Thu, 17 Apr 2014 17:32:55 -0400
    Subject: [PATCH 11/18] keep archive path internally as bytes, fix parentdir
     test
    
    ---
     twisted/python/zippath.py | 18 +++++++++++++-----
     1 file changed, 13 insertions(+), 5 deletions(-)
    
    diff --git a/twisted/python/zippath.py b/twisted/python/zippath.py
    index c8ddd39..5ed0905 100644
    a b class ZipPath(AbstractFilePath): 
    5656        @param pathInArchive: a ZIP_PATH_SEP-separated string.
    5757        """
    5858        self.archive = archive
    59         self.pathInArchive = pathInArchive
     59
     60        # keep pathInArchive as bytes
     61        if isinstance(pathInArchive, bytes):
     62            self.pathInArchive = pathInArchive
     63        else:
     64            self.pathInArchive = pathInArchive.encode(ENCODING)
     65
    6066        # self.path pretends to be os-specific because that's the way the
    6167        # 'zipimport' module does it.
    6268        self.path = os.path.join(archive.zipfile.filename.encode(),
    63                                  *(self.pathInArchive.encode().split(ZIP_PATH_SEP)))
     69                                 *(self.pathInArchive.split(ZIP_PATH_SEP)))
    6470
    6571    def __cmp__(self, other):
    6672        if not isinstance(other, ZipPath):
    class ZipPath(AbstractFilePath): 
    7177
    7278    def __repr__(self):
    7379        parts = [os.path.abspath(self.archive.path)]
    74         parts.extend(self.pathInArchive.encode().split(ZIP_PATH_SEP))
     80        parts.extend(self.pathInArchive.split(ZIP_PATH_SEP))
    7581        path = os.sep.encode().join(parts)
    7682        return "ZipPath(%r)" % (path,)
    7783
    7884
    7985    def parent(self):
    80         splitup = self.pathInArchive.encode().split(ZIP_PATH_SEP)
     86        splitup = self.pathInArchive.split(ZIP_PATH_SEP)
    8187        if len(splitup) == 1:
    8288            return self.archive
    8389        return ZipPath(self.archive, ZIP_PATH_SEP.join(splitup[:-1]))
    class ZipPath(AbstractFilePath): 
    95101            it) as this means it may include special names with special
    96102            meaning outside of the context of a zip archive.
    97103        """
    98         return ZipPath(self.archive, ZIP_PATH_SEP.join([self.pathInArchive, path]))
     104        encodedPath = path.encode(ENCODING)
     105        return ZipPath(self.archive,
     106                       ZIP_PATH_SEP.join([self.pathInArchive, encodedPath]))
    99107
    100108
    101109    def sibling(self, path):
  • twisted/python/test/test_zippath.py

    -- 
    1.7.12.4 (Apple Git-37)
    
    
    From 3aba52936bdd98f0010f4f180d1db51466e8b075 Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Thu, 17 Apr 2014 17:35:55 -0400
    Subject: [PATCH 12/18] fix bytes mixing issue
    
    ---
     twisted/python/test/test_zippath.py | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/twisted/python/test/test_zippath.py b/twisted/python/test/test_zippath.py
    index 8c71a8d..e1e4a50 100644
    a b class ZipFilePathTestCase(AbstractFilePathTestCase): 
    105105        self.assertEqual(repr(self.path), pathRepr)
    106106
    107107        # Create a path to the file rooted in the current working directory
    108         relativeCommon = self.cmn.replace(os.getcwd() + os.sep, "", 1) + ".zip"
     108        relativeCommon = self.cmn.replace(os.getcwd().encode(encoding) + os.sep.encode(encoding), b"", 1) + b".zip"
    109109        relpath = ZipArchive(relativeCommon)
    110110
    111111        # Check using a path without the cwd prepended
  • twisted/python/zippath.py

    -- 
    1.7.12.4 (Apple Git-37)
    
    
    From 8db91d6fffe764bf955f8b565b884ee65e3faea8 Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Thu, 17 Apr 2014 23:05:59 -0400
    Subject: [PATCH 13/18] fix double encoding error.  broken equality check now
     :(
    
    ---
     twisted/python/zippath.py | 6 +++++-
     1 file changed, 5 insertions(+), 1 deletion(-)
    
    diff --git a/twisted/python/zippath.py b/twisted/python/zippath.py
    index 5ed0905..0b0ac82 100644
    a b class ZipPath(AbstractFilePath): 
    101101            it) as this means it may include special names with special
    102102            meaning outside of the context of a zip archive.
    103103        """
    104         encodedPath = path.encode(ENCODING)
     104        try:
     105            encodedPath = path.encode(ENCODING)
     106        except AttributeError:
     107            encodedPath = path
     108
    105109        return ZipPath(self.archive,
    106110                       ZIP_PATH_SEP.join([self.pathInArchive, encodedPath]))
    107111
  • twisted/python/zippath.py

    -- 
    1.7.12.4 (Apple Git-37)
    
    
    From 44fe46156b9a33e25e39f639bfb46553567e0b0d Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Sat, 26 Apr 2014 13:37:14 -0500
    Subject: [PATCH 14/18] fix error with getting file info from archive. was
     hashed against 'str', not 'bytes'
    
    ---
     twisted/python/zippath.py | 6 ++++--
     1 file changed, 4 insertions(+), 2 deletions(-)
    
    diff --git a/twisted/python/zippath.py b/twisted/python/zippath.py
    index 0b0ac82..89e6196 100644
    a b class ZipPath(AbstractFilePath): 
    173173        @return: file size, in bytes
    174174        """
    175175
    176         return self.archive.zipfile.NameToInfo[self.pathInArchive].file_size
     176        pathInArchive = self.pathInArchive.decode("utf-8")
     177        return self.archive.zipfile.NameToInfo[pathInArchive].file_size
    177178
    178179    def getAccessTime(self):
    179180        """
    class ZipPath(AbstractFilePath): 
    192193
    193194        @return: a number of seconds since the epoch.
    194195        """
     196        pathInArchive = self.pathInArchive.decode("utf-8")
    195197        return time.mktime(
    196             self.archive.zipfile.NameToInfo[self.pathInArchive].date_time
     198            self.archive.zipfile.NameToInfo[pathInArchive].date_time
    197199            + (0, 0, 0))
    198200
    199201
  • twisted/python/zippath.py

    -- 
    1.7.12.4 (Apple Git-37)
    
    
    From 34b213f514a5a351bed098f73b3cc1ea4690cbd6 Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Sat, 26 Apr 2014 13:43:17 -0500
    Subject: [PATCH 15/18] fix 'validFiles' test, python3 zipfile doesn't look at
     bytestrings. fixed encoding consistency
    
    ---
     twisted/python/zippath.py | 14 +++++++-------
     1 file changed, 7 insertions(+), 7 deletions(-)
    
    diff --git a/twisted/python/zippath.py b/twisted/python/zippath.py
    index 89e6196..96b4213 100644
    a b class ZipPath(AbstractFilePath): 
    122122        return self.pathInArchive in self.archive.childmap
    123123
    124124    def isfile(self):
    125         return self.pathInArchive in self.archive.zipfile.NameToInfo
     125        return self.pathInArchive.decode(ENCODING) in self.archive.zipfile.NameToInfo
    126126
    127127    def islink(self):
    128128        return False
    class ZipPath(AbstractFilePath): 
    130130    def listdir(self):
    131131        if self.exists():
    132132            if self.isdir():
    133                 return self.archive.childmap[self.pathInArchive].keys()
     133                return self.archive.childmap[self.pathInArchive.decode(ENCODING)].keys()
    134134            else:
    135135                raise OSError(errno.ENOTDIR, "Leaf zip entry listed")
    136136        else:
    class ZipPath(AbstractFilePath): 
    157157
    158158    def open(self, mode="r"):
    159159        if _USE_ZIPFILE:
    160             return self.archive.zipfile.open(self.pathInArchive, mode=mode)
     160            return self.archive.zipfile.open(self.pathInArchive.decode(ENCODING), mode=mode)
    161161        else:
    162162            # XXX oh man, is this too much hax?
    163163            self.archive.zipfile.mode = mode
    164             return self.archive.zipfile.readfile(self.pathInArchive)
     164            return self.archive.zipfile.readfile(self.pathInArchive.decode(ENCODING))
    165165
    166166    def changed(self):
    167167        pass
    class ZipPath(AbstractFilePath): 
    173173        @return: file size, in bytes
    174174        """
    175175
    176         pathInArchive = self.pathInArchive.decode("utf-8")
     176        pathInArchive = self.pathInArchive.decode(ENCODING)
    177177        return self.archive.zipfile.NameToInfo[pathInArchive].file_size
    178178
    179179    def getAccessTime(self):
    class ZipPath(AbstractFilePath): 
    193193
    194194        @return: a number of seconds since the epoch.
    195195        """
    196         pathInArchive = self.pathInArchive.decode("utf-8")
     196        pathInArchive = self.pathInArchive.decode(ENCODING)
    197197        return time.mktime(
    198198            self.archive.zipfile.NameToInfo[pathInArchive].date_time
    199199            + (0, 0, 0))
    class ZipArchive(ZipPath): 
    230230        else:
    231231            self.zipfile = ChunkingZipFile(archivePathname)
    232232        try:
    233             self.path = archivePathname.encode("utf-8")
     233            self.path = archivePathname.encode(ENCODING)
    234234        except AttributeError:
    235235            self.path = archivePathname
    236236
  • twisted/python/zippath.py

    -- 
    1.7.12.4 (Apple Git-37)
    
    
    From b0837cc9166ce796fba26d367d8e74c968b83467 Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Sun, 27 Apr 2014 01:18:58 -0500
    Subject: [PATCH 16/18] fix last tests -- keep internal modeling with bytes,
     otherwise switch to str with stdlib zipfile
    
    ---
     twisted/python/zippath.py | 9 +++++++--
     1 file changed, 7 insertions(+), 2 deletions(-)
    
    diff --git a/twisted/python/zippath.py b/twisted/python/zippath.py
    index 96b4213..c7c72ca 100644
    a b class ZipPath(AbstractFilePath): 
    122122        return self.pathInArchive in self.archive.childmap
    123123
    124124    def isfile(self):
    125         return self.pathInArchive.decode(ENCODING) in self.archive.zipfile.NameToInfo
     125        return self.pathInArchive in self.archive.zipfile.NameToInfo
    126126
    127127    def islink(self):
    128128        return False
    class ZipPath(AbstractFilePath): 
    130130    def listdir(self):
    131131        if self.exists():
    132132            if self.isdir():
    133                 return self.archive.childmap[self.pathInArchive.decode(ENCODING)].keys()
     133                # py3 changes the return type of dict().keys(),
     134                # so a manual conversion is needed to reflect FilePath.listdir()
     135                return list(self.archive.childmap[self.pathInArchive])
    134136            else:
    135137                raise OSError(errno.ENOTDIR, "Leaf zip entry listed")
    136138        else:
    class ZipArchive(ZipPath): 
    244246            for x in range(len(name)):
    245247                child = name[-x]
    246248                parent = ZIP_PATH_SEP.decode().join(name[:-x])
     249                # convert back to bytes to reflect correct file path api
     250                parent = parent.encode(ENCODING)
     251                child = child.encode(ENCODING)
    247252                if parent not in self.childmap:
    248253                    self.childmap[parent] = {}
    249254                self.childmap[parent][child] = 1
  • twisted/python/test/test_zippath.py

    -- 
    1.7.12.4 (Apple Git-37)
    
    
    From af5627d270db249cc99dd1d55c5344eefc2bd897 Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Sun, 27 Apr 2014 10:45:34 -0500
    Subject: [PATCH 17/18] fix twistedchecker errors
    
    ---
     twisted/python/test/test_zippath.py |  7 ++++++-
     twisted/python/zippath.py           | 22 +++++++++++++---------
     2 files changed, 19 insertions(+), 10 deletions(-)
    
    diff --git a/twisted/python/test/test_zippath.py b/twisted/python/test/test_zippath.py
    index e1e4a50..f531629 100644
    a b class ZipFilePathTestCase(AbstractFilePathTestCase): 
    105105        self.assertEqual(repr(self.path), pathRepr)
    106106
    107107        # Create a path to the file rooted in the current working directory
    108         relativeCommon = self.cmn.replace(os.getcwd().encode(encoding) + os.sep.encode(encoding), b"", 1) + b".zip"
     108        relativeCommon = self.cmn.replace(
     109            os.getcwd().encode(encoding) + os.sep.encode(encoding),
     110            b"",
     111            1
     112        )
     113        relativeCommon = relativeCommon + b".zip"
    109114        relpath = ZipArchive(relativeCommon)
    110115
    111116        # Check using a path without the cwd prepended
  • twisted/python/zippath.py

    diff --git a/twisted/python/zippath.py b/twisted/python/zippath.py
    index c7c72ca..41f7b4b 100644
    a b from twisted.python.filepath import IFilePath, FilePath, AbstractFilePath 
    3030
    3131from zope.interface import implementer
    3232
    33 # using FilePath here exclusively rather than os to make sure that we don't do
     33# Using FilePath here exclusively rather than os to make sure that we don't do
    3434# anything OS-path-specific here.
    3535
    3636ZIP_PATH_SEP = b'/'             # In zipfiles, "/" is universally used as the
    class ZipPath(AbstractFilePath): 
    5757        """
    5858        self.archive = archive
    5959
    60         # keep pathInArchive as bytes
     60        # Keep pathInArchive as bytes
    6161        if isinstance(pathInArchive, bytes):
    6262            self.pathInArchive = pathInArchive
    6363        else:
    class ZipPath(AbstractFilePath): 
    130130    def listdir(self):
    131131        if self.exists():
    132132            if self.isdir():
    133                 # py3 changes the return type of dict().keys(),
    134                 # so a manual conversion is needed to reflect FilePath.listdir()
     133                # py3's dict().keys() is no longer a list
    135134                return list(self.archive.childmap[self.pathInArchive])
    136135            else:
    137136                raise OSError(errno.ENOTDIR, "Leaf zip entry listed")
    class ZipPath(AbstractFilePath): 
    152151    def basename(self):
    153152        return self.pathInArchive.split(ZIP_PATH_SEP)[-1]
    154153
     154
    155155    def dirname(self):
    156156        # XXX NOTE: This API isn't a very good idea on filepath, but it's even
    157157        # less meaningful here.
    158158        return self.parent().path
    159159
     160
    160161    def open(self, mode="r"):
    161162        if _USE_ZIPFILE:
    162             return self.archive.zipfile.open(self.pathInArchive.decode(ENCODING), mode=mode)
     163            return self.archive.zipfile.open(
     164                self.pathInArchive.decode(ENCODING), mode=mode)
    163165        else:
    164166            # XXX oh man, is this too much hax?
    165167            self.archive.zipfile.mode = mode
    166             return self.archive.zipfile.readfile(self.pathInArchive.decode(ENCODING))
     168            return self.archive.zipfile.readfile(
     169                self.pathInArchive.decode(ENCODING))
    167170
    168171    def changed(self):
    169172        pass
    class ZipPath(AbstractFilePath): 
    213216
    214217
    215218class ZipArchive(ZipPath):
    216     """ I am a FilePath-like object which can wrap a zip archive as if it were a
    217     directory.
     219    """ I am a FilePath-like object which can wrap a zip archive as if it were
     220    a directory.
    218221    """
    219222    archive = property(lambda self: self)
    220223    def __init__(self, archivePathname):
    221         """Create a ZipArchive, treating the archive at archivePathname as a zip file.
     224        """Create a ZipArchive, treating the archive at archivePathname as a
     225        zip file.
    222226
    223227        @param archivePathname: a str, naming a path in the filesystem.
    224228        """
  • twisted/python/zippath.py

    -- 
    1.7.12.4 (Apple Git-37)
    
    
    From 38bce6d96f442132563db883f7ba20e5a8929db9 Mon Sep 17 00:00:00 2001
    From: Conrad Dean <conrad.p.dean@gmail.com>
    Date: Sun, 27 Apr 2014 23:48:11 -0500
    Subject: [PATCH 18/18] removing commits about __eq__, using original __cmp__
     with class decorator
    
    ---
     twisted/python/zippath.py | 2 ++
     1 file changed, 2 insertions(+)
    
    diff --git a/twisted/python/zippath.py b/twisted/python/zippath.py
    index 41f7b4b..940a00b 100644
    a b else: 
    2929from twisted.python.filepath import IFilePath, FilePath, AbstractFilePath
    3030
    3131from zope.interface import implementer
     32from twisted.python.compat import comparable, cmp
    3233
    3334# Using FilePath here exclusively rather than os to make sure that we don't do
    3435# anything OS-path-specific here.
    ZIP_PATH_SEP = b'/' # In zipfiles, "/" is universally used as the 
    3940ENCODING = sys.getfilesystemencoding()
    4041
    4142
     43@comparable
    4244@implementer(IFilePath)
    4345class ZipPath(AbstractFilePath):
    4446    """