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'

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

# The version info for the project you're documenting, acts as replacement for
# |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
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'python-libarchive.tex', u'python-libarchive Documentation',
u'Ben Timby', 'manual'),
('index', 'python-libarchive.tex', 'python-libarchive Documentation',
'Ben Timby', 'manual'),
]

# 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
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'python-libarchive', u'python-libarchive Documentation',
[u'Ben Timby'], 1)
('index', 'python-libarchive', 'python-libarchive Documentation',
['Ben Timby'], 1)
]

+ 11
- 11
libarchive/__init__.py View File

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

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

# Suggested block size for libarchive. Libarchive may adjust it.
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
unlikely to be an archive.'''
if formats is None:
formats = FORMAT_EXTENSIONS.values()
formats = list(FORMAT_EXTENSIONS.values())
format, filter = guess_format(filename)
if format in formats:
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
format(s)/filter(s).'''
if isinstance(f, basestring):
if isinstance(f, str):
f = file(f, 'r')
a = _libarchive.archive_read_new()
for format in formats:
@@ -165,7 +165,7 @@ def is_archive(f, formats=(None, ), filters=(None, )):
filter = get_func(filter, FILTERS, 0)
if filter is None:
return False
filter(a)
list(filter(a))
try:
try:
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:
entry = cls(encoding=encoding)
if entry.pathname is None:
if isinstance(f, basestring):
if isinstance(f, str):
st = os.stat(f)
entry.pathname = f
entry.size = st.st_size
@@ -390,7 +390,7 @@ class Archive(object):
self._stream = None
self.encoding = encoding
self.blocksize = blocksize
if isinstance(f, basestring):
if isinstance(f, str):
self.filename = f
f = file(f, mode)
# Only close it if we opened it...
@@ -520,7 +520,7 @@ class Archive(object):
def readpath(self, f):
'''Write current archive entry contents to file. f can be a file-like object or
a path.'''
if isinstance(f, basestring):
if isinstance(f, str):
basedir = os.path.basename(f)
if not os.path.exists(basedir):
os.makedirs(basedir)
@@ -534,7 +534,7 @@ class Archive(object):

def write(self, member, data=None):
'''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)
if 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
write() to do the actual writing.'''
member = self.entry_class.from_file(f, encoding=self.encoding)
if isinstance(f, basestring):
if isinstance(f, str):
if os.path.isfile(f):
f = file(f, 'r')
if pathname:
@@ -587,7 +587,7 @@ class SeekableArchive(Archive):
self._stream = None
# Convert file to open file. We need this to reopen the archive.
mode = kwargs.setdefault('mode', 'r')
if isinstance(f, basestring):
if isinstance(f, str):
f = file(f, mode)
super(SeekableArchive, self).__init__(f, **kwargs)
self.entries = []


+ 2
- 2
libarchive/tar.py View File

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

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

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


+ 1
- 1
libarchive/zip.py View File

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

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

file_size = property(get_file_size, set_file_size)


Loading…
Cancel
Save