# HG changeset patch
# User Yuya Nishihara <y...@tcha.org>
# Date 1489363485 25200
#      Sun Mar 12 17:04:45 2017 -0700
# Node ID 75c128696f8dbc4aaa56f0e2200ebd7f560a36d5
# Parent  7359157b9e46908645cc9cef62a5cf46224dba71
pycompat: add helper to iterate each char in bytes

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -76,6 +76,10 @@ if ispy3:
     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 @@ else:
     import cStringIO
 
     bytechr = chr
+    iterbytestr = iter
 
     def sysstr(s):
         return s
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to