MCPcopy Index your code
hub / github.com/RustPython/RustPython / nti

Function nti

Lib/tarfile.py:173–191  ·  view source on GitHub ↗

Convert a number field to a python number.

(s)

Source from the content-addressed store, hash-verified

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

Callers 2

frombufMethod · 0.85
_proc_sparseMethod · 0.85

Calls 4

lenFunction · 0.85
ntsFunction · 0.85
InvalidHeaderErrorClass · 0.85
stripMethod · 0.45

Tested by

no test coverage detected