Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop python2 support #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions bloscpack/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


import blosc
from six import integer_types, string_types


from .abstract_objects import (MutableMappingObject,
Expand Down Expand Up @@ -182,7 +181,7 @@ def calculate_nchunks(in_file_size, chunk_size=DEFAULT_CHUNK_SIZE):
return (1, 0, 0)
log.verbose("Input was length zero, ignoring 'chunk_size'")
# convert a human readable description to an int
if isinstance(chunk_size, string_types):
if isinstance(chunk_size, str):
chunk_size = reverse_pretty(chunk_size)
check_range('chunk_size', chunk_size, 1, blosc.BLOSC_MAX_BUFFERSIZE)
# downcast
Expand Down Expand Up @@ -265,15 +264,15 @@ def _handle_max_apps(offsets, nchunks, max_app_chunks):
# it's a callable all right
log.debug("max_app_chunks is a callable")
max_app_chunks = max_app_chunks(nchunks)
if not isinstance(max_app_chunks, integer_types):
if not isinstance(max_app_chunks, int):
raise ValueError(
"max_app_chunks callable returned a non integer "
"of type '%s'" % type(max_app_chunks))
# check that the result is still positive, might be quite large
if max_app_chunks < 0:
raise ValueError(
'max_app_chunks callable returned a negative integer')
elif isinstance(max_app_chunks, integer_types):
elif isinstance(max_app_chunks, int):
# it's a plain int, check its range
log.debug("max_app_chunks is an int")
check_range('max_app_chunks', max_app_chunks, 0, MAX_CHUNKS)
Expand Down Expand Up @@ -426,7 +425,7 @@ def meta_codec_name(self):
def effective_max_meta_size(self, meta_size):
if hasattr(self.max_meta_size, '__call__'):
max_meta_size = self.max_meta_size(meta_size)
elif isinstance(self.max_meta_size, integer_types):
elif isinstance(self.max_meta_size, int):
max_meta_size = self.max_meta_size
log.debug('max meta size is deemed to be: %d' % max_meta_size)
return max_meta_size
Expand Down
12 changes: 5 additions & 7 deletions bloscpack/file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import os.path as path

import blosc
import six
from six.moves import xrange
from deprecated import deprecated


Expand Down Expand Up @@ -87,7 +85,7 @@ def _write_metadata(output_fp, metadata, metadata_args):
serializer_impl = SERIALIZERS_LOOKUP[metadata_args.magic_format]
metadata = serializer_impl.dumps(metadata)
meta_size = len(metadata)
if six.PY3 and isinstance(metadata, str):
if isinstance(metadata, str):
metadata = metadata.encode()
if metadata_args.should_compress:
codec_impl = metadata_args.meta_codec_impl
Expand Down Expand Up @@ -129,7 +127,7 @@ def _write_metadata(output_fp, metadata, metadata_args):
output_fp.write(raw_metadata_header)
output_fp.write(metadata)
prealloc = max_meta_size - meta_comp_size
for i in xrange(prealloc):
for i in range(prealloc):
output_fp.write(b'\x00')
metadata_total += prealloc
log.debug("metadata has %d preallocated empty bytes" % prealloc)
Expand Down Expand Up @@ -228,7 +226,7 @@ def _read_metadata(input_fp):
('compressed' if metadata_header.meta_codec != 'None' else
'uncompressed', metadata_header.meta_comp_size))
serializer_impl = SERIALIZERS_LOOKUP[metadata_header.magic_format]
if six.PY3 and isinstance(metadata, bytes):
if isinstance(metadata, bytes):
metadata = metadata.decode()
metadata = serializer_impl.loads(metadata)
return metadata, metadata_header
Expand Down Expand Up @@ -258,7 +256,7 @@ def _read_offsets(input_fp, bloscpack_header):
offsets_raw = input_fp.read(8 * total_entries)
log.debug('Read raw offsets: %s' % repr(offsets_raw))
offsets = [decode_int64(offsets_raw[j - 8:j]) for j in
xrange(8, bloscpack_header.nchunks * 8 + 1, 8)]
range(8, bloscpack_header.nchunks * 8 + 1, 8)]
log.debug('Offsets: %s' % offsets)
return offsets
else:
Expand Down Expand Up @@ -364,7 +362,7 @@ def __init__(self, input_fp):
self.nchunks = self.bloscpack_header.nchunks

def __iter__(self):
for i in xrange(self.nchunks):
for i in range(self.nchunks):
compressed, header, digest = _read_compressed_chunk_fp(self.input_fp, self.checksum_impl)
yield compressed, digest

Expand Down
15 changes: 4 additions & 11 deletions bloscpack/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


import blosc
from six import PY3, integer_types, binary_type

from .abstract_objects import (MutableMappingObject,
)
Expand Down Expand Up @@ -41,7 +40,7 @@

def check_range(name, value, min_, max_):
""" Check that a variable is in range. """
if not isinstance(value, integer_types):
if not isinstance(value, int):
raise TypeError("'%s' must be of type 'int'" % name)
elif not min_ <= value <= max_:
raise ValueError(
Expand All @@ -50,7 +49,7 @@ def check_range(name, value, min_, max_):


def _check_str(name, value, max_len):
if not isinstance(value, binary_type):
if not isinstance(value, bytes):
raise TypeError("'%s' must be of type 'str'/'bytes'" % name)
elif len(value) > max_len:
raise ValueError("'%s' can be of max length '%i' but is: '%s'" %
Expand Down Expand Up @@ -104,10 +103,7 @@ def check_options_zero(options, indices):


def decode_uint8(byte):
if PY3:
return byte
else:
return struct.unpack('<B', byte)[0]
return byte


def decode_uint32(fourbyte):
Expand All @@ -127,10 +123,7 @@ def decode_bitfield(byte):


def decode_magic_string(str_):
if PY3:
return str_.strip(b'\x00')
else:
return str_.strip('\x00')
return str_.strip(b'\x00')


def encode_uint8(byte):
Expand Down
3 changes: 1 addition & 2 deletions bloscpack/memory_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# vim :set ft=py:

import blosc
from six.moves import xrange

from .abstract_io import (PlainSource,
CompressedSource,
Expand Down Expand Up @@ -39,7 +38,7 @@ def __init__(self, compressed_memory_sink):
self.checksums = compressed_memory_sink.checksums

def __iter__(self):
for i in xrange(self.nchunks):
for i in range(self.nchunks):
compressed = self.chunks[i]
digest = self.checksums[i] if self.checksum else None
yield compressed, digest
Expand Down
6 changes: 1 addition & 5 deletions bloscpack/numpy_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import blosc
import numpy
import six
from six.moves import xrange
from deprecated import deprecated


Expand Down Expand Up @@ -89,7 +87,7 @@ def __iter__(self):
)
self.nitems = int(self.chunk_size / self.ndarray.itemsize)
offset = self.ptr
for i in xrange(self.nchunks - 1):
for i in range(self.nchunks - 1):
yield offset, self.nitems
offset += self.chunk_size
yield offset, int(self.last_chunk / self.ndarray.itemsize)
Expand All @@ -112,8 +110,6 @@ def _conv(descr):
descr = [_conv(d) for d in descr]
else:
descr = tuple([_conv(d) for d in descr])
elif six.PY2 and isinstance(descr, unicode): # pragma: no cover
descr = str(descr)
return descr


Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
blosc
numpy
six
deprecated