diff options
author | Pauli Virtanen <pav@iki.fi> | 2010-02-20 18:12:29 +0000 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2010-02-20 18:12:29 +0000 |
commit | cb8c9b33c94d078e56e5ffaf22061aeab317d3a1 (patch) | |
tree | d8add9fdc170abe3548cb9290929b410a9c37a75 /numpy/lib | |
parent | f8401465c6b5876c57d3908e38ca37c39695033f (diff) | |
download | numpy-cb8c9b33c94d078e56e5ffaf22061aeab317d3a1.tar.gz |
3K: lib: bytes vs. str fixes in lib.format and lib.io
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/format.py | 8 | ||||
-rw-r--r-- | numpy/lib/io.py | 4 |
2 files changed, 7 insertions, 5 deletions
diff --git a/numpy/lib/format.py b/numpy/lib/format.py index a28108f5f..520c6bd25 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -141,7 +141,7 @@ import numpy 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 @@ def magic(major, minor): 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 @@ def write_array_header_1_0(fp, d): # 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): """ diff --git a/numpy/lib/io.py b/numpy/lib/io.py index ec3f39cc2..83fd4d809 100644 --- a/numpy/lib/io.py +++ b/numpy/lib/io.py @@ -23,6 +23,8 @@ from _iotools import LineSplitter, NameValidator, StringConverter, \ _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 @@ def load(file, mmap_mode=None): 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 |