[PATCH 4 of 9] util.py: use fakebuffer as buffer in py3k

Renato Cunha renatoc at gmail.com
Wed Jul 14 21:18:37 CDT 2010


# HG changeset patch
# User Renato Cunha <renatoc at gmail.com>
# Date 1279159197 10800
# Branch stable
# Node ID 12c5cab6b8b8594f6b3df9833bee0b4fc59e49ee
# Parent  f1975eb501930bb8f3cb56ceac2eb7137d9a8c57
util.py: 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.

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -38,8 +38,12 @@
 
 import __builtin__
 
-def fakebuffer(sliceable, offset=0):
-    return sliceable[offset:]
+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
 except NameError:


More information about the Mercurial-devel mailing list