comparison mercurial/util.py @ 11565:7546d4a272c8

util: improved the check for the existence of the 'buffer' builtin 2to3 is unable to translate '__builtin__' calls to 'builtins' when hasattr is used (as in hasattr(__builtin__, buffer)). Translating the check to the format try: whatever except NameError # define whatever __builtin__.whatever = whatever is a correct way of checking for the name and has the benefit of being translated by 2to3. This patch implements the same idea for the aforementioned example.
author Renato Cunha <renatoc@gmail.com>
date Wed, 14 Jul 2010 22:59:43 -0300
parents c37f35d7f2f5
children 4d11fde55cc5
comparison
equal deleted inserted replaced
11564:9bbfeba33aa3 11565:7546d4a272c8
38 38
39 import __builtin__ 39 import __builtin__
40 40
41 def fakebuffer(sliceable, offset=0): 41 def fakebuffer(sliceable, offset=0):
42 return sliceable[offset:] 42 return sliceable[offset:]
43 if not hasattr(__builtin__, 'buffer'): 43 try:
44 buffer
45 except NameError:
44 __builtin__.buffer = fakebuffer 46 __builtin__.buffer = fakebuffer
45 47
46 import subprocess 48 import subprocess
47 closefds = os.name == 'posix' 49 closefds = os.name == 'posix'
48 50