id
int64
1
6.07M
name
stringlengths
1
295
code
stringlengths
12
426k
language
stringclasses
1 value
source_file
stringlengths
5
202
start_line
int64
1
158k
end_line
int64
1
158k
repo
dict
9,601
isprintable
def isprintable(b: bytes) -> bool: return all(0x20 <= c < 0x7f for c in b)
python
Tools/build/deepfreeze.py
27
28
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,602
make_string_literal
def make_string_literal(b: bytes) -> str: res = ['"'] if isprintable(b): res.append(b.decode("ascii").replace("\\", "\\\\").replace("\"", "\\\"")) else: for i in b: res.append(f"\\x{i:02x}") res.append('"') return "".join(res)
python
Tools/build/deepfreeze.py
31
39
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,603
get_localsplus
def get_localsplus(code: types.CodeType): a = collections.defaultdict(int) for name in code.co_varnames: a[name] |= CO_FAST_LOCAL for name in code.co_cellvars: a[name] |= CO_FAST_CELL for name in code.co_freevars: a[name] |= CO_FAST_FREE return tuple(a.keys()), bytes(a.values...
python
Tools/build/deepfreeze.py
48
56
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,604
get_localsplus_counts
def get_localsplus_counts(code: types.CodeType, names: Tuple[str, ...], kinds: bytes) -> Tuple[int, int, int, int]: nlocals = 0 ncellvars = 0 nfreevars = 0 assert len(names) == len(kinds) for name, kind in zip(names, kinds): if kind & CO_FA...
python
Tools/build/deepfreeze.py
59
79
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,605
analyze_character_width
def analyze_character_width(s: str) -> Tuple[int, bool]: maxchar = ' ' for c in s: maxchar = max(maxchar, c) ascii = False if maxchar <= '\xFF': kind = PyUnicode_1BYTE_KIND ascii = maxchar <= '\x7F' elif maxchar <= '\uFFFF': kind = PyUnicode_2BYTE_KIND else: ...
python
Tools/build/deepfreeze.py
87
99
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,606
removesuffix
def removesuffix(base: str, suffix: str) -> str: if base.endswith(suffix): return base[:len(base) - len(suffix)] return base
python
Tools/build/deepfreeze.py
102
105
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,607
__init__
def __init__(self, file: TextIO) -> None: self.level = 0 self.file = file self.cache: Dict[tuple[type, object, str], str] = {} self.hits, self.misses = 0, 0 self.finis: list[str] = [] self.inits: list[str] = [] self.identifiers, self.strings = self.get_identifiers...
python
Tools/build/deepfreeze.py
109
123
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,608
get_identifiers_and_strings
def get_identifiers_and_strings(self) -> tuple[set[str], dict[str, str]]: filename = os.path.join(ROOT, "Include", "internal", "pycore_global_strings.h") with open(filename) as fp: lines = fp.readlines() identifiers: set[str] = set() strings: dict[str, str] = {} for l...
python
Tools/build/deepfreeze.py
125
136
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,609
indent
def indent(self) -> None: save_level = self.level try: self.level += 1 yield finally: self.level = save_level
python
Tools/build/deepfreeze.py
139
145
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,610
write
def write(self, arg: str) -> None: self.file.writelines((" "*self.level, arg, "\n"))
python
Tools/build/deepfreeze.py
147
148
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,611
block
def block(self, prefix: str, suffix: str = "") -> None: self.write(prefix + " {") with self.indent(): yield self.write("}" + suffix)
python
Tools/build/deepfreeze.py
151
155
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,612
object_head
def object_head(self, typename: str) -> None: self.write(f".ob_base = _PyObject_HEAD_INIT(&{typename}),")
python
Tools/build/deepfreeze.py
157
158
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,613
object_var_head
def object_var_head(self, typename: str, size: int) -> None: self.write(f".ob_base = _PyVarObject_HEAD_INIT(&{typename}, {size}),")
python
Tools/build/deepfreeze.py
160
161
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,614
field
def field(self, obj: object, name: str) -> None: self.write(f".{name} = {getattr(obj, name)},")
python
Tools/build/deepfreeze.py
163
164
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,615
generate_bytes
def generate_bytes(self, name: str, b: bytes) -> str: if b == b"": return "(PyObject *)&_Py_SINGLETON(bytes_empty)" if len(b) == 1: return f"(PyObject *)&_Py_SINGLETON(bytes_characters[{b[0]}])" self.write("static") with self.indent(): with self.block(...
python
Tools/build/deepfreeze.py
166
181
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,616
generate_unicode
def generate_unicode(self, name: str, s: str) -> str: if s in self.strings: return f"&_Py_STR({self.strings[s]})" if s in self.identifiers: return f"&_Py_ID({s})" if len(s) == 1: c = ord(s) if c < 128: return f"(PyObject *)&_Py_SING...
python
Tools/build/deepfreeze.py
183
242
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,617
generate_code
def generate_code(self, name: str, code: types.CodeType) -> str: global next_code_version # The ordering here matches PyCode_NewWithPosOnlyArgs() # (but see below). co_consts = self.generate(name + "_consts", code.co_consts) co_names = self.generate(name + "_names", code.co_names...
python
Tools/build/deepfreeze.py
245
306
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,618
generate_tuple
def generate_tuple(self, name: str, t: Tuple[object, ...]) -> str: if len(t) == 0: return f"(PyObject *)& _Py_SINGLETON(tuple_empty)" items = [self.generate(f"{name}_{i}", it) for i, it in enumerate(t)] self.write("static") with self.indent(): with self.block("str...
python
Tools/build/deepfreeze.py
308
327
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,619
_generate_int_for_bits
def _generate_int_for_bits(self, name: str, i: int, digit: int) -> None: sign = (i > 0) - (i < 0) i = abs(i) digits: list[int] = [] while i: i, rem = divmod(i, digit) digits.append(rem) self.write("static") with self.indent(): with self...
python
Tools/build/deepfreeze.py
329
347
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,620
generate_int
def generate_int(self, name: str, i: int) -> str: if -5 <= i <= 256: return f"(PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS + {i}]" if i >= 0: name = f"const_int_{i}" else: name = f"const_int_negative_{abs(i)}" if abs(i) < 2**15: self._...
python
Tools/build/deepfreeze.py
349
368
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,621
generate_float
def generate_float(self, name: str, x: float) -> str: with self.block(f"static PyFloatObject {name} =", ";"): self.object_head("PyFloat_Type") self.write(f".ob_fval = {x},") return f"&{name}.ob_base"
python
Tools/build/deepfreeze.py
370
374
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,622
generate_complex
def generate_complex(self, name: str, z: complex) -> str: with self.block(f"static PyComplexObject {name} =", ";"): self.object_head("PyComplex_Type") self.write(f".cval = {{ {z.real}, {z.imag} }},") return f"&{name}.ob_base"
python
Tools/build/deepfreeze.py
376
380
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,623
generate_frozenset
def generate_frozenset(self, name: str, fs: FrozenSet[object]) -> str: try: fs = sorted(fs) except TypeError: # frozen set with incompatible types, fallback to repr() fs = sorted(fs, key=repr) ret = self.generate_tuple(name, tuple(fs)) self.write("// T...
python
Tools/build/deepfreeze.py
382
390
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,624
generate_file
def generate_file(self, module: str, code: object)-> None: module = module.replace(".", "_") self.generate(f"{module}_toplevel", code) self.write(EPILOGUE.format(name=module))
python
Tools/build/deepfreeze.py
392
395
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,625
generate
def generate(self, name: str, obj: object) -> str: # Use repr() in the key to distinguish -0.0 from +0.0 key = (type(obj), obj, repr(obj)) if key in self.cache: self.hits += 1 # print(f"Cache hit {key!r:.40}: {self.cache[key]!r:.40}") return self.cache[key] ...
python
Tools/build/deepfreeze.py
397
434
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,626
is_frozen_header
def is_frozen_header(source: str) -> bool: return source.startswith((FROZEN_COMMENT_C, FROZEN_COMMENT_PY))
python
Tools/build/deepfreeze.py
451
452
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,627
decode_frozen_data
def decode_frozen_data(source: str) -> types.CodeType: values: list[int] = [] for line in source.splitlines(): if re.match(FROZEN_DATA_LINE, line): values.extend([int(x) for x in line.split(",") if x.strip()]) data = bytes(values) return umarshal.loads(data)
python
Tools/build/deepfreeze.py
455
461
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,628
generate
def generate(args: list[str], output: TextIO) -> None: printer = Printer(output) for arg in args: file, modname = arg.rsplit(':', 1) with open(file, "r", encoding="utf8") as fd: source = fd.read() if is_frozen_header(source): code = decode_frozen_data(sour...
python
Tools/build/deepfreeze.py
464
485
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,629
report_time
def report_time(label: str): t0 = time.time() try: yield finally: t1 = time.time() if verbose: print(f"{label}: {t1-t0:.3f} sec")
python
Tools/build/deepfreeze.py
497
504
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,630
main
def main() -> None: global verbose args = parser.parse_args() verbose = args.verbose output = args.output if args.file: if verbose: print(f"Reading targets from {args.file}") with open(args.file, "rt", encoding="utf-8-sig") as fin: rules = [x.strip() for x in...
python
Tools/build/deepfreeze.py
507
525
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,631
load_tokens
def load_tokens(path): tok_names = [] string_to_tok = {} ERRORTOKEN = None with open(path) as fp: for line in fp: line = line.strip() # strip comments i = line.find('#') if i >= 0: line = line[:i].strip() if not line: ...
python
Tools/build/generate_token.py
14
37
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,632
update_file
def update_file(file, content): try: with open(file, 'r') as fobj: if fobj.read() == content: return False except (OSError, ValueError): pass with open(file, 'w') as fobj: fobj.write(content) return True
python
Tools/build/generate_token.py
40
49
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,633
make_h
def make_h(infile, outfile='Include/internal/pycore_token.h'): tok_names, ERRORTOKEN, string_to_tok = load_tokens(infile) defines = [] for value, name in enumerate(tok_names[:ERRORTOKEN + 1]): defines.append("#define %-15s %d\n" % (name, value)) if update_file(outfile, token_h_template % ( ...
python
Tools/build/generate_token.py
99
111
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,634
generate_chars_to_token
def generate_chars_to_token(mapping, n=1): result = [] write = result.append indent = ' ' * n write(indent) write('switch (c%d) {\n' % (n,)) for c in sorted(mapping): write(indent) value = mapping[c] if isinstance(value, dict): write("case '%s':\n" % (c,)) ...
python
Tools/build/generate_token.py
152
170
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,635
make_c
def make_c(infile, outfile='Parser/token.c'): tok_names, ERRORTOKEN, string_to_tok = load_tokens(infile) string_to_tok['<>'] = string_to_tok['!='] chars_to_token = {} for string, value in string_to_tok.items(): assert 1 <= len(string) <= 3 name = tok_names[value] m = chars_to_tok...
python
Tools/build/generate_token.py
172
197
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,636
make_rst
def make_rst(infile, outfile='Doc/library/token-list.inc'): tok_names, ERRORTOKEN, string_to_tok = load_tokens(infile) tok_to_string = {value: s for s, value in string_to_tok.items()} names = [] for value, name in enumerate(tok_names[:ERRORTOKEN + 1]): names.append('.. data:: %s' % (name,)) ...
python
Tools/build/generate_token.py
208
221
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,637
make_py
def make_py(infile, outfile='Lib/token.py'): tok_names, ERRORTOKEN, string_to_tok = load_tokens(infile) constants = [] for value, name in enumerate(tok_names): constants.append('%s = %d' % (name, value)) constants.insert(ERRORTOKEN, "# These aren't used by the C tokenizer but are needed...
python
Tools/build/generate_token.py
255
274
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,638
main
def main(op, infile='Grammar/Tokens', *args): make = globals()['make_' + op] make(infile, *args)
python
Tools/build/generate_token.py
277
279
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,639
updating_file_with_tmpfile
def updating_file_with_tmpfile(filename, tmpfile=None): """A context manager for updating a file via a temp file. The context manager provides two open files: the source file open for reading, and the temp file, open for writing. Upon exiting: both files are closed, and the source file is replaced ...
python
Tools/build/update_file.py
16
46
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,640
update_file_with_tmpfile
def update_file_with_tmpfile(filename, tmpfile, *, create=False): try: targetfile = open(filename, 'rb') except FileNotFoundError: if not create: raise # re-raise outcome = 'created' os.replace(tmpfile, filename) else: with targetfile: old_con...
python
Tools/build/update_file.py
49
69
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,641
__init__
def __init__(self): self.contents = dict()
python
Tools/build/stable_abi.py
57
58
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,642
add
def add(self, item): if item.name in self.contents: # We assume that stable ABI items do not share names, # even if they're different kinds (e.g. function vs. macro). raise ValueError(f'duplicate ABI item {item.name}') self.contents[item.name] = item
python
Tools/build/stable_abi.py
60
65
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,643
select
def select(self, kinds, *, include_abi_only=True, ifdef=None): """Yield selected items of the manifest kinds: set of requested kinds, e.g. {'function', 'macro'} include_abi_only: if True (default), include all items of the stable ABI. If False, include only items from th...
python
Tools/build/stable_abi.py
67
89
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,644
dump
def dump(self): """Yield lines to recreate the manifest file (sans comments/newlines)""" for item in self.contents.values(): fields = dataclasses.fields(item) yield f"[{item.kind}.{item.name}]" for field in fields: if field.name in {'name', 'value', 'k...
python
Tools/build/stable_abi.py
91
105
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,645
itemclass
def itemclass(kind): """Register the decorated class in `itemclasses`""" def decorator(cls): itemclasses[kind] = cls return cls return decorator
python
Tools/build/stable_abi.py
109
114
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,646
decorator
def decorator(cls): itemclasses[kind] = cls return cls
python
Tools/build/stable_abi.py
111
113
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,647
parse_manifest
def parse_manifest(file): """Parse the given file (iterable of lines) to a Manifest""" manifest = Manifest() data = tomllib.load(file) for kind, itemclass in itemclasses.items(): for name, item_data in data[kind].items(): try: item = itemclass(name=name, kind=kind,...
python
Tools/build/stable_abi.py
146
162
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,648
generator
def generator(var_name, default_path): """Decorates a file generator: function that writes to a file""" def _decorator(func): func.var_name = var_name func.arg_name = '--' + var_name.replace('_', '-') func.default_path = default_path generators.append(func) return func ...
python
Tools/build/stable_abi.py
170
178
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,649
_decorator
def _decorator(func): func.var_name = var_name func.arg_name = '--' + var_name.replace('_', '-') func.default_path = default_path generators.append(func) return func
python
Tools/build/stable_abi.py
172
177
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,650
gen_python3dll
def gen_python3dll(manifest, args, outfile): """Generate/check the source for the Windows stable ABI library""" write = partial(print, file=outfile) content = f"""\ /* Re-export stable Python ABI */ /* Generated by {SCRIPT_NAME} */ """ content += r""" #ifdef _M_IX86 ...
python
Tools/build/stable_abi.py
182
226
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,651
sort_key
def sort_key(item): return item.name.lower()
python
Tools/build/stable_abi.py
204
205
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,652
gen_doc_annotations
def gen_doc_annotations(manifest, args, outfile): """Generate/check the stable ABI list for documentation annotations""" writer = csv.DictWriter( outfile, ['role', 'name', 'added', 'ifdef_note', 'struct_abi_kind'], lineterminator='\n') writer.writeheader() for item in manifest.se...
python
Tools/build/stable_abi.py
238
263
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,653
gen_ctypes_test
def gen_ctypes_test(manifest, args, outfile): """Generate/check the ctypes-based test for exported symbols""" write = partial(print, file=outfile) write(textwrap.dedent(f'''\ # Generated by {SCRIPT_NAME} """Test that all symbols of the Stable ABI are accessible using ctypes """ ...
python
Tools/build/stable_abi.py
266
340
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,654
gen_testcapi_feature_macros
def gen_testcapi_feature_macros(manifest, args, outfile): """Generate/check the stable ABI list for documentation annotations""" write = partial(print, file=outfile) write(f'// Generated by {SCRIPT_NAME}') write() write('// Add an entry in dict `result` for each Stable ABI feature macro.') write...
python
Tools/build/stable_abi.py
344
361
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,655
generate_or_check
def generate_or_check(manifest, args, path, func): """Generate/check a file with a single generator Return True if successful; False if a comparison failed. """ outfile = io.StringIO() func(manifest, args, outfile) generated = outfile.getvalue() existing = path.read_text() if generate...
python
Tools/build/stable_abi.py
364
388
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,656
do_unixy_check
def do_unixy_check(manifest, args): """Check headers & library using "Unixy" tools (GCC/clang, binutils)""" okay = True # Get all macros first: we'll need feature macros like HAVE_FORK and # MS_WINDOWS for everything else present_macros = gcc_get_limited_api_macros(['Include/Python.h']) feature...
python
Tools/build/stable_abi.py
391
451
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,657
_report_unexpected_items
def _report_unexpected_items(items, msg): """If there are any `items`, report them using "msg" and return false""" if items: print(msg, file=sys.stderr) for item in sorted(items): print(' -', item, file=sys.stderr) return False return True
python
Tools/build/stable_abi.py
454
461
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,658
binutils_get_exported_symbols
def binutils_get_exported_symbols(library, dynamic=False): """Retrieve exported symbols using the nm(1) tool from binutils""" # Only look at dynamic symbols args = ["nm", "--no-sort"] if dynamic: args.append("--dynamic") args.append(library) proc = subprocess.run(args, stdout=subprocess....
python
Tools/build/stable_abi.py
464
493
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,659
binutils_check_library
def binutils_check_library(manifest, library, expected_symbols, dynamic): """Check that library exports all expected_symbols""" available_symbols = set(binutils_get_exported_symbols(library, dynamic)) missing_symbols = expected_symbols - available_symbols if missing_symbols: print(textwrap.deden...
python
Tools/build/stable_abi.py
496
512
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,660
gcc_get_limited_api_macros
def gcc_get_limited_api_macros(headers): """Get all limited API macros from headers. Runs the preprocessor over all the header files in "Include" setting "-DPy_LIMITED_API" to the correct value for the running version of the interpreter and extracting all macro definitions (via adding -dM to the co...
python
Tools/build/stable_abi.py
515
549
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,661
gcc_get_limited_api_definitions
def gcc_get_limited_api_definitions(headers): """Get all limited API definitions from headers. Run the preprocessor over all the header files in "Include" setting "-DPy_LIMITED_API" to the correct value for the running version of the interpreter. The limited API symbols will be extracted from the ...
python
Tools/build/stable_abi.py
552
596
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,662
check_private_names
def check_private_names(manifest): """Ensure limited API doesn't contain private names Names prefixed by an underscore are private by definition. """ for name, item in manifest.contents.items(): if name.startswith('_') and not item.abi_only: raise ValueError( f'`{nam...
python
Tools/build/stable_abi.py
598
607
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,663
check_dump
def check_dump(manifest, filename): """Check that manifest.dump() corresponds to the data. Mainly useful when debugging this script. """ dumped = tomllib.loads('\n'.join(manifest.dump())) with filename.open('rb') as file: from_file = tomllib.load(file) if dumped != from_file: pr...
python
Tools/build/stable_abi.py
609
629
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,664
main
def main(): parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, ) parser.add_argument( "file", type=Path, metavar='FILE', help="file with the stable abi manifest", ) parser.add_argument( "--generate", ac...
python
Tools/build/stable_abi.py
631
757
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,665
update_file
def update_file(file, content): try: with open(file, 'r', encoding='utf-8') as fobj: if fobj.read() == content: return False except (OSError, ValueError): pass with open(file, 'w', encoding='utf-8') as fobj: fobj.write(content) return True
python
Tools/build/generate_re_casefix.py
10
19
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,666
uname
def uname(i): return unicodedata.name(chr(i), r'U+%04X' % i)
python
Tools/build/generate_re_casefix.py
31
32
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,667
__repr__
def __repr__(self): return '%#06x' % self
python
Tools/build/generate_re_casefix.py
35
36
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,668
alpha
def alpha(i): c = chr(i) return c if c.isalpha() else ascii(c)[1:-1]
python
Tools/build/generate_re_casefix.py
38
40
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,669
main
def main(outfile='Lib/re/_casefix.py'): # Find sets of characters which have the same uppercase. equivalent_chars = collections.defaultdict(str) for c in map(chr, range(sys.maxunicode + 1)): equivalent_chars[c.upper()] += c equivalent_chars = [t for t in equivalent_chars.values() if len(t) > 1] ...
python
Tools/build/generate_re_casefix.py
43
91
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,670
print_notice
def print_notice(file_path: str, message: str) -> None: if GITHUB_ACTIONS: message = f"::notice file={file_path}::{message}" print(message, end="\n\n")
python
Tools/build/verify_ensurepip_wheels.py
23
26
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,671
print_error
def print_error(file_path: str, message: str) -> None: if GITHUB_ACTIONS: message = f"::error file={file_path}::{message}" print(message, end="\n\n")
python
Tools/build/verify_ensurepip_wheels.py
29
32
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,672
verify_wheel
def verify_wheel(package_name: str) -> bool: # Find the package on disk package_paths = list(WHEEL_DIR.glob(f"{package_name}*.whl")) if len(package_paths) != 1: if package_paths: for p in package_paths: print_error(p, f"Found more than one wheel for package {package_name}...
python
Tools/build/verify_ensurepip_wheels.py
35
95
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,673
iter_files
def iter_files(): for name in ('Modules', 'Objects', 'Parser', 'PC', 'Programs', 'Python'): root = os.path.join(ROOT, name) for dirname, _, files in os.walk(root): for name in files: if not name.endswith(('.c', '.h')): continue yield os...
python
Tools/build/generate_global_objects.py
149
156
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,674
iter_global_strings
def iter_global_strings(): id_regex = re.compile(r'\b_Py_ID\((\w+)\)') str_regex = re.compile(r'\b_Py_DECLARE_STR\((\w+), "(.*?)"\)') for filename in iter_files(): try: infile = open(filename, encoding='utf-8') except FileNotFoundError: # The file must have been a tem...
python
Tools/build/generate_global_objects.py
159
175
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,675
iter_to_marker
def iter_to_marker(lines, marker): for line in lines: if line.rstrip() == marker: break yield line
python
Tools/build/generate_global_objects.py
178
182
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,676
__init__
def __init__(self, file): self.level = 0 self.file = file self.continuation = [False]
python
Tools/build/generate_global_objects.py
187
190
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,677
indent
def indent(self): save_level = self.level try: self.level += 1 yield finally: self.level = save_level
python
Tools/build/generate_global_objects.py
193
199
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,678
write
def write(self, arg): eol = '\n' if self.continuation[-1]: eol = f' \\{eol}' if arg else f'\\{eol}' self.file.writelines((" "*self.level, arg, eol))
python
Tools/build/generate_global_objects.py
201
205
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,679
block
def block(self, prefix, suffix="", *, continuation=None): if continuation is None: continuation = self.continuation[-1] self.continuation.append(continuation) self.write(prefix + " {") with self.indent(): yield self.continuation.pop() self.write("...
python
Tools/build/generate_global_objects.py
208
217
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,680
open_for_changes
def open_for_changes(filename, orig): """Like open() but only write to the file if it changed.""" outfile = io.StringIO() yield outfile text = outfile.getvalue() if text != orig: with open(filename, 'w', encoding='utf-8') as outfile: outfile.write(text) else: print(f'...
python
Tools/build/generate_global_objects.py
221
230
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,681
generate_global_strings
def generate_global_strings(identifiers, strings): filename = os.path.join(INTERNAL, 'pycore_global_strings.h') # Read the non-generated part of the file. with open(filename) as infile: orig = infile.read() lines = iter(orig.rstrip().splitlines()) before = '\n'.join(iter_to_marker(lines, ST...
python
Tools/build/generate_global_objects.py
240
273
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,682
generate_runtime_init
def generate_runtime_init(identifiers, strings): # First get some info from the declarations. nsmallposints = None nsmallnegints = None with open(os.path.join(INTERNAL, 'pycore_global_objects.h')) as infile: for line in infile: if line.startswith('#define _PY_NSMALLPOSINTS'): ...
python
Tools/build/generate_global_objects.py
276
345
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,683
generate_static_strings_initializer
def generate_static_strings_initializer(identifiers, strings): # Target the runtime initializer. filename = os.path.join(INTERNAL, 'pycore_unicodeobject_generated.h') # Read the non-generated part of the file. with open(filename) as infile: orig = infile.read() lines = iter(orig.rstrip().sp...
python
Tools/build/generate_global_objects.py
348
377
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,684
generate_global_object_finalizers
def generate_global_object_finalizers(generated_immortal_objects): # Target the runtime initializer. filename = os.path.join(INTERNAL, 'pycore_global_objects_fini_generated.h') # Read the non-generated part of the file. with open(filename) as infile: orig = infile.read() lines = iter(orig.r...
python
Tools/build/generate_global_objects.py
380
411
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,685
get_identifiers_and_strings
def get_identifiers_and_strings() -> 'tuple[set[str], dict[str, str]]': identifiers = set(IDENTIFIERS) strings = {} for name, string, *_ in iter_global_strings(): if string is None: if name not in IGNORED: identifiers.add(name) else: if string not in s...
python
Tools/build/generate_global_objects.py
414
426
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,686
main
def main() -> None: identifiers, strings = get_identifiers_and_strings() generate_global_strings(identifiers, strings) generated_immortal_objects = generate_runtime_init(identifiers, strings) generate_static_strings_initializer(identifiers, strings) generate_global_object_finalizers(generated_immor...
python
Tools/build/generate_global_objects.py
432
438
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,687
update_file
def update_file(file, content): try: with open(file, 'r') as fobj: if fobj.read() == content: return False except (OSError, ValueError): pass with open(file, 'w') as fobj: fobj.write(content) return True
python
Tools/build/generate_sre_constants.py
7
16
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,688
main
def main( infile="Lib/re/_constants.py", outfile_constants="Modules/_sre/sre_constants.h", outfile_targets="Modules/_sre/sre_targets.h", ): ns = {} with open(infile) as fp: code = fp.read() exec(code, ns) def dump(d, prefix): items = sorted(d) for item in items: ...
python
Tools/build/generate_sre_constants.py
34
75
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,689
dump
def dump(d, prefix): items = sorted(d) for item in items: yield "#define %s_%s %d\n" % (prefix, item, item)
python
Tools/build/generate_sre_constants.py
44
47
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,690
dump2
def dump2(d, prefix): items = [(value, name) for name, value in d.items() if name.startswith(prefix)] for value, name in sorted(items): yield "#define %s %d\n" % (name, value)
python
Tools/build/generate_sre_constants.py
49
53
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,691
dump_gotos
def dump_gotos(d, prefix): for i, item in enumerate(sorted(d)): assert i == item yield f" &&{prefix}_{item},\n"
python
Tools/build/generate_sre_constants.py
55
58
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,692
__init__
def __init__(self, **kwds: Any): self.__dict__.update(kwds)
python
Tools/build/umarshal.py
52
53
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,693
__repr__
def __repr__(self) -> str: return f"Code(**{self.__dict__})"
python
Tools/build/umarshal.py
55
56
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,694
get_localsplus_names
def get_localsplus_names(self, select_kind: int) -> Tuple[str, ...]: varnames: list[str] = [] for name, kind in zip(self.co_localsplusnames, self.co_localspluskinds): if kind & select_kind: varnames.append(name) return tuple(varnames)
python
Tools/build/umarshal.py
61
67
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,695
co_varnames
def co_varnames(self) -> Tuple[str, ...]: return self.get_localsplus_names(CO_FAST_LOCAL)
python
Tools/build/umarshal.py
70
71
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,696
co_cellvars
def co_cellvars(self) -> Tuple[str, ...]: return self.get_localsplus_names(CO_FAST_CELL)
python
Tools/build/umarshal.py
74
75
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,697
co_freevars
def co_freevars(self) -> Tuple[str, ...]: return self.get_localsplus_names(CO_FAST_FREE)
python
Tools/build/umarshal.py
78
79
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,698
co_nlocals
def co_nlocals(self) -> int: return len(self.co_varnames)
python
Tools/build/umarshal.py
82
83
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,699
__init__
def __init__(self, data: bytes): self.data: bytes = data self.end: int = len(self.data) self.pos: int = 0 self.refs: list[Any] = [] self.level: int = 0
python
Tools/build/umarshal.py
89
94
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,700
r_string
def r_string(self, n: int) -> bytes: assert 0 <= n <= self.end - self.pos buf = self.data[self.pos : self.pos + n] self.pos += n return buf
python
Tools/build/umarshal.py
96
100
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }