From patchwork Mon Apr 11 22:49:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [7, of, 7] store: treat range as a generator instead of a list for py3 compat From: timeless@mozdev.org X-Patchwork-Id: 14536 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Mon, 11 Apr 2016 17:49:01 -0500 # HG changeset patch # User timeless # Date 1460273306 0 # Sun Apr 10 07:28:26 2016 +0000 # Node ID cb9b085c8911b9896f3567593a7cb2e2b1e26852 # Parent eefe59718f11944738153111debc79f8b926a80a store: treat range as a generator instead of a list for py3 compat diff --git a/mercurial/store.py b/mercurial/store.py --- a/mercurial/store.py +++ b/mercurial/store.py @@ -57,6 +57,15 @@ .replace(".i.hg/", ".i/") .replace(".hg.hg/", ".hg/")) +def _reserved(): + winreserved = [ord(x) for x in '\\:*?"<>|'] + for x in range(32): + yield x + for x in range(126, 256): + yield x + for x in winreserved: + yield x + def _buildencodefun(): ''' >>> enc, dec = _buildencodefun() @@ -82,11 +91,10 @@ 'the\\x07quick\\xadshot' ''' e = '_' - winreserved = [ord(x) for x in '\\:*?"<>|'] cmap = dict([(chr(x), chr(x)) for x in xrange(127)]) - for x in (range(32) + range(126, 256) + winreserved): + for x in _reserved(): cmap[chr(x)] = "~%02x" % x - for x in range(ord("A"), ord("Z") + 1) + [ord(e)]: + for x in list(range(ord("A"), ord("Z") + 1)) + [ord(e)]: cmap[chr(x)] = e + chr(x).lower() dmap = {} for k, v in cmap.items(): @@ -134,9 +142,8 @@ >>> f('the\x07quick\xADshot') 'the~07quick~adshot' ''' - winreserved = [ord(x) for x in '\\:*?"<>|'] cmap = dict([(chr(x), chr(x)) for x in xrange(127)]) - for x in (range(32) + range(126, 256) + winreserved): + for x in _reserved(): cmap[chr(x)] = "~%02x" % x for x in range(ord("A"), ord("Z") + 1): cmap[chr(x)] = chr(x).lower() diff --git a/tests/test-check-py3-compat.t b/tests/test-check-py3-compat.t --- a/tests/test-check-py3-compat.t +++ b/tests/test-check-py3-compat.t @@ -177,8 +177,6 @@ mercurial/sshpeer.py: error importing: invalid syntax (bundle*.py, line *) (error at wireproto.py:*) (glob) mercurial/sshserver.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) (glob) mercurial/statichttprepo.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) (glob) - mercurial/store.py: error importing module: unsupported operand type(s) for +: 'range' and 'range' (line *) (glob) - mercurial/streamclone.py: error importing: unsupported operand type(s) for +: 'range' and 'range' (error at store.py:*) (glob) mercurial/subrepo.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) (glob) mercurial/templatefilters.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) (glob) mercurial/templatekw.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) (glob)