[Checkins] SVN: BTrees/branches/py3k/ Work with OIDs as bytes.

Tres Seaver cvs-admin at zope.org
Mon Dec 10 23:13:47 UTC 2012


Log message for revision 128578:
  Work with OIDs as bytes.

Changed:
  _U  BTrees/branches/py3k/
  U   BTrees/branches/py3k/BTrees/tests/test_utils.py
  U   BTrees/branches/py3k/BTrees/utils.py

-=-
Modified: BTrees/branches/py3k/BTrees/tests/test_utils.py
===================================================================
--- BTrees/branches/py3k/BTrees/tests/test_utils.py	2012-12-10 22:50:11 UTC (rev 128577)
+++ BTrees/branches/py3k/BTrees/tests/test_utils.py	2012-12-10 23:13:46 UTC (rev 128578)
@@ -72,16 +72,16 @@
             self.assertEqual(self._callFUT(faux), repr(faux))
 
     def test_w_zero(self):
-        self.assertEqual(self._callFUT('\0\0\0\0\0\0\0\0'), '0x00')
+        self.assertEqual(self._callFUT(b'\0\0\0\0\0\0\0\0'), b'0x00')
 
     def test_w_one(self):
-        self.assertEqual(self._callFUT('\0\0\0\0\0\0\0\1'), '0x01')
+        self.assertEqual(self._callFUT(b'\0\0\0\0\0\0\0\1'), b'0x01')
 
     def test_w_even_length(self):
-        self.assertEqual(self._callFUT('\0\0\0\0\0\0\xAB\xC4'), '0xabc4')
+        self.assertEqual(self._callFUT(b'\0\0\0\0\0\0\xAB\xC4'), b'0xabc4')
 
     def test_w_odd_length(self):
-        self.assertEqual(self._callFUT('\0\0\0\0\0\0\x0D\xEF'), '0x0def')
+        self.assertEqual(self._callFUT(b'\0\0\0\0\0\0\x0D\xEF'), b'0x0def')
 
 
 def test_suite():

Modified: BTrees/branches/py3k/BTrees/utils.py
===================================================================
--- BTrees/branches/py3k/BTrees/utils.py	2012-12-10 22:50:11 UTC (rev 128577)
+++ BTrees/branches/py3k/BTrees/utils.py	2012-12-10 23:13:46 UTC (rev 128578)
@@ -15,6 +15,8 @@
 
 from binascii import hexlify
 
+from ._compat import _bytes
+
 def non_negative(int_val):
     if int_val < 0:
         # Coerce to non-negative.
@@ -28,14 +30,16 @@
 
 
 def oid_repr(oid):
-    if isinstance(oid, str) and len(oid) == 8:
+    if isinstance(oid, _bytes) and len(oid) == 8:
         # Convert to hex and strip leading zeroes.
-        as_hex = hexlify(oid).lstrip('0')
+        as_hex = hexlify(oid).lstrip(b'0')
         # Ensure two characters per input byte.
+        chunks = [b'0x']
         if len(as_hex) & 1:
-            as_hex = '0' + as_hex
-        elif as_hex == '':
-            as_hex = '00'
-        return '0x' + as_hex
+            chunks.append(b'0')
+        elif as_hex == b'':
+            as_hex = b'00'
+        chunks.append(as_hex)
+        return b''.join(chunks)
     else:
         return repr(oid)



More information about the checkins mailing list