예제 #1
0
def type_name_to_typeref(name, mod, type_overrides = TYPE_OVERRIDES):
    arg_type = type_overrides.get(name, None)
    if arg_type is None:
        if name in BUILTIN_TYPES:
            arg_type = PythonScraper.type_to_typeref(get_builtin(name))
        elif mod is not None and name in mod.__dict__:
            arg_type = PythonScraper.typename_to_typeref(mod.__name__, name)
        elif name.startswith('list'):
            arg_type = PythonScraper.type_to_typeref(list)
        else:
            # see if we can find it in any module we've imported...
            for mod_name, mod in sys.modules.items():
                if mod is not None and name in mod.__dict__ and isinstance(mod.__dict__[name], type):
                    arg_type = PythonScraper.typename_to_typeref(mod_name, name)
                    break
            else:
                first_space = name.find(' ')
                if first_space != -1:
                    return type_name_to_typeref(name[:first_space], mod, type_overrides)
                arg_type = PythonScraper.typename_to_typeref(name)
    return arg_type
예제 #2
0
def type_name_to_typeref(name, mod, type_overrides=TYPE_OVERRIDES):
    arg_type = type_overrides.get(name, None)
    if arg_type is None:
        if name in BUILTIN_TYPES:
            arg_type = PythonScraper.type_to_typeref(get_builtin(name))
        elif mod is not None and name in mod.__dict__:
            arg_type = PythonScraper.typename_to_typeref(mod.__name__, name)
        elif name.startswith('list'):
            arg_type = PythonScraper.type_to_typeref(list)
        else:
            # see if we can find it in any module we've imported...
            for mod_name, mod in list(sys.modules.items()):
                if mod is not None and name in mod.__dict__ and isinstance(
                        mod.__dict__[name], type):
                    arg_type = PythonScraper.typename_to_typeref(
                        mod_name, name)
                    break
            else:
                first_space = name.find(' ')
                if first_space != -1:
                    return type_name_to_typeref(name[:first_space], mod,
                                                type_overrides)
                arg_type = PythonScraper.typename_to_typeref(name)
    return arg_type
예제 #3
0

safe_getattr = PythonScraper.safe_getattr

BUILTIN_TYPES = [
    type_name for type_name in builtins_keys()
    if type(get_builtin(type_name)) is type
]
if sys.version_info[0] >= 3:
    BUILTIN = 'builtins'
    unicode = str
else:
    BUILTIN = '__builtin__'

TYPE_OVERRIDES = {
    'string': PythonScraper.type_to_typeref(types.CodeType),
    's': PythonScraper.type_to_typeref(str),
    'integer': PythonScraper.type_to_typeref(int),
    'boolean': PythonScraper.type_to_typeref(bool),
    'number': PythonScraper.type_to_typeref(int),
    'pid': PythonScraper.type_to_typeref(int),
    'ppid': PythonScraper.type_to_typeref(int),
    'fd': PythonScraper.type_to_typeref(int),
    'handle': PythonScraper.type_to_typeref(int),
    'Exit': PythonScraper.type_to_typeref(int),
    'fd2': PythonScraper.type_to_typeref(int),
    'Integral': PythonScraper.type_to_typeref(int),
    'exit_status': PythonScraper.type_to_typeref(int),
    'old_mask': PythonScraper.type_to_typeref(int),
    'source': PythonScraper.type_to_typeref(str),
    'newpos': PythonScraper.type_to_typeref(int),
예제 #4
0
    if isinstance(__builtins__, dict):
        return __builtins__[name]

    return getattr(__builtins__, name)

safe_getattr = PythonScraper.safe_getattr

BUILTIN_TYPES = [type_name for type_name in builtins_keys() if type(get_builtin(type_name)) is type]
if sys.version_info[0] >= 3:
    BUILTIN = 'builtins'
    unicode = str
else:
    BUILTIN = '__builtin__'

TYPE_OVERRIDES = {
    'string': PythonScraper.type_to_typeref(types.CodeType),
    's': PythonScraper.type_to_typeref(str),
    'integer': PythonScraper.type_to_typeref(int),
    'boolean': PythonScraper.type_to_typeref(bool),
    'number': PythonScraper.type_to_typeref(int),
    'pid': PythonScraper.type_to_typeref(int),
    'ppid': PythonScraper.type_to_typeref(int),
    'fd': PythonScraper.type_to_typeref(int),
    'handle': PythonScraper.type_to_typeref(int),
    'Exit': PythonScraper.type_to_typeref(int),
    'fd2': PythonScraper.type_to_typeref(int),
    'Integral': PythonScraper.type_to_typeref(int),
    'exit_status':PythonScraper.type_to_typeref(int),
    'old_mask': PythonScraper.type_to_typeref(int),
    'source': PythonScraper.type_to_typeref(str),
    'newpos': PythonScraper.type_to_typeref(int),