From 2732b6bd86a52a47263f662f98f89d94bbd62a7c Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Tue, 4 Jul 2023 20:10:26 -0400 Subject: [PATCH] Remove Python 2.7 compatibility. It is no longer support on GitHub actions anymore, so it is time to give up on it. Signed-off-by: Chris Lalancette --- Makefile | 2 - docs/design.md | 1 - docs/python-compatibility.md | 2 +- pycdlib/backport_functools.py | 216 --------- pycdlib/dates.py | 13 +- pycdlib/dr.py | 10 +- pycdlib/eltorito.py | 13 +- pycdlib/facade.py | 10 +- pycdlib/headervd.py | 12 +- pycdlib/inode.py | 12 +- pycdlib/isohybrid.py | 25 +- pycdlib/path_table_record.py | 4 +- pycdlib/pycdlib.py | 52 +-- pycdlib/pycdlibio.py | 31 +- pycdlib/rockridge.py | 48 +- pycdlib/udf.py | 125 ++--- pycdlib/utils.py | 33 +- pylint.conf | 4 +- setup.py | 3 +- tests/integration/test_common.py | 28 +- tests/integration/test_facade.py | 102 ++-- tests/integration/test_hybrid.py | 154 +++---- tests/integration/test_new.py | 769 +++++++++++++++---------------- tests/integration/test_parse.py | 3 +- tests/unit/test_dates.py | 14 +- tests/unit/test_dr.py | 9 +- tests/unit/test_eltorito.py | 9 +- tests/unit/test_headervd.py | 9 +- tests/unit/test_inode.py | 9 +- tests/unit/test_isohybrid.py | 9 +- tests/unit/test_ptr.py | 9 +- tests/unit/test_rockridge.py | 9 +- tests/unit/test_udf.py | 9 +- tests/unit/test_utils.py | 26 +- tools/pycdlib-explorer | 2 - tools/pycdlib-extract-files | 2 - tools/pycdlib-genisoimage | 41 +- 37 files changed, 706 insertions(+), 1123 deletions(-) delete mode 100644 pycdlib/backport_functools.py diff --git a/Makefile b/Makefile index ed907895..fa7832e4 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,6 @@ sdist: python3 setup.py sdist slowtests: - -PYCDLIB_TRACK_WRITES=1 [ -x /usr/bin/py.test-2 ] && py.test-2 --basetemp=/var/tmp/pycdlib-tests --runslow --verbose tests PYCDLIB_TRACK_WRITES=1 py.test-3 --basetemp=/var/tmp/pycdlib-tests --runslow --verbose tests srpm: sdist @@ -53,7 +52,6 @@ test-coverage: xdg-open htmlcov/index.html tests: - -[ -x /usr/bin/py.test-2 ] && py.test-2 --verbose tests py.test-3 --verbose tests .PHONY: clean deb docs flake8 lineprof mypy profile pylint rpm sdist slowtests srpm test-coverage tests diff --git a/docs/design.md b/docs/design.md index 67016bf6..b8f89a1d 100644 --- a/docs/design.md +++ b/docs/design.md @@ -12,7 +12,6 @@ The original motivation for writing the library was to replace the subprocess ca * Support for all of the common optical disk filesystems and their extensions. * Compatibility with the large corpus of existing ISOs (this implies reading ISOs that violate the standards). * Relatively simple API. -* Python 2 and Python 3 compatibility. * Expansive test coverage. * In-place modification of existing ISOs, something that none of the other libraries support. * Performance approaching that of genisoimage. diff --git a/docs/python-compatibility.md b/docs/python-compatibility.md index 4a143a4c..f5f1ffdb 100644 --- a/docs/python-compatibility.md +++ b/docs/python-compatibility.md @@ -1,5 +1,5 @@ # Python Compatibility -PyCdlib works equally well with Python 2.7 and Python 3.4+. The [test suite](design.md#testing) ensures that the core PyCdlib code works with both flavors of Python. Note that all of the command-line tools use Python 3 by default. +The [test suite](design.md#testing) ensures that the core PyCdlib code works with all versions of Python greater than or equal to Python 3.7. --- diff --git a/pycdlib/backport_functools.py b/pycdlib/backport_functools.py deleted file mode 100644 index 2f176ab4..00000000 --- a/pycdlib/backport_functools.py +++ /dev/null @@ -1,216 +0,0 @@ -# Vendored copy of https://github.com/jaraco/backports.functools_lru_cache/blob/master/backports/functools_lru_cache.py -# MIT License: -# Copyright Jason R. Coombs -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -""" -backport_functools.py - Tools for working with functions and callable objects -backported from python3 to python2. -""" - -from __future__ import absolute_import - -import functools -from collections import namedtuple -from threading import RLock - -_CacheInfo = namedtuple("_CacheInfo", ["hits", "misses", "maxsize", "currsize"]) - - -@functools.wraps(functools.update_wrapper) -def update_wrapper(wrapper, - wrapped, - assigned=functools.WRAPPER_ASSIGNMENTS, - updated=functools.WRAPPER_UPDATES): - """Patch two bugs in functools.update_wrapper.""" - # workaround for http://bugs.python.org/issue3445 - assigned = tuple(attr for attr in assigned if hasattr(wrapped, attr)) - wrapper = functools.update_wrapper(wrapper, wrapped, assigned, updated) - # workaround for https://bugs.python.org/issue17482 - wrapper.__wrapped__ = wrapped - return wrapper - - -class _HashedSeq(list): - """ - Guarantees that hash() will be called no more than once per element. - This is important because the lru_cache() will hash the key multiple - times on a cache miss. - """ - - __slots__ = ('hashvalue',) - - def __init__(self, tup): - list.__init__(self) - self[:] = tup - self.hashvalue = hash(tup) - - def __hash__(self): - return self.hashvalue - - -def _make_key(args, kwds, typed): - """Make a cache key from optionally typed positional and keyword arguments.""" - key = args - if kwds: - sorted_items = sorted(kwds.items()) - key += (object(),) - for item in sorted_items: - key += item - if typed: - key += tuple(type(v) for v in args) - if kwds: - key += tuple(type(v) for k, v in sorted_items) - elif len(key) == 1 and isinstance(key[0], (frozenset, int, str, type(None))): - return key[0] - return _HashedSeq(key) - - -def lru_cache(maxsize=100, typed=False): - """ - Least-recently-used cache decorator. - - If *maxsize* is set to None, the LRU features are disabled and the cache - can grow without bound. - - If *typed* is True, arguments of different types will be cached separately. - For example, f(3.0) and f(3) will be treated as distinct calls with - distinct results. - - Arguments to the cached function must be hashable. - - View the cache statistics named tuple (hits, misses, maxsize, currsize) with - f.cache_info(). Clear the cache and statistics with f.cache_clear(). - Access the underlying function with f.__wrapped__. - - See: http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used - """ - - # Users should only access the lru_cache through its public API: - # cache_info, cache_clear, and f.__wrapped__ - # The internals of the lru_cache are encapsulated for thread safety and - # to allow the implementation to change (including a possible C version). - - def decorating_function(user_function): - """Decorator implementation.""" - cache = {} - stats = [0, 0] # make statistics updateable non-locally - HITS, MISSES = 0, 1 # names for the stats fields - make_key = _make_key - cache_get = cache.get # bound method to lookup key or return None - _len = len # localize the global len() function - lock = RLock() # because linkedlist updates aren't threadsafe - root = [] # root of the circular doubly linked list - root[:] = [root, root, None, None] # initialize by pointing to self - nonlocal_root = [root] # make updateable non-locally - PREV, NEXT, KEY, RESULT = 0, 1, 2, 3 # names for the link fields - - if maxsize == 0: - - def wrapper(*args, **kwds): - """Wrapper to only call user_function and update statistics.""" - # no caching, just do a statistics update after a successful call - result = user_function(*args, **kwds) - stats[MISSES] += 1 - return result - - elif maxsize is None: - - def wrapper(*args, **kwds): - """Wrapper to cache without ordering or size limit.""" - # simple caching without ordering or size limit - key = make_key(args, kwds, typed) - result = cache_get(key, root) # root used here as a unique not-found sentinel - if result is not root: - stats[HITS] += 1 - return result - result = user_function(*args, **kwds) - cache[key] = result - stats[MISSES] += 1 - return result - - else: - - def wrapper(*args, **kwds): - """Wrapper to cache with LRU algorithm.""" - # size limited caching that tracks accesses by recency - key = make_key(args, kwds, typed) if kwds or typed else args - with lock: - link = cache_get(key) - if link is not None: - # record recent use of the key by moving it to the front of the list - root, = nonlocal_root - link_prev, link_next, key, result = link - link_prev[NEXT] = link_next - link_next[PREV] = link_prev - last = root[PREV] - last[NEXT] = root[PREV] = link - link[PREV] = last - link[NEXT] = root - stats[HITS] += 1 - return result - result = user_function(*args, **kwds) - with lock: - root, = nonlocal_root - if key in cache: - # getting here means that this same key was added to the - # cache while the lock was released. since the link - # update is already done, we need only return the - # computed result and update the count of misses. - pass - elif _len(cache) >= maxsize: - # use the old root to store the new key and result - oldroot = root - oldroot[KEY] = key - oldroot[RESULT] = result - # empty the oldest link and make it the new root - root = nonlocal_root[0] = oldroot[NEXT] - oldkey = root[KEY] - root[KEY] = root[RESULT] = None - # now update the cache dictionary for the new links - del cache[oldkey] - cache[key] = oldroot - else: - # put result in a new link at the front of the list - last = root[PREV] - link = [last, root, key, result] - last[NEXT] = root[PREV] = cache[key] = link - stats[MISSES] += 1 - return result - - def cache_info(): - """Report cache statistics.""" - with lock: - return _CacheInfo(stats[HITS], stats[MISSES], maxsize, len(cache)) - - def cache_clear(): - """Clear the cache and cache statistics.""" - with lock: - cache.clear() - root = nonlocal_root[0] - root[:] = [root, root, None, None] - stats[:] = [0, 0] - - wrapper.__wrapped__ = user_function - wrapper.cache_info = cache_info - wrapper.cache_clear = cache_clear - return update_wrapper(wrapper, user_function) - - return decorating_function diff --git a/pycdlib/dates.py b/pycdlib/dates.py index d49cbc02..c87284d0 100644 --- a/pycdlib/dates.py +++ b/pycdlib/dates.py @@ -18,20 +18,15 @@ Classes and utilities for ISO date support. """ -from __future__ import absolute_import - +import functools import struct import time -try: - from functools import lru_cache -except ImportError: - from pycdlib.backport_functools import lru_cache # type: ignore from pycdlib import pycdlibexception from pycdlib import utils -@lru_cache(maxsize=256) +@functools.lru_cache(maxsize=256) def string_to_timestruct(input_string): # type: (bytes) -> time.struct_time """ @@ -59,7 +54,7 @@ def string_to_timestruct(input_string): return timestruct -class DirectoryRecordDate(object): +class DirectoryRecordDate: """ A class to represent a Directory Record date as described in Ecma-119 section 9.1.5. The Directory Record date consists of the number of years @@ -147,7 +142,7 @@ def __ne__(self, other): self.second != other.second or self.gmtoffset != other.gmtoffset -class VolumeDescriptorDate(object): +class VolumeDescriptorDate: """ A class to represent a Volume Descriptor Date as described in Ecma-119 section 8.4.26.1. The Volume Descriptor Date consists of a year (from 1 to diff --git a/pycdlib/dr.py b/pycdlib/dr.py index cdb78d96..ee4dfb54 100644 --- a/pycdlib/dr.py +++ b/pycdlib/dr.py @@ -18,8 +18,6 @@ The class to support ISO9660 Directory Records. """ -from __future__ import absolute_import - import bisect import struct @@ -31,13 +29,13 @@ # For mypy annotations if False: # pylint: disable=using-constant-test - from typing import BinaryIO, List, Optional, Tuple, Union # NOQA pylint: disable=unused-import + from typing import Any, IO, List, Optional, Tuple, Union # NOQA pylint: disable=unused-import # NOTE: these imports have to be here to avoid circular deps from pycdlib import headervd # NOQA pylint: disable=unused-import from pycdlib import path_table_record # NOQA pylint: disable=unused-import -class XARecord(object): +class XARecord: """ A class that represents an ISO9660 Extended Attribute record as defined in the Philips Yellow Book standard. @@ -149,7 +147,7 @@ def length(): return 14 -class DirectoryRecord(object): +class DirectoryRecord: """A class that represents an ISO9660 directory record.""" __slots__ = ('initialized', 'new_extent_loc', 'ptr', 'extents_to_here', 'offset_to_here', 'data_continuation', 'vd', 'children', @@ -1190,7 +1188,7 @@ def set_data_length(self, length): @property def data_fp(self): - # type: () -> Optional[Union[BinaryIO, str]] + # type: () -> Optional[Union[IO[Any], str]] """Backwards compatibility property for 'data_fp'.""" if self.inode is None: return None diff --git a/pycdlib/eltorito.py b/pycdlib/eltorito.py index 5d6067ec..88cd2a06 100644 --- a/pycdlib/eltorito.py +++ b/pycdlib/eltorito.py @@ -16,9 +16,6 @@ """Classes to support El Torito.""" -from __future__ import absolute_import -from __future__ import print_function - import logging import struct @@ -38,7 +35,7 @@ _logger = logging.getLogger('pycdlib') -class EltoritoBootInfoTable(object): +class EltoritoBootInfoTable: """ A class that represents an El Torito Boot Info Table. The Boot Info Table is an optional table that may be patched into the boot file at offset 8, @@ -132,7 +129,7 @@ def header_length(): return 16 -class EltoritoValidationEntry(object): +class EltoritoValidationEntry: """ A class that represents an El Torito Validation Entry. El Torito requires that the first entry in the El Torito Boot Catalog be a validation entry. @@ -277,7 +274,7 @@ def record(self): return self._record() -class EltoritoEntry(object): +class EltoritoEntry: """A class that represents an El Torito Entry (Initial or Section).""" __slots__ = ('_initialized', 'inode', 'boot_indicator', 'boot_media_type', 'load_segment', 'system_type', @@ -493,7 +490,7 @@ def set_data_length(self, length): self.sector_count = utils.ceiling_div(length, 512) -class EltoritoSectionHeader(object): +class EltoritoSectionHeader: """A class that represents an El Torito Section Header.""" __slots__ = ('_initialized', 'header_indicator', 'platform_id', 'num_section_entries', 'id_string', 'section_entries') @@ -621,7 +618,7 @@ def record(self): return b''.join(outlist) -class EltoritoBootCatalog(object): +class EltoritoBootCatalog: """ A class that represents an El Torito Boot Catalog. The boot catalog is the basic unit of El Torito, and is expected to contain a validation entry, diff --git a/pycdlib/facade.py b/pycdlib/facade.py index 691a828a..e204982f 100644 --- a/pycdlib/facade.py +++ b/pycdlib/facade.py @@ -16,8 +16,6 @@ """Facade classes to make the main PyCdlib object easier to use.""" -from __future__ import absolute_import - from pycdlib import dr from pycdlib import pycdlibexception from pycdlib import udf as udfmod @@ -61,7 +59,7 @@ def iso_path_to_rr_name(iso_path, interchange_level, is_dir): return rr_name -class PyCdlibISO9660(object): +class PyCdlibISO9660: """The class representing the PyCdlib ISO9660 facade.""" __slots__ = ('pycdlib_obj',) @@ -256,7 +254,7 @@ def open_file_from_iso(self, iso_path): return self.pycdlib_obj.open_file_from_iso(iso_path=iso_path) -class PyCdlibJoliet(object): +class PyCdlibJoliet: """The class representing the PyCdlib Joliet facade.""" __slots__ = ('pycdlib_obj',) @@ -448,7 +446,7 @@ def open_file_from_iso(self, joliet_path): return self.pycdlib_obj.open_file_from_iso(joliet_path=joliet_path) -class PyCdlibRockRidge(object): +class PyCdlibRockRidge: """The class representing the PyCdlib Rock Ridge facade.""" __slots__ = ('pycdlib_obj',) @@ -738,7 +736,7 @@ def open_file_from_iso(self, rr_path): return self.pycdlib_obj.open_file_from_iso(rr_path=rr_path) -class PyCdlibUDF(object): +class PyCdlibUDF: """The class representing the PyCdlib UDF facade.""" __slots__ = ('pycdlib_obj',) diff --git a/pycdlib/headervd.py b/pycdlib/headervd.py index 96f76945..59fe5e2f 100644 --- a/pycdlib/headervd.py +++ b/pycdlib/headervd.py @@ -16,8 +16,6 @@ """Implementation of header Volume Descriptors for Ecma-119/ISO9660.""" -from __future__ import absolute_import - import struct import time @@ -40,7 +38,7 @@ allzero = b'\x00' * 2048 -class PrimaryOrSupplementaryVD(object): +class PrimaryOrSupplementaryVD: """ A class representing a Primary or Supplementary Volume Descriptor on this ISO. These are the first things on the ISO that are parsed, and contain all @@ -919,7 +917,7 @@ def joliet_vd_factory(joliet, sys_ident, vol_ident, set_size, seqnum, return svd -class FileOrTextIdentifier(object): +class FileOrTextIdentifier: """ A class to represent a file or text identifier as specified in Ecma-119 section 8.4.20 (Primary Volume Descriptor Publisher Identifier), @@ -1007,7 +1005,7 @@ def __ne__(self, other): return not equal -class VolumeDescriptorSetTerminator(object): +class VolumeDescriptorSetTerminator: """ A class that represents a Volume Descriptor Set Terminator. The VDST signals the end of volume descriptors on the ISO. @@ -1136,7 +1134,7 @@ def vdst_factory(): return vdst -class BootRecord(object): +class BootRecord: """A class representing an ISO9660 Boot Record.""" __slots__ = ('_initialized', 'boot_system_identifier', 'boot_identifier', 'boot_system_use', 'orig_extent_loc', 'new_extent_loc') @@ -1267,7 +1265,7 @@ def set_extent_location(self, extent): self.new_extent_loc = extent -class VersionVolumeDescriptor(object): +class VersionVolumeDescriptor: """ A class representing a Version Volume Descriptor. This volume descriptor is not mentioned in any of the standards, but is included by genisoimage, so it diff --git a/pycdlib/inode.py b/pycdlib/inode.py index 22ee9c83..824079e3 100644 --- a/pycdlib/inode.py +++ b/pycdlib/inode.py @@ -16,20 +16,18 @@ """PyCdlib Inode class.""" -from __future__ import absolute_import - from pycdlib import pycdlibexception # For mypy annotations if False: # pylint: disable=using-constant-test - from typing import BinaryIO, List, Optional, Tuple, Union # NOQA pylint: disable=unused-import + from typing import Any, BinaryIO, IO, List, Optional, Tuple, Union # NOQA pylint: disable=unused-import # NOTE: this import has to be here to avoid circular deps from pycdlib import dr # NOQA pylint: disable=unused-import from pycdlib import eltorito # NOQA pylint: disable=unused-import from pycdlib import udf # NOQA pylint: disable=unused-import -class Inode(object): +class Inode: """ A class that represents an inode, the pointer to a piece of data (not metadata) on an ISO. @@ -52,7 +50,7 @@ def __init__(self): self.new_extent_loc = -1 def new(self, length, fp, manage_fp, offset): - # type: (int, Union[BinaryIO, str], bool, int) -> None + # type: (int, Union[IO[Any], str], bool, int) -> None """ Initialize a new Inode. @@ -74,7 +72,7 @@ def new(self, length, fp, manage_fp, offset): self._initialized = True def parse(self, extent, length, fp, log_block_size): - # type: (int, int, BinaryIO, int) -> None + # type: (int, int, IO[Any], int) -> None """ Parse an existing Inode. This just saves off the extent for later use. @@ -179,7 +177,7 @@ def update_fp(self, fp, length): self.fp_offset = 0 -class InodeOpenData(object): +class InodeOpenData: """A class to be a contextmanager for opening data on a DirectoryRecord object.""" __slots__ = ('ino', 'logical_block_size', 'data_fp') diff --git a/pycdlib/isohybrid.py b/pycdlib/isohybrid.py index dcf83a9d..ad2a9e83 100644 --- a/pycdlib/isohybrid.py +++ b/pycdlib/isohybrid.py @@ -16,11 +16,8 @@ """Implementation of ISO hybrid support.""" -from __future__ import absolute_import - import random import struct -import sys import uuid from pycdlib import pycdlibexception @@ -97,10 +94,6 @@ 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D) -have_py_3 = True -if sys.version_info.major == 2: - have_py_3 = False - def crc32(data): # type: (bytes) -> int @@ -113,17 +106,13 @@ def crc32(data): The CRC32 of the data. """ crc = 0xFFFFFFFF - if have_py_3: - for x in data: - crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32_table[(crc ^ x) & 0xFF] - else: - for x in data: - crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32_table[(crc ^ ord(x)) & 0xFF] # type: ignore + for x in data: + crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32_table[(crc ^ x) & 0xFF] return crc ^ 0xffffffff -class APMPartHeader(object): +class APMPartHeader: """A class that represents an APM (Apple Partition Map) Partition Header.""" __slots__ = ('_initialized', 'map_count', 'start_block', 'block_count', 'name', 'type_desc', 'data_start', 'data_count', 'status', @@ -225,7 +214,7 @@ def record(self): self.processor, self.driver_sig, b'\x00' * 372) -class GPTPartHeader(object): +class GPTPartHeader: """A class that represents a GPT Partition Header.""" __slots__ = ('_initialized', 'part_guid', 'part_type_guid', 'first_lba', 'last_lba', 'attributes', 'name') @@ -312,7 +301,7 @@ def record(self): self.name.encode('utf-16_le')) -class GPTHeader(object): +class GPTHeader: """A class that represents a GPT Header.""" __slots__ = ('_initialized', 'current_lba', 'backup_lba', 'first_usable_lba', 'last_usable_lba', 'disk_guid', 'partition_entries_lba', @@ -454,7 +443,7 @@ def record(self, part_entries_crc): return bytes(ba) -class GPT(object): +class GPT: """ A class representing one GPT on an ISO. There are generally two; the primary one at the beginning (in the system area), and secondary one at the @@ -651,7 +640,7 @@ def record(self): return b''.join(outlist) -class IsoHybrid(object): +class IsoHybrid: """ A class that represents an ISO hybrid; that is, an ISO that can be booted via CD or via an alternate boot mechanism (such as USB). diff --git a/pycdlib/path_table_record.py b/pycdlib/path_table_record.py index 9fa4d9db..1ca18c0f 100644 --- a/pycdlib/path_table_record.py +++ b/pycdlib/path_table_record.py @@ -16,8 +16,6 @@ """Class to support ISO9660 Path Table Records.""" -from __future__ import absolute_import - import struct from pycdlib import pycdlibexception @@ -28,7 +26,7 @@ from typing import Type # NOQA pylint: disable=unused-import -class PathTableRecord(object): +class PathTableRecord: """A class that represents a single ISO9660 Path Table Record.""" __slots__ = ('_initialized', 'len_di', 'xattr_length', 'extent_location', 'parent_directory_num', 'directory_identifier', 'dirrecord') diff --git a/pycdlib/pycdlib.py b/pycdlib/pycdlib.py index 42f0aa87..ab700e02 100644 --- a/pycdlib/pycdlib.py +++ b/pycdlib/pycdlib.py @@ -16,25 +16,16 @@ """Main PyCdlib class and support classes and utilities.""" -from __future__ import absolute_import - import bisect import collections +import functools import inspect import io import os import struct import sys import time -try: - from cStringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO - -try: - from functools import lru_cache -except ImportError: - from pycdlib.backport_functools import lru_cache # type: ignore + from pycdlib import dr from pycdlib import eltorito from pycdlib import facade @@ -51,10 +42,6 @@ if False: # pylint: disable=using-constant-test from typing import Any, BinaryIO, Callable, Deque, Dict, Generator, IO, List, Optional, Tuple, Union # NOQA pylint: disable=unused-import -have_py_3 = True -if sys.version_info.major == 2: - have_py_3 = False - # There are a number of specific ways that numerical data is stored in the # ISO9660/Ecma-119 standard. In the text these are reference by the section # number they are stored in. A brief synopsis: @@ -542,7 +529,7 @@ def _find_dr_record_by_name(vd, path, encoding): raise pycdlibexception.PyCdlibInvalidInput('Could not find path') -class PyCdlib(object): +class PyCdlib: """The main class for manipulating ISOs.""" __slots__ = ('_initialized', '_cdfp', 'pvds', 'svds', 'vdsts', 'brs', 'pvd', 'rock_ridge', '_always_consistent', '_has_udf', 'joliet_vd', @@ -568,7 +555,7 @@ def _initialize(self): Returns: Nothing. """ - self._cdfp = BytesIO() + self._cdfp = io.BytesIO() # type: IO[Any] self.svds = [] # type: List[headervd.PrimaryOrSupplementaryVD] self.brs = [] # type: List[headervd.BootRecord] self.vdsts = [] # type: List[headervd.VolumeDescriptorSetTerminator] @@ -717,7 +704,7 @@ def _seek_to_extent(self, extent): """ self._cdfp.seek(extent * self.logical_block_size) - @lru_cache(maxsize=256) + @functools.lru_cache(maxsize=256) def _find_iso_record(self, iso_path): # type: (bytes) -> dr.DirectoryRecord """ @@ -733,7 +720,7 @@ def _find_iso_record(self, iso_path): """ return _find_dr_record_by_name(self.pvd, iso_path, 'utf-8') - @lru_cache(maxsize=256) + @functools.lru_cache(maxsize=256) def _find_rr_record(self, rr_path): # type: (bytes) -> dr.DirectoryRecord """ @@ -810,7 +797,7 @@ def _find_rr_record(self, rr_path): raise pycdlibexception.PyCdlibInvalidInput('Could not find path') - @lru_cache(maxsize=256) + @functools.lru_cache(maxsize=256) def _find_joliet_record(self, joliet_path): # type: (bytes) -> dr.DirectoryRecord """ @@ -828,7 +815,7 @@ def _find_joliet_record(self, joliet_path): raise pycdlibexception.PyCdlibInternalError('Joliet path requested on non-Joliet ISO') return _find_dr_record_by_name(self.joliet_vd, joliet_path, 'utf-16_be') - @lru_cache(maxsize=256) + @functools.lru_cache(maxsize=256) def _find_udf_record(self, udf_path): # type: (bytes) -> Tuple[Optional[udfmod.UDFFileIdentifierDescriptor], udfmod.UDFFileEntry] """ @@ -1582,7 +1569,7 @@ def _reshuffle_extents(self): current_extent += utils.ceiling_div(self.eltorito_boot_catalog.dirrecords[0].get_data_length(), self.logical_block_size) - class _EltoritoEncapsulation(object): + class _EltoritoEncapsulation: """ An internal class to encapsulate an El Torito Entry object with additional necessary metadata for sorting. @@ -2511,7 +2498,7 @@ def _get_file_from_iso_fp(self, outfp, blocksize, iso_path, rr_path, else: break - class _WriteRange(object): + class _WriteRange: """ A class to store the offset and length of a written section of data. A sorted list of these is used to determine whether we are unintentionally @@ -2595,7 +2582,7 @@ def _output_file_data(self, outfp, blocksize, ino): self._outfp_write_with_check(outfp, rec, enable_overwrite_check=False) outfp.seek(old) - class _Progress(object): + class _Progress: """ An inner class to deal with progress. """ @@ -2608,10 +2595,7 @@ def __init__(self, total, progress_cb, progress_opaque): self.progress_cb = progress_cb self.progress_opaque = progress_opaque if self.progress_cb is not None: - if have_py_3: - arglen = len(inspect.getfullargspec(self.progress_cb).args) - else: - arglen = len(inspect.getargspec(self.progress_cb).args) # type: ignore # pylint: disable=W1505,E1101 + arglen = len(inspect.getfullargspec(self.progress_cb).args) if arglen == 2: self._call = lambda done, total, opaque: self.progress_cb(done, total) # type: ignore @@ -4075,7 +4059,7 @@ def open(self, filename, mode='rb'): if self._initialized: raise pycdlibexception.PyCdlibInvalidInput('This object already has an ISO; either close it or create a new object') - fp = open(filename, mode) # pylint: disable=consider-using-with + fp = open(filename, mode) # pylint: disable=consider-using-with,unspecified-encoding self._managing_fp = True try: self._open_fp(fp) @@ -5384,7 +5368,7 @@ def add_symlink(self, symlink_path=None, rr_symlink_name=None, rr_path=None, # The inode for the symlink array. ino = inode.Inode() - ino.new(len(symlink_bytearray), BytesIO(symlink_bytearray), False, 0) + ino.new(len(symlink_bytearray), io.BytesIO(symlink_bytearray), False, 0) ino.linked_records.append((file_entry, False)) ino.num_udf += 1 file_entry.inode = ino @@ -5711,12 +5695,8 @@ def full_path_from_dirrecord(self, rec, rockridge=False): names.insert(0, name.decode(encoding)) udf_rec = udf_rec.parent - if have_py_3: - # Python 3, just return the encoded version. - return '/'.join(names) - - # Python 2. - return '/'.join(names).encode('utf-8') # type: ignore + # Return the encoded version. + return '/'.join(names) def duplicate_pvd(self): # type: () -> None diff --git a/pycdlib/pycdlibio.py b/pycdlib/pycdlibio.py index 1263f59a..333bb4d2 100644 --- a/pycdlib/pycdlibio.py +++ b/pycdlib/pycdlibio.py @@ -16,11 +16,7 @@ """PyCdlibIO class.""" -from __future__ import absolute_import - -import array import io -import sys from pycdlib import inode from pycdlib import pycdlibexception @@ -33,10 +29,6 @@ import pickle # NOQA pylint: disable=unused-import from typing import Any, Optional, Union # NOQA pylint: disable=unused-import -have_py_3 = True -if sys.version_info.major == 2: - have_py_3 = False - class PyCdlibIO(io.RawIOBase): """ @@ -120,23 +112,12 @@ def readinto(self, b): readsize = self._length - self._offset if readsize > 0: - if have_py_3: - mv = memoryview(b) - m = mv.cast('B') - readsize = min(readsize, len(m)) - data = self._fp.read(readsize) - n = len(data) - m[:n] = data - else: - readsize = min(readsize, len(b)) # type: ignore - data = self._fp.read(readsize) - n = len(data) - try: - b[:n] = data # type: ignore - except TypeError as err: - if not isinstance(b, array.array): - raise err - b[:n] = array.array(b'b', data) # type: ignore + mv = memoryview(b) + m = mv.cast('B') + readsize = min(readsize, len(m)) + data = self._fp.read(readsize) + n = len(data) + m[:n] = data else: n = 0 diff --git a/pycdlib/rockridge.py b/pycdlib/rockridge.py index 840105d0..dc2140ed 100644 --- a/pycdlib/rockridge.py +++ b/pycdlib/rockridge.py @@ -16,8 +16,6 @@ """Classes and utilities to support Rock Ridge extensions.""" -from __future__ import absolute_import - import bisect import struct @@ -42,7 +40,7 @@ EXT_SRC_112 = b'PLEASE CONTACT THE IEEE STANDARDS DEPARTMENT, PISCATAWAY, NJ, USA FOR THE P1282 SPECIFICATION' -class RRSPRecord(object): +class RRSPRecord: """ A class that represents a Rock Ridge Sharing Protocol record. This record indicates that the sharing protocol is in use, and how many bytes to skip @@ -130,7 +128,7 @@ def length(): return 7 -class RRRRRecord(object): +class RRRRRecord: """ A class that represents a Rock Ridge Rock Ridge record. This optional record indicates which other Rock Ridge fields are present. @@ -245,7 +243,7 @@ def length(): return 5 -class RRCERecord(object): +class RRCERecord: """ A class that represents a Rock Ridge Continuation Entry record. This record represents additional information that did not fit in the standard @@ -401,7 +399,7 @@ def length(): return 28 -class RRPXRecord(object): +class RRPXRecord: """ A class that represents a Rock Ridge POSIX File Attributes record. This record contains information about the POSIX file mode, file links, @@ -554,7 +552,7 @@ def length(rr_version): raise pycdlibexception.PyCdlibInternalError('Invalid rr_version') -class RRERRecord(object): +class RRERRecord: """A class that represents a Rock Ridge Extensions Reference record.""" __slots__ = ('_initialized', 'ext_id', 'ext_des', 'ext_src', 'ext_ver') @@ -664,7 +662,7 @@ def length(ext_id, ext_des, ext_src): return 8 + len(ext_id) + len(ext_des) + len(ext_src) -class RRESRecord(object): +class RRESRecord: """A class that represents a Rock Ridge Extension Selector record.""" __slots__ = ('_initialized', 'extension_sequence') @@ -747,7 +745,7 @@ def length(): return 5 -class RRPNRecord(object): +class RRPNRecord: """ A class that represents a Rock Ridge POSIX Device Number record. This record represents a device major and minor special file. @@ -851,7 +849,7 @@ def length(): return 20 -class RRSLRecord(object): +class RRSLRecord: """ A class that represents a Rock Ridge Symbolic Link record. This record represents some or all of a symbolic link. For a symbolic link, Rock Ridge @@ -861,7 +859,7 @@ class RRSLRecord(object): """ __slots__ = ('_initialized', 'symlink_components', 'flags') - class Component(object): + class Component: """A class that represents one component of a Symbolic Link Record.""" __slots__ = ('flags', 'curr_length', 'data') @@ -1261,7 +1259,7 @@ def length(symlink_components): return length -class RRALRecord(object): +class RRALRecord: """ A class that represents an Arbitrary Attribute Interchange Protocol record. This is an unoffical extension by libisofs: https://dev.lovelyhq.com/libburnia/libisofs/src/commit/d297ce3aed5935e469bb108a36b7d6e31763a075/doc/susp_aaip_2_0.txt @@ -1271,7 +1269,7 @@ class RRALRecord(object): """ __slots__ = ('_initialized', 'flags', 'components') - class Component(object): + class Component: """A class that represents one component of an Arbitrary Attribute.""" __slots__ = ('flags', 'curr_length', 'data') @@ -1544,7 +1542,7 @@ def length(attrs): return length -class RRNMRecord(object): +class RRNMRecord: """A class that represents a Rock Ridge Alternate Name record.""" __slots__ = ('_initialized', 'posix_name_flags', 'posix_name') @@ -1652,7 +1650,7 @@ def length(rr_name): return 5 + len(rr_name) -class RRCLRecord(object): +class RRCLRecord: """ A class that represents a Rock Ridge Child Link record. This record represents the logical block where a deeply nested directory was relocated @@ -1760,7 +1758,7 @@ def length(): return 12 -class RRPLRecord(object): +class RRPLRecord: """ A class that represents a Rock Ridge Parent Link record. This record represents the logical block where a deeply nested directory was located @@ -1867,7 +1865,7 @@ def length(): return 12 -class RRTFRecord(object): +class RRTFRecord: """ A class that represents a Rock Ridge Time Stamp record. This record represents the creation timestamp, the access time timestamp, the @@ -2009,7 +2007,7 @@ def length(time_flags): return 5 + tf_each_size * tf_num -class RRSFRecord(object): +class RRSFRecord: """ A class that represents a Rock Ridge Sparse File record. This record represents the full file size of a sparsely-populated file. @@ -2138,7 +2136,7 @@ def length(rr_version): raise pycdlibexception.PyCdlibInternalError('Invalid rr_version') -class RRRERecord(object): +class RRRERecord: """ A class that represents a Rock Ridge Relocated Directory record. This record is used to mark an entry as having been relocated because it was @@ -2224,7 +2222,7 @@ def length(): return 4 -class RRSTRecord(object): +class RRSTRecord: """ A class that represents a Rock Ridge System Terminator record. This record is used to terminate the SUSP/Rock Ridge records in a Directory @@ -2310,7 +2308,7 @@ def length(): return 4 -class RRPDRecord(object): +class RRPDRecord: """ A class that represents a Rock Ridge Platform Dependent record. This record is used to add platform-specific information to a Directory @@ -2395,7 +2393,7 @@ def length(padding): return 4 + len(padding) -class RockRidgeEntries(object): +class RockRidgeEntries: """ A simple class container to hold a long list of possible Rock Ridge records. @@ -2436,7 +2434,7 @@ def __init__(self): # than 8.3. Rock Ridge depends on the System Use and Sharing Protocol (SUSP), # which defines some standards on how to use the System Area. -class RockRidge(object): +class RockRidge: """A class representing Rock Ridge entries.""" __slots__ = ('_initialized', 'dr_entries', 'ce_entries', 'cl_to_moved_dr', 'moved_to_cl_dr', 'parent_link', 'rr_version', 'ce_block', @@ -3586,7 +3584,7 @@ def update_ce_block(self, block): self.ce_block = block -class RockRidgeContinuationEntry(object): +class RockRidgeContinuationEntry: """ A class representing one 'abstract' Rock Ridge Continuation Entry. These entries are strictly for keeping tabs of the offset and size @@ -3629,7 +3627,7 @@ def __lt__(self, other): return self._offset < other.offset -class RockRidgeContinuationBlock(object): +class RockRidgeContinuationBlock: """ A class representing one 'abstract' Rock Ridge Continuation Block. A Continuation Block is one extent holding many Rock Ridge Continuation diff --git a/pycdlib/udf.py b/pycdlib/udf.py index 58862e06..886c2c57 100644 --- a/pycdlib/udf.py +++ b/pycdlib/udf.py @@ -16,17 +16,11 @@ """Classes to support UDF.""" -from __future__ import absolute_import - +import io import logging import random import struct -import sys import time -try: - from cStringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO # pylint: disable=ungrouped-imports from pycdlib import pycdlibexception from pycdlib import utils @@ -88,11 +82,6 @@ 20053, 24180, 11923, 16050, 3793, 7920) -have_py_3 = True -if sys.version_info.major == 2: - have_py_3 = False - - _logger = logging.getLogger('pycdlib') @@ -107,12 +96,8 @@ def crc_ccitt(data): The CCITT CRC of the data. """ crc = 0 - if have_py_3: - for x in data: - crc = crc_ccitt_table[x ^ ((crc >> 8) & 0xFF)] ^ ((crc << 8) & 0xFF00) - else: - for x in data: - crc = crc_ccitt_table[ord(x) ^ ((crc >> 8) & 0xFF)] ^ ((crc << 8) & 0xFF00) # type: ignore + for x in data: + crc = crc_ccitt_table[x ^ ((crc >> 8) & 0xFF)] ^ ((crc << 8) & 0xFF00) return crc @@ -120,10 +105,7 @@ def crc_ccitt(data): def _ostaunicode(src): # type: (str) -> bytes """Internal function to create an OSTA byte string from a source string.""" - if have_py_3: - bytename = src - else: - bytename = src.decode('utf-8') # type: ignore + bytename = src try: enc = bytename.encode('latin-1') @@ -150,7 +132,7 @@ def _ostaunicode_zero_pad(src, fulllen): return byte_src + b'\x00' * (fulllen - 1 - len(byte_src)) + (struct.pack('=B', len(byte_src))) -class BEAVolumeStructure(object): +class BEAVolumeStructure: """ A class representing a UDF Beginning Extended Area Volume Structure (ECMA-167, Part 2, 9.2). @@ -255,7 +237,7 @@ def set_extent_location(self, extent): self.new_extent_loc = extent -class NSRVolumeStructure(object): +class NSRVolumeStructure: """A class representing a UDF NSR Volume Structure (ECMA-167, Part 3, 9.1).""" __slots__ = ('_initialized', 'orig_extent_loc', 'new_extent_loc', 'standard_ident') @@ -366,7 +348,7 @@ def set_extent_location(self, extent): self.new_extent_loc = extent -class TEAVolumeStructure(object): +class TEAVolumeStructure: """ A class representing a UDF Terminating Extended Area Volume Structure (ECMA-167, Part 2, 9.3). @@ -471,7 +453,7 @@ def set_extent_location(self, extent): self.new_extent_loc = extent -class UDFBootDescriptor(object): +class UDFBootDescriptor: """A class representing a UDF Boot Descriptor (ECMA-167, Part 2, 9.4).""" __slots__ = ('_initialized', 'architecture_type', 'boot_identifier', 'boot_extent_loc', 'boot_extent_len', 'load_address', @@ -634,19 +616,14 @@ def _compute_csum(data): The checksum. """ csum = 0 - if have_py_3: - for byte in data: - csum += byte - csum -= data[4] - else: - for byte in data: - csum += ord(byte) # type: ignore - csum -= ord(data[4]) # type: ignore + for byte in data: + csum += byte + csum -= data[4] return csum % 256 -class UDFTag(object): +class UDFTag: """A class representing a UDF Descriptor Tag (ECMA-167, Part 3, 7.2).""" __slots__ = ('_initialized', 'tag_ident', 'desc_version', 'tag_serial_number', 'tag_location', 'desc_crc_length') @@ -766,7 +743,7 @@ def __eq__(self, other): self.desc_crc_length == other.desc_crc_length -class UDFAnchorVolumeStructure(object): +class UDFAnchorVolumeStructure: """A class representing a UDF Anchor Volume Structure (ECMA-167, Part 3, 10.2).""" __slots__ = ('_initialized', 'orig_extent_loc', 'new_extent_loc', 'main_vd', 'reserve_vd', 'desc_tag') @@ -898,7 +875,7 @@ def __eq__(self, other): return self.main_vd.extent_location == other.main_vd.extent_location and self.reserve_vd.extent_location == other.reserve_vd.extent_location -class UDFVolumeDescriptorPointer(object): +class UDFVolumeDescriptorPointer: """A class representing a UDF Volume Descriptor Pointer (ECMA-167, Part 3, 10.3).""" __slots__ = ('initialized', 'orig_extent_loc', 'new_extent_loc', 'vol_seqnum', 'next_vol_desc_seq_extent', 'desc_tag') @@ -1014,7 +991,7 @@ def set_extent_location(self, new_location): self.desc_tag.tag_location = new_location -class UDFTimestamp(object): +class UDFTimestamp: """A class representing a UDF timestamp (ECMA-167, Part 1, 7.3).""" __slots__ = ('_initialized', 'year', 'month', 'day', 'hour', 'minute', 'second', 'centiseconds', 'hundreds_microseconds', @@ -1138,7 +1115,7 @@ def __eq__(self, other): self.timetype == other.timetype and self.tz == other.tz -class UDFEntityID(object): +class UDFEntityID: """A class representing a UDF Entity ID (ECMA-167, Part 1, 7.4).""" __slots__ = ('_initialized', 'flags', 'identifier', 'suffix') @@ -1220,7 +1197,7 @@ def __eq__(self, other): return self.flags == other.flags and self.identifier == other.identifier and self.suffix == other.suffix -class UDFCharspec(object): +class UDFCharspec: """A class representing a UDF charspec (ECMA-167, Part 1, 7.2.1).""" __slots__ = ('_initialized', 'set_type', 'set_information') @@ -1300,7 +1277,7 @@ def __eq__(self, other): return self.set_type == other.set_type and self.set_information == other.set_information -class UDFExtentAD(object): +class UDFExtentAD: """A class representing a UDF Extent Descriptor (ECMA-167, Part 3, 7.1).""" __slots__ = ('_initialized', 'extent_length', 'extent_location') @@ -1374,7 +1351,7 @@ def __eq__(self, other): return self.extent_length == other.extent_length and self.extent_location == other.extent_location -class UDFPrimaryVolumeDescriptor(object): +class UDFPrimaryVolumeDescriptor: """A class representing a UDF Primary Volume Descriptor (ECMA-167, Part 3, 10.1).""" __slots__ = ('_initialized', 'orig_extent_loc', 'new_extent_loc', 'vol_desc_seqnum', 'desc_num', 'vol_ident', 'vol_set_ident', @@ -1589,7 +1566,7 @@ def __eq__(self, other): self.flags == other.flags -class UDFImplementationUseVolumeDescriptorImplementationUse(object): +class UDFImplementationUseVolumeDescriptorImplementationUse: """ A class representing the Implementation Use field of the Implementation Use Volume Descriptor. @@ -1686,7 +1663,7 @@ def __eq__(self, other): self.impl_use == other.impl_use -class UDFImplementationUseVolumeDescriptor(object): +class UDFImplementationUseVolumeDescriptor: """A class representing a UDF Implementation Use Volume Structure (ECMA-167, Part 3, 10.4).""" __slots__ = ('_initialized', 'orig_extent_loc', 'new_extent_loc', 'vol_desc_seqnum', 'impl_use', 'desc_tag', 'impl_ident') @@ -1821,7 +1798,7 @@ def __eq__(self, other): self.impl_ident == other.impl_ident -class UDFPartitionHeaderDescriptor(object): +class UDFPartitionHeaderDescriptor: """A class representing a UDF Partition Header Descriptor.""" __slots__ = ('_initialized', 'unalloc_space_table', 'unalloc_space_bitmap', 'partition_integrity_table', 'freed_space_table', @@ -1928,7 +1905,7 @@ def __eq__(self, other): self.freed_space_bitmap == other.freed_space_bitmap -class UDFPartitionVolumeDescriptor(object): +class UDFPartitionVolumeDescriptor: """A class representing a UDF Partition Volume Structure (ECMA-167, Part 3, 10.5).""" __slots__ = ('_initialized', 'orig_extent_loc', 'new_extent_loc', 'vol_desc_seqnum', 'part_flags', 'part_num', 'access_type', @@ -2112,7 +2089,7 @@ def __eq__(self, other): self.part_contents_use == other.part_contents_use -class UDFType0PartitionMap(object): +class UDFType0PartitionMap: """A class representing a UDF Type 0 Partition Map (ECMA-167, Part 3, 10.7).""" __slots__ = ('_initialized', 'data') @@ -2180,7 +2157,7 @@ def new(self): self._initialized = True -class UDFType1PartitionMap(object): +class UDFType1PartitionMap: """A class representing a UDF Type 1 Partition Map (ECMA-167, Part 3, 10.7).""" __slots__ = ('_initialized', 'part_num', 'vol_seqnum') @@ -2247,7 +2224,7 @@ def new(self): self._initialized = True -class UDFType2PartitionMap(object): +class UDFType2PartitionMap: """A class representing a UDF Type 2 Partition Map (ECMA-167, Part 3, 10.7).""" __slots__ = ('_initialized', 'part_ident') @@ -2312,7 +2289,7 @@ def new(self): self._initialized = True -class UDFExtendedAD(object): +class UDFExtendedAD: """A class representing a UDF Extended Allocation Descriptor (ECMA-167, Part 4, 14.14.3).""" __slots__ = ('_initialized', 'extent_length', 'recorded_length', 'information_length', 'extent_location', 'impl_use') @@ -2384,7 +2361,7 @@ def new(self): self._initialized = True -class UDFShortAD(object): +class UDFShortAD: """A class representing a UDF Short Allocation Descriptor (ECMA-167, Part 4, 14.14.1).""" __slots__ = ('_initialized', 'extent_length', 'log_block_num', 'offset', 'extent_type') @@ -2491,7 +2468,7 @@ def __eq__(self, other): return self.extent_length == other.extent_length and self.log_block_num == other.log_block_num -class UDFLongAD(object): +class UDFLongAD: """ A class representing a UDF Long Allocation Descriptor (ECMA-167, Part 4, 14.14.2). @@ -2599,7 +2576,7 @@ def __eq__(self, other): self.impl_use == other.impl_use -class UDFInlineAD(object): +class UDFInlineAD: """ A class representing a UDF Inline Allocation Descriptor. This isn't explicitly defined in the specification, but is a convenient structure @@ -2696,7 +2673,7 @@ def length(self): return self.extent_length -class UDFLogicalVolumeDescriptor(object): +class UDFLogicalVolumeDescriptor: """A class representing a UDF Logical Volume Descriptor (ECMA-167, Part 3, 10.6).""" __slots__ = ('_initialized', 'orig_extent_loc', 'new_extent_loc', 'vol_desc_seqnum', 'desc_char_set', 'logical_vol_ident', @@ -2808,7 +2785,7 @@ def record(self): for part in self.partition_maps: all_partmaps += part.record() - partmap_pad = BytesIO() + partmap_pad = io.BytesIO() utils.zero_pad(partmap_pad, len(all_partmaps), 72) rec = struct.pack(self.FMT, b'\x00' * 16, @@ -2960,7 +2937,7 @@ def __eq__(self, other): self.logical_volume_contents_use == other.logical_volume_contents_use -class UDFUnallocatedSpaceDescriptor(object): +class UDFUnallocatedSpaceDescriptor: """A class representing a UDF Unallocated Space Descriptor (ECMA-167, Part 3, 10.8).""" __slots__ = ('_initialized', 'orig_extent_loc', 'new_extent_loc', 'vol_desc_seqnum', 'desc_tag', 'num_alloc_descriptors', @@ -3095,7 +3072,7 @@ def __eq__(self, other): self.num_alloc_descriptors == other.num_alloc_descriptors -class UDFTerminatingDescriptor(object): +class UDFTerminatingDescriptor: """A class representing a UDF Terminating Descriptor (ECMA-167, Part 3, 10.9).""" __slots__ = ('initialized', 'orig_extent_loc', 'new_extent_loc', 'desc_tag') @@ -3198,7 +3175,7 @@ def set_extent_location(self, new_location, tag_location=-1): self.desc_tag.tag_location = tag_location -class UDFLogicalVolumeHeaderDescriptor(object): +class UDFLogicalVolumeHeaderDescriptor: """A class representing a UDF Logical Volume Header Descriptor (ECMA-167, Part 4, 14.15).""" __slots__ = ('_initialized', 'unique_id') @@ -3258,7 +3235,7 @@ def new(self): self._initialized = True -class UDFLogicalVolumeImplementationUse(object): +class UDFLogicalVolumeImplementationUse: """A class representing a UDF Logical Volume Implementation Use.""" __slots__ = ('_initialized', 'num_files', 'num_dirs', 'min_udf_read_revision', 'min_udf_write_revision', @@ -3341,7 +3318,7 @@ def new(self): self._initialized = True -class UDFLogicalVolumeIntegrityDescriptor(object): +class UDFLogicalVolumeIntegrityDescriptor: """A class representing a UDF Logical Volume Integrity Descriptor (ECMA-167, Part 3, 10.10).""" __slots__ = ('_initialized', 'orig_extent_loc', 'new_extent_loc', 'length_impl_use', 'free_space_tables', 'size_tables', @@ -3511,7 +3488,7 @@ def set_extent_location(self, new_location): self.desc_tag.tag_location = new_location -class UDFFileSetDescriptor(object): +class UDFFileSetDescriptor: """A class representing a UDF File Set Descriptor (ECMA-167, Part 4, 14.1).""" __slots__ = ('_initialized', 'orig_extent_loc', 'new_extent_loc', 'file_set_num', 'log_vol_char_set', 'log_vol_ident', @@ -3688,7 +3665,7 @@ def set_extent_location(self, new_location): self.new_extent_loc = new_location -class UDFLBAddr(object): +class UDFLBAddr: """A class reprenting a UDF lb_addr (ECMA-167, Part 4, 7.1).""" __slots__ = ('_initialized', 'logical_block_num', 'part_ref_num') @@ -3749,7 +3726,7 @@ def new(self, logical_block_num): self._initialized = True -class UDFICBTag(object): +class UDFICBTag: """A class representing a UDF ICB Tag (ECMA-167, Part 4, 14.6).""" __slots__ = ('_initialized', 'prior_num_direct_entries', 'strategy_type', 'strategy_param', 'max_num_entries', 'file_type', 'parent_icb', @@ -3841,7 +3818,7 @@ def new(self, file_type): self._initialized = True -class UDFFileEntry(object): +class UDFFileEntry: """A class representing a UDF File Entry (ECMA-167, Part 4, 14.9).""" __slots__ = ('_initialized', 'orig_extent_loc', 'new_extent_loc', 'uid', 'gid', 'perms', 'file_link_count', 'info_len', 'hidden', @@ -4391,7 +4368,7 @@ def is_dotdot(self): return False -class UDFFileIdentifierDescriptor(object): +class UDFFileIdentifierDescriptor: """A class representing a UDF File Identifier Descriptor (ECMA-167, Part 4, 14.4).""" __slots__ = ('_initialized', 'orig_extent_loc', 'new_extent_loc', 'desc_tag', 'file_characteristics', 'len_fi', 'len_impl_use', @@ -4693,7 +4670,7 @@ def __eq__(self, other): return self.fi == other.fi -class UDFSpaceBitmapDescriptor(object): +class UDFSpaceBitmapDescriptor: """A class representing a UDF Space Bitmap Descriptor.""" __slots__ = ('_initialized', 'num_bits', 'num_bytes', 'bitmap', 'new_extent_loc', 'orig_extent_loc', 'desc_tag') @@ -4802,7 +4779,7 @@ def set_extent_location(self, extent): self.new_extent_loc = extent -class UDFAllocationExtentDescriptor(object): +class UDFAllocationExtentDescriptor: """A class representing a UDF Space Bitmap Descriptor (ECMA-167, Part 4, 14.5).""" __slots__ = ('_initialized', 'prev_allocation_extent_loc', 'len_allocation_descs', 'new_extent_loc', 'orig_extent_loc', @@ -4913,7 +4890,7 @@ def set_extent_location(self, extent): self.new_extent_loc = extent -class UDFIndirectEntry(object): +class UDFIndirectEntry: """A class representing a UDF Indirect Entry (ECMA-167, Part 4, 14.7).""" __slots__ = ('_initialized', 'icb_tag', 'indirect_icb', 'desc_tag') @@ -4994,7 +4971,7 @@ def new(self, file_type): self._initialized = True -class UDFTerminalEntry(object): +class UDFTerminalEntry: """A class representing a UDF Terminal Entry (ECMA-167, Part 4, 14.8).""" __slots__ = ('_initialized', 'icb_tag', 'desc_tag') @@ -5068,7 +5045,7 @@ def new(self, file_type): self._initialized = True -class UDFExtendedAttributeHeaderDescriptor(object): +class UDFExtendedAttributeHeaderDescriptor: """A class representing a UDF Extended Attribute Header Descriptor (ECMA-167, Part 4, 14.10.1).""" __slots__ = ('_initialized', 'impl_attr_loc', 'app_attr_loc', 'icb_tag', 'desc_tag') @@ -5142,7 +5119,7 @@ def new(self): self._initialized = True -class UDFUnallocatedSpaceEntry(object): +class UDFUnallocatedSpaceEntry: """A class representing a UDF Unallocated Space Entry (ECMA-167, Part 4, 14.11).""" __slots__ = ('_initialized', 'alloc_descs', 'icb_tag', 'desc_tag') @@ -5234,7 +5211,7 @@ def new(self, file_type): self._initialized = True -class UDFPartitionIntegrityEntry(object): +class UDFPartitionIntegrityEntry: """A class representing a UDF Partition Integrity Entry (ECMA-167, Part 4, 14.13).""" __slots__ = ('_initialized', 'integrity_type', 'timestamp', 'impl_ident', 'impl_use', 'icb_tag', 'desc_tag') @@ -5330,7 +5307,7 @@ def new(self, file_type): self._initialized = True -class UDFExtendedFileEntry(object): +class UDFExtendedFileEntry: """A class representing a UDF Extended File Entry (ECMA-167, Part 4, 14.17).""" __slots__ = ('_initialized', 'uid', 'gid', 'permissions', 'file_link_count', 'record_format', 'record_display_attrs', 'record_len', @@ -5606,7 +5583,7 @@ def _parse_allocation_descriptors(flags, data, length, start_offset, extent): return alloc_descs -class UDFDescriptorSequence(object): +class UDFDescriptorSequence: ''' A class to represent a UDF Descriptor Sequence. ''' diff --git a/pycdlib/utils.py b/pycdlib/utils.py index 5864c20f..dcffe074 100644 --- a/pycdlib/utils.py +++ b/pycdlib/utils.py @@ -16,13 +16,6 @@ """Various utilities for PyCdlib.""" -from __future__ import absolute_import - -try: - import cStringIO # pylint: disable=import-error -except ImportError: - pass - import io import math import os @@ -45,7 +38,7 @@ # For mypy annotations if False: # pylint: disable=using-constant-test - from typing import BinaryIO, Generator, List, Optional, Tuple # NOQA pylint: disable=unused-import + from typing import Any, BinaryIO, Generator, IO, List, Optional, Tuple # NOQA pylint: disable=unused-import def swab_32bit(x): @@ -99,7 +92,7 @@ def ceiling_div(numer, denom): def copy_data_yield(data_length, blocksize, infp, outfp): - # type: (int, int, BinaryIO, BinaryIO) -> Generator + # type: (int, int, BinaryIO, IO[Any]) -> Generator """ A utility function to copy data from the input file object to the output file object. @@ -131,7 +124,7 @@ def copy_data_yield(data_length, blocksize, infp, outfp): def copy_data(data_length, blocksize, infp, outfp): - # type: (int, int, BinaryIO, BinaryIO) -> None + # type: (int, int, BinaryIO, IO[Any]) -> None """ A utility function to copy data from the input file object to the output file object. @@ -210,10 +203,7 @@ def normpath(path): elif new_comps: new_comps.pop() newpath = sep * initial_slashes + sep.join(new_comps) - if sys.version_info >= (3, 0): - newpath_bytes = newpath.encode('utf-8') - else: - newpath_bytes = newpath.decode('utf-8').encode('utf-8') + newpath_bytes = newpath.encode('utf-8') if not starts_with_slash(newpath_bytes): raise pycdlibexception.PyCdlibInvalidInput('Must be a path starting with /') @@ -249,7 +239,7 @@ def gmtoffset_from_tm(tm, localtime): def zero_pad(fp, data_size, pad_size): - # type: (BinaryIO, int, int) -> int + # type: (IO[Any], int, int) -> int """ A function to write padding out from data_size up to pad_size efficiently. @@ -275,8 +265,8 @@ def starts_with_slash(path): # type: (bytes) -> bool """ A function to determine if a path starts with a slash. This is somewhat - difficult to do portably between Python2 and Python3 and with performance, - so we have a dedicated function for it. + difficult to do portably with performance, so we have a dedicated function + for it. Parameters: path - The path to determine if it starts with a slash @@ -317,12 +307,7 @@ def file_object_supports_binary(fp): if hasattr(fp, 'mode'): return 'b' in fp.mode - # Python 3 - if sys.version_info >= (3, 0): - return isinstance(fp, (io.RawIOBase, io.BufferedIOBase)) - - # Python 2 - return isinstance(fp, (cStringIO.OutputType, cStringIO.InputType, io.RawIOBase, io.BufferedIOBase)) + return isinstance(fp, (io.RawIOBase, io.BufferedIOBase)) def truncate_basename(basename, iso_level, is_dir): @@ -460,7 +445,7 @@ def mangle_dir_for_iso9660(orig, iso_level): return truncate_basename(orig, iso_level, True) -class Win32RawDevice(object): +class Win32RawDevice: """ Class to read and seek a Windows Raw Device IO object without bother. It deals with getting the full size, allowing full access to all sectors, diff --git a/pylint.conf b/pylint.conf index 2270003f..57cde7d4 100644 --- a/pylint.conf +++ b/pylint.conf @@ -55,10 +55,8 @@ confidence= # Here's what we have disabled: # W0201 - attribute-defined-outside-init # C0103 - invalid-name -# R0205 - useless-object-inheritance (we still support Python 2) # C0209 - consider-using-f-string (we still support Python 2) -# W1514 - unspecified-encoding (we still support Python 2) -disable=W0201,C0103,R0205,C0209,W1514 +disable=W0201,C0103,C0209 [REPORTS] diff --git a/setup.py b/setup.py index 5b7a4077..4faf9fc2 100644 --- a/setup.py +++ b/setup.py @@ -49,8 +49,7 @@ def run(self): 'Intended Audience :: Developers', 'License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)', 'Natural Language :: English', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.7', ], keywords='iso9660 iso ecma119 rockridge joliet eltorito udf', packages=['pycdlib'], diff --git a/tests/integration/test_common.py b/tests/integration/test_common.py index a000dc46..dd851c34 100644 --- a/tests/integration/test_common.py +++ b/tests/integration/test_common.py @@ -1,22 +1,16 @@ # -*- coding: utf-8 -*- -try: - from cStringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO -import pytest +import io import os import sys import struct +import pytest + sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import pycdlib -have_py_3 = True -if sys.version_info.major == 2: - have_py_3 = False - # Technically, Rock Ridge doesn't impose a length limitation on NM (alternate # name) or SL (symlinks). However, in practice, the Linux kernel (at least # ext4) doesn't support any names longer than 255, and the ISO driver doesn't @@ -440,7 +434,7 @@ def internal_check_dotdot_dir_record(dotdot_record, rr, rr_nlinks, xa, rr_onetwe assert(dotdot_record.rock_ridge.dr_entries.re_record == None) def internal_check_file_contents(iso, path, contents, which): - fout = BytesIO() + fout = io.BytesIO() if which == 'iso_path': iso.get_file_from_iso_fp(fout, iso_path=path) elif which == 'rr_path': @@ -644,12 +638,8 @@ def internal_check_joliet_root_dir_record(jroot_dir_record, num_children, def internal_check_rr_longname(iso, dir_record, extent, letter): bytes_iso_name = letter.upper()*8 + b'.;1' - if have_py_3: - str_iso_path = '/' + bytes_iso_name.decode('ascii') - str_rr_path = '/' + letter.decode('ascii')*RR_MAX_FILENAME_LENGTH - else: - str_iso_path = '/' + bytes_iso_name.encode('ascii') - str_rr_path = '/' + letter.encode('ascii')*RR_MAX_FILENAME_LENGTH + str_iso_path = '/' + bytes_iso_name.decode('ascii') + str_rr_path = '/' + letter.decode('ascii')*RR_MAX_FILENAME_LENGTH internal_check_file(dir_record, name=bytes_iso_name, dr_len=None, loc=extent, datalen=3, hidden=False, multi_extent=False) internal_check_file_contents(iso, path=str_iso_path, contents=letter*2+b'\n', which='iso_path') # Now check rock ridge extensions. @@ -1018,7 +1008,7 @@ def check_nofiles(iso, filesize): # Check to make sure accessing a missing file results in an exception. with pytest.raises(pycdlib.pycdlibexception.PyCdlibException): - iso.get_file_from_iso_fp(BytesIO(), iso_path='/FOO.;1') + iso.get_file_from_iso_fp(io.BytesIO(), iso_path='/FOO.;1') def check_onefile(iso, filesize): assert(filesize == 51200) @@ -3254,7 +3244,7 @@ def check_eltorito_hide_boot(iso, filesize): initial_entry_offset = iso.eltorito_boot_catalog.initial_entry.get_rba() # Re-render the output into a string. - myout = BytesIO() + myout = io.BytesIO() iso.write_fp(myout) # Now seek within the string to the right location. @@ -4341,7 +4331,7 @@ def check_eltorito_bootlink(iso, filesize): initial_entry_offset = iso.eltorito_boot_catalog.initial_entry.get_rba() # Re-render the output into a string. - myout = BytesIO() + myout = io.BytesIO() iso.write_fp(myout) # Now seek within the string to the right location. diff --git a/tests/integration/test_facade.py b/tests/integration/test_facade.py index c95c829e..c5542132 100644 --- a/tests/integration/test_facade.py +++ b/tests/integration/test_facade.py @@ -1,14 +1,10 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import - -import pytest +import io import os import sys -try: - from cStringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO + +import pytest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) @@ -24,7 +20,7 @@ def test_facade_iso9660_get_file_from_iso(tmpdir): facade = iso.get_iso9660_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + facade.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') foofile = os.path.join(str(tmpdir), 'foo') facade.get_file_from_iso(foofile, '/FOO.;1') @@ -41,9 +37,9 @@ def test_facade_iso9660_get_file_from_iso_fp(): facade = iso.get_iso9660_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + facade.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') - out = BytesIO() + out = io.BytesIO() facade.get_file_from_iso_fp(out, '/FOO.;1') assert(out.getvalue() == b'foo\n') @@ -57,9 +53,9 @@ def test_facade_iso9660_add_fp(): facade = iso.get_iso9660_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + facade.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') - out = BytesIO() + out = io.BytesIO() facade.get_file_from_iso_fp(out, '/FOO.;1') assert(out.getvalue() == b'foo\n') @@ -73,9 +69,9 @@ def test_facade_iso9660_add_fp_with_rr(): facade = iso.get_iso9660_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + facade.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') - out = BytesIO() + out = io.BytesIO() facade.get_file_from_iso_fp(out, '/FOO.;1') assert(out.getvalue() == b'foo\n') @@ -90,7 +86,7 @@ def test_facade_iso9660_add_fp_with_rr_bad_name(): foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - facade.add_fp(BytesIO(foostr), len(foostr), 'FOO.;1') + facade.add_fp(io.BytesIO(foostr), len(foostr), 'FOO.;1') assert(str(excinfo.value) == "iso_path must start with '/'") iso.close() @@ -107,7 +103,7 @@ def test_facade_iso9660_add_file(tmpdir): facade.add_file(str(testout), '/FOO.;1') - out = BytesIO() + out = io.BytesIO() facade.get_file_from_iso_fp(out, '/FOO.;1') assert(out.getvalue() == b'foo\n') @@ -126,7 +122,7 @@ def test_facade_iso9660_add_file_with_rr(tmpdir): facade.add_file(str(testout), '/FOO.;1') - out = BytesIO() + out = io.BytesIO() facade.get_file_from_iso_fp(out, '/FOO.;1') assert(out.getvalue() == b'foo\n') @@ -166,7 +162,7 @@ def test_facade_iso9660_rm_file(): facade = iso.get_iso9660_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + facade.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') rec = facade.get_record('/') assert(len(rec.children) == 3) @@ -203,7 +199,7 @@ def test_facade_iso9660_list_children(): facade.add_directory('/DIR1') bootstr = b'boot\n' - facade.add_fp(BytesIO(bootstr), len(bootstr), '/DIR1/BOOT.;1') + facade.add_fp(io.BytesIO(bootstr), len(bootstr), '/DIR1/BOOT.;1') full_path = None for child in facade.list_children('/DIR1'): @@ -253,7 +249,7 @@ def test_facade_iso9660_open_file_from_iso(): facade = iso.get_iso9660_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + facade.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with facade.open_file_from_iso('/FOO.;1') as infp: assert(infp.read() == b'foo\n') @@ -276,7 +272,7 @@ def test_facade_joliet_get_file_from_iso(tmpdir): facade = iso.get_joliet_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo') + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo') foofile = os.path.join(str(tmpdir), 'foo') facade.get_file_from_iso(foofile, '/foo') @@ -293,9 +289,9 @@ def test_facade_joliet_get_file_from_iso_fp(): facade = iso.get_joliet_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo') + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo') - out = BytesIO() + out = io.BytesIO() facade.get_file_from_iso_fp(out, '/foo') assert(out.getvalue() == b'foo\n') @@ -309,9 +305,9 @@ def test_facade_joliet_add_fp(): facade = iso.get_joliet_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo') + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo') - out = BytesIO() + out = io.BytesIO() facade.get_file_from_iso_fp(out, '/foo') assert(out.getvalue() == b'foo\n') @@ -330,7 +326,7 @@ def test_facade_joliet_add_file(tmpdir): facade.add_file(str(testout), '/foo') - out = BytesIO() + out = io.BytesIO() facade.get_file_from_iso_fp(out, '/foo') assert(out.getvalue() == b'foo\n') @@ -357,7 +353,7 @@ def test_facade_joliet_rm_file(): facade = iso.get_joliet_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo') + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo') rec = facade.get_record('/') assert(len(rec.children) == 3) @@ -394,7 +390,7 @@ def test_facade_joliet_list_children(): facade.add_directory('/dir1') bootstr = b'boot\n' - facade.add_fp(BytesIO(bootstr), len(bootstr), '/dir1/boot') + facade.add_fp(io.BytesIO(bootstr), len(bootstr), '/dir1/boot') full_path = None for child in facade.list_children('/dir1'): @@ -444,7 +440,7 @@ def test_facade_joliet_open_file_from_iso(): facade = iso.get_joliet_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo') + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo') with facade.open_file_from_iso('/foo') as infp: assert(infp.read() == b'foo\n') @@ -467,7 +463,7 @@ def test_facade_rock_ridge_get_file_from_iso(tmpdir): facade = iso.get_rock_ridge_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo', 0o040555) + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo', 0o040555) foofile = os.path.join(str(tmpdir), 'foo') facade.get_file_from_iso(foofile, '/foo') @@ -484,9 +480,9 @@ def test_facade_rock_ridge_get_file_from_iso_fp(): facade = iso.get_rock_ridge_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo', 0o040555) + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo', 0o040555) - out = BytesIO() + out = io.BytesIO() facade.get_file_from_iso_fp(out, '/foo') assert(out.getvalue() == b'foo\n') @@ -500,9 +496,9 @@ def test_facade_rock_ridge_add_fp(): facade = iso.get_rock_ridge_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo', 0o040555) + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo', 0o040555) - out = BytesIO() + out = io.BytesIO() facade.get_file_from_iso_fp(out, '/foo') assert(out.getvalue() == b'foo\n') @@ -517,7 +513,7 @@ def test_facade_rock_ridge_add_fp_bad_filename(): foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - facade.add_fp(BytesIO(foostr), len(foostr), 'foo', 0o040555) + facade.add_fp(io.BytesIO(foostr), len(foostr), 'foo', 0o040555) assert(str(excinfo.value) == "rr_path must start with '/'") iso.close() @@ -534,7 +530,7 @@ def test_facade_rock_ridge_add_file(tmpdir): facade.add_file(str(testout), '/foo', 0o040555) - out = BytesIO() + out = io.BytesIO() facade.get_file_from_iso_fp(out, '/foo') assert(out.getvalue() == b'foo\n') @@ -561,7 +557,7 @@ def test_facade_rock_ridge_rm_file(): facade = iso.get_rock_ridge_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo', 0o040555) + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo', 0o040555) rec = facade.get_record('/') assert(len(rec.children) == 3) @@ -579,7 +575,7 @@ def test_facade_rock_ridge_rm_file_bad_filename(): facade = iso.get_rock_ridge_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo', 0o040555) + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo', 0o040555) rec = facade.get_record('/') assert(len(rec.children) == 3) @@ -596,7 +592,7 @@ def test_facade_rock_ridge_rm_file_root(): facade = iso.get_rock_ridge_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo', 0o040555) + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo', 0o040555) rec = facade.get_record('/') assert(len(rec.children) == 3) @@ -629,7 +625,7 @@ def test_facade_rock_ridge_rm_directory_root(): facade = iso.get_rock_ridge_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo', 0o040555) + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo', 0o040555) rec = facade.get_record('/') assert(len(rec.children) == 3) @@ -646,7 +642,7 @@ def test_facade_rock_ridge_add_symlink(): facade = iso.get_rock_ridge_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo', 0o040555) + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo', 0o040555) facade.add_symlink('/sym', 'foo') @@ -665,7 +661,7 @@ def test_facade_rock_ridge_list_children(): facade.add_directory('/dir1', 0o040555) bootstr = b'boot\n' - facade.add_fp(BytesIO(bootstr), len(bootstr), '/dir1/boot', 0o040555) + facade.add_fp(io.BytesIO(bootstr), len(bootstr), '/dir1/boot', 0o040555) full_path = None for child in facade.list_children('/dir1'): @@ -715,7 +711,7 @@ def test_facade_rock_ridge_open_file_from_iso(): facade = iso.get_rock_ridge_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo', 0o040555) + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo', 0o040555) with facade.open_file_from_iso('/foo') as infp: assert(infp.read() == b'foo\n') @@ -738,7 +734,7 @@ def test_facade_udf_get_file_from_iso(tmpdir): facade = iso.get_udf_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo') + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo') foofile = os.path.join(str(tmpdir), 'foo') facade.get_file_from_iso(foofile, '/foo') @@ -755,9 +751,9 @@ def test_facade_udf_get_file_from_iso_fp(): facade = iso.get_udf_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo') + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo') - out = BytesIO() + out = io.BytesIO() facade.get_file_from_iso_fp(out, '/foo') assert(out.getvalue() == b'foo\n') @@ -771,9 +767,9 @@ def test_facade_udf_add_fp(): facade = iso.get_udf_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo') + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo') - out = BytesIO() + out = io.BytesIO() facade.get_file_from_iso_fp(out, '/foo') assert(out.getvalue() == b'foo\n') @@ -792,7 +788,7 @@ def test_facade_udf_add_file(tmpdir): facade.add_file(str(testout), '/foo') - out = BytesIO() + out = io.BytesIO() facade.get_file_from_iso_fp(out, '/foo') assert(out.getvalue() == b'foo\n') @@ -819,7 +815,7 @@ def test_facade_udf_rm_file(): facade = iso.get_udf_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo') + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo') rec = facade.get_record('/foo') assert(rec.is_file()) @@ -848,7 +844,7 @@ def test_facade_udf_add_symlink(): facade = iso.get_udf_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo') + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo') facade.add_symlink('/sym', 'foo') @@ -867,7 +863,7 @@ def test_facade_udf_list_children(): facade.add_directory('/dir1') bootstr = b'boot\n' - facade.add_fp(BytesIO(bootstr), len(bootstr), '/dir1/boot') + facade.add_fp(io.BytesIO(bootstr), len(bootstr), '/dir1/boot') full_path = None for child in facade.list_children('/dir1'): @@ -917,7 +913,7 @@ def test_facade_udf_open_file_from_iso(): facade = iso.get_udf_facade() foostr = b'foo\n' - facade.add_fp(BytesIO(foostr), len(foostr), '/foo') + facade.add_fp(io.BytesIO(foostr), len(foostr), '/foo') with facade.open_file_from_iso('/foo') as infp: assert(infp.read() == b'foo\n') diff --git a/tests/integration/test_hybrid.py b/tests/integration/test_hybrid.py index 8e5474b8..89c0cca4 100644 --- a/tests/integration/test_hybrid.py +++ b/tests/integration/test_hybrid.py @@ -1,13 +1,11 @@ -import pytest -import subprocess +import io import os +import subprocess import sys -try: - from cStringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO import shutil +import pytest + sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import pycdlib @@ -15,7 +13,7 @@ from test_common import * def do_a_test(iso, check_func): - out = BytesIO() + out = io.BytesIO() iso.write_fp(out) check_func(iso, len(out.getvalue())) @@ -58,7 +56,7 @@ def test_hybrid_onefile(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') do_a_test(iso, check_onefile) @@ -97,7 +95,7 @@ def test_hybrid_twofiles(tmpdir): iso.open(str(outfile)) barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/BAR.;1') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/BAR.;1') do_a_test(iso, check_twofiles) @@ -118,7 +116,7 @@ def test_hybrid_twofiles2(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') do_a_test(iso, check_twofiles) @@ -137,10 +135,10 @@ def test_hybrid_twofiles3(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/BAR.;1') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/BAR.;1') do_a_test(iso, check_twofiles) @@ -159,10 +157,10 @@ def test_hybrid_twofiles4(tmpdir): iso.open(str(outfile)) barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/BAR.;1') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/BAR.;1') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') do_a_test(iso, check_twofiles) @@ -321,7 +319,7 @@ def test_hybrid_onefileonedir2(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') do_a_test(iso, check_onefileonedir) @@ -342,7 +340,7 @@ def test_hybrid_onefileonedir3(tmpdir): iso.add_directory('/DIR1') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') do_a_test(iso, check_onefileonedir) @@ -361,7 +359,7 @@ def test_hybrid_onefileonedir4(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.add_directory('/DIR1') @@ -386,7 +384,7 @@ def test_hybrid_onefile_onedirwithfile(tmpdir): iso.add_directory('/DIR1') barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/DIR1/BAR.;1') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/DIR1/BAR.;1') do_a_test(iso, check_onefile_onedirwithfile) @@ -406,10 +404,10 @@ def test_hybrid_onefile_onedirwithfile2(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/DIR1/BAR.;1') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/DIR1/BAR.;1') do_a_test(iso, check_onefile_onedirwithfile) @@ -428,12 +426,12 @@ def test_hybrid_onefile_onedirwithfile3(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.add_directory('/DIR1') barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/DIR1/BAR.;1') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/DIR1/BAR.;1') do_a_test(iso, check_onefile_onedirwithfile) @@ -455,7 +453,7 @@ def test_hybrid_onefile_onedirwithfile4(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') do_a_test(iso, check_onefile_onedirwithfile) @@ -479,7 +477,7 @@ def test_hybrid_twoextentfile(tmpdir): outstr += struct.pack('=B', i) outstr += struct.pack('=B', 0) - iso.add_fp(BytesIO(outstr), len(outstr), '/BIGFILE.;1') + iso.add_fp(io.BytesIO(outstr), len(outstr), '/BIGFILE.;1') do_a_test(iso, check_twoextentfile) @@ -645,10 +643,10 @@ def test_hybrid_add_new_file_to_subdir(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/DIR1/BAR.;1') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/DIR1/BAR.;1') do_a_test(iso, check_onefile_onedirwithfile) @@ -668,7 +666,7 @@ def test_hybrid_eltorito_add(tmpdir): # Now add the eltorito stuff bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') do_a_test(iso, check_eltorito_nofiles) @@ -751,7 +749,7 @@ def test_hybrid_rr_onefile(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') do_a_test(iso, check_rr_onefile) @@ -813,10 +811,10 @@ def test_hybrid_rr_onefileonedirwithfile(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/DIR1/BAR.;1', rr_name='bar') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/DIR1/BAR.;1', rr_name='bar') do_a_test(iso, check_rr_onefileonedirwithfile) @@ -855,7 +853,7 @@ def test_hybrid_rr_and_joliet_onefile(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/foo') do_a_test(iso, check_joliet_and_rr_onefile) @@ -894,7 +892,7 @@ def test_hybrid_rr_and_eltorito_nofiles2(tmpdir): iso.open(str(outfile)) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') do_a_test(iso, check_rr_and_eltorito_nofiles) @@ -914,11 +912,11 @@ def test_hybrid_rr_and_eltorito_onefile(tmpdir): iso.open(str(outfile)) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') do_a_test(iso, check_rr_and_eltorito_onefile) @@ -939,7 +937,7 @@ def test_hybrid_rr_and_eltorito_onefile2(tmpdir): iso.open(str(outfile)) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') do_a_test(iso, check_rr_and_eltorito_onefile) @@ -962,7 +960,7 @@ def test_hybrid_rr_and_eltorito_onefile3(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') do_a_test(iso, check_rr_and_eltorito_onefile) @@ -981,7 +979,7 @@ def test_hybrid_rr_and_eltorito_onedir(tmpdir): iso.open(str(outfile)) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') iso.add_directory('/DIR1', rr_name='dir1') @@ -1005,7 +1003,7 @@ def test_hybrid_rr_and_eltorito_onedir2(tmpdir): iso.add_directory('/DIR1', rr_name='dir1') bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') do_a_test(iso, check_rr_and_eltorito_onedir) @@ -1026,7 +1024,7 @@ def test_hybrid_rr_and_eltorito_onedir3(tmpdir): iso.open(str(outfile)) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') do_a_test(iso, check_rr_and_eltorito_onedir) @@ -1138,7 +1136,7 @@ def test_hybrid_joliet_and_eltorito_onefile(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') do_a_test(iso, check_joliet_and_eltorito_onefile) @@ -1157,10 +1155,10 @@ def test_hybrid_joliet_and_eltorito_onefile2(tmpdir): iso.open(str(outfile)) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') @@ -1183,7 +1181,7 @@ def test_hybrid_joliet_and_eltorito_onefile3(tmpdir): iso.open(str(outfile)) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') @@ -1205,7 +1203,7 @@ def test_hybrid_joliet_and_eltorito_onedir(tmpdir): iso.open(str(outfile)) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') @@ -1247,7 +1245,7 @@ def test_hybrid_isohybrid(tmpdir): # Add Eltorito isolinuxstr = b'\x00'*0x40 + b'\xfb\xc0\x78\x70' - iso.add_fp(BytesIO(isolinuxstr), len(isolinuxstr), '/ISOLINUX.BIN;1') + iso.add_fp(io.BytesIO(isolinuxstr), len(isolinuxstr), '/ISOLINUX.BIN;1') iso.add_eltorito('/ISOLINUX.BIN;1', '/BOOT.CAT;1', boot_load_size=4) # Now add the syslinux iso.add_isohybrid() @@ -1343,7 +1341,7 @@ def test_hybrid_joliet_rr_and_eltorito_nofiles2(tmpdir): iso.open(str(outfile)) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') @@ -1367,7 +1365,7 @@ def test_hybrid_joliet_rr_and_eltorito_onefile(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/foo') do_a_test(iso, check_joliet_rr_and_eltorito_onefile) @@ -1388,7 +1386,7 @@ def test_hybrid_joliet_rr_and_eltorito_onefile2(tmpdir): iso.open(str(outfile)) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') @@ -1409,10 +1407,10 @@ def test_hybrid_joliet_rr_and_eltorito_onefile3(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/foo') bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') @@ -1434,7 +1432,7 @@ def test_hybrid_joliet_rr_and_eltorito_onedir(tmpdir): iso.open(str(outfile)) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') @@ -1455,7 +1453,7 @@ def test_hybrid_joliet_rr_and_eltorito_onedir2(tmpdir): iso.open(str(outfile)) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') @@ -1577,7 +1575,7 @@ def test_hybrid_xa_onefile(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') do_a_test(iso, check_xa_onefile) @@ -1654,7 +1652,7 @@ def test_hybrid_xa_joliet_onefile(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') do_a_test(iso, check_xa_joliet_onefile) @@ -1716,7 +1714,7 @@ def test_hybrid_isolevel4_eltorito(tmpdir): iso.open(str(outfile)) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/boot') iso.add_eltorito('/boot', '/boot.cat') @@ -1762,7 +1760,7 @@ def test_hybrid_eltorito_multi_boot(tmpdir): iso.open(str(outfile)) boot2str = b'boot2\n' - iso.add_fp(BytesIO(boot2str), len(boot2str), '/boot2') + iso.add_fp(io.BytesIO(boot2str), len(boot2str), '/boot2') iso.add_eltorito('/boot2', '/boot.cat') do_a_test(iso, check_eltorito_multi_boot) @@ -1785,7 +1783,7 @@ def test_hybrid_eltorito_multi_boot_boot_info(tmpdir): iso.open(str(outfile)) boot2str = b'boot2\n' - iso.add_fp(BytesIO(boot2str), len(boot2str), '/boot2') + iso.add_fp(io.BytesIO(boot2str), len(boot2str), '/boot2') iso.add_eltorito('/boot2', '/boot.cat', boot_info_table=True) do_a_test(iso, check_eltorito_multi_boot) @@ -1808,7 +1806,7 @@ def test_hybrid_eltorito_multi_boot_hard_link(tmpdir): iso.open(str(outfile)) boot2str = b'boot2\n' - iso.add_fp(BytesIO(boot2str), len(boot2str), '/boot2') + iso.add_fp(io.BytesIO(boot2str), len(boot2str), '/boot2') iso.add_hard_link(iso_new_path='/bootlink', iso_old_path='/boot2') iso.add_eltorito('/boot2', '/boot.cat') @@ -1835,7 +1833,7 @@ def test_hybrid_modify_in_place_onefile(tmpdir): iso = pycdlib.PyCdlib() iso.open(str(outfile), 'r+b') foostr = b'foo\n' - iso.modify_file_in_place(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.modify_file_in_place(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.close() # Now re-open it and check things out. @@ -1854,7 +1852,7 @@ def test_hybrid_joliet_modify_in_place_onefile(tmpdir): iso = pycdlib.PyCdlib() iso.open(str(outfile), 'r+b') foostr = b'foo\n' - iso.modify_file_in_place(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.modify_file_in_place(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') iso.close() # Now re-open it and check things out. @@ -1873,7 +1871,7 @@ def test_hybrid_modify_in_place_iso_level4_onefile(tmpdir): iso = pycdlib.PyCdlib() iso.open(str(outfile), 'r+b') foostr = b'foo\n' - iso.modify_file_in_place(BytesIO(foostr), len(foostr), '/foo') + iso.modify_file_in_place(io.BytesIO(foostr), len(foostr), '/foo') iso.close() # Now open up the ISO with pycdlib and modify it. @@ -1892,7 +1890,7 @@ def test_hybrid_modify_in_place_udf(tmpdir): iso = pycdlib.PyCdlib() iso.open(str(outfile), 'r+b') foostr = b'foo\n' - iso.modify_file_in_place(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.modify_file_in_place(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.close() # Now open up the ISO with pycdlib and modify it. @@ -1911,7 +1909,7 @@ def test_hybrid_modify_in_place_udf_shrink(tmpdir): iso = pycdlib.PyCdlib() iso.open(str(outfile), 'r+b') foostr = b'foo\n' - iso.modify_file_in_place(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.modify_file_in_place(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.close() # Now open up the ISO with pycdlib and modify it. @@ -1967,7 +1965,7 @@ def test_hybrid_modify_in_place_not_initialized(tmpdir): foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.modify_file_in_place(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/foo') + iso.modify_file_in_place(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/foo') assert(str(excinfo.value) == 'This object is not initialized; call either open() or new() to create an ISO') def test_hybrid_modify_in_place_read_only(tmpdir): @@ -1987,7 +1985,7 @@ def test_hybrid_modify_in_place_read_only(tmpdir): foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.modify_file_in_place(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/foo') + iso.modify_file_in_place(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/foo') assert(str(excinfo.value) == 'To modify a file in place, the original ISO must have been opened in a write mode (r+, w, or a)') iso.close() @@ -2234,7 +2232,7 @@ def test_hybrid_addfile_not_initialized(tmpdir): foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') assert(str(excinfo.value) == 'This object is not initialized; call either open() or new() to create an ISO') def test_hybrid_modify_in_place_bad_path(tmpdir): @@ -2253,7 +2251,7 @@ def test_hybrid_modify_in_place_bad_path(tmpdir): foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.modify_file_in_place(BytesIO(foostr), len(foostr), 'foo', rr_name='foo', joliet_path='/foo') + iso.modify_file_in_place(io.BytesIO(foostr), len(foostr), 'foo', rr_name='foo', joliet_path='/foo') assert(str(excinfo.value) == 'Must be a path starting with /') iso.close() @@ -2274,7 +2272,7 @@ def test_hybrid_modify_in_place_grow_file(tmpdir): foostr = b'f'*2049 with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.modify_file_in_place(BytesIO(foostr), len(foostr), '/foo') + iso.modify_file_in_place(io.BytesIO(foostr), len(foostr), '/foo') assert(str(excinfo.value) == 'When modifying a file in-place, the number of extents for a file cannot change!') iso.close() @@ -2296,7 +2294,7 @@ def test_hybrid_modify_in_place_modify_dir(tmpdir): foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.modify_file_in_place(BytesIO(foostr), len(foostr), '/dir1') + iso.modify_file_in_place(io.BytesIO(foostr), len(foostr), '/dir1') assert(str(excinfo.value) == 'Cannot modify a directory with modify_file_in_place') iso.close() @@ -2335,7 +2333,7 @@ def test_hybrid_joliet_isolevel4_2(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/foo', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/foo', joliet_path='/foo') do_a_test(iso, check_joliet_isolevel4) @@ -2354,7 +2352,7 @@ def test_hybrid_joliet_isolevel4_3(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/foo', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/foo', joliet_path='/foo') iso.add_directory('/dir1', joliet_path='/dir1') @@ -2402,7 +2400,7 @@ def test_hybrid_modify_in_place_dirrecord_spillover(tmpdir): iso = pycdlib.PyCdlib() iso.open(str(outfile), 'r+b') foostr = b'foo\n' - iso.modify_file_in_place(BytesIO(foostr), len(foostr), '/DIR1/FOO48.;1') + iso.modify_file_in_place(io.BytesIO(foostr), len(foostr), '/DIR1/FOO48.;1') iso.close() # Now open up the ISO with pycdlib and modify it. @@ -2424,7 +2422,7 @@ def test_hybrid_modify_in_place_dirrecord_spillover2(tmpdir): iso = pycdlib.PyCdlib() iso.open(str(outfile), 'r+b') foostr = b'foo\n' - iso.modify_file_in_place(BytesIO(foostr), len(foostr), '/DIR1/FOO40.;1') + iso.modify_file_in_place(io.BytesIO(foostr), len(foostr), '/DIR1/FOO40.;1') iso.close() # Now open up the ISO with pycdlib and modify it. @@ -2591,7 +2589,7 @@ def test_hybrid_isohybrid_file_before(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') do_a_test(iso, check_isohybrid_file_before) @@ -2794,7 +2792,7 @@ def test_hybrid_rr_hidden_relocated(tmpdir): iso.add_directory('/DIR1/DIR2/DIR3/DIR4/DIR5/DIR6/DIR7/DIR8/DIR9', rr_name='dir9') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/DIR1/DIR2/DIR3/DIR4/DIR5/DIR6/DIR7/DIR8/DIR9/FOO.;1', 'foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/DIR1/DIR2/DIR3/DIR4/DIR5/DIR6/DIR7/DIR8/DIR9/FOO.;1', 'foo') do_a_test(iso, check_rr_relocated_hidden) @@ -3015,7 +3013,7 @@ def test_hybrid_udf_get_from_iso_zero_udf_file_entry(tmpdir): iso.open(str(outfile)) - out = BytesIO() + out = io.BytesIO() with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.get_file_from_iso_fp(out, udf_path='/foo') assert(str(excinfo.value) == 'Cannot get the contents of an empty UDF File Entry') @@ -3044,9 +3042,9 @@ def test_hybrid_boot_record_retain_system_use(tmpdir): iso.open(str(outfile)) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') - out = BytesIO() + out = io.BytesIO() iso.write_fp(out) out.seek(system_use_offset) diff --git a/tests/integration/test_new.py b/tests/integration/test_new.py index 3e8c7f06..50e1b4cd 100644 --- a/tests/integration/test_new.py +++ b/tests/integration/test_new.py @@ -1,17 +1,12 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import - import io -import pytest import os import sys -try: - from cStringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO import struct +import pytest + sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import pycdlib @@ -20,7 +15,7 @@ def do_a_test(iso, check_func, tmpdir=None): if tmpdir is None: - out = BytesIO() + out = io.BytesIO() def do_getlen(obj): return len(obj.getvalue()) @@ -65,7 +60,7 @@ def test_new_onefile(): iso.new() # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') do_a_test(iso, check_onefile) @@ -88,9 +83,9 @@ def test_new_twofiles(): iso.new() # Add new files. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/BAR.;1') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/BAR.;1') do_a_test(iso, check_twofiles) @@ -102,9 +97,9 @@ def test_new_twofiles2(): iso.new() # Add new files. barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/BAR.;1') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/BAR.;1') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') do_a_test(iso, check_twofiles) @@ -142,7 +137,7 @@ def test_new_onefileonedir(): iso.new() # Add new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') # Add new directory. iso.add_directory('/DIR1') @@ -158,7 +153,7 @@ def test_new_onefileonedir2(): iso.add_directory('/DIR1') # Add new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') do_a_test(iso, check_onefileonedir) @@ -170,12 +165,12 @@ def test_new_onefile_onedirwithfile(): iso.new() # Add new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') # Add new directory. iso.add_directory('/DIR1') # Add new sub-file. barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/DIR1/BAR.;1') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/DIR1/BAR.;1') do_a_test(iso, check_onefile_onedirwithfile) @@ -241,7 +236,7 @@ def test_new_twoextentfile(): outstr += struct.pack('=B', i) outstr += struct.pack('=B', 0) - iso.add_fp(BytesIO(outstr), len(outstr), '/BIGFILE.;1') + iso.add_fp(io.BytesIO(outstr), len(outstr), '/BIGFILE.;1') do_a_test(iso, check_twoextentfile) @@ -269,7 +264,7 @@ def test_new_twoleveldeepfile(): iso.add_directory('/DIR1') iso.add_directory('/DIR1/SUBDIR1') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/DIR1/SUBDIR1/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/DIR1/SUBDIR1/FOO.;1') do_a_test(iso, check_twoleveldeepfile) @@ -306,7 +301,7 @@ def test_new_toodeepdir(): assert(str(excinfo.value) == 'Directory levels too deep (maximum is 7)') # Now make sure we can re-open the written ISO. - out = BytesIO() + out = io.BytesIO() iso.write_fp(out) pycdlib.PyCdlib().open_fp(out) @@ -326,11 +321,11 @@ def test_new_toodeepfile(): iso.add_directory('/DIR1/DIR2/DIR3/DIR4/DIR5/DIR6/DIR7') foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.add_fp(BytesIO(foostr), len(foostr), '/DIR1/DIR2/DIR3/DIR4/DIR5/DIR6/DIR7/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/DIR1/DIR2/DIR3/DIR4/DIR5/DIR6/DIR7/FOO.;1') assert(str(excinfo.value) == 'Directory levels too deep (maximum is 7)') # Now make sure we can re-open the written ISO. - out = BytesIO() + out = io.BytesIO() iso.write_fp(out) pycdlib.PyCdlib().open_fp(out) @@ -343,11 +338,11 @@ def test_new_removefile(): # Add new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') # Add second new file. barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/BAR.;1') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/BAR.;1') # Remove the second file. iso.rm_file('/BAR.;1') @@ -363,7 +358,7 @@ def test_new_removedir(): # Add new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') # Add new directory. iso.add_directory('/DIR1') @@ -381,7 +376,7 @@ def test_new_eltorito(): iso.new() bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') do_a_test(iso, check_eltorito_nofiles) @@ -394,7 +389,7 @@ def test_new_rm_eltorito(): iso.new() bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') iso.rm_eltorito() @@ -410,11 +405,11 @@ def test_new_eltorito_twofile(): iso.new() bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AA.;1') + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AA.;1') do_a_test(iso, check_eltorito_twofile) @@ -436,7 +431,7 @@ def test_new_rr_onefile(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') do_a_test(iso, check_rr_onefile) @@ -449,11 +444,11 @@ def test_new_rr_twofile(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') # Add a new file. barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/BAR.;1', rr_name='bar') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/BAR.;1', rr_name='bar') do_a_test(iso, check_rr_twofile) @@ -466,7 +461,7 @@ def test_new_rr_onefileonedir(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') # Add new directory. iso.add_directory('/DIR1', rr_name='dir1') @@ -482,14 +477,14 @@ def test_new_rr_onefileonedirwithfile(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') # Add new directory. iso.add_directory('/DIR1', rr_name='dir1') # Add a new file. barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/DIR1/BAR.;1', rr_name='bar') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/DIR1/BAR.;1', rr_name='bar') do_a_test(iso, check_rr_onefileonedirwithfile) @@ -502,7 +497,7 @@ def test_new_rr_symlink(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') iso.add_symlink('/SYM.;1', 'sym', 'foo') @@ -520,7 +515,7 @@ def test_new_rr_symlink2(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/DIR1/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/DIR1/FOO.;1', rr_name='foo') iso.add_symlink('/SYM.;1', 'sym', 'dir1/foo') @@ -567,7 +562,7 @@ def test_new_rr_verylongname(): iso.new(rock_ridge='1.09') aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='a'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='a'*RR_MAX_FILENAME_LENGTH) do_a_test(iso, check_rr_verylongname) @@ -579,7 +574,7 @@ def test_new_rr_verylongname_joliet(): iso.new(rock_ridge='1.09', joliet=3) aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='a'*RR_MAX_FILENAME_LENGTH, joliet_path='/'+'a'*64) + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='a'*RR_MAX_FILENAME_LENGTH, joliet_path='/'+'a'*64) do_a_test(iso, check_rr_verylongname_joliet) @@ -591,25 +586,25 @@ def test_new_rr_manylongname(): iso.new(rock_ridge='1.09') aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='a'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='a'*RR_MAX_FILENAME_LENGTH) bbstr = b'bb\n' - iso.add_fp(BytesIO(bbstr), len(bbstr), '/BBBBBBBB.;1', rr_name='b'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(bbstr), len(bbstr), '/BBBBBBBB.;1', rr_name='b'*RR_MAX_FILENAME_LENGTH) ccstr = b'cc\n' - iso.add_fp(BytesIO(ccstr), len(ccstr), '/CCCCCCCC.;1', rr_name='c'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(ccstr), len(ccstr), '/CCCCCCCC.;1', rr_name='c'*RR_MAX_FILENAME_LENGTH) ddstr = b'dd\n' - iso.add_fp(BytesIO(ddstr), len(ddstr), '/DDDDDDDD.;1', rr_name='d'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(ddstr), len(ddstr), '/DDDDDDDD.;1', rr_name='d'*RR_MAX_FILENAME_LENGTH) eestr = b'ee\n' - iso.add_fp(BytesIO(eestr), len(eestr), '/EEEEEEEE.;1', rr_name='e'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(eestr), len(eestr), '/EEEEEEEE.;1', rr_name='e'*RR_MAX_FILENAME_LENGTH) ffstr = b'ff\n' - iso.add_fp(BytesIO(ffstr), len(ffstr), '/FFFFFFFF.;1', rr_name='f'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(ffstr), len(ffstr), '/FFFFFFFF.;1', rr_name='f'*RR_MAX_FILENAME_LENGTH) ggstr = b'gg\n' - iso.add_fp(BytesIO(ggstr), len(ggstr), '/GGGGGGGG.;1', rr_name='g'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(ggstr), len(ggstr), '/GGGGGGGG.;1', rr_name='g'*RR_MAX_FILENAME_LENGTH) do_a_test(iso, check_rr_manylongname) @@ -621,28 +616,28 @@ def test_new_rr_manylongname2(): iso.new(rock_ridge='1.09') aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='a'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='a'*RR_MAX_FILENAME_LENGTH) bbstr = b'bb\n' - iso.add_fp(BytesIO(bbstr), len(bbstr), '/BBBBBBBB.;1', rr_name='b'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(bbstr), len(bbstr), '/BBBBBBBB.;1', rr_name='b'*RR_MAX_FILENAME_LENGTH) ccstr = b'cc\n' - iso.add_fp(BytesIO(ccstr), len(ccstr), '/CCCCCCCC.;1', rr_name='c'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(ccstr), len(ccstr), '/CCCCCCCC.;1', rr_name='c'*RR_MAX_FILENAME_LENGTH) ddstr = b'dd\n' - iso.add_fp(BytesIO(ddstr), len(ddstr), '/DDDDDDDD.;1', rr_name='d'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(ddstr), len(ddstr), '/DDDDDDDD.;1', rr_name='d'*RR_MAX_FILENAME_LENGTH) eestr = b'ee\n' - iso.add_fp(BytesIO(eestr), len(eestr), '/EEEEEEEE.;1', rr_name='e'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(eestr), len(eestr), '/EEEEEEEE.;1', rr_name='e'*RR_MAX_FILENAME_LENGTH) ffstr = b'ff\n' - iso.add_fp(BytesIO(ffstr), len(ffstr), '/FFFFFFFF.;1', rr_name='f'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(ffstr), len(ffstr), '/FFFFFFFF.;1', rr_name='f'*RR_MAX_FILENAME_LENGTH) ggstr = b'gg\n' - iso.add_fp(BytesIO(ggstr), len(ggstr), '/GGGGGGGG.;1', rr_name='g'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(ggstr), len(ggstr), '/GGGGGGGG.;1', rr_name='g'*RR_MAX_FILENAME_LENGTH) hhstr = b'hh\n' - iso.add_fp(BytesIO(hhstr), len(hhstr), '/HHHHHHHH.;1', rr_name='h'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(hhstr), len(hhstr), '/HHHHHHHH.;1', rr_name='h'*RR_MAX_FILENAME_LENGTH) do_a_test(iso, check_rr_manylongname2) @@ -654,7 +649,7 @@ def test_new_rr_verylongnameandsymlink(): iso.new(rock_ridge='1.09') aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='a'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='a'*RR_MAX_FILENAME_LENGTH) iso.add_symlink('/BBBBBBBB.;1', 'b'*RR_MAX_FILENAME_LENGTH, 'a'*RR_MAX_FILENAME_LENGTH) @@ -668,20 +663,20 @@ def test_new_alternating_subdir(): iso.new() ddstr = b'dd\n' - iso.add_fp(BytesIO(ddstr), len(ddstr), '/DD.;1') + iso.add_fp(io.BytesIO(ddstr), len(ddstr), '/DD.;1') bbstr = b'bb\n' - iso.add_fp(BytesIO(bbstr), len(bbstr), '/BB.;1') + iso.add_fp(io.BytesIO(bbstr), len(bbstr), '/BB.;1') iso.add_directory('/CC') iso.add_directory('/AA') subdirfile1 = b'sub1\n' - iso.add_fp(BytesIO(subdirfile1), len(subdirfile1), '/AA/SUB1.;1') + iso.add_fp(io.BytesIO(subdirfile1), len(subdirfile1), '/AA/SUB1.;1') subdirfile2 = b'sub2\n' - iso.add_fp(BytesIO(subdirfile2), len(subdirfile2), '/CC/SUB2.;1') + iso.add_fp(io.BytesIO(subdirfile2), len(subdirfile2), '/CC/SUB2.;1') do_a_test(iso, check_alternating_subdir) @@ -713,7 +708,7 @@ def test_new_joliet_onefile(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') do_a_test(iso, check_joliet_onefile) @@ -725,7 +720,7 @@ def test_new_joliet_onefileonedir(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') iso.add_directory('/DIR1', joliet_path='/dir1') @@ -748,7 +743,7 @@ def test_new_joliet_and_rr_onefile(): iso.new(joliet=3, rock_ridge='1.09') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/foo') do_a_test(iso, check_joliet_and_rr_onefile) @@ -772,7 +767,7 @@ def test_new_rr_and_eltorito_nofiles(): iso.new(rock_ridge='1.09') bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') do_a_test(iso, check_rr_and_eltorito_nofiles) @@ -785,11 +780,11 @@ def test_new_rr_and_eltorito_onefile(): iso.new(rock_ridge='1.09') bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') do_a_test(iso, check_rr_and_eltorito_onefile) @@ -801,7 +796,7 @@ def test_new_rr_and_eltorito_onedir(): iso.new(rock_ridge='1.09') bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') iso.add_directory('/DIR1', rr_name='dir1') @@ -818,7 +813,7 @@ def test_new_rr_and_eltorito_onedir2(): iso.add_directory('/DIR1', rr_name='dir1') bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') do_a_test(iso, check_rr_and_eltorito_onedir) @@ -831,7 +826,7 @@ def test_new_joliet_and_eltorito_nofiles(): iso.new(joliet=3) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') do_a_test(iso, check_joliet_and_eltorito_nofiles) @@ -844,11 +839,11 @@ def test_new_joliet_and_eltorito_onefile(): iso.new(joliet=3) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') do_a_test(iso, check_joliet_and_eltorito_onefile) @@ -860,7 +855,7 @@ def test_new_joliet_and_eltorito_onedir(): iso.new(joliet=3) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') iso.add_directory('/DIR1', joliet_path='/dir1') @@ -875,7 +870,7 @@ def test_new_isohybrid(): iso.new() # Add Eltorito isolinuxstr = b'\x00'*0x40 + b'\xfb\xc0\x78\x70' - iso.add_fp(BytesIO(isolinuxstr), len(isolinuxstr), '/ISOLINUX.BIN;1') + iso.add_fp(io.BytesIO(isolinuxstr), len(isolinuxstr), '/ISOLINUX.BIN;1') iso.add_eltorito('/ISOLINUX.BIN;1', '/BOOT.CAT;1', boot_load_size=4) # Now add the syslinux data iso.add_isohybrid() @@ -890,11 +885,11 @@ def test_new_isohybrid_mac(): iso.new() # Add Eltorito isolinuxstr = b'\x00'*0x40 + b'\xfb\xc0\x78\x70' - iso.add_fp(BytesIO(isolinuxstr), len(isolinuxstr), '/ISOLINUX.BIN;1') + iso.add_fp(io.BytesIO(isolinuxstr), len(isolinuxstr), '/ISOLINUX.BIN;1') efibootstr = b'a' - iso.add_fp(BytesIO(efibootstr), len(efibootstr), '/EFIBOOT.IMG;1') + iso.add_fp(io.BytesIO(efibootstr), len(efibootstr), '/EFIBOOT.IMG;1') macbootstr = b'b' - iso.add_fp(BytesIO(macbootstr), len(macbootstr), '/MACBOOT.IMG;1') + iso.add_fp(io.BytesIO(macbootstr), len(macbootstr), '/MACBOOT.IMG;1') iso.add_eltorito('/ISOLINUX.BIN;1', '/BOOT.CAT;1', boot_load_size=4, boot_info_table=True) iso.add_eltorito('/MACBOOT.IMG;1', efi=True) @@ -910,9 +905,9 @@ def test_new_isohybrid_uefi(): iso.new() # Add Eltorito isolinuxstr = b'\x00'*0x40 + b'\xfb\xc0\x78\x70' - iso.add_fp(BytesIO(isolinuxstr), len(isolinuxstr), '/ISOLINUX.BIN;1') + iso.add_fp(io.BytesIO(isolinuxstr), len(isolinuxstr), '/ISOLINUX.BIN;1') efibootstr = b'a' - iso.add_fp(BytesIO(efibootstr), len(efibootstr), '/EFIBOOT.IMG;1') + iso.add_fp(io.BytesIO(efibootstr), len(efibootstr), '/EFIBOOT.IMG;1') iso.add_eltorito('/ISOLINUX.BIN;1', '/BOOT.CAT;1', boot_load_size=4, boot_info_table=True) iso.add_eltorito('/EFIBOOT.IMG;1', efi=True) @@ -929,11 +924,11 @@ def test_new_isohybrid_mac_uefi(): iso.new() # Add Eltorito isolinuxstr = b'\x00'*0x40 + b'\xfb\xc0\x78\x70' - iso.add_fp(BytesIO(isolinuxstr), len(isolinuxstr), '/ISOLINUX.BIN;1') + iso.add_fp(io.BytesIO(isolinuxstr), len(isolinuxstr), '/ISOLINUX.BIN;1') efibootstr = b'a' - iso.add_fp(BytesIO(efibootstr), len(efibootstr), '/EFIBOOT.IMG;1') + iso.add_fp(io.BytesIO(efibootstr), len(efibootstr), '/EFIBOOT.IMG;1') macbootstr = b'b' - iso.add_fp(BytesIO(macbootstr), len(macbootstr), '/MACBOOT.IMG;1') + iso.add_fp(io.BytesIO(macbootstr), len(macbootstr), '/MACBOOT.IMG;1') iso.add_eltorito('/ISOLINUX.BIN;1', '/BOOT.CAT;1', boot_load_size=4, boot_info_table=True) iso.add_eltorito('/MACBOOT.IMG;1', efi=True) @@ -951,7 +946,7 @@ def test_new_joliet_rr_and_eltorito_nofiles(): iso.new(rock_ridge='1.09', joliet=3) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') do_a_test(iso, check_joliet_rr_and_eltorito_nofiles) @@ -964,11 +959,11 @@ def test_new_joliet_rr_and_eltorito_onefile(): iso.new(rock_ridge='1.09', joliet=3) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/foo') do_a_test(iso, check_joliet_rr_and_eltorito_onefile) @@ -980,7 +975,7 @@ def test_new_joliet_rr_and_eltorito_onedir(): iso.new(rock_ridge='1.09', joliet=3) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') iso.add_directory('/DIR1', rr_name='dir1', joliet_path='/dir1') @@ -995,7 +990,7 @@ def test_new_rr_rmfile(): iso.new(rock_ridge='1.09') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') iso.rm_file('/FOO.;1', rr_name='foo') @@ -1022,7 +1017,7 @@ def test_new_joliet_rmfile(): iso.new(joliet=3) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') iso.rm_file('/BOOT.;1', joliet_path='/boot') @@ -1076,7 +1071,7 @@ def test_new_xa_onefile(): iso.new(xa=True) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') do_a_test(iso, check_xa_onefile) @@ -1125,7 +1120,7 @@ def test_new_xa_joliet_onefile(): iso.new(joliet=3, xa=True) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') do_a_test(iso, check_xa_joliet_onefile) @@ -1157,7 +1152,7 @@ def test_new_isolevel4_onefile(): iso.new(interchange_level=4) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/foo') do_a_test(iso, check_isolevel4_onefile) @@ -1180,7 +1175,7 @@ def test_new_isolevel4_eltorito(): iso.new(interchange_level=4) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/boot') iso.add_eltorito('/boot', '/boot.cat') do_a_test(iso, check_isolevel4_eltorito) @@ -1202,14 +1197,14 @@ def test_new_everything(): iso.add_directory('/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8', rr_name='dir8', joliet_path='/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8') bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/boot', rr_name='boot', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/boot', rr_name='boot', joliet_path='/boot') iso.add_eltorito('/boot', '/boot.cat', boot_info_table=True) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/foo', rr_name='foo', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/foo', rr_name='foo', joliet_path='/foo') barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/bar', rr_name='bar', joliet_path='/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/bar') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/bar', rr_name='bar', joliet_path='/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/bar') iso.add_symlink('/sym', 'sym', 'foo', joliet_path='/sym') @@ -1235,7 +1230,7 @@ def test_new_rr_xa_onefile(): iso.new(rock_ridge='1.09', xa=True) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') do_a_test(iso, check_rr_xa_onefile) @@ -1258,7 +1253,7 @@ def test_new_rr_joliet_symlink(): iso.new(rock_ridge='1.09', joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/foo') iso.add_symlink('/SYM.;1', 'sym', 'foo', joliet_path='/sym') @@ -1300,11 +1295,11 @@ def test_new_eltorito_multi_boot(): iso.new(interchange_level=4) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/boot') iso.add_eltorito('/boot', '/boot.cat') boot2str = b'boot2\n' - iso.add_fp(BytesIO(boot2str), len(boot2str), '/boot2') + iso.add_fp(io.BytesIO(boot2str), len(boot2str), '/boot2') iso.add_eltorito('/boot2', '/boot.cat') do_a_test(iso, check_eltorito_multi_boot) @@ -1317,7 +1312,7 @@ def test_new_eltorito_boot_table(): iso.new(interchange_level=4) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/boot') iso.add_eltorito('/boot', '/boot.cat', boot_info_table=True) do_a_test(iso, check_eltorito_boot_info_table) @@ -1330,7 +1325,7 @@ def test_new_eltorito_boot_table_large(): iso.new(interchange_level=4) bootstr = b'boot'*20 - iso.add_fp(BytesIO(bootstr), len(bootstr), '/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/boot') iso.add_eltorito('/boot', '/boot.cat', boot_info_table=True) do_a_test(iso, check_eltorito_boot_info_table_large) @@ -1343,7 +1338,7 @@ def test_new_hard_link(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') # Add a directory. iso.add_directory('/DIR1') @@ -1382,7 +1377,7 @@ def test_new_add_fp_not_initialized(): foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') assert(str(excinfo.value) == 'This object is not initialized; call either open() or new() to create an ISO') def test_new_add_fp_no_rr_name(): @@ -1392,7 +1387,7 @@ def test_new_add_fp_no_rr_name(): foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') assert(str(excinfo.value) == 'Rock Ridge name must be supplied for a Rock Ridge new path') iso.close() @@ -1404,7 +1399,7 @@ def test_new_add_fp_rr_name(): foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') assert(str(excinfo.value) == 'A rock ridge name can only be specified for a rock-ridge ISO') iso.close() @@ -1415,7 +1410,7 @@ def test_new_add_fp_no_joliet_name(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') do_a_test(iso, check_onefile_joliet_no_file) @@ -1428,7 +1423,7 @@ def test_new_add_fp_joliet_name(): foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') assert(str(excinfo.value) == 'A Joliet path can only be specified for a Joliet ISO') iso.close() @@ -1440,7 +1435,7 @@ def test_new_add_fp_joliet_name_too_long(): foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/'+'a'*65) + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/'+'a'*65) assert(str(excinfo.value) == 'Joliet names can be a maximum of 64 characters') iso.close() @@ -1486,7 +1481,7 @@ def test_new_add_isohybrid_bad_boot_load_size(): iso.new() isolinuxstr = b'\x00'*0x801 - iso.add_fp(BytesIO(isolinuxstr), len(isolinuxstr), '/ISOLINUX.BIN;1') + iso.add_fp(io.BytesIO(isolinuxstr), len(isolinuxstr), '/ISOLINUX.BIN;1') iso.add_eltorito('/ISOLINUX.BIN;1', '/BOOT.CAT;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: @@ -1502,7 +1497,7 @@ def test_new_add_isohybrid_bad_file_signature(): # Add a new file. isolinuxstr = b'\x00'*0x44 - iso.add_fp(BytesIO(isolinuxstr), len(isolinuxstr), '/ISOLINUX.BIN;1') + iso.add_fp(io.BytesIO(isolinuxstr), len(isolinuxstr), '/ISOLINUX.BIN;1') iso.add_eltorito('/ISOLINUX.BIN;1', '/BOOT.CAT;1', boot_load_size=4) with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.add_isohybrid() @@ -1566,7 +1561,7 @@ def test_new_rr_symlink_no_rr(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.add_symlink('/SYM.;1', 'sym', 'foo') @@ -1620,7 +1615,7 @@ def test_new_write_fp_not_initialized(): # Create a new ISO. iso = pycdlib.PyCdlib() - out = BytesIO() + out = io.BytesIO() with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.write_fp(out) assert(str(excinfo.value) == 'This object is not initialized; call either open() or new() to create an ISO') @@ -1647,7 +1642,7 @@ def test_new_joliet_isolevel4(): iso.new(interchange_level=4, joliet=3) # Add new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/foo', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/foo', joliet_path='/foo') # Add new directory. iso.add_directory('/dir1', joliet_path='/dir1') @@ -1661,7 +1656,7 @@ def test_new_eltorito_hide(): iso.new() bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') iso.rm_hard_link(iso_path='/BOOT.CAT;1') @@ -1675,7 +1670,7 @@ def test_new_eltorito_nofiles_hide_joliet(): iso.new(joliet=3) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') iso.rm_hard_link(joliet_path='/boot.cat') iso.rm_hard_link(iso_path='/BOOT.CAT;1') @@ -1690,7 +1685,7 @@ def test_new_eltorito_nofiles_hide_joliet_only(): iso.new(joliet=3) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') # After add_fp: # boot - 1 link (1 Joliet) iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') @@ -1712,7 +1707,7 @@ def test_new_eltorito_nofiles_hide_iso_only(): iso.new(joliet=3) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') iso.rm_hard_link(iso_path='/BOOT.CAT;1') @@ -1725,7 +1720,7 @@ def test_new_hard_link_reshuffle(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.add_hard_link(iso_new_path='/BAR.;1', iso_old_path='/FOO.;1') @@ -1776,7 +1771,7 @@ def test_new_invalid_filename_character(): # Add a new file. foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.add_fp(BytesIO(foostr), len(foostr), '/FO#.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FO#.;1') assert(str(excinfo.value) == 'ISO9660 filenames must consist of characters A-Z, 0-9, and _') def test_new_invalid_filename_semicolons(): @@ -1786,7 +1781,7 @@ def test_new_invalid_filename_semicolons(): # Add a new file. foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.add_fp(BytesIO(foostr), len(foostr), '/FO0;1.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FO0;1.;1') assert(str(excinfo.value) == 'ISO9660 filenames must contain exactly one semicolon') def test_new_invalid_filename_version(): @@ -1796,7 +1791,7 @@ def test_new_invalid_filename_version(): # Add a new file. foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;32768') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;32768') assert(str(excinfo.value) == 'ISO9660 filenames must have a version between 1 and 32767') def test_new_invalid_filename_dotonly(): @@ -1806,7 +1801,7 @@ def test_new_invalid_filename_dotonly(): # Add a new file. foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.add_fp(BytesIO(foostr), len(foostr), '/.') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/.') assert(str(excinfo.value) == 'ISO9660 filenames must have a non-empty name or extension') def test_new_invalid_filename_toolong(): @@ -1816,7 +1811,7 @@ def test_new_invalid_filename_toolong(): # Add a new file. foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.add_fp(BytesIO(foostr), len(foostr), '/THISISAVERYLONGNAME.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/THISISAVERYLONGNAME.;1') assert(str(excinfo.value) == 'ISO9660 filenames at interchange level 1 cannot have more than 8 characters or 3 characters in the extension') def test_new_invalid_extension_toolong(): @@ -1826,7 +1821,7 @@ def test_new_invalid_extension_toolong(): # Add a new file. foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.add_fp(BytesIO(foostr), len(foostr), '/NAME.LONGEXT;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/NAME.LONGEXT;1') assert(str(excinfo.value) == 'ISO9660 filenames at interchange level 1 cannot have more than 8 characters or 3 characters in the extension') def test_new_invalid_dirname(): @@ -1888,7 +1883,7 @@ def test_new_hard_link_no_eltorito(): iso.new() bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.add_hard_link(boot_catalog_old=True) @@ -1942,7 +1937,7 @@ def test_new_hard_link_eltorito(): iso.new() bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') iso.rm_hard_link('/BOOT.CAT;1') @@ -2013,7 +2008,7 @@ def test_new_rm_hard_link_remove_file(): iso.new() bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.rm_hard_link(iso_path='/BOOT.;1') @@ -2027,7 +2022,7 @@ def test_new_rm_hard_link_joliet_remove_file(): iso.new(joliet=3) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') iso.rm_hard_link(iso_path='/BOOT.;1') iso.rm_hard_link(joliet_path='/boot') @@ -2042,7 +2037,7 @@ def test_new_rm_hard_link_rm_second(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.add_hard_link(iso_old_path='/FOO.;1', iso_new_path='/BAR.;1') iso.add_hard_link(iso_old_path='/FOO.;1', iso_new_path='/BAZ.;1') @@ -2059,7 +2054,7 @@ def test_new_rm_hard_link_rm_joliet_first(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') iso.rm_hard_link(joliet_path='/foo') iso.rm_hard_link(iso_path='/FOO.;1') @@ -2074,7 +2069,7 @@ def test_new_rm_hard_link_rm_joliet_and_links(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') iso.add_hard_link(iso_old_path='/FOO.;1', iso_new_path='/BAR.;1') iso.add_hard_link(iso_old_path='/FOO.;1', iso_new_path='/BAZ.;1') @@ -2093,7 +2088,7 @@ def test_new_rm_hard_link_isolevel4(): iso.new(interchange_level=4) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.rm_hard_link(iso_path='/FOO.;1') @@ -2107,7 +2102,7 @@ def test_add_hard_link_joliet_to_joliet(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') iso.add_hard_link(joliet_old_path='/foo', joliet_new_path='/bar') iso.close() @@ -2145,7 +2140,7 @@ def test_new_eltorito_boot_table_large_odd(): iso.new(interchange_level=4) bootstr = b'boo'*27 - iso.add_fp(BytesIO(bootstr), len(bootstr), '/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/boot') iso.add_eltorito('/boot', '/boot.cat', boot_info_table=True) do_a_test(iso, check_eltorito_boot_info_table_large_odd) @@ -2193,10 +2188,10 @@ def test_new_zero_byte_file(): iso.new(interchange_level=1) foostr = b'' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/BAR.;1') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/BAR.;1') do_a_test(iso, check_zero_byte_file) @@ -2208,7 +2203,7 @@ def test_new_eltorito_hide_boot(): iso.new() bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') iso.rm_hard_link(iso_path='/BOOT.;1') @@ -2225,7 +2220,7 @@ def test_new_full_path_from_dirrecord(): iso.add_directory('/DIR1') bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/DIR1/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/DIR1/BOOT.;1') full_path = None for child in iso.list_children(iso_path='/DIR1'): @@ -2251,7 +2246,7 @@ def test_new_rock_ridge_one_point_twelve(): iso.new(rock_ridge='1.12') bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') iso.close() @@ -2261,7 +2256,7 @@ def test_new_duplicate_pvd(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.duplicate_pvd() @@ -2282,15 +2277,15 @@ def test_new_eltorito_multi_multi_boot(): iso.new(interchange_level=4) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/boot') iso.add_eltorito('/boot', '/boot.cat') boot2str = b'boot2\n' - iso.add_fp(BytesIO(boot2str), len(boot2str), '/boot2') + iso.add_fp(io.BytesIO(boot2str), len(boot2str), '/boot2') iso.add_eltorito('/boot2', '/boot.cat') boot3str = b'boot3\n' - iso.add_fp(BytesIO(boot3str), len(boot3str), '/boot3') + iso.add_fp(io.BytesIO(boot3str), len(boot3str), '/boot3') iso.add_eltorito('/boot3', '/boot.cat') do_a_test(iso, check_eltorito_multi_multi_boot) @@ -2303,11 +2298,11 @@ def test_new_duplicate_pvd_not_same(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.duplicate_pvd() - out = BytesIO() + out = io.BytesIO() iso.write_fp(out) iso.close() @@ -2347,7 +2342,7 @@ def test_new_rr_exceedinglylongname(): iso.new(rock_ridge='1.09') aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='a'*500) + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='a'*500) do_a_test(iso, infinitenamechecks) @@ -2362,7 +2357,7 @@ def test_new_rr_symlink_path(): iso.new(rock_ridge='1.09') aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='aaaaaaaa') + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='aaaaaaaa') iso.add_symlink('/BBBBBBBB.;1', 'bbbbbbbb', 'aaaaaaaa') @@ -2376,7 +2371,7 @@ def test_new_rr_symlink_path_not_symlink(): iso.new(rock_ridge='1.09') aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='aaaaaaaa') + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='aaaaaaaa') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.pvd.root_dir_record.children[2].rock_ridge.symlink_path() @@ -2391,7 +2386,7 @@ def test_new_rr_verylongnameandsymlink_symlink_path(): iso.new(rock_ridge='1.09') aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='a'*RR_MAX_FILENAME_LENGTH) + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='a'*RR_MAX_FILENAME_LENGTH) iso.add_symlink('/BBBBBBBB.;1', 'b'*RR_MAX_FILENAME_LENGTH, 'a'*RR_MAX_FILENAME_LENGTH) @@ -2408,7 +2403,7 @@ def test_new_rr_verylongsymlink_symlink_path(): iso.new(rock_ridge='1.09') aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='aaaaaaaa') + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='aaaaaaaa') iso.add_symlink('/BBBBBBBB.;1', 'bbbbbbbb', 'a'*RR_MAX_FILENAME_LENGTH) @@ -2425,7 +2420,7 @@ def test_new_rr_extremelylongsymlink_symlink_path(): iso.new(rock_ridge='1.09') aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='aaaaaaaa') + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', rr_name='aaaaaaaa') iso.add_symlink('/BBBBBBBB.;1', 'bbbbbbbb', 'a'*500) @@ -2448,7 +2443,7 @@ def test_new_rr_onefile_onetwelve(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') do_a_test(iso, check_rr_onefile_onetwelve) @@ -2459,7 +2454,7 @@ def test_new_set_hidden_file(): iso.new() aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1') + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1') iso.set_hidden('/AAAAAAAA.;1') do_a_test(iso, check_hidden_file) @@ -2482,7 +2477,7 @@ def test_new_set_hidden_joliet_file(): iso.new(joliet=3) aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', joliet_path='/aaaaaaaa') + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', joliet_path='/aaaaaaaa') iso.set_hidden(joliet_path='/aaaaaaaa') do_a_test(iso, check_hidden_joliet_file) @@ -2505,7 +2500,7 @@ def test_new_set_hidden_rr_onefileonedir(): iso.new(rock_ridge='1.09') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') iso.set_hidden(rr_path='/foo') iso.add_directory('/DIR1', rr_name='dir1') @@ -2520,7 +2515,7 @@ def test_new_clear_hidden_joliet_file(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') iso.clear_hidden(joliet_path='/foo') do_a_test(iso, check_joliet_onefile) @@ -2543,7 +2538,7 @@ def test_new_clear_hidden_rr_onefileonedir(): iso.new(rock_ridge='1.09') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') iso.clear_hidden(rr_path='/foo') iso.add_directory('/DIR1', rr_name='dir1') @@ -2558,7 +2553,7 @@ def test_new_set_hidden_not_initialized(): iso.new() aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1') + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1') iso.close() with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.set_hidden('/AAAAAAAA.;1') @@ -2569,7 +2564,7 @@ def test_new_clear_hidden_file(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.clear_hidden('/FOO.;1') do_a_test(iso, check_onefile) @@ -2592,7 +2587,7 @@ def test_new_clear_hidden_not_initialized(): iso.new() aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1') + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1') iso.close() with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.clear_hidden('/AAAAAAAA.;1') @@ -2615,10 +2610,10 @@ def test_new_duplicate_rrmoved_name(): iso.add_directory('/A/B/C/D/E/F/H/1', rr_name='1') firststr = b'first\n' - iso.add_fp(BytesIO(firststr), len(firststr), '/A/B/C/D/E/F/G/1/FIRST.;1', rr_name='first') + iso.add_fp(io.BytesIO(firststr), len(firststr), '/A/B/C/D/E/F/G/1/FIRST.;1', rr_name='first') secondstr = b'second\n' - iso.add_fp(BytesIO(secondstr), len(secondstr), '/A/B/C/D/E/F/H/1/SECOND.;1', rr_name='second') + iso.add_fp(io.BytesIO(secondstr), len(secondstr), '/A/B/C/D/E/F/H/1/SECOND.;1', rr_name='second') do_a_test(iso, check_rr_two_dirs_same_level) @@ -2630,7 +2625,7 @@ def test_new_eltorito_hd_emul(): iso.new(interchange_level=1) bootstr = b'\x00'*446 + b'\x00\x01\x01\x00\x02\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*16 + b'\x00'*16 + b'\x00'*16 + b'\x55' + b'\xaa' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1', media_name='hdemul') do_a_test(iso, check_eltorito_hd_emul) @@ -2643,7 +2638,7 @@ def test_new_eltorito_hd_emul_too_short(): iso.new(interchange_level=1) bootstr = b'\x00'*446 - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1', media_name='hdemul') assert(str(excinfo.value) == 'Could not read entire HD MBR, must be at least 512 bytes') @@ -2656,7 +2651,7 @@ def test_new_eltorito_hd_emul_bad_keybyte1(): iso.new(interchange_level=1) bootstr = b'\x00'*446 + b'\x00\x01\x01\x00\x02\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*16 + b'\x00'*16 + b'\x00'*16 + b'\x56' + b'\xaa' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1', media_name='hdemul') assert(str(excinfo.value) == 'Invalid magic on HD MBR') @@ -2669,7 +2664,7 @@ def test_new_eltorito_hd_emul_bad_keybyte2(): iso.new(interchange_level=1) bootstr = b'\x00'*446 + b'\x00\x01\x01\x00\x02\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*16 + b'\x00'*16 + b'\x00'*16 + b'\x55' + b'\xab' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1', media_name='hdemul') assert(str(excinfo.value) == 'Invalid magic on HD MBR') @@ -2682,7 +2677,7 @@ def test_new_eltorito_hd_emul_multiple_part(): iso.new(interchange_level=1) bootstr = b'\x00'*446 + b'\x00\x01\x01\x00\x02\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x01\x01\x00\x02\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*16 + b'\x00'*16 + b'\x55' + b'\xaa' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1', media_name='hdemul') assert(str(excinfo.value) == 'Boot image has multiple partitions') @@ -2695,7 +2690,7 @@ def test_new_eltorito_hd_emul_no_part(): iso.new(interchange_level=1) bootstr = b'\x00'*446 + b'\x00'*16 + b'\x00'*16 + b'\x00'*16 + b'\x00'*16 + b'\x55' + b'\xaa' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1', media_name='hdemul') assert(str(excinfo.value) == 'Boot image has no partitions') @@ -2708,7 +2703,7 @@ def test_new_eltorito_hd_emul_bad_sec(): iso.new(interchange_level=1) bootstr = b'\x00'*446 + b'\x00\x00\x00\x00\x02\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*16 + b'\x00'*16 + b'\x00'*16 + b'\x55' + b'\xaa' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1', media_name='hdemul') do_a_test(iso, check_eltorito_hd_emul_bad_sec) @@ -2721,7 +2716,7 @@ def test_new_eltorito_hd_emul_invalid_geometry(): iso.new(interchange_level=1) bootstr = b'\x00'*446 + b'\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*16 + b'\x00'*16 + b'\x00'*16 + b'\x55' + b'\xaa' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1', media_name='hdemul') do_a_test(iso, check_eltorito_hd_emul_invalid_geometry) @@ -2734,7 +2729,7 @@ def test_new_eltorito_hd_emul_not_bootable(): iso.new(interchange_level=1) bootstr = b'\x00'*446 + b'\x00\x01\x01\x00\x02\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*16 + b'\x00'*16 + b'\x00'*16 + b'\x55' + b'\xaa' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1', media_name='hdemul', bootable=False) do_a_test(iso, check_eltorito_hd_emul_not_bootable) @@ -2747,7 +2742,7 @@ def test_new_eltorito_floppy12(): iso.new(interchange_level=1) bootstr = b'\x00'*(2400*512) - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1', media_name='floppy', bootable=True) do_a_test(iso, check_eltorito_floppy12) @@ -2760,7 +2755,7 @@ def test_new_eltorito_floppy144(): iso.new(interchange_level=1) bootstr = b'\x00'*(2880*512) - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1', media_name='floppy', bootable=True) do_a_test(iso, check_eltorito_floppy144) @@ -2773,7 +2768,7 @@ def test_new_eltorito_floppy288(): iso.new(interchange_level=1) bootstr = b'\x00'*(5760*512) - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1', media_name='floppy', bootable=True) do_a_test(iso, check_eltorito_floppy288) @@ -2786,7 +2781,7 @@ def test_new_eltorito_bad_floppy(): iso.new(interchange_level=1) bootstr = b'\x00'*(576*512) - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1', media_name='floppy', bootable=True) assert(str(excinfo.value) == 'Invalid sector count for floppy media type; must be 2400, 2880, or 5760') @@ -2799,11 +2794,11 @@ def test_new_eltorito_multi_hidden(): iso.new(interchange_level=4) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/boot') iso.add_eltorito('/boot', '/boot.cat') boot2str = b'boot2\n' - iso.add_fp(BytesIO(boot2str), len(boot2str), '/boot2') + iso.add_fp(io.BytesIO(boot2str), len(boot2str), '/boot2') iso.add_eltorito('/boot2', '/boot.cat') iso.rm_hard_link(iso_path='/boot2') @@ -2817,7 +2812,7 @@ def test_new_eltorito_rr_verylongname(): iso = pycdlib.PyCdlib() iso.new(rock_ridge='1.09') bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot') iso.add_eltorito('/BOOT.;1', '/AAAAAAAA.;1', rr_bootcatname='a'*RR_MAX_FILENAME_LENGTH) @@ -2831,14 +2826,14 @@ def test_new_isohybrid_file_before(): iso.new() # Add Eltorito isolinuxstr = b'\x00'*0x40 + b'\xfb\xc0\x78\x70' - iso.add_fp(BytesIO(isolinuxstr), len(isolinuxstr), '/ISOLINUX.BIN;1') + iso.add_fp(io.BytesIO(isolinuxstr), len(isolinuxstr), '/ISOLINUX.BIN;1') iso.add_eltorito('/ISOLINUX.BIN;1', '/BOOT.CAT;1', boot_load_size=4) # Now add the syslinux data iso.add_isohybrid() # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') do_a_test(iso, check_isohybrid_file_before) @@ -2857,7 +2852,7 @@ def test_new_eltorito_rr_joliet_verylongname(): iso = pycdlib.PyCdlib() iso.new(rock_ridge='1.09', joliet=3) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', rr_name='boot', joliet_path='/boot') iso.add_eltorito('/BOOT.;1', '/AAAAAAAA.;1', rr_bootcatname='a'*RR_MAX_FILENAME_LENGTH, joliet_bootcatfile='/'+'a'*64) @@ -2915,7 +2910,7 @@ def test_new_overflow_root_dir_record(): for letter in ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'o'): thisstr = b'\n' - iso.add_fp(BytesIO(thisstr), len(thisstr), '/'+letter.upper()*7+'.;1', rr_name=letter*20, joliet_path='/'+letter*20) + iso.add_fp(io.BytesIO(thisstr), len(thisstr), '/'+letter.upper()*7+'.;1', rr_name=letter*20, joliet_path='/'+letter*20) do_a_test(iso, check_overflow_root_dir_record) @@ -2928,11 +2923,11 @@ def test_new_overflow_correct_extents(): thisstr = b'\n' for letter in ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'): - iso.add_fp(BytesIO(thisstr), len(thisstr), '/'+letter.upper()*8+'.;1', rr_name=letter*136, joliet_path='/'+letter*64) + iso.add_fp(io.BytesIO(thisstr), len(thisstr), '/'+letter.upper()*8+'.;1', rr_name=letter*136, joliet_path='/'+letter*64) - iso.add_fp(BytesIO(thisstr), len(thisstr), '/OOOOOOOO.;1', rr_name='o'*57, joliet_path='/'+'o'*57) + iso.add_fp(io.BytesIO(thisstr), len(thisstr), '/OOOOOOOO.;1', rr_name='o'*57, joliet_path='/'+'o'*57) - iso.add_fp(BytesIO(thisstr), len(thisstr), '/P.;1', rr_name='p', joliet_path='/p') + iso.add_fp(io.BytesIO(thisstr), len(thisstr), '/P.;1', rr_name='p', joliet_path='/p') do_a_test(iso, check_overflow_correct_extents) @@ -2945,12 +2940,12 @@ def test_new_overflow_correct_extents2(): thisstr = b'\n' - iso.add_fp(BytesIO(thisstr), len(thisstr), '/P.;1', rr_name='p', joliet_path='/p') + iso.add_fp(io.BytesIO(thisstr), len(thisstr), '/P.;1', rr_name='p', joliet_path='/p') - iso.add_fp(BytesIO(thisstr), len(thisstr), '/OOOOOOOO.;1', rr_name='o'*57, joliet_path='/'+'o'*57) + iso.add_fp(io.BytesIO(thisstr), len(thisstr), '/OOOOOOOO.;1', rr_name='o'*57, joliet_path='/'+'o'*57) for letter in ('n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a'): - iso.add_fp(BytesIO(thisstr), len(thisstr), '/'+letter.upper()*8+'.;1', rr_name=letter*136, joliet_path='/'+letter*64) + iso.add_fp(io.BytesIO(thisstr), len(thisstr), '/'+letter.upper()*8+'.;1', rr_name=letter*136, joliet_path='/'+letter*64) do_a_test(iso, check_overflow_correct_extents) @@ -2989,7 +2984,7 @@ def test_new_always_consistent(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') iso.rm_hard_link(joliet_path='/foo') @@ -2999,13 +2994,13 @@ def test_new_always_consistent(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') iso.rm_file('/FOO.;1', joliet_path='/foo') iso.rm_directory('/DIR1', joliet_path='/dir1') - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') iso.add_eltorito('/FOO.;1', '/BOOT.CAT;1') iso.rm_eltorito() @@ -3074,7 +3069,7 @@ def test_new_duplicate_pvd_always_consistent(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.duplicate_pvd() @@ -3089,7 +3084,7 @@ def test_new_rr_symlink_always_consistent(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') iso.add_symlink('/SYM.;1', 'sym', 'foo') @@ -3103,7 +3098,7 @@ def test_new_eltorito_always_consistent(): iso.new() bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') do_a_test(iso, check_eltorito_nofiles) @@ -3134,11 +3129,11 @@ def test_new_eltorito_multi_boot_always_consistent(): iso.new(interchange_level=4) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/boot') iso.add_eltorito('/boot', '/boot.cat') boot2str = b'boot2\n' - iso.add_fp(BytesIO(boot2str), len(boot2str), '/boot2') + iso.add_fp(io.BytesIO(boot2str), len(boot2str), '/boot2') iso.add_eltorito('/boot2', '/boot.cat') do_a_test(iso, check_eltorito_multi_boot) @@ -3151,7 +3146,7 @@ def test_new_rm_joliet_hard_link(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') iso.rm_hard_link(joliet_path='/foo') @@ -3185,7 +3180,7 @@ def test_new_add_joliet_directory_isolevel4(): iso.new(interchange_level=4, joliet=3) # Add new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/foo', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/foo', joliet_path='/foo') # Add new directory. iso.add_directory('/dir1') iso.add_joliet_directory('/dir1') @@ -3290,10 +3285,10 @@ def test_new_rr_deep_weird_layout(): iso.add_directory('/ASTROID/ASTROID/TESTS/TESTDATA/PYTHON3/DATA/ABSIMP/SIDEPACK', rr_name='sidepackage') strstr = b'from __future__ import absolute_import, print_functino\nimport string\nprint(string)\n' - iso.add_fp(BytesIO(strstr), len(strstr), '/ASTROID/ASTROID/TESTS/TESTDATA/PYTHON3/DATA/ABSIMP/STRING.PY;1', rr_name='string.py') + iso.add_fp(io.BytesIO(strstr), len(strstr), '/ASTROID/ASTROID/TESTS/TESTDATA/PYTHON3/DATA/ABSIMP/STRING.PY;1', rr_name='string.py') initstr = b'"""a side package with nothing in it\n"""\n' - iso.add_fp(BytesIO(initstr), len(initstr), '/ASTROID/ASTROID/TESTS/TESTDATA/PYTHON3/DATA/ABSIMP/SIDEPACK/__INIT__.PY;1', rr_name='__init__.py') + iso.add_fp(io.BytesIO(initstr), len(initstr), '/ASTROID/ASTROID/TESTS/TESTDATA/PYTHON3/DATA/ABSIMP/SIDEPACK/__INIT__.PY;1', rr_name='__init__.py') do_a_test(iso, check_rr_deep_weird_layout) @@ -3343,7 +3338,7 @@ def test_new_duplicate_pvd_joliet(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.duplicate_pvd() @@ -3416,7 +3411,7 @@ def test_new_get_and_write_dir(): iso.add_directory('/DIR1') - out = BytesIO() + out = io.BytesIO() with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.get_and_write_fp('/DIR1', out) assert(str(excinfo.value) == 'Cannot write out a directory') @@ -3429,9 +3424,9 @@ def test_new_get_and_write_joliet(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') - out = BytesIO() + out = io.BytesIO() iso.get_and_write_fp('/foo', out) assert(out.getvalue() == b'foo\n') @@ -3443,9 +3438,9 @@ def test_new_get_and_write_iso9660(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') - out = BytesIO() + out = io.BytesIO() iso.get_and_write_fp('/FOO.;1', out) assert(out.getvalue() == b'foo\n') @@ -3457,9 +3452,9 @@ def test_new_get_and_write_rr(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') - out = BytesIO() + out = io.BytesIO() iso.get_and_write_fp('/foo', out) assert(out.getvalue() == b'foo\n') @@ -3471,9 +3466,9 @@ def test_new_get_and_write_iso9660_no_rr(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') - out = BytesIO() + out = io.BytesIO() with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.get_and_write_fp('/BAR.;1', out) assert(str(excinfo.value) == 'Could not find path') @@ -3552,36 +3547,36 @@ def test_new_different_joliet_name(): iso.new(joliet=3, rock_ridge='1.09') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/bar') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', joliet_path='/bar') foojstr = b'foojoliet\n' - iso.add_fp(BytesIO(foojstr), len(foojstr), '/FOOJ.;1', rr_name='fooj', joliet_path='/foo') + iso.add_fp(io.BytesIO(foojstr), len(foojstr), '/FOOJ.;1', rr_name='fooj', joliet_path='/foo') do_a_test(iso, check_joliet_different_names) # Check that we can get the content for the first file using its various names - out = BytesIO() + out = io.BytesIO() iso.get_file_from_iso_fp(out, iso_path='/FOO.;1') assert(out.getvalue() == b'foo\n') - out2 = BytesIO() + out2 = io.BytesIO() iso.get_file_from_iso_fp(out2, rr_path='/foo') assert(out2.getvalue() == b'foo\n') - out3 = BytesIO() + out3 = io.BytesIO() iso.get_file_from_iso_fp(out3, joliet_path='/bar') assert(out3.getvalue() == b'foo\n') # Check that we can get the content for the second file using its various names - out4 = BytesIO() + out4 = io.BytesIO() iso.get_file_from_iso_fp(out4, iso_path='/FOOJ.;1') assert(out4.getvalue() == b'foojoliet\n') - out5 = BytesIO() + out5 = io.BytesIO() iso.get_file_from_iso_fp(out5, rr_path='/fooj') assert(out5.getvalue() == b'foojoliet\n') - out6 = BytesIO() + out6 = io.BytesIO() iso.get_file_from_iso_fp(out6, joliet_path='/foo') assert(out6.getvalue() == b'foojoliet\n') @@ -3592,16 +3587,16 @@ def test_new_different_rr_isolevel4_name(): iso.new(interchange_level=4, rock_ridge='1.09') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/foo', rr_name='bar') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/foo', rr_name='bar') barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/bar', rr_name='foo') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/bar', rr_name='foo') - out = BytesIO() + out = io.BytesIO() iso.get_file_from_iso_fp(out, iso_path='/foo') assert(out.getvalue() == b'foo\n') - out2 = BytesIO() + out2 = io.BytesIO() iso.get_file_from_iso_fp(out2, rr_path='/bar') assert(out2.getvalue() == b'foo\n') @@ -3734,9 +3729,9 @@ def test_new_get_file_from_iso_invalid_path(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') - out = BytesIO() + out = io.BytesIO() with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.get_file_from_iso_fp(out, iso_path='/FOO.;1/BAR.;1') assert(str(excinfo.value) == 'Could not find path') @@ -3748,9 +3743,9 @@ def test_new_get_file_from_iso_invalid_joliet_path(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') - out = BytesIO() + out = io.BytesIO() with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.get_file_from_iso_fp(out, joliet_path='/foo/bar') assert(str(excinfo.value) == 'Could not find path') @@ -3762,9 +3757,9 @@ def test_new_get_file_from_iso_joliet_path_not_absolute(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') - out = BytesIO() + out = io.BytesIO() with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.get_file_from_iso_fp(out, joliet_path='foo') assert(str(excinfo.value) == 'Must be a path starting with /') @@ -3776,9 +3771,9 @@ def test_new_get_file_from_iso_joliet_path_not_found(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') - out = BytesIO() + out = io.BytesIO() with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.get_file_from_iso_fp(out, joliet_path='/bar') assert(str(excinfo.value) == 'Could not find path') @@ -3790,9 +3785,9 @@ def test_new_get_file_from_iso_blocksize(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') - out = BytesIO() + out = io.BytesIO() iso.get_file_from_iso_fp(out, joliet_path='/foo', blocksize=16384) assert(out.getvalue() == b'foo\n') @@ -3804,9 +3799,9 @@ def test_new_get_file_from_iso_no_joliet(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') - out = BytesIO() + out = io.BytesIO() with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.get_file_from_iso_fp(out, joliet_path='/foo') assert(str(excinfo.value) == 'Cannot fetch a joliet_path from a non-Joliet ISO') @@ -3818,9 +3813,9 @@ def test_new_get_file_from_iso_no_rr(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') - out = BytesIO() + out = io.BytesIO() with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.get_file_from_iso_fp(out, rr_path='/foo') assert(str(excinfo.value) == 'Cannot fetch a rr_path from a non-Rock Ridge ISO') @@ -3832,7 +3827,7 @@ def test_new_set_hidden_no_paths(): iso.new() aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1') + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.set_hidden() assert(str(excinfo.value) == 'Must provide exactly one of iso_path, rr_path, or joliet_path') @@ -3844,7 +3839,7 @@ def test_new_clear_hidden_no_paths(): iso.new() aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1') + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.clear_hidden() assert(str(excinfo.value) == 'Must provide exactly one of iso_path, rr_path, or joliet_path') @@ -3856,7 +3851,7 @@ def test_new_set_hidden_too_many_paths(): iso.new(joliet=3) aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', joliet_path='/aaaaaaaa') + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', joliet_path='/aaaaaaaa') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.set_hidden(iso_path='/AAAAAAAA.;1', joliet_path='/aaaaaaaa') assert(str(excinfo.value) == 'Must provide exactly one of iso_path, rr_path, or joliet_path') @@ -3868,7 +3863,7 @@ def test_new_clear_hidden_too_many_paths(): iso.new(joliet=3) aastr = b'aa\n' - iso.add_fp(BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', joliet_path='/aaaaaaaa') + iso.add_fp(io.BytesIO(aastr), len(aastr), '/AAAAAAAA.;1', joliet_path='/aaaaaaaa') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.clear_hidden(iso_path='/AAAAAAAA.;1', joliet_path='/aaaaaaaa') assert(str(excinfo.value) == 'Must provide exactly one of iso_path, rr_path, or joliet_path') @@ -3901,7 +3896,7 @@ def test_new_full_path_rockridge(): iso.add_directory(iso_path='/DIR1', rr_name='dir1') bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/DIR1/BOOT.;1', rr_name='boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/DIR1/BOOT.;1', rr_name='boot') full_path = None for child in iso.list_children(rr_path='/dir1'): @@ -3920,7 +3915,7 @@ def test_new_list_children_joliet_subdir(): iso.add_directory(iso_path='/DIR1', joliet_path='/dir1') bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/DIR1/BOOT.;1', joliet_path='/dir1/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/DIR1/BOOT.;1', joliet_path='/dir1/boot') full_path = None for child in iso.list_children(joliet_path='/dir1'): @@ -3942,12 +3937,12 @@ def test_new_joliet_encoded_system_identifier(): chpasswd: { expire: False } ssh_pwauth: True ''' - iso.add_fp(BytesIO(user_data_str), len(user_data_str), '/user-data', rr_name='user-data', joliet_path='/user-data') + iso.add_fp(io.BytesIO(user_data_str), len(user_data_str), '/user-data', rr_name='user-data', joliet_path='/user-data') meta_data_str = b'''\ local-hostname: cloudimg ''' - iso.add_fp(BytesIO(meta_data_str), len(meta_data_str), '/meta-data', rr_name='meta-data', joliet_path='/meta-data') + iso.add_fp(io.BytesIO(meta_data_str), len(meta_data_str), '/meta-data', rr_name='meta-data', joliet_path='/meta-data') do_a_test(iso, check_joliet_ident_encoding) @@ -3961,7 +3956,7 @@ def test_new_duplicate_pvd_isolevel4(): iso.new(interchange_level=4) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.duplicate_pvd() @@ -3974,7 +3969,7 @@ def test_new_joliet_hidden_iso_file(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') iso.rm_hard_link(iso_path='/FOO.;1') @@ -3987,7 +3982,7 @@ def test_new_add_file_hard_link_rm_file(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.add_hard_link(iso_old_path='/FOO.;1', iso_new_path='/LINK.;1') @@ -4004,7 +3999,7 @@ def test_new_file_mode_not_rock_ridge(): foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', file_mode=0o0100444) + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', file_mode=0o0100444) assert(str(excinfo.value) == 'Can only specify a file mode for Rock Ridge ISOs') iso.close() @@ -4015,7 +4010,7 @@ def test_new_eltorito_hide_boot_link(): iso.new() bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_hard_link(iso_old_path='/BOOT.;1', iso_new_path='/BOOTLINK.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') @@ -4030,7 +4025,7 @@ def test_new_iso_only_add_rm_hard_link(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.add_hard_link(iso_old_path='/FOO.;1', iso_new_path='/BAR.;1') @@ -4048,7 +4043,7 @@ def test_new_rm_hard_link_twice(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.add_hard_link(iso_old_path='/FOO.;1', iso_new_path='/BAR.;1') iso.rm_hard_link(iso_path='/BAR.;1') @@ -4064,7 +4059,7 @@ def test_new_rm_hard_link_twice2(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.add_hard_link(iso_old_path='/FOO.;1', iso_new_path='/BAR.;1') iso.rm_hard_link(iso_path='/FOO.;1') @@ -4080,7 +4075,7 @@ def test_new_rm_eltorito_leave_file(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.add_eltorito('/FOO.;1', '/BOOT.CAT;1') @@ -4095,7 +4090,7 @@ def test_new_add_eltorito_rm_file(): iso.new() bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') @@ -4111,11 +4106,11 @@ def test_new_eltorito_multi_boot_rm_file(): iso.new(interchange_level=4) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/boot') iso.add_eltorito('/boot', '/boot.cat') boot2str = b'boot2\n' - iso.add_fp(BytesIO(boot2str), len(boot2str), '/boot2') + iso.add_fp(io.BytesIO(boot2str), len(boot2str), '/boot2') iso.add_eltorito('/boot2', '/boot.cat') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: @@ -4131,11 +4126,11 @@ def test_new_get_file_from_iso_symlink(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') iso.add_symlink('/SYM.;1', 'sym', 'foo') - out = BytesIO() + out = io.BytesIO() with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.get_file_from_iso_fp(out, iso_path='/SYM.;1') @@ -4211,7 +4206,7 @@ def test_new_udf_onefile(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') do_a_test(iso, check_udf_onefile) @@ -4225,7 +4220,7 @@ def test_new_udf_onefileonedir(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') do_a_test(iso, check_udf_onefileonedir) @@ -4237,7 +4232,7 @@ def test_new_udf_rm_file(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') iso.rm_file('/FOO.;1', udf_path='/foo') @@ -4277,7 +4272,7 @@ def test_new_udf_iso_hidden(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') iso.rm_hard_link(iso_path='/FOO.;1') @@ -4291,7 +4286,7 @@ def test_new_udf_hard_link(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.add_hard_link(iso_old_path='/FOO.;1', udf_new_path='/foo') @@ -4305,7 +4300,7 @@ def test_new_udf_rm_add_hard_link(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') iso.rm_hard_link(iso_path='/FOO.;1') @@ -4321,7 +4316,7 @@ def test_new_udf_hidden(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') iso.rm_hard_link(udf_path='/foo') @@ -4445,7 +4440,7 @@ def test_new_lookup_after_rmfile(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') rec = iso.get_record(iso_path='/FOO.;1') assert(rec.file_identifier() == b'FOO.;1') @@ -4480,7 +4475,7 @@ def test_new_udf_lookup_after_rmfile(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') rec = iso.get_record(udf_path='/foo') @@ -4497,7 +4492,7 @@ def test_new_full_path_no_rr(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') rec = iso.get_record(iso_path='/FOO.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: @@ -4514,7 +4509,7 @@ def test_new_list_children_udf(): iso.add_directory('/DIR1', udf_path='/dir1') bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/DIR1/BOOT.;1', udf_path='/dir1/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/DIR1/BOOT.;1', udf_path='/dir1/boot') full_path = None for child in iso.list_children(udf_path='/dir1'): @@ -4532,7 +4527,7 @@ def test_new_udf_list_children_file(): iso.new(udf='2.60') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: for c in iso.list_children(udf_path='/foo'): @@ -4547,7 +4542,7 @@ def test_new_list_children_file(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: for c in iso.list_children(iso_path='/FOO.;1'): @@ -4562,7 +4557,7 @@ def test_new_list_children_joliet_file(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: for c in iso.list_children(joliet_path='/foo'): @@ -4612,7 +4607,7 @@ def test_new_rm_link_udf_path_not_udf(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.rm_hard_link(udf_path='/foo') @@ -4639,7 +4634,7 @@ def test_new_add_link_udf_path_not_udf(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.add_hard_link(iso_old_path='/FOO.;1', udf_new_path='/foo') @@ -4654,7 +4649,7 @@ def test_new_add_fp_udf_path_not_udf(): foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') assert(str(excinfo.value) == 'Can only specify a UDF path for a UDF ISO') iso.close() @@ -4664,9 +4659,9 @@ def test_new_get_file_from_iso_fp_udf_path_not_udf(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') - out = BytesIO() + out = io.BytesIO() with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.get_file_from_iso_fp(out, udf_path='/foo') assert(str(excinfo.value) == 'Cannot fetch a udf_path from a non-UDF ISO') @@ -4702,7 +4697,7 @@ def test_new_udf_symlink(): iso.new(udf='2.60') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') iso.add_symlink('/BAR.;1', udf_symlink_path='/bar', udf_target='foo') @@ -4717,7 +4712,7 @@ def test_new_udf_symlink_in_dir(): iso.add_directory('/DIR1', udf_path='/dir1') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/DIR1/FOO.;1', udf_path='/dir1/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/DIR1/FOO.;1', udf_path='/dir1/foo') iso.add_symlink('/BAR.;1', udf_symlink_path='/bar', udf_target='dir1/foo') @@ -4822,7 +4817,7 @@ def test_new_rr_rm_symlink(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') iso.add_symlink('/SYM.;1', 'sym', 'foo') @@ -4839,7 +4834,7 @@ def test_new_udf_rm_link_symlink(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') # Add: any new extents for FI container (0) + log_block_size (File Entry) + file_entry.info_len iso.add_symlink('/SYM.;1', udf_symlink_path='/sym', udf_target='/foo') @@ -4858,7 +4853,7 @@ def test_new_udf_rr_symlink(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo', udf_path='/foo') # Add: any new extents for FI container (0) + log_block_size (File Entry) + file_entry.info_len iso.add_symlink('/SYM.;1', rr_symlink_name='sym', rr_path='foo', udf_symlink_path='/sym', udf_target='foo') @@ -4888,7 +4883,7 @@ def test_new_udf_hardlink(): iso.new(udf='2.60') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') iso.add_hard_link(udf_old_path='/foo', udf_new_path='/bar') @@ -4901,7 +4896,7 @@ def test_new_multi_hard_link(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.add_hard_link(iso_old_path='/FOO.;1', iso_new_path='/BAR.;1') @@ -4916,7 +4911,7 @@ def test_new_multi_hard_link2(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.add_hard_link(iso_old_path='/FOO.;1', iso_new_path='/BAR.;1') @@ -4931,7 +4926,7 @@ def test_new_joliet_with_version(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo.;1') do_a_test(iso, check_joliet_with_version) @@ -4942,7 +4937,7 @@ def test_new_link_joliet_to_iso(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') iso.rm_hard_link(iso_path='/FOO.;1') iso.add_hard_link(joliet_old_path='/foo', iso_new_path='/FOO.;1') @@ -4956,7 +4951,7 @@ def test_new_udf_joliet_onefile(): iso.new(joliet=3, udf='2.60') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo', udf_path='/foo') do_a_test(iso, check_udf_joliet_onefile) @@ -4967,7 +4962,7 @@ def test_new_link_joliet_to_udf(): iso.new(joliet=3, udf='2.60') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') iso.add_hard_link(joliet_old_path='/foo', udf_new_path='/foo') @@ -4980,7 +4975,7 @@ def test_new_link_udf_to_joliet(): iso.new(joliet=3, udf='2.60') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') iso.add_hard_link(udf_old_path='/foo', joliet_new_path='/foo') @@ -4994,7 +4989,7 @@ def test_new_joliet_hard_link_eltorito(): iso.new(joliet=3) bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', joliet_path='/boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') iso.rm_hard_link('/BOOT.CAT;1') @@ -5012,7 +5007,7 @@ def test_new_udf_hard_link_eltorito(): iso.new(udf='2.60') bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1', udf_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1', udf_path='/boot') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') iso.rm_hard_link('/BOOT.CAT;1') @@ -5031,7 +5026,7 @@ def test_new_bogus_symlink(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.add_symlink('/SYM.;1', 'sym') @@ -5046,7 +5041,7 @@ def test_new_joliet_symlink_no_joliet(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.add_symlink('/SYM.;1', 'sym', 'foo', joliet_path='/foo') @@ -5061,7 +5056,7 @@ def test_new_eltorito_udf_rm_eltorito(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') iso.add_eltorito('/FOO.;1', '/BOOT.CAT;1') @@ -5078,7 +5073,7 @@ def test_new_add_eltorito_udf_path_no_udf(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.add_eltorito('/FOO.;1', '/BOOT.CAT;1', udf_bootcatfile='/foo') @@ -5093,7 +5088,7 @@ def test_new_add_eltorito_joliet_path_no_joliet(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.add_eltorito('/FOO.;1', '/BOOT.CAT;1', joliet_bootcatfile='/foo') @@ -5108,7 +5103,7 @@ def test_new_rm_file_linked_by_eltorito_bootcat(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.add_eltorito('/FOO.;1', '/BOOT.CAT;1') @@ -5131,7 +5126,7 @@ def test_new_udf_rm_hard_link_multi_links(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/bar') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/bar') iso.add_hard_link(udf_old_path='/bar', udf_new_path='/foo') iso.add_hard_link(udf_old_path='/bar', udf_new_path='/baz') @@ -5148,7 +5143,7 @@ def test_new_hard_link_invalid_new_keyword(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.add_hard_link(iso_old_path='/FOO.;1', blah='some') @@ -5163,7 +5158,7 @@ def test_new_udf_dotdot_symlink(): iso.add_directory('/DIR1', udf_path='/dir1') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') iso.add_symlink('/DIR1/SYM.;1', udf_symlink_path='/dir1/sym', udf_target='../foo') @@ -5176,7 +5171,7 @@ def test_new_udf_dot_symlink(): iso.new(udf='2.60') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') iso.add_symlink('/SYM.;1', udf_symlink_path='/sym', udf_target='./foo') @@ -5190,10 +5185,10 @@ def test_new_udf_zero_byte_file(): iso.new(udf='2.60') foostr = b'' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/BAR.;1', udf_path='/bar') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/BAR.;1', udf_path='/bar') do_a_test(iso, check_udf_zero_byte_file) @@ -5216,10 +5211,10 @@ def test_new_udf_onefile_onedirwithfile(): iso.add_directory('/DIR1', udf_path='/dir1') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') barstr = b'bar\n' - iso.add_fp(BytesIO(barstr), len(barstr), '/DIR1/BAR.;1', udf_path='/dir1/bar') + iso.add_fp(io.BytesIO(barstr), len(barstr), '/DIR1/BAR.;1', udf_path='/dir1/bar') do_a_test(iso, check_udf_onefile_onedirwithfile) @@ -5230,9 +5225,9 @@ def test_new_udf_get_invalid(): iso.new(udf='2.60') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') - out = BytesIO() + out = io.BytesIO() with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.get_file_from_iso_fp(out, udf_path='/foo/some') assert(str(excinfo.value) == 'Could not find path') @@ -5244,7 +5239,7 @@ def test_new_zero_byte_hard_link(): iso.new() foostr = b'' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') iso.add_hard_link(iso_old_path='/FOO.;1', iso_new_path='/BAR.;1') do_a_test(iso, check_zero_byte_hard_link) @@ -5256,7 +5251,7 @@ def test_new_udf_zero_byte_hard_link(): iso.new(udf='2.60') foostr = b'' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') iso.add_hard_link(udf_old_path='/foo', udf_new_path='/bar') do_a_test(iso, check_udf_zero_byte_hard_link) @@ -5268,7 +5263,7 @@ def test_new_unicode_name(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/F__O.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/F__O.;1') do_a_test(iso, check_unicode_name) @@ -5279,7 +5274,7 @@ def test_new_unicode_name_isolevel4(): iso.new(interchange_level=4) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/föo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/föo') do_a_test(iso, check_unicode_name_isolevel4) @@ -5290,7 +5285,7 @@ def test_new_unicode_name_joliet(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/F__O.;1', joliet_path='/föo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/F__O.;1', joliet_path='/föo') do_a_test(iso, check_unicode_name_joliet) @@ -5301,7 +5296,7 @@ def test_new_unicode_name_udf(): iso.new(udf='2.60') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/F__O.;1', udf_path='/föo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/F__O.;1', udf_path='/föo') do_a_test(iso, check_unicode_name_udf) @@ -5312,7 +5307,7 @@ def test_new_unicode_name_two_byte(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/F___O.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/F___O.;1') do_a_test(iso, check_unicode_name_two_byte) @@ -5323,7 +5318,7 @@ def test_new_unicode_name_two_byte_isolevel4(): iso.new(interchange_level=4) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/fᴔo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/fᴔo') do_a_test(iso, check_unicode_name_two_byte_isolevel4) @@ -5334,7 +5329,7 @@ def test_new_unicode_name_two_byte_joliet(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/F___O.;1', joliet_path='/fᴔo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/F___O.;1', joliet_path='/fᴔo') do_a_test(iso, check_unicode_name_two_byte_joliet) @@ -5345,7 +5340,7 @@ def test_new_unicode_name_two_byte_udf(): iso.new(udf='2.60') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/F___O.;1', udf_path='/fᴔo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/F___O.;1', udf_path='/fᴔo') do_a_test(iso, check_unicode_name_two_byte_udf) @@ -5356,7 +5351,7 @@ def test_new_unicode_name_two_byte_isolevel4_list_children(): iso.new(interchange_level=4) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/fᴔo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/fᴔo') full_path = None for child in iso.list_children(iso_path='/'): @@ -5374,7 +5369,7 @@ def test_new_unicode_name_two_byte_joliet_list_children(): iso.new(joliet=3) foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/F___O.;1', joliet_path='/fᴔo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/F___O.;1', joliet_path='/fᴔo') full_path = None for child in iso.list_children(joliet_path='/'): @@ -5392,7 +5387,7 @@ def test_new_unicode_name_two_byte_udf_list_children(): iso.new(udf='2.60') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/F___O.;1', udf_path='/fᴔo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/F___O.;1', udf_path='/fᴔo') full_path = None for child in iso.list_children(udf_path='/'): @@ -5421,12 +5416,12 @@ def test_new_udf_get_symlink_file(): iso.new(udf='2.60') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') iso.add_symlink('/BAR.;1', udf_symlink_path='/bar', udf_target='/foo') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.get_file_from_iso_fp(BytesIO(), udf_path='/bar') + iso.get_file_from_iso_fp(io.BytesIO(), udf_path='/bar') assert(str(excinfo.value) == 'Can only write out a file') iso.close() @@ -5436,7 +5431,7 @@ def test_new_udf_unicode_symlink(): iso.new(udf='2.60') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/F___O.;1', udf_path='/fᴔo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/F___O.;1', udf_path='/fᴔo') iso.add_symlink('/BAR.;1', udf_symlink_path='/bar', udf_target='fᴔo') @@ -5449,7 +5444,7 @@ def test_new_udf_bad_tag_location(): iso = pycdlib.PyCdlib() iso.new(udf='2.60') - out = BytesIO() + out = io.BytesIO() iso.write_fp(out) iso.close() @@ -5480,11 +5475,11 @@ def test_new_eltorito_rm_multi_boot(): iso.new() bootstr = b'foo\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/FOO.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/FOO.;1') iso.add_eltorito('/FOO.;1', '/BOOT.CAT;1') boot2str = b'boot2\n' - iso.add_fp(BytesIO(boot2str), len(boot2str), '/BOOT2.;1') + iso.add_fp(io.BytesIO(boot2str), len(boot2str), '/BOOT2.;1') iso.add_eltorito('/BOOT2.;1', '/BOOT.CAT;1') iso.rm_eltorito() @@ -5533,10 +5528,10 @@ def test_new_walk_iso(): iso.add_directory('/DIR1') iso.add_directory('/DIR1/SUBDIR1') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/DIR1/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/DIR1/FOO.;1') iso.add_directory('/DIR2') - iso.add_fp(BytesIO(foostr), len(foostr), '/DIR2/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/DIR2/FOO.;1') iso.add_directory('/DIR3') iso.add_directory('/DIR3/SUBDIR3') @@ -5567,10 +5562,10 @@ def test_new_walk_rr(): iso.add_directory('/DIR1', rr_name='dir1') iso.add_directory('/DIR1/SUBDIR1', rr_name='subdir1') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/DIR1/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/DIR1/FOO.;1', rr_name='foo') iso.add_directory('/DIR2', rr_name='dir2') - iso.add_fp(BytesIO(foostr), len(foostr), '/DIR2/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/DIR2/FOO.;1', rr_name='foo') iso.add_directory('/DIR3', rr_name='dir3') iso.add_directory('/DIR3/SUBDIR3', rr_name='subdir3') @@ -5601,10 +5596,10 @@ def test_new_walk_joliet(): iso.add_directory('/DIR1', joliet_path='/dir1') iso.add_directory('/DIR1/SUBDIR1', joliet_path='/dir1/subdir1') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/DIR1/FOO.;1', joliet_path='/dir1/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/DIR1/FOO.;1', joliet_path='/dir1/foo') iso.add_directory('/DIR2', joliet_path='/dir2') - iso.add_fp(BytesIO(foostr), len(foostr), '/DIR2/FOO.;1', joliet_path='/dir2/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/DIR2/FOO.;1', joliet_path='/dir2/foo') iso.add_directory('/DIR3', joliet_path='/dir3') iso.add_directory('/DIR3/SUBDIR3', joliet_path='/dir3/subdir3') @@ -5635,10 +5630,10 @@ def test_new_walk_udf(): iso.add_directory('/DIR1', udf_path='/dir1') iso.add_directory('/DIR1/SUBDIR1', udf_path='/dir1/subdir1') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/DIR1/FOO.;1', udf_path='/dir1/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/DIR1/FOO.;1', udf_path='/dir1/foo') iso.add_directory('/DIR2', udf_path='/dir2') - iso.add_fp(BytesIO(foostr), len(foostr), '/DIR2/FOO.;1', udf_path='/dir2/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/DIR2/FOO.;1', udf_path='/dir2/foo') iso.add_directory('/DIR3', udf_path='/dir3') iso.add_directory('/DIR3/SUBDIR3', udf_path='/dir3/subdir3') @@ -5743,10 +5738,10 @@ def test_new_walk_iso_remove_dirlist_entry(): iso.add_directory('/DIR1') iso.add_directory('/DIR1/SUBDIR1') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/DIR1/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/DIR1/FOO.;1') iso.add_directory('/DIR2') - iso.add_fp(BytesIO(foostr), len(foostr), '/DIR2/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/DIR2/FOO.;1') iso.add_directory('/DIR3') iso.add_directory('/DIR3/SUBDIR3') @@ -5776,7 +5771,7 @@ def test_new_walk_filename(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: for dirname, dirlist, filelist in iso.walk(iso_path='/FOO.;1'): @@ -5788,7 +5783,7 @@ def test_new_walk_udf_filename(): iso.new(udf='2.60') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: for dirname, dirlist, filelist in iso.walk(udf_path='/foo'): @@ -5811,7 +5806,7 @@ def test_new_open_file_from_iso_invalid_kwarg(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.open_file_from_iso(foo_path='/FOO.;1') @@ -5824,7 +5819,7 @@ def test_new_open_file_from_iso_too_many_kwarg(): iso.new(udf='2.60') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.open_file_from_iso(iso_path='/FOO.;1', udf_path='/foo') @@ -5837,7 +5832,7 @@ def test_new_open_file_from_iso_too_few_kwarg(): iso.new(udf='2.60') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.open_file_from_iso() @@ -5850,7 +5845,7 @@ def test_new_open_file_from_iso_invalid_joliet(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.open_file_from_iso(joliet_path='/foo') @@ -5863,7 +5858,7 @@ def test_new_open_file_from_iso_invalid_rr(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.open_file_from_iso(rr_path='/foo') @@ -5876,7 +5871,7 @@ def test_new_open_file_from_iso_invalid_udf(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.open_file_from_iso(udf_path='/foo') @@ -5937,7 +5932,7 @@ def test_new_open_file_from_iso_ctxt_manager(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: assert(infp.read() == b'foo\n') @@ -5950,7 +5945,7 @@ def test_new_open_file_from_iso_past_eof(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: infp.seek(20) @@ -5964,7 +5959,7 @@ def test_new_open_file_from_iso_single(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: assert(infp.read(1) == b'f') @@ -5977,7 +5972,7 @@ def test_new_open_file_from_iso_past_half_past_eof(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: infp.seek(2) @@ -5991,7 +5986,7 @@ def test_new_open_file_from_iso_readall(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: assert(infp.readall() == b'foo\n') @@ -6004,7 +5999,7 @@ def test_new_open_file_from_iso_readall_past_eof(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: infp.seek(20) @@ -6018,7 +6013,7 @@ def test_new_open_file_from_iso_readall_half_past_eof(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: infp.seek(2) @@ -6032,7 +6027,7 @@ def test_new_open_file_from_iso_seek_invalid_offset(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: @@ -6046,7 +6041,7 @@ def test_new_open_file_from_iso_seek_invalid_whence(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: @@ -6060,7 +6055,7 @@ def test_new_open_file_from_iso_seek_whence_begin(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: infp.seek(1, whence=0) @@ -6074,7 +6069,7 @@ def test_new_open_file_from_iso_seek_whence_negative_begin(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: @@ -6088,7 +6083,7 @@ def test_new_open_file_from_iso_seek_whence_begin_beyond_eof(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: infp.seek(10, whence=0) @@ -6103,7 +6098,7 @@ def test_new_open_file_from_iso_seek_whence_curr(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: infp.seek(1, whence=1) @@ -6120,7 +6115,7 @@ def test_new_open_file_from_iso_seek_whence_curr_before_start(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: @@ -6134,7 +6129,7 @@ def test_new_open_file_from_iso_seek_whence_curr_negative(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: assert(infp.readall() == b'foo\n') @@ -6150,7 +6145,7 @@ def test_new_open_file_from_iso_seek_whence_end(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: infp.seek(-2, whence=2) @@ -6165,7 +6160,7 @@ def test_new_open_file_from_iso_seek_whence_end_before_start(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: @@ -6179,7 +6174,7 @@ def test_new_open_file_from_iso_not_open(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: infp.close() @@ -6215,7 +6210,7 @@ def test_new_open_file_from_iso_length(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: assert(infp.length() == 4) @@ -6227,7 +6222,7 @@ def test_new_open_file_from_iso_readable(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: assert(infp.readable()) @@ -6239,7 +6234,7 @@ def test_new_open_file_from_iso_seekable(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: assert(infp.seekable()) @@ -6251,7 +6246,7 @@ def test_new_open_file_from_iso_readinto(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: arr = bytearray(4) @@ -6265,7 +6260,7 @@ def test_new_open_file_from_iso_readinto_partial(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: arr = bytearray(2) @@ -6281,7 +6276,7 @@ def test_new_open_file_from_iso_readinto_past_eof(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with iso.open_file_from_iso(iso_path='/FOO.;1') as infp: infp.seek(4) @@ -6296,15 +6291,15 @@ def test_new_udf_cyrillic(): iso.new(udf='2.60') teststr = b'' - iso.add_fp(BytesIO(teststr), len(teststr), '/TEST.TXT;1', udf_path='/test.txt') + iso.add_fp(io.BytesIO(teststr), len(teststr), '/TEST.TXT;1', udf_path='/test.txt') iso.add_directory('/__', udf_path='/РЭ') iso.add_directory('/__/PORT', udf_path='/РЭ/Port') iso.add_directory('/__/________', udf_path='/РЭ/Руководства') - iso.add_fp(BytesIO(teststr), len(teststr), '/__/PORT/________.TXT;1', udf_path='/РЭ/Port/виртуальный порт.txt') + iso.add_fp(io.BytesIO(teststr), len(teststr), '/__/PORT/________.TXT;1', udf_path='/РЭ/Port/виртуальный порт.txt') - iso.add_fp(BytesIO(teststr), len(teststr), '/__/________/________.TXT;1', udf_path='/РЭ/Руководства/Руководство по.txt') + iso.add_fp(io.BytesIO(teststr), len(teststr), '/__/________/________.TXT;1', udf_path='/РЭ/Руководства/Руководство по.txt') do_a_test(iso, check_udf_unicode) @@ -6316,7 +6311,7 @@ def test_new_eltorito_get_bootcat(): iso.new() bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') do_a_test(iso, check_eltorito_get_bootcat) @@ -6329,7 +6324,7 @@ def test_new_eltorito_invalid_platform_id(): iso.new() bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1', None, None, None, 0xff) assert(str(excinfo.value) == 'Invalid platform ID (must be one of 0, 1, 2, or 0xef)') @@ -6342,7 +6337,7 @@ def test_new_eltorito_uefi(): iso.new() bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1', None, None, None, 0xef) do_a_test(iso, check_eltorito_uefi) @@ -6376,7 +6371,7 @@ def test_new_open_file_from_iso_eltorito_boot_catalog(): iso.new() bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/BOOT.;1') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/BOOT.;1') iso.add_eltorito('/BOOT.;1', '/BOOT.CAT;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: @@ -6391,7 +6386,7 @@ def test_new_add_fp_all_none(): foostr = b'foo\n' with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: - iso.add_fp(BytesIO(foostr), len(foostr)) + iso.add_fp(io.BytesIO(foostr), len(foostr)) assert(str(excinfo.value) == "At least one of 'iso_path', 'joliet_path', or 'udf_path' must be provided") iso.close() @@ -6402,7 +6397,7 @@ def test_new_rm_joliet_only(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', joliet_path='/foo') iso.rm_file(joliet_path='/foo') @@ -6416,7 +6411,7 @@ def test_new_rm_udf_only(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') iso.rm_file(udf_path='/foo') @@ -6429,7 +6424,7 @@ def test_new_udf_zero_byte_rm_file(): iso.new(udf='2.60') foostr = b'' - iso.add_fp(BytesIO(foostr), len(foostr), udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), udf_path='/foo') iso.rm_file(udf_path='/foo') @@ -6442,7 +6437,7 @@ def test_new_rm_file_no_udf(): iso.new(joliet=3) foostr = b'' - iso.add_fp(BytesIO(foostr), len(foostr), joliet_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), joliet_path='/foo') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.rm_file(udf_path='/foo') @@ -6469,7 +6464,7 @@ def test_new_eltorito_udf_rm_eltorito(): # Add a new file. foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', udf_path='/foo') iso.add_eltorito('/FOO.;1', '/BOOT.CAT;1') @@ -6485,11 +6480,11 @@ def test_new_udf_eltorito_multi_boot_rm_file(): iso.new(interchange_level=4, udf='2.60') bootstr = b'boot\n' - iso.add_fp(BytesIO(bootstr), len(bootstr), '/boot', udf_path='/boot') + iso.add_fp(io.BytesIO(bootstr), len(bootstr), '/boot', udf_path='/boot') iso.add_eltorito('/boot', '/boot.cat') boot2str = b'boot2\n' - iso.add_fp(BytesIO(boot2str), len(boot2str), '/boot2', udf_path='/boot2') + iso.add_fp(io.BytesIO(boot2str), len(boot2str), '/boot2', udf_path='/boot2') iso.add_eltorito('/boot2', '/boot.cat') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: @@ -6503,7 +6498,7 @@ def test_new_rr_file_mode(): iso.new(rock_ridge='1.09') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') assert(iso.file_mode(rr_path='/foo') == 0o0100444) @@ -6521,7 +6516,7 @@ def test_new_rr_file_mode_bad_kwarg(): iso.new(rock_ridge='1.09') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.file_mode(foo_path='/foo') @@ -6534,7 +6529,7 @@ def test_new_rr_file_mode_multiple_kwarg(): iso.new(rock_ridge='1.09') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1', rr_name='foo') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.file_mode(rr_path='/foo', iso_path='/FOO.;1') @@ -6547,7 +6542,7 @@ def test_new_rr_file_mode_not_rr(): iso.new() foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/FOO.;1') with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo: iso.file_mode(rr_path='/foo') @@ -6583,7 +6578,7 @@ def test_new_isolevel4_deep_directory(): iso.add_directory('/dir1/dir2/dir3/dir4/dir5/dir6/dir7') foostr = b'foo\n' - iso.add_fp(BytesIO(foostr), len(foostr), '/dir1/dir2/dir3/dir4/dir5/dir6/dir7/foo') + iso.add_fp(io.BytesIO(foostr), len(foostr), '/dir1/dir2/dir3/dir4/dir5/dir6/dir7/foo') do_a_test(iso, check_isolevel4_deep_directory) diff --git a/tests/integration/test_parse.py b/tests/integration/test_parse.py index bcb3782d..7e4ce0ef 100644 --- a/tests/integration/test_parse.py +++ b/tests/integration/test_parse.py @@ -1,11 +1,12 @@ # -*- coding: utf-8 -*- -import pytest import subprocess import os import sys import struct +import pytest + sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import pycdlib diff --git a/tests/unit/test_dates.py b/tests/unit/test_dates.py index 86dcf69d..0b083d4d 100644 --- a/tests/unit/test_dates.py +++ b/tests/unit/test_dates.py @@ -1,15 +1,10 @@ -from __future__ import absolute_import - -import pytest import os import sys -try: - from cStringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO import struct import time +import pytest + prefix = '.' for i in range(0, 3): if os.path.isdir(os.path.join(prefix, 'pycdlib')): @@ -22,9 +17,8 @@ import pycdlib.pycdlibexception def test_string_to_timestruct_invalid_input_type(): - if sys.version_info >= (3, 0): - with pytest.raises(AttributeError) as exc_info: - ts = pycdlib.dates.string_to_timestruct('') + with pytest.raises(AttributeError) as exc_info: + ts = pycdlib.dates.string_to_timestruct('') def test_string_to_timestruct_blank_bytes(): ts = pycdlib.dates.string_to_timestruct(b'') diff --git a/tests/unit/test_dr.py b/tests/unit/test_dr.py index daf4fa83..edc8c38c 100644 --- a/tests/unit/test_dr.py +++ b/tests/unit/test_dr.py @@ -1,15 +1,10 @@ -from __future__ import absolute_import - -import pytest import os import sys -try: - from cStringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO import struct import time +import pytest + prefix = '.' for i in range(0, 3): if os.path.isdir(os.path.join(prefix, 'pycdlib')): diff --git a/tests/unit/test_eltorito.py b/tests/unit/test_eltorito.py index 5493089b..f1ae17c1 100644 --- a/tests/unit/test_eltorito.py +++ b/tests/unit/test_eltorito.py @@ -1,14 +1,9 @@ -from __future__ import absolute_import - -import pytest import os import sys -try: - from cStringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO import struct +import pytest + prefix = '.' for i in range(0, 3): if os.path.isdir(os.path.join(prefix, 'pycdlib')): diff --git a/tests/unit/test_headervd.py b/tests/unit/test_headervd.py index 5bb5f837..ab9c8c10 100644 --- a/tests/unit/test_headervd.py +++ b/tests/unit/test_headervd.py @@ -1,14 +1,9 @@ -from __future__ import absolute_import - -import pytest import os import sys -try: - from cStringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO import struct +import pytest + prefix = '.' for i in range(0, 3): if os.path.isdir(os.path.join(prefix, 'pycdlib')): diff --git a/tests/unit/test_inode.py b/tests/unit/test_inode.py index 7ccf1c29..7aa04cf4 100644 --- a/tests/unit/test_inode.py +++ b/tests/unit/test_inode.py @@ -1,15 +1,10 @@ -from __future__ import absolute_import - -import pytest import os import sys -try: - from cStringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO import struct import time +import pytest + prefix = '.' for i in range(0, 3): if os.path.isdir(os.path.join(prefix, 'pycdlib')): diff --git a/tests/unit/test_isohybrid.py b/tests/unit/test_isohybrid.py index be831ed6..b92cb791 100644 --- a/tests/unit/test_isohybrid.py +++ b/tests/unit/test_isohybrid.py @@ -1,14 +1,9 @@ -from __future__ import absolute_import - -import pytest import os import sys -try: - from cStringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO import struct +import pytest + prefix = '.' for i in range(0, 3): if os.path.isdir(os.path.join(prefix, 'pycdlib')): diff --git a/tests/unit/test_ptr.py b/tests/unit/test_ptr.py index 7db70000..08e8c50a 100644 --- a/tests/unit/test_ptr.py +++ b/tests/unit/test_ptr.py @@ -1,14 +1,9 @@ -from __future__ import absolute_import - -import pytest import os import sys -try: - from cStringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO import struct +import pytest + prefix = '.' for i in range(0, 3): if os.path.isdir(os.path.join(prefix, 'pycdlib')): diff --git a/tests/unit/test_rockridge.py b/tests/unit/test_rockridge.py index 3a3de878..4d4f2386 100644 --- a/tests/unit/test_rockridge.py +++ b/tests/unit/test_rockridge.py @@ -1,15 +1,10 @@ -from __future__ import absolute_import - -import pytest import os import sys -try: - from cStringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO import struct import time +import pytest + prefix = '.' for i in range(0, 3): if os.path.isdir(os.path.join(prefix, 'pycdlib')): diff --git a/tests/unit/test_udf.py b/tests/unit/test_udf.py index 5eb58cf7..a3519192 100644 --- a/tests/unit/test_udf.py +++ b/tests/unit/test_udf.py @@ -1,15 +1,10 @@ -from __future__ import absolute_import - -import pytest import os import sys -try: - from cStringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO import struct import time +import pytest + prefix = '.' for i in range(0, 3): if os.path.isdir(os.path.join(prefix, 'pycdlib')): diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 08be3c01..25b847cb 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -1,15 +1,11 @@ -from __future__ import absolute_import - -import pytest +import io import os import sys -try: - from cStringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO import struct import time +import pytest + prefix = '.' for i in range(0, 3): if os.path.isdir(os.path.join(prefix, 'pycdlib')): @@ -51,8 +47,8 @@ def test_ceiling_div_nan(): pycdlib.utils.ceiling_div(2048, 0) def test_copy_data(): - infp = BytesIO() - outfp = BytesIO() + infp = io.BytesIO() + outfp = io.BytesIO() infp.write(b'\x00'*1) infp.seek(0) @@ -62,8 +58,8 @@ def test_copy_data(): assert(outfp.getvalue() == b'\x00') def test_copy_data_short(): - infp = BytesIO() - outfp = BytesIO() + infp = io.BytesIO() + outfp = io.BytesIO() infp.write(b'\x00'*10) infp.seek(0) @@ -155,17 +151,17 @@ def test_gmtoffset_from_tm_2023_rollover(): restore_tz(oldtz) def test_zero_pad(): - fp = BytesIO() + fp = io.BytesIO() pycdlib.utils.zero_pad(fp, 5, 10) assert(fp.getvalue() == b'\x00'*5) def test_zero_pad_no_pad(): - fp = BytesIO() + fp = io.BytesIO() pycdlib.utils.zero_pad(fp, 5, 5) assert(fp.getvalue() == b'') def test_zero_pad_negative_pad(): - fp = BytesIO() + fp = io.BytesIO() pycdlib.utils.zero_pad(fp, 5, 4) assert(fp.getvalue() == b'\x00'*3) @@ -196,7 +192,7 @@ def test_split_path_trailing_slash(): assert(pycdlib.utils.split_path(b'/foo/') == [b'foo', b'']) def test_file_object_supports_binary_bytesio(): - fp = BytesIO() + fp = io.BytesIO() assert(pycdlib.utils.file_object_supports_binary(fp)) def test_truncate_basename_isolevel4(): diff --git a/tools/pycdlib-explorer b/tools/pycdlib-explorer index 460517e4..d4cd025c 100755 --- a/tools/pycdlib-explorer +++ b/tools/pycdlib-explorer @@ -21,8 +21,6 @@ The main code for the pycdlib-explorer tool, which can open, read, write, and otherwise manipulate ISOs in an interactive way. """ -from __future__ import print_function - import cmd import collections import os diff --git a/tools/pycdlib-extract-files b/tools/pycdlib-extract-files index 8c2d2e9d..95acfe2c 100755 --- a/tools/pycdlib-extract-files +++ b/tools/pycdlib-extract-files @@ -21,8 +21,6 @@ The main code for the pycdlib-extract-files tool, which can extract all or a subset of files from an ISO. """ -from __future__ import print_function - import argparse import collections import os diff --git a/tools/pycdlib-genisoimage b/tools/pycdlib-genisoimage index 0fbd9ae4..8c97cbee 100755 --- a/tools/pycdlib-genisoimage +++ b/tools/pycdlib-genisoimage @@ -21,38 +21,25 @@ A drop-in replacement program for the 'genisoimage' executable that uses PyCdlib under the hood. """ -from __future__ import print_function - import argparse import collections import fileinput import fnmatch +import io import os import sys import time -try: - from cStringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO import pycdlib ################################ MURMER3 HASH FUNCTIONS ############################## -if sys.version_info >= (3, 0): - def xrange(a, b, c): - """An xrange that works for Python 3.""" - return range(a, b, c) - - def xencode(x): - """A version of encode that works for bytes, bytearrays, or strings.""" - if isinstance(x, (bytearray, bytes)): - return x - return x.encode() -else: - def xencode(x): - """The identity version of xencode for Python 2.""" + +def xencode(x): + """A version of encode that works for bytes, bytearrays, or strings.""" + if isinstance(x, (bytearray, bytes)): return x + return x.encode() def mm3hash(key, seed=0x0): @@ -78,7 +65,7 @@ def mm3hash(key, seed=0x0): c2 = 0x1b873593 # body - for block_start in xrange(0, nblocks * 4, 4): + for block_start in range(0, nblocks * 4, 4): # ??? big endian? k1 = key[block_start + 3] << 24 | key[block_start + 2] << 16 | key[block_start + 1] << 8 | key[block_start + 0] @@ -163,7 +150,7 @@ def parse_file_list(thelist): Nothing. """ for f in thelist: - with open(f, 'r') as infp: + with open(f, 'r', encoding='locale') as infp: for line in infp.xreadlines(): yield line.rstrip() @@ -214,7 +201,7 @@ def build_udf_path(root, name): return intermediate + '/' + name -class EltoritoEntry(object): +class EltoritoEntry: """ A class that represents a single El Torito entry on the ISO. There may be more than one of these per-ISO, so each one is tracked separately. @@ -505,7 +492,7 @@ def determine_eltorito_entries(args): return eltorito_entries -class DirLevel(object): +class DirLevel: """ A class to hold information about one directory level of the directory hierarchy. Each level has an iso_path, a joliet_path, and a set of @@ -590,11 +577,11 @@ def main(): eltorito_entries = determine_eltorito_entries(args) if args.quiet: - logfp = open(os.devnull, 'w') # pylint: disable=consider-using-with + logfp = open(os.devnull, 'w', encoding='locale') # pylint: disable=consider-using-with else: if args.log_file is not None: print('re-directing all messages to %s' % (args.log_file)) - logfp = open(args.log_file, 'w') # pylint: disable=consider-using-with + logfp = open(args.log_file, 'w', encoding='locale') # pylint: disable=consider-using-with else: logfp = sys.stdout @@ -653,7 +640,7 @@ def main(): ignore_patterns.extend(('*~*', '*#*', '*.bak')) if args.print_size: - fp = BytesIO() + fp = io.BytesIO() else: if args.output is None: print('Output file must be specified (use -o)', file=logfp) @@ -895,7 +882,7 @@ def main(): else: raise - class ProgressData(object): + class ProgressData: """ A private class to hold onto the data from the last progress call. """