Remove Python 2.7 crutch for izip and izip_longest

This commit is contained in:
Robert Smallshire
2015-05-05 13:30:32 +02:00
parent 60acf5f3db
commit 6e3494586a
5 changed files with 10 additions and 22 deletions
+3 -2
View File
@@ -1,7 +1,8 @@
from collections import OrderedDict
from struct import Struct
from itertools import zip_longest
from segpy.datatypes import SEG_Y_TYPE_TO_CTYPE
from segpy.portability import izip_longest
from segpy.util import pairwise, intervals_partially_overlap, complementary_intervals
@@ -89,7 +90,7 @@ def compile_struct(header_format_class, length_in_bytes=None, endian='>'):
# Create a format string usable with the struct module
format_chunks = [endian]
representative_fields = (fields[0] for fields in offset_to_fields.values())
for gap_interval, field in izip_longest(gap_intervals, representative_fields, fillvalue=None):
for gap_interval, field in zip_longest(gap_intervals, representative_fields, fillvalue=None):
gap_length = len(gap_interval)
if gap_length > 0:
format_chunks.append('x' * gap_length)
-9
View File
@@ -4,15 +4,6 @@ import sys
EMPTY_BYTE_STRING = b'' if sys.version_info >= (3, 0) else ''
if sys.version_info >= (3, 0):
izip = zip
from itertools import zip_longest as izip_longest
else:
from itertools import (izip, izip_longest)
izip = izip # Keep the static analyzer happy
izip_longest = izip_longest # Keep the static analyzer happy
if sys.version_info >= (3, 0):
def four_bytes(byte_str):
a, b, c, d = byte_str[:4]
-1
View File
@@ -2,7 +2,6 @@ from __future__ import print_function
from segpy.encoding import ASCII
from segpy.packer import HeaderPacker
from segpy.portability import seekable
from segpy.trace_header import TraceHeaderRev1
from segpy.util import file_length, filename_from_handle
from segpy.datatypes import DATA_SAMPLE_FORMAT_TO_SEG_Y_TYPE, SEG_Y_TYPE_DESCRIPTION, SEG_Y_TYPE_TO_CTYPE, size_in_bytes
+6 -7
View File
@@ -1,16 +1,15 @@
from __future__ import print_function
from array import array
from collections import namedtuple, OrderedDict
import itertools
from collections import OrderedDict
from itertools import zip_longest, count
import os
import struct
import re
import logging
from segpy import textual_reel_header_definition
from segpy.catalog import CatalogBuilder
from segpy.datatypes import SEG_Y_TYPE_TO_CTYPE, size_in_bytes
from segpy.encoding import guess_encoding, is_supported_encoding, UnsupportedEncodingError
@@ -20,7 +19,7 @@ from segpy.packer import HeaderPacker
from segpy.revisions import canonicalize_revision
from segpy.trace_header import TraceHeaderRev1
from segpy.util import file_length, batched, pad, complementary_intervals, NATIVE_ENDIANNESS
from segpy.portability import EMPTY_BYTE_STRING, izip_longest
from segpy.portability import EMPTY_BYTE_STRING
HEADER_NEWLINE = '\r\n'
@@ -351,7 +350,7 @@ def catalog_traces(fh, bps, trace_header_format=TraceHeaderRev1, endian='>', pro
alt_line_catalog_builder = CatalogBuilder()
cdp_catalog_builder = CatalogBuilder()
for trace_number in itertools.count():
for trace_number in count():
progress_callback(_READ_PROPORTION * pos_begin / length)
fh.seek(pos_begin)
data = fh.read(TRACE_HEADER_NUM_BYTES)
@@ -535,7 +534,7 @@ def format_standard_textual_header(revision, **kwargs):
background_slices = complementary_intervals(placeholder_slices.values(), 0, len(template))
chunks = []
for bg_slice, placeholder in izip_longest(background_slices, placeholder_slices.items()):
for bg_slice, placeholder in zip_longest(background_slices, placeholder_slices.items()):
if bg_slice is not None:
chunks.append(template[bg_slice])
+1 -3
View File
@@ -5,8 +5,6 @@ import sys
from itertools import (islice, cycle, tee, chain, repeat)
from segpy.portability import izip
NATIVE_ENDIANNESS = '<' if sys.byteorder == 'little' else '>'
UNSET = object()
@@ -25,7 +23,7 @@ def pairwise(iterable):
"""
a, b = tee(iterable)
next(b)
yield from izip(a, b)
yield from zip(a, b)
def batched(iterable, batch_size, padding=UNSET):