Mercurial > python-hglib
comparison hglib/util.py @ 141:ea80bd2775f6
hglib: introduce util.b() (issue4520)
The util.b() function will be used to mark all string literals in the
code base which should be treated as bytes instead of text. This is to
help with supporting Python 3.
author | Brett Cannon <brett@python.org> |
---|---|
date | Sat, 07 Mar 2015 10:08:52 -0500 |
parents | 1b47146a4a2c |
children | fe74d5599539 |
comparison
equal
deleted
inserted
replaced
140:9c4f52467208 | 141:ea80bd2775f6 |
---|---|
1 import itertools, cStringIO, error, os, subprocess | 1 import itertools, cStringIO, error, os, subprocess, sys |
2 | |
3 if sys.version_info[0] > 2: | |
4 def b(s): | |
5 """Encode the string as bytes.""" | |
6 return s.encode('latin-1') | |
7 else: | |
8 def b(s): | |
9 """Encode the string as bytes.""" | |
10 return s | |
2 | 11 |
3 def grouper(n, iterable): | 12 def grouper(n, iterable): |
4 ''' list(grouper(2, range(4))) -> [(0, 1), (2, 3)] ''' | 13 ''' list(grouper(2, range(4))) -> [(0, 1), (2, 3)] ''' |
5 args = [iter(iterable)] * n | 14 args = [iter(iterable)] * n |
6 return itertools.izip(*args) | 15 return itertools.izip(*args) |