本文整理匯總了Python中tarfile.XHDTYPE屬性的典型用法代碼示例。如果您正苦於以下問題:Python tarfile.XHDTYPE屬性的具體用法?Python tarfile.XHDTYPE怎麽用?Python tarfile.XHDTYPE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類tarfile
的用法示例。
在下文中一共展示了tarfile.XHDTYPE屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _create_pax_generic_header
# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import XHDTYPE [as 別名]
def _create_pax_generic_header(cls, pax_headers, type=tarfile.XHDTYPE):
"""Return a POSIX.1-2001 extended or global header sequence
that contains a list of keyword, value pairs. The values
must be unicode objects.
"""
records = []
for keyword, value in pax_headers.iteritems():
try:
keyword = keyword.encode("utf8")
except Exception:
pass
try:
value = value.encode("utf8")
except Exception:
pass
l = len(keyword) + len(value) + 3 # ' ' + '=' + '\n'
n = p = 0
while True:
n = l + len(str(p))
if n == p:
break
p = n
records.append("%d %s=%s\n" % (p, keyword, value))
records = "".join(records)
# We use a hardcoded "././@PaxHeader" name like star does
# instead of the one that POSIX recommends.
info = {}
info["name"] = "././@PaxHeader"
info["type"] = type
info["size"] = len(records)
info["magic"] = tarfile.POSIX_MAGIC
# Create pax header + record blocks.
return cls._create_header(info, tarfile.USTAR_FORMAT) + \
cls._create_payload(records)