def _prepare_schema_coercer_global_cache(): '''Prepare global cache for scheme coercer.''' from xoutil import Undefined from xoutil.eight import zip from xoutil.values import (coercer as checker_coerce, iterable, identity_coerce, identifier_coerce, positive_int_coerce) pos_coerce = iterable(positive_int_coerce, outer_coerce=set) alias_coerce = iterable(identifier_coerce, outer_coerce=set) default_coerce = identity_coerce checker_default = identity_coerce pos_default = set() alias_default = set() default_default = Undefined names = ('checker', 'pos', 'aliases', 'default') coercers = dict(zip(names, (checker_coerce, pos_coerce, alias_coerce, default_coerce))) defaults = dict(zip(names, (checker_default, pos_default, alias_default, default_default))) return (names, coercers, defaults)
def findlinestarts(code): """Find the offsets in a byte code which are start of lines in the source. Generate pairs (offset, lineno) as described in Python/compile.c. """ from xoutil.eight import zip byte_increments = [_ord(x) for x in code.co_lnotab[0::2]] line_increments = [_ord(x) for x in code.co_lnotab[1::2]] lastlineno = None lineno = code.co_firstlineno addr = 0 for byte_incr, line_incr in zip(byte_increments, line_increments): if byte_incr: if lineno != lastlineno: yield (addr, lineno) lastlineno = lineno addr += byte_incr lineno += line_incr if lineno != lastlineno: yield (addr, lineno)