本文整理汇总了Python中gzip.WRITE属性的典型用法代码示例。如果您正苦于以下问题:Python gzip.WRITE属性的具体用法?Python gzip.WRITE怎么用?Python gzip.WRITE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类gzip
的用法示例。
在下文中一共展示了gzip.WRITE属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: close
# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import WRITE [as 别名]
def close(self):
fileobj = self.fileobj
if fileobj is None:
return
self.fileobj = None
try:
if self.mode == gzip.WRITE:
fileobj.write(self.compress.flush(Z_FINISH))
gzip.write32u(fileobj, self.crc)
# self.size may exceed 2GB, or even 4GB
gzip.write32u(fileobj, self.size & 0xffffffff)
fileobj.flush()
finally:
myfileobj = self.myfileobj
if myfileobj:
self.myfileobj = None
myfileobj.close()
示例2: _fileobj_normalize_mode
# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import WRITE [as 别名]
def _fileobj_normalize_mode(f):
"""Takes care of some corner cases in Python where the mode string
is either oddly formatted or does not truly represent the file mode.
"""
mode = f.mode
# Special case: Gzip modes:
if isinstance(f, gzip.GzipFile):
# GzipFiles can be either readonly or writeonly
if mode == gzip.READ:
return 'rb'
elif mode == gzip.WRITE:
return 'wb'
else:
return None # This shouldn't happen?
# Sometimes Python can produce modes like 'r+b' which will be normalized
# here to 'rb+'
if '+' in mode:
mode = mode.replace('+', '')
mode += '+'
return mode
示例3: close
# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import WRITE [as 别名]
def close(self):
# GzipFile.close() doesn't actuallly close anything.
if self.mode == GZ_WRITE:
self._write_gzip(None)
self._reset_buffer()
return GzipFile.close(self)