本文整理匯總了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)