Mercurial > hg-stable
changeset 31391:c9fd842dc886
pycompat: add helper to iterate each char in bytes
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 12 Mar 2017 17:04:45 -0700 |
parents | 7359157b9e46 |
children | 7556fe09cc48 |
files | mercurial/pycompat.py |
diffstat | 1 files changed, 5 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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