encoding: use range() instead of xrange()
authorGregory Szorc <gregory.szorc@gmail.com>
Fri, 11 Mar 2016 21:27:26 -0800
changeset 28508 3c6e94d0811c
parent 28507 9bcbd9412225
child 28509 9e3ecb6f4995
encoding: use range() instead of xrange() Python 3 doesn't have xrange(). Instead, range() on Python 3 is a generator, like xrange() is on Python 2. The benefits of xrange() over range() are when there are very large ranges that are too expensive to pre-allocate. The code here is only creating <128 values, so the benefits of xrange() should be negligible. With this patch, encoding.py imports safely on Python 3.
mercurial/encoding.py
--- a/mercurial/encoding.py	Fri Mar 11 21:23:34 2016 -0800
+++ b/mercurial/encoding.py	Fri Mar 11 21:27:26 2016 -0800
@@ -387,8 +387,8 @@
     other = 0
 
 _jsonmap = []
-_jsonmap.extend("\\u%04x" % x for x in xrange(32))
-_jsonmap.extend(chr(x) for x in xrange(32, 127))
+_jsonmap.extend("\\u%04x" % x for x in range(32))
+_jsonmap.extend(chr(x) for x in range(32, 127))
 _jsonmap.append('\\u007f')
 _jsonmap[0x09] = '\\t'
 _jsonmap[0x0a] = '\\n'
@@ -400,7 +400,7 @@
 _paranoidjsonmap = _jsonmap[:]
 _paranoidjsonmap[0x3c] = '\\u003c'  # '<' (e.g. escape "</script>")
 _paranoidjsonmap[0x3e] = '\\u003e'  # '>'
-_jsonmap.extend(chr(x) for x in xrange(128, 256))
+_jsonmap.extend(chr(x) for x in range(128, 256))
 
 def jsonescape(s, paranoid=False):
     '''returns a string suitable for JSON