Browse Source

Update to python 3

test_fixup
Jessica Hair 5 years ago
parent
commit
cdb7e6750a
4 changed files with 20 additions and 20 deletions
  1. +6
    -6
      docs/conf.py
  2. +11
    -11
      libarchive/__init__.py
  3. +2
    -2
      libarchive/tar.py
  4. +1
    -1
      libarchive/zip.py

+ 6
- 6
docs/conf.py View File

@@ -40,8 +40,8 @@ source_suffix = '.rst'
master_doc = 'index' master_doc = 'index'


# General information about the project. # General information about the project.
project = u'python-libarchive' project = 'python-libarchive'
copyright = u'2012, Ben Timby' copyright = '2012, Ben Timby'


# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the
@@ -178,8 +178,8 @@ htmlhelp_basename = 'python-libarchivedoc'
# Grouping the document tree into LaTeX files. List of tuples # Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]). # (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [ latex_documents = [
('index', 'python-libarchive.tex', u'python-libarchive Documentation', ('index', 'python-libarchive.tex', 'python-libarchive Documentation',
u'Ben Timby', 'manual'), 'Ben Timby', 'manual'),
] ]


# The name of an image file (relative to this directory) to place at the top of # The name of an image file (relative to this directory) to place at the top of
@@ -211,6 +211,6 @@ latex_documents = [
# One entry per manual page. List of tuples # One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [ man_pages = [
('index', 'python-libarchive', u'python-libarchive Documentation', ('index', 'python-libarchive', 'python-libarchive Documentation',
[u'Ben Timby'], 1) ['Ben Timby'], 1)
] ]

+ 11
- 11
libarchive/__init__.py View File

@@ -31,9 +31,9 @@ import warnings


from libarchive import _libarchive from libarchive import _libarchive
try: try:
from cStringIO import StringIO from io import StringIO
except ImportError: except ImportError:
from StringIO import StringIO from io import StringIO


# Suggested block size for libarchive. Libarchive may adjust it. # Suggested block size for libarchive. Libarchive may adjust it.
BLOCK_SIZE = 10240 BLOCK_SIZE = 10240
@@ -134,7 +134,7 @@ def is_archive_name(filename, formats=None):
This function will return the name of the most likely archive format, None if the file is This function will return the name of the most likely archive format, None if the file is
unlikely to be an archive.''' unlikely to be an archive.'''
if formats is None: if formats is None:
formats = FORMAT_EXTENSIONS.values() formats = list(FORMAT_EXTENSIONS.values())
format, filter = guess_format(filename) format, filter = guess_format(filename)
if format in formats: if format in formats:
return format return format
@@ -153,7 +153,7 @@ def is_archive(f, formats=(None, ), filters=(None, )):


This function will return True if the file can be opened as an archive using the given This function will return True if the file can be opened as an archive using the given
format(s)/filter(s).''' format(s)/filter(s).'''
if isinstance(f, basestring): if isinstance(f, str):
f = file(f, 'r') f = file(f, 'r')
a = _libarchive.archive_read_new() a = _libarchive.archive_read_new()
for format in formats: for format in formats:
@@ -165,7 +165,7 @@ def is_archive(f, formats=(None, ), filters=(None, )):
filter = get_func(filter, FILTERS, 0) filter = get_func(filter, FILTERS, 0)
if filter is None: if filter is None:
return False return False
filter(a) list(filter(a))
try: try:
try: try:
call_and_check(_libarchive.archive_read_open_fd, a, a, f.fileno(), BLOCK_SIZE) call_and_check(_libarchive.archive_read_open_fd, a, a, f.fileno(), BLOCK_SIZE)
@@ -330,7 +330,7 @@ class Entry(object):
if entry is None: if entry is None:
entry = cls(encoding=encoding) entry = cls(encoding=encoding)
if entry.pathname is None: if entry.pathname is None:
if isinstance(f, basestring): if isinstance(f, str):
st = os.stat(f) st = os.stat(f)
entry.pathname = f entry.pathname = f
entry.size = st.st_size entry.size = st.st_size
@@ -390,7 +390,7 @@ class Archive(object):
self._stream = None self._stream = None
self.encoding = encoding self.encoding = encoding
self.blocksize = blocksize self.blocksize = blocksize
if isinstance(f, basestring): if isinstance(f, str):
self.filename = f self.filename = f
f = file(f, mode) f = file(f, mode)
# Only close it if we opened it... # Only close it if we opened it...
@@ -520,7 +520,7 @@ class Archive(object):
def readpath(self, f): def readpath(self, f):
'''Write current archive entry contents to file. f can be a file-like object or '''Write current archive entry contents to file. f can be a file-like object or
a path.''' a path.'''
if isinstance(f, basestring): if isinstance(f, str):
basedir = os.path.basename(f) basedir = os.path.basename(f)
if not os.path.exists(basedir): if not os.path.exists(basedir):
os.makedirs(basedir) os.makedirs(basedir)
@@ -534,7 +534,7 @@ class Archive(object):


