# HG changeset patch # User Yuya Nishihara # Date 2017-03-13 00:04:45 # Node ID c9fd842dc8864ea48b4b2519878e6a7f7d40c90d # 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