[PATCH 4 of 5] util.py: Use fakebuffer as buffer in py3k

Renato Cunha renatoc at gmail.com
Fri Jul 2 23:26:56 CDT 2010


# HG changeset patch
# User Renato Cunha <renatoc at gmail.com>
# Date 1278105364 10800
# Node ID 221894022b4274527770c6fad841fc07deb43b54
# Parent  6c82a0c29e179f7e05e2b9541b50326dcc1c9550
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