Rev 3735: Fix U32, LOWU32 disapearance in python-2.6. in file:///v/home/vila/src/bzr/experimental/bzr-py26-compat/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Sep 25 16:17:17 BST 2008


At file:///v/home/vila/src/bzr/experimental/bzr-py26-compat/

------------------------------------------------------------
revno: 3735
revision-id: v.ladeuil+lp at free.fr-20080925151715-69kcjx7p2vcuuc5w
parent: pqm at pqm.ubuntu.com-20080924081540-ecfvp6xq4x9gs81n
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: gzip-changes
timestamp: Thu 2008-09-25 17:17:15 +0200
message:
  Fix U32, LOWU32 disapearance in python-2.6.
  
  * bzrlib/tuned_gzip.py:
  (U32, LOWU32): These functions are gone in python-2.6, they are
  trivial enough to be copied as is.
-------------- next part --------------
=== modified file 'bzrlib/tuned_gzip.py'
--- a/bzrlib/tuned_gzip.py	2008-04-24 07:22:53 +0000
+++ b/bzrlib/tuned_gzip.py	2008-09-25 15:17:15 +0000
@@ -21,7 +21,7 @@
 
 # make GzipFile faster:
 import gzip
-from gzip import U32, LOWU32, FEXTRA, FCOMMENT, FNAME, FHCRC
+from gzip import FEXTRA, FCOMMENT, FNAME, FHCRC
 import sys
 import struct
 import zlib
@@ -32,6 +32,21 @@
 __all__ = ["GzipFile", "bytes_to_gzip"]
 
 
+def U32(i):
+    """Return i as an unsigned integer, assuming it fits in 32 bits.
+
+    If it's >= 2GB when viewed as a 32-bit unsigned int, return a long.
+    """
+    if i < 0:
+        i += 1L << 32
+    return i
+
+
+def LOWU32(i):
+    """Return the low-order 32 bits of an int, as a non-negative int."""
+    return i & 0xFFFFFFFFL
+
+
 def bytes_to_gzip(bytes, factory=zlib.compressobj,
     level=zlib.Z_DEFAULT_COMPRESSION, method=zlib.DEFLATED,
     width=-zlib.MAX_WBITS, mem=zlib.DEF_MEM_LEVEL,



More information about the bazaar-commits mailing list