def gzip_open_unicode(filename, mode="rb", compresslevel=9,
encoding='utf-8', fileobj=None, errors=None, newline=None):
if fileobj is None:
fileobj = GzipFile(filename, mode, compresslevel, fileobj)
return io.TextIOWrapper(fileobj, encoding, errors, newline)
python类filename()的实例源码
def __init__(self, filename=None, mode=None, compresslevel=9,
fileobj=None, **kwargs):
"""
Return a buffered gzip file object.
:param filename: a filesystem path
:type filename: str
:param mode: a file mode which can be any of 'r', 'rb', 'a', 'ab',
'w', or 'wb'
:type mode: str
:param compresslevel: The compresslevel argument is an integer from 1
to 9 controlling the level of compression; 1 is fastest and
produces the least compression, and 9 is slowest and produces the
most compression. The default is 9.
:type compresslevel: int
:param fileobj: a BytesIO stream to read from instead of a file.
:type fileobj: BytesIO
:param size: number of bytes to buffer during calls to read() and write()
:type size: int
:rtype: BufferedGzipFile
"""
GzipFile.__init__(self, filename, mode, compresslevel, fileobj)
self._size = kwargs.get('size', self.SIZE)
# Note: In > Python3.5, GzipFile is already using a
# buffered reader in the backend which has a variable self._buffer
# See https://github.com/nltk/nltk/issues/1308
if sys.version.startswith('3.5'):
sys.stderr.write("Use the native Python gzip.GzipFile instead.")
self._nltk_buffer = BytesIO()
# cStringIO does not support len.
self._len = 0
def __init__(self, zipfile, entry=''):
"""
Create a new path pointer pointing at the specified entry
in the given zipfile.
:raise IOError: If the given zipfile does not exist, or if it
does not contain the specified entry.
"""
if isinstance(zipfile, string_types):
zipfile = OpenOnDemandZipFile(os.path.abspath(zipfile))
# Normalize the entry string, it should be relative:
entry = normalize_resource_name(entry, True, '/').lstrip('/')
# Check that the entry exists:
if entry:
try:
zipfile.getinfo(entry)
except Exception:
# Sometimes directories aren't explicitly listed in
# the zip file. So if `entry` is a directory name,
# then check if the zipfile contains any files that
# are under the given directory.
if (entry.endswith('/') and
[n for n in zipfile.namelist() if n.startswith(entry)]):
pass # zipfile contains a file in that directory.
else:
# Otherwise, complain.
raise IOError('Zipfile %r does not contain %r' %
(zipfile.filename, entry))
self._zipfile = zipfile
self._entry = entry
def __repr__(self):
return str('ZipFilePathPointer(%r, %r)') % (
self._zipfile.filename, self._entry)
def __str__(self):
return os.path.normpath(os.path.join(self._zipfile.filename, self._entry))
######################################################################
# Access Functions
######################################################################
# Don't use a weak dictionary, because in the common case this
# causes a lot more reloading that necessary.
def __init__(self, filename):
if not isinstance(filename, string_types):
raise TypeError('ReopenableZipFile filename must be a string')
zipfile.ZipFile.__init__(self, filename)
assert self.filename == filename
self.close()
# After closing a ZipFile object, the _fileRefCnt needs to be cleared
# for Python2and3 compatible code.
self._fileRefCnt = 0
def read(self, name):
assert self.fp is None
self.fp = open(self.filename, 'rb')
value = zipfile.ZipFile.read(self, name)
# Ensure that _fileRefCnt needs to be set for Python2and3 compatible code.
# Since we only opened one file here, we add 1.
self._fileRefCnt += 1
self.close()
return value
def __repr__(self):
return repr(str('OpenOnDemandZipFile(%r)') % self.filename)
######################################################################
#{ Seekable Unicode Stream Reader
######################################################################
data.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 26
收藏 0
点赞 0
评论 0
def gzip_open_unicode(filename, mode="rb", compresslevel=9,
encoding='utf-8', fileobj=None, errors=None, newline=None):
if fileobj is None:
fileobj = GzipFile(filename, mode, compresslevel, fileobj)
return io.TextIOWrapper(fileobj, encoding, errors, newline)
data.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def __init__(self, filename=None, mode=None, compresslevel=9,
fileobj=None, **kwargs):
"""
Return a buffered gzip file object.
:param filename: a filesystem path
:type filename: str
:param mode: a file mode which can be any of 'r', 'rb', 'a', 'ab',
'w', or 'wb'
:type mode: str
:param compresslevel: The compresslevel argument is an integer from 1
to 9 controlling the level of compression; 1 is fastest and
produces the least compression, and 9 is slowest and produces the
most compression. The default is 9.
:type compresslevel: int
:param fileobj: a BytesIO stream to read from instead of a file.
:type fileobj: BytesIO
:param size: number of bytes to buffer during calls to read() and write()
:type size: int
:rtype: BufferedGzipFile
"""
GzipFile.__init__(self, filename, mode, compresslevel, fileobj)
self._size = kwargs.get('size', self.SIZE)
# Note: In > Python3.5, GzipFile is already using a
# buffered reader in the backend which has a variable self._buffer
# See https://github.com/nltk/nltk/issues/1308
if sys.version.startswith('3.5'):
sys.stderr.write("Use the native Python gzip.GzipFile instead.")
self._nltk_buffer = BytesIO()
# cStringIO does not support len.
self._len = 0
data.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 25
收藏 0
点赞 0
评论 0
def __init__(self, zipfile, entry=''):
"""
Create a new path pointer pointing at the specified entry
in the given zipfile.
:raise IOError: If the given zipfile does not exist, or if it
does not contain the specified entry.
"""
if isinstance(zipfile, string_types):
zipfile = OpenOnDemandZipFile(os.path.abspath(zipfile))
# Normalize the entry string, it should be relative:
entry = normalize_resource_name(entry, True, '/').lstrip('/')
# Check that the entry exists:
if entry:
try:
zipfile.getinfo(entry)
except Exception:
# Sometimes directories aren't explicitly listed in
# the zip file. So if `entry` is a directory name,
# then check if the zipfile contains any files that
# are under the given directory.
if (entry.endswith('/') and
[n for n in zipfile.namelist() if n.startswith(entry)]):
pass # zipfile contains a file in that directory.
else:
# Otherwise, complain.
raise IOError('Zipfile %r does not contain %r' %
(zipfile.filename, entry))
self._zipfile = zipfile
self._entry = entry
data.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def __repr__(self):
return str('ZipFilePathPointer(%r, %r)') % (
self._zipfile.filename, self._entry)
data.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 25
收藏 0
点赞 0
评论 0
def __str__(self):
return os.path.normpath(os.path.join(self._zipfile.filename, self._entry))
######################################################################
# Access Functions
######################################################################
# Don't use a weak dictionary, because in the common case this
# causes a lot more reloading that necessary.
data.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def __init__(self, filename):
if not isinstance(filename, string_types):
raise TypeError('ReopenableZipFile filename must be a string')
zipfile.ZipFile.__init__(self, filename)
assert self.filename == filename
self.close()
# After closing a ZipFile object, the _fileRefCnt needs to be cleared
# for Python2and3 compatible code.
self._fileRefCnt = 0
data.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
def read(self, name):
assert self.fp is None
self.fp = open(self.filename, 'rb')
value = zipfile.ZipFile.read(self, name)
# Ensure that _fileRefCnt needs to be set for Python2and3 compatible code.
# Since we only opened one file here, we add 1.
self._fileRefCnt += 1
self.close()
return value
data.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def __repr__(self):
return repr(str('OpenOnDemandZipFile(%r)') % self.filename)
######################################################################
#{ Seekable Unicode Stream Reader
######################################################################
def gzip_open_unicode(filename, mode="rb", compresslevel=9,
encoding='utf-8', fileobj=None, errors=None, newline=None):
if fileobj is None:
fileobj = GzipFile(filename, mode, compresslevel, fileobj)
return io.TextIOWrapper(fileobj, encoding, errors, newline)
def __init__(self, filename=None, mode=None, compresslevel=9,
fileobj=None, **kwargs):
"""
Return a buffered gzip file object.
:param filename: a filesystem path
:type filename: str
:param mode: a file mode which can be any of 'r', 'rb', 'a', 'ab',
'w', or 'wb'
:type mode: str
:param compresslevel: The compresslevel argument is an integer from 1
to 9 controlling the level of compression; 1 is fastest and
produces the least compression, and 9 is slowest and produces the
most compression. The default is 9.
:type compresslevel: int
:param fileobj: a BytesIO stream to read from instead of a file.
:type fileobj: BytesIO
:param size: number of bytes to buffer during calls to read() and write()
:type size: int
:rtype: BufferedGzipFile
"""
GzipFile.__init__(self, filename, mode, compresslevel, fileobj)
self._size = kwargs.get('size', self.SIZE)
self._buffer = BytesIO()
# cStringIO does not support len.
self._len = 0
def __init__(self, zipfile, entry=''):
"""
Create a new path pointer pointing at the specified entry
in the given zipfile.
:raise IOError: If the given zipfile does not exist, or if it
does not contain the specified entry.
"""
if isinstance(zipfile, string_types):
zipfile = OpenOnDemandZipFile(os.path.abspath(zipfile))
# Normalize the entry string, it should be relative:
entry = normalize_resource_name(entry, True, '/').lstrip('/')
# Check that the entry exists:
if entry:
try:
zipfile.getinfo(entry)
except Exception:
# Sometimes directories aren't explicitly listed in
# the zip file. So if `entry` is a directory name,
# then check if the zipfile contains any files that
# are under the given directory.
if (entry.endswith('/') and
[n for n in zipfile.namelist() if n.startswith(entry)]):
pass # zipfile contains a file in that directory.
else:
# Otherwise, complain.
raise IOError('Zipfile %r does not contain %r' %
(zipfile.filename, entry))
self._zipfile = zipfile
self._entry = entry
def __repr__(self):
return str('ZipFilePathPointer(%r, %r)') % (
self._zipfile.filename, self._entry)
def __str__(self):
return os.path.normpath(os.path.join(self._zipfile.filename, self._entry))
######################################################################
# Access Functions
######################################################################
# Don't use a weak dictionary, because in the common case this
# causes a lot more reloading that necessary.
def __init__(self, filename):
if not isinstance(filename, string_types):
raise TypeError('ReopenableZipFile filename must be a string')
zipfile.ZipFile.__init__(self, filename)
assert self.filename == filename
self.close()
def read(self, name):
assert self.fp is None
self.fp = open(self.filename, 'rb')
value = zipfile.ZipFile.read(self, name)
self.close()
return value
def __repr__(self):
return repr(str('OpenOnDemandZipFile(%r)') % self.filename)
######################################################################
#{ Seekable Unicode Stream Reader
######################################################################
def gzip_open_unicode(filename, mode="rb", compresslevel=9,
encoding='utf-8', fileobj=None, errors=None, newline=None):
if fileobj is None:
fileobj = GzipFile(filename, mode, compresslevel, fileobj)
return io.TextIOWrapper(fileobj, encoding, errors, newline)
def __init__(self, filename=None, mode=None, compresslevel=9,
fileobj=None, **kwargs):
"""
Return a buffered gzip file object.
:param filename: a filesystem path
:type filename: str
:param mode: a file mode which can be any of 'r', 'rb', 'a', 'ab',
'w', or 'wb'
:type mode: str
:param compresslevel: The compresslevel argument is an integer from 1
to 9 controlling the level of compression; 1 is fastest and
produces the least compression, and 9 is slowest and produces the
most compression. The default is 9.
:type compresslevel: int
:param fileobj: a BytesIO stream to read from instead of a file.
:type fileobj: BytesIO
:param size: number of bytes to buffer during calls to read() and write()
:type size: int
:rtype: BufferedGzipFile
"""
GzipFile.__init__(self, filename, mode, compresslevel, fileobj)
self._size = kwargs.get('size', self.SIZE)
self._nltk_buffer = BytesIO()
# cStringIO does not support len.
self._len = 0
def __init__(self, zipfile, entry=''):
"""
Create a new path pointer pointing at the specified entry
in the given zipfile.
:raise IOError: If the given zipfile does not exist, or if it
does not contain the specified entry.
"""
if isinstance(zipfile, string_types):
zipfile = OpenOnDemandZipFile(os.path.abspath(zipfile))
# Normalize the entry string, it should be relative:
entry = normalize_resource_name(entry, True, '/').lstrip('/')
# Check that the entry exists:
if entry:
try:
zipfile.getinfo(entry)
except Exception:
# Sometimes directories aren't explicitly listed in
# the zip file. So if `entry` is a directory name,
# then check if the zipfile contains any files that
# are under the given directory.
if (entry.endswith('/') and
[n for n in zipfile.namelist() if n.startswith(entry)]):
pass # zipfile contains a file in that directory.
else:
# Otherwise, complain.
raise IOError('Zipfile %r does not contain %r' %
(zipfile.filename, entry))
self._zipfile = zipfile
self._entry = entry
def __repr__(self):
return str('ZipFilePathPointer(%r, %r)') % (
self._zipfile.filename, self._entry)
def __str__(self):
return os.path.normpath(os.path.join(self._zipfile.filename, self._entry))
######################################################################
# Access Functions
######################################################################
# Don't use a weak dictionary, because in the common case this
# causes a lot more reloading that necessary.
def __init__(self, filename):
if not isinstance(filename, string_types):
raise TypeError('ReopenableZipFile filename must be a string')
zipfile.ZipFile.__init__(self, filename)
assert self.filename == filename
self.close()
# After closing a ZipFile object, the _fileRefCnt needs to be cleared
# for Python2and3 compatible code.
self._fileRefCnt = 0