MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / nti

Function nti

tools/python-3.11.9-amd64/Lib/tarfile.py:176–194  ·  view source on GitHub ↗

Convert a number field to a python number.

(s)

Source from the content-addressed store, hash-verified

174 return s.decode(encoding, errors)
175
176def nti(s):
177 """Convert a number field to a python number.
178 """
179 # There are two possible encodings for a number field, see
180 # itn() below.
181 if s[0] in (0o200, 0o377):
182 n = 0
183 for i in range(len(s) - 1):
184 n <<= 8
185 n += s[i + 1]
186 if s[0] == 0o377:
187 n = -(256 ** (len(s) - 1) - n)
188 else:
189 try:
190 s = nts(s, "ascii", "strict")
191 n = int(s.strip() or "0", 8)
192 except ValueError:
193 raise InvalidHeaderError("invalid header")
194 return n
195
196def itn(n, digits=8, format=DEFAULT_FORMAT):
197 """Convert a python number to a number field.

Callers 2

frombufMethod · 0.85
_proc_sparseMethod · 0.85

Calls 3

ntsFunction · 0.85
InvalidHeaderErrorClass · 0.85
stripMethod · 0.80

Tested by

no test coverage detected