Mercurial > hg
comparison mercurial/util.py @ 11566:4d11fde55cc5
util: use fakebuffer as buffer in py3k
There's no buffer type in py3k, util.py has a function, called
fakebuffer, that implements a similar API. This patch implements
fakebuffer as a memoryview wrapper in py3k.
author | Renato Cunha <renatoc@gmail.com> |
---|---|
date | Wed, 14 Jul 2010 22:59:57 -0300 |
parents | 7546d4a272c8 |
children | def08249d4db |
comparison
equal
deleted
inserted
replaced
11565:7546d4a272c8 | 11566:4d11fde55cc5 |
---|---|
36 _fastsha1 = sha1 = _sha1 | 36 _fastsha1 = sha1 = _sha1 |
37 return _sha1(s) | 37 return _sha1(s) |
38 | 38 |
39 import __builtin__ | 39 import __builtin__ |
40 | 40 |
41 def fakebuffer(sliceable, offset=0): | 41 if sys.version_info[0] < 3: |
42 return sliceable[offset:] | 42 def fakebuffer(sliceable, offset=0): |
43 return sliceable[offset:] | |
44 else: | |
45 def fakebuffer(sliceable, offset=0): | |
46 return memoryview(sliceable)[offset:] | |
43 try: | 47 try: |
44 buffer | 48 buffer |
45 except NameError: | 49 except NameError: |
46 __builtin__.buffer = fakebuffer | 50 __builtin__.buffer = fakebuffer |
47 | 51 |