[PATCH 02 of 13] Py2/Py3 compatibility layer

Alejandro Santos alejolp at alejolp.com
Wed Aug 5 15:55:36 CDT 2009


# HG changeset patch
# User Alejandro Santos <alejolp at alejolp.com>
# Date 1249486789 10800
# Node ID 0980e0b497e4f788d31504f78583db3835b6c047
# Parent  ef9c62cd2ad6ef208e7110202b42fecee28f18c7
Py2/Py3 compatibility layer

diff -r ef9c62cd2ad6 -r 0980e0b497e4 mercurial/py2compat.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial/py2compat.py	Wed Aug 05 12:39:49 2009 -0300
@@ -0,0 +1,14 @@
+"""
+py2compat.py - Mercurial wrapper functions for Python compatibility
+
+ Copyright 2009 Alejandro Santos <alejolp at alejolp.com>
+
+This software may be used and distributed according to the terms
+of the GNU General Public License, incorporated herein by reference.
+
+This file contains helper functions for Python 2 (see py3compat.py)
+"""
+
+import __builtin__
+
+buffer = __builtin__.buffer
diff -r ef9c62cd2ad6 -r 0980e0b497e4 mercurial/py3compat.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial/py3compat.py	Wed Aug 05 12:39:49 2009 -0300
@@ -0,0 +1,13 @@
+"""
+py3compat.py - Mercurial wrapper functions for Python compatibility
+
+ Copyright 2009 Alejandro Santos <alejolp at alejolp.com>
+
+This software may be used and distributed according to the terms
+of the GNU General Public License, incorporated herein by reference.
+
+This file contains helper functions for Python 3 (see py2compat.py)
+"""
+
+def buffer(data, offset=None, size=None):
+    return memoryview(data)[offset:size and offset + size]
diff -r ef9c62cd2ad6 -r 0980e0b497e4 mercurial/util.py
--- a/mercurial/util.py	Wed Aug 05 12:39:49 2009 -0300
+++ b/mercurial/util.py	Wed Aug 05 12:39:49 2009 -0300
@@ -21,6 +21,11 @@
 
 # Python compatibility
 
+if sys.version_info[0] >= 3:
+    from py3compat import *
+else:
+    from py2compat import *
+
 def sha1(s):
     return _fastsha1(s)
 


More information about the Mercurial-devel mailing list