Lines Matching defs:encoding

160 def stn(s, length, encoding, errors):
165 s = s.encode(encoding, errors)
168 def nts(s, encoding, errors):
174 return s.decode(encoding, errors)
203 # particular encoding, the following digits-1 bytes are a big-endian
265 encoding = getattr(sys.stdout, 'encoding', None)
266 if encoding is not None:
267 s = s.encode(encoding, 'backslashreplace').decode(encoding)
976 def tobuf(self, format=DEFAULT_FORMAT, encoding=ENCODING, errors="surrogateescape"):
985 return self.create_ustar_header(info, encoding, errors)
987 return self.create_gnu_header(info, encoding, errors)
989 return self.create_pax_header(info, encoding)
993 def create_ustar_header(self, info, encoding, errors):
998 if len(info["linkname"].encode(encoding, errors)) > LENGTH_LINK:
1001 if len(info["name"].encode(encoding, errors)) > LENGTH_NAME:
1002 info["prefix"], info["name"] = self._posix_split_name(info["name"], encoding, errors)
1004 return self._create_header(info, USTAR_FORMAT, encoding, errors)
1006 def create_gnu_header(self, info, encoding, errors):
1012 if len(info["linkname"].encode(encoding, errors)) > LENGTH_LINK:
1013 buf += self._create_gnu_long_header(info["linkname"], GNUTYPE_LONGLINK, encoding, errors)
1015 if len(info["name"].encode(encoding, errors)) > LENGTH_NAME:
1016 buf += self._create_gnu_long_header(info["name"], GNUTYPE_LONGNAME, encoding, errors)
1018 return buf + self._create_header(info, GNU_FORMAT, encoding, errors)
1020 def create_pax_header(self, info, encoding):
1029 # be represented in ASCII encoding.
1072 buf = self._create_pax_generic_header(pax_headers, XHDTYPE, encoding)
1084 def _posix_split_name(self, name, encoding, errors):
1092 if len(prefix.encode(encoding, errors)) <= LENGTH_PREFIX and \
1093 len(name.encode(encoding, errors)) <= LENGTH_NAME:
1101 def _create_header(info, format, encoding, errors):
1110 devmajor = stn("", 8, encoding, errors)
1111 devminor = stn("", 8, encoding, errors)
1120 stn(info.get("name", ""), 100, encoding, errors),
1128 stn(info.get("linkname", ""), 100, encoding, errors),
1130 stn(info.get("uname", ""), 32, encoding, errors),
1131 stn(info.get("gname", ""), 32, encoding, errors),
1134 stn(info.get("prefix", ""), 155, encoding, errors)
1153 def _create_gnu_long_header(cls, name, type, encoding, errors):
1157 name = name.encode(encoding, errors) + NUL
1166 return cls._create_header(info, USTAR_FORMAT, encoding, errors) + \
1170 def _create_pax_generic_header(cls, pax_headers, type, encoding):
1194 # Needless to say, that the encoding must match the string.
1195 value = value.encode(encoding, "surrogateescape")
1221 def frombuf(cls, buf, encoding, errors):
1236 obj.name = nts(buf[0:100], encoding, errors)
1244 obj.linkname = nts(buf[157:257], encoding, errors)
1245 obj.uname = nts(buf[265:297], encoding, errors)
1246 obj.gname = nts(buf[297:329], encoding, errors)
1249 prefix = nts(buf[345:500], encoding, errors)
1289 obj = cls.frombuf(buf, tarfile.encoding, tarfile.errors)
1330 self._apply_pax_info(tarfile.pax_headers, tarfile.encoding, tarfile.errors)
1355 next.name = nts(buf, tarfile.encoding, tarfile.errors)
1357 next.linkname = nts(buf, tarfile.encoding, tarfile.errors)
1414 encoding = None
1440 # the encoding of the path, linkpath, uname and gname fields. Normally,
1448 if raw_keyword == b"hdrcharset" and encoding is None:
1450 encoding = tarfile.encoding
1452 encoding = "utf-8"
1457 if encoding is None:
1458 encoding = "utf-8"
1462 # Normally, we could just use "utf-8" as the encoding and "strict"
1467 # We first try the strict standard encoding, and if that fails we
1468 # fall back on the user's encoding and error handler.
1472 value = self._decode_pax_field(raw_value, encoding, tarfile.encoding,
1501 next._apply_pax_info(pax_headers, tarfile.encoding, tarfile.errors)
1557 def _apply_pax_info(self, pax_headers, encoding, errors):
1580 def _decode_pax_field(self, value, encoding, fallback_encoding, fallback_errors):
1584 return value.decode(encoding, "strict")
1655 encoding = ENCODING # Encoding for 8-bit character strings.
1666 tarinfo=None, dereference=None, ignore_zeros=None, encoding=None,
1709 if encoding is not None:
1710 self.encoding = encoding
2224 buf = tarinfo.tobuf(self.format, self.encoding, self.errors)