changeset 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 9bbfeba33aa3
children 4d11fde55cc5
files mercurial/util.py
diffstat 1 files changed, 3 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Wed Jul 14 22:58:29 2010 -0300
+++ b/mercurial/util.py	Wed Jul 14 22:59:43 2010 -0300
@@ -40,7 +40,9 @@
 
 def fakebuffer(sliceable, offset=0):
     return sliceable[offset:]
-if not hasattr(__builtin__, 'buffer'):
+try:
+    buffer
+except NameError:
     __builtin__.buffer = fakebuffer
 
 import subprocess