util: don't mess with builtins to emulate buffer()
authorMatt Mackall <mpm@selenic.com>
Thu, 15 Dec 2011 15:27:11 -0600
changeset 15657 d976b1ef6760
parent 15656 4f5a78fa4917
child 15659 7fba5a245acc
child 15675 34cb1fd2b3b9
util: don't mess with builtins to emulate buffer()
mercurial/manifest.py
mercurial/mdiff.py
mercurial/util.py
--- a/mercurial/manifest.py	Thu Dec 15 14:59:22 2011 -0600
+++ b/mercurial/manifest.py	Thu Dec 15 15:27:11 2011 -0600
@@ -6,7 +6,7 @@
 # GNU General Public License version 2 or any later version.
 
 from i18n import _
-import mdiff, parsers, error, revlog
+import mdiff, parsers, error, revlog, util
 import array, struct
 
 class manifestdict(dict):
@@ -164,7 +164,7 @@
             dline = [""]
             start = 0
             # zero copy representation of addlist as a buffer
-            addbuf = buffer(addlist)
+            addbuf = util.buffer(addlist)
 
             # start with a readonly loop that finds the offset of
             # each line and creates the deltas
@@ -196,7 +196,7 @@
             # apply the delta to the addlist, and get a delta for addrevision
             cachedelta = (self.rev(p1), addlistdelta(addlist, delta))
             arraytext = addlist
-            text = buffer(arraytext)
+            text = util.buffer(arraytext)
 
         n = self.addrevision(text, transaction, link, p1, p2, cachedelta)
         self._mancache = (n, map, arraytext)
--- a/mercurial/mdiff.py	Thu Dec 15 14:59:22 2011 -0600
+++ b/mercurial/mdiff.py	Thu Dec 15 15:27:11 2011 -0600
@@ -318,7 +318,7 @@
 def patch(a, bin):
     if len(a) == 0:
         # skip over trivial delta header
-        return buffer(bin, 12)
+        return util.buffer(bin, 12)
     return mpatch.patches(a, [bin])
 
 # similar to difflib.SequenceMatcher.get_matching_blocks
--- a/mercurial/util.py	Thu Dec 15 14:59:22 2011 -0600
+++ b/mercurial/util.py	Thu Dec 15 15:27:11 2011 -0600
@@ -104,18 +104,15 @@
     _fastsha1 = sha1 = _sha1
     return _sha1(s)
 
-import __builtin__
-
-if sys.version_info[0] < 3:
-    def fakebuffer(sliceable, offset=0):
-        return sliceable[offset:]
-else:
-    def fakebuffer(sliceable, offset=0):
-        return memoryview(sliceable)[offset:]
 try:
-    buffer
+    buffer = buffer
 except NameError:
-    __builtin__.buffer = fakebuffer
+    if sys.version_info[0] < 3:
+        def buffer(sliceable, offset=0):
+            return sliceable[offset:]
+    else:
+        def buffer(sliceable, offset=0):
+            return memoryview(sliceable)[offset:]
 
 import subprocess
 closefds = os.name == 'posix'