pycompat: add helper to iterate each char in bytes
authorYuya Nishihara <yuya@tcha.org>
Sun, 12 Mar 2017 17:04:45 -0700
changeset 31382 c9fd842dc886
parent 31381 7359157b9e46
child 31383 7556fe09cc48
pycompat: add helper to iterate each char in bytes
mercurial/pycompat.py
--- a/mercurial/pycompat.py	Sun Mar 12 19:47:51 2017 -0400
+++ b/mercurial/pycompat.py	Sun Mar 12 17:04:45 2017 -0700
@@ -76,6 +76,10 @@
     def bytechr(i):
         return bytes([i])
 
+    def iterbytestr(s):
+        """Iterate bytes as if it were a str object of Python 2"""
+        return iter(s[i:i + 1] for i in range(len(s)))
+
     def sysstr(s):
         """Return a keyword str to be passed to Python functions such as
         getattr() and str.encode()
@@ -142,6 +146,7 @@
     import cStringIO
 
     bytechr = chr
+    iterbytestr = iter
 
     def sysstr(s):
         return s