[Numpy-svn] r8162 - trunk/numpy/lib

numpy-svn@scip... numpy-svn@scip...
Sat Feb 20 12:12:29 CST 2010


Author: ptvirtan
Date: 2010-02-20 12:12:29 -0600 (Sat, 20 Feb 2010)
New Revision: 8162

Modified:
   trunk/numpy/lib/format.py
   trunk/numpy/lib/io.py
Log:
3K: lib: bytes vs. str fixes in lib.format and lib.io

Modified: trunk/numpy/lib/format.py
===================================================================
--- trunk/numpy/lib/format.py	2010-02-20 18:12:14 UTC (rev 8161)
+++ trunk/numpy/lib/format.py	2010-02-20 18:12:29 UTC (rev 8162)
@@ -141,7 +141,7 @@
 from numpy.lib.utils import safe_eval
 from numpy.compat import asbytes, isfileobj
 
-MAGIC_PREFIX = '\x93NUMPY'
+MAGIC_PREFIX = asbytes('\x93NUMPY')
 MAGIC_LEN = len(MAGIC_PREFIX) + 2
 
 def magic(major, minor):
@@ -164,7 +164,7 @@
         raise ValueError("major version must be 0 <= major < 256")
     if minor < 0 or minor > 255:
         raise ValueError("minor version must be 0 <= minor < 256")
-    return '%s%s%s' % (MAGIC_PREFIX, chr(major), chr(minor))
+    return asbytes('%s%s%s' % (MAGIC_PREFIX, chr(major), chr(minor)))
 
 def read_magic(fp):
     """ Read the magic string to get the version of the file format.
@@ -271,12 +271,12 @@
     # advantage of our premature optimization.
     current_header_len = MAGIC_LEN + 2 + len(header) + 1  # 1 for the newline
     topad = 16 - (current_header_len % 16)
-    header = '%s%s\n' % (header, ' '*topad)
+    header = asbytes('%s%s\n' % (header, ' '*topad))
     if len(header) >= (256*256):
         raise ValueError("header does not fit inside %s bytes" % (256*256))
     header_len_str = struct.pack('<H', len(header))
     fp.write(header_len_str)
-    fp.write(asbytes(header))
+    fp.write(header)
 
 def read_array_header_1_0(fp):
     """

Modified: trunk/numpy/lib/io.py
===================================================================
--- trunk/numpy/lib/io.py	2010-02-20 18:12:14 UTC (rev 8161)
+++ trunk/numpy/lib/io.py	2010-02-20 18:12:29 UTC (rev 8162)
@@ -23,6 +23,8 @@
                      _is_string_like, has_nested_fields, flatten_dtype, \
                      easy_dtype
 
+from numpy.compat import asbytes
+
 _file = open
 _string_like = _is_string_like
 
@@ -282,7 +284,7 @@
         fid = file
 
     # Code to distinguish from NumPy binary files and pickles.
-    _ZIP_PREFIX = 'PK\x03\x04'
+    _ZIP_PREFIX = asbytes('PK\x03\x04')
     N = len(format.MAGIC_PREFIX)
     magic = fid.read(N)
     fid.seek(-N, 1) # back-up



More information about the Numpy-svn mailing list