Mercurial > public > mercurial-scm > python-hglib
comparison hglib/util.py @ 152:0808bb03add5
util: don't try to use itertools.izip under Python 3 (issue4520)
In Python 3, itertools.izip became builtins.zip.
author | Brett Cannon <brett@python.org> |
---|---|
date | Fri, 20 Mar 2015 16:32:53 -0400 |
parents | b94e1263836c |
children | ef8eb78fc88d |
comparison
equal
deleted
inserted
replaced
151:b91356bf7186 | 152:0808bb03add5 |
---|---|
1 import itertools, os, subprocess, sys | 1 import os, subprocess, sys |
2 from hglib import error | 2 from hglib import error |
3 try: | 3 try: |
4 from io import BytesIO | 4 from io import BytesIO |
5 except ImportError: | 5 except ImportError: |
6 from cStringIO import StringIO as BytesIO | 6 from cStringIO import StringIO as BytesIO |
7 | 7 |
8 if sys.version_info[0] > 2: | 8 if sys.version_info[0] > 2: |
9 izip = zip | |
10 | |
9 def b(s): | 11 def b(s): |
10 """Encode the string as bytes.""" | 12 """Encode the string as bytes.""" |
11 return s.encode('latin-1') | 13 return s.encode('latin-1') |
12 else: | 14 else: |
15 from itertools import izip | |
16 | |
13 def b(s): | 17 def b(s): |
14 """Encode the string as bytes.""" | 18 """Encode the string as bytes.""" |
15 return s | 19 return s |
16 | 20 |
17 def strtobytes(s): | 21 def strtobytes(s): |
19 return str(s).encode('latin-1') | 23 return str(s).encode('latin-1') |
20 | 24 |
21 def grouper(n, iterable): | 25 def grouper(n, iterable): |
22 ''' list(grouper(2, range(4))) -> [(0, 1), (2, 3)] ''' | 26 ''' list(grouper(2, range(4))) -> [(0, 1), (2, 3)] ''' |
23 args = [iter(iterable)] * n | 27 args = [iter(iterable)] * n |
24 return itertools.izip(*args) | 28 return izip(*args) |
25 | 29 |
26 def eatlines(s, n): | 30 def eatlines(s, n): |
27 """ | 31 """ |
28 >>> eatlines("1\\n2", 1) | 32 >>> eatlines("1\\n2", 1) |
29 '2' | 33 '2' |