Patchwork [4,of,7] pycompat: add iteritems itervalues

login
register
mail settings
Submitter timeless@mozdev.org
Date April 11, 2016, 10:48 p.m.
Message ID <dec8f62743049c2a93e9.1460414938@waste.org>
Download mbox | patch
Permalink /patch/14533/
State Rejected
Headers show

Comments

timeless@mozdev.org - April 11, 2016, 10:48 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1460134304 0
#      Fri Apr 08 16:51:44 2016 +0000
# Node ID dec8f62743049c2a93e92f44f13d7f9740cb1ea6
# Parent  112ca3e0b4f25cf0d3503b93e94e8dba887923c9
pycompat: add iteritems itervalues

Patch

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -11,6 +11,20 @@ 
 from __future__ import absolute_import
 
 try:
+    dict.iteritems
+    # Python 2
+    def iteritems(d):
+        return d.iteritems()
+    def itervalues(d):
+        return d.itervalues()
+except AttributeError:
+    # Python 3
+    def iteritems(d):
+        return iter(d.items())
+    def itervalues(d):
+        return iter(d.values())
+
+try:
     import cStringIO as io
     stringio = io.StringIO
 except ImportError:
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -47,6 +47,8 @@ 
 
 for attr in (
     'empty',
+    'iteritems',
+    'itervalues',
     'queue',
     'urlerr',
     # we do import urlreq, but we do it outside the loop