def write(self, member, data=None): def write(self, member, data=None):
'''Writes a string buffer to the archive as the given entry.''' '''Writes a string buffer to the archive as the given entry.'''
if isinstance(member, basestring): if isinstance(member, str):
member = self.entry_class(pathname=member, encoding=self.encoding) member = self.entry_class(pathname=member, encoding=self.encoding)
if data: if data:
member.size = len(data) member.size = len(data)
@@ -548,7 +548,7 @@ class Archive(object):
'''Writes a file to the archive. f can be a file-like object or a path. Uses '''Writes a file to the archive. f can be a file-like object or a path. Uses
write() to do the actual writing.''' write() to do the actual writing.'''
member = self.entry_class.from_file(f, encoding=self.encoding) member = self.entry_class.from_file(f, encoding=self.encoding)
if isinstance(f, basestring): if isinstance(f, str):
if os.path.isfile(f): if os.path.isfile(f):
f = file(f, 'r') f = file(f, 'r')
if pathname: if pathname:
@@ -587,7 +587,7 @@ class SeekableArchive(Archive):
self._stream = None self._stream = None
# Convert file to open file. We need this to reopen the archive. # Convert file to open file. We need this to reopen the archive.
mode = kwargs.setdefault('mode', 'r') mode = kwargs.setdefault('mode', 'r')
if isinstance(f, basestring): if isinstance(f, str):
f = file(f, mode) f = file(f, mode)
super(SeekableArchive, self).__init__(f, **kwargs) super(SeekableArchive, self).__init__(f, **kwargs)
self.entries = [] self.entries = []


+ 2
- 2
libarchive/tar.py View File

@@ -76,14 +76,14 @@ class TarFile(SeekableArchive):
def getnames(self): def getnames(self):
return list(self.iterpaths) return list(self.iterpaths)


def next(self): def __next__(self):
raise NotImplementedError raise NotImplementedError
pass # TODO: how to do this? pass # TODO: how to do this?


def extract(self, member, path=None): def extract(self, member, path=None):
if path is None: if path is None:
path = os.getcwd() path = os.getcwd()
if isinstance(member, basestring): if isinstance(member, str):
f = os.path.join(path, member) f = os.path.join(path, member)
else: else:
f = os.path.join(path, member.pathname) f = os.path.join(path, member.pathname)


+ 1
- 1
libarchive/zip.py View File

@@ -23,7 +23,7 @@ class ZipEntry(Entry):
return self.size return self.size


def set_file_size(self, value): def set_file_size(self, value):
assert isinstance(value, (int, long)), 'Please provide size as int or long.' assert isinstance(value, int), 'Please provide size as int or long.'
self.size = value self.size = value


file_size = property(get_file_size, set_file_size) file_size = property(get_file_size, set_file_size)


||||||
x
 
000:0
Loading…
Cancel
Save