Recursively save default aliases for pythonic functions.
497314
def save_intrinsic_alias(module):
    
    for v in module.values():
        if isinstance(v, dict):  # Submodules case
            save_intrinsic_alias(v)
        else:
            IntrinsicAliases[v] = frozenset((v,))
            if isinstance(v, Class):
                save_intrinsic_alias(v.fields)
608956
def _flat_alias(t):
    
    t.name = t.parsed_name
    t.alias = t.parsed_alias[0] if t.parsed_alias else ''
    return t
1370470
def format_name(self):
        '''
        
        '''
        if not hasattr(self.module, '__func_alias__'):
            # Resume normal sphinx.ext.autodoc operation
            return super(FunctionDocumenter, self).format_name()

        if not self.objpath:
            # Resume normal sphinx.ext.autodoc operation
            return super(FunctionDocumenter, self).format_name()

        if len(self.objpath) > 1:
            # Resume normal sphinx.ext.autodoc operation
            return super(FunctionDocumenter, self).format_name()

        # Use the salt func aliased name instead of the real name
        return self.module.__func_alias__.get(self.objpath[0], self.objpath[0])
484606
def defaults(default=None):
    
    def _f(func):
        @functools.wraps(func)
        def __f(self, *args, **kwargs):
            try:
                return func(self, *args, **kwargs)
            except Exception:
                return default
        return __f
    return _f
507664
def linearize_aliases(self):
        # type: () -> typing.List[Alias]
        
        linearized_aliases = []
        seen_aliases = set()  # type: typing.Set[Alias]

        def add_alias(alias):
            # type: (Alias) -> None
            if alias in seen_aliases:
                return
            elif alias.namespace != self:
                return
            if is_alias(alias.data_type):
                add_alias(alias.data_type)
            linearized_aliases.append(alias)
            seen_aliases.add(alias)

        for alias in self.aliases:
            add_alias(alias)

        return linearized_aliases
1332679
def save(func):
    
    def aux(self, *args, **kwargs):
        out = func(self, *args, **kwargs)
        path = (hasattr(self, 'path') and self.path
                or os.path.join(os.getcwd(), '.td'))
        gpath = (hasattr(self, 'gpath') and self.gpath
                 or os.path.expanduser('~/.tdrc'))
        if os.path.exists(path):
            shutil.copy2(path, os.path.join(os.path.dirname(path), '.td~'))
        open(path, 'w').write(
            json.dumps({
                'items': self.data,
                'refs': self.refs,
                'options': self.options
            })
        )
        open(gpath, 'w').write(json.dumps(self.globalOptions))
        return out
    return aux
878450
def get_default(__func: Callable, __arg: str) -> str:
    
    return signature(__func).parameters[__arg].default
1084029
def save_tabs_when_changed(func):
    

    def wrapper(*args, **kwargs):
        func(*args, **kwargs)
        log.debug("mom, I've been called: %s %s", func.__name__, func)

        # Find me the Guake!
        clsname = args[0].__class__.__name__
        g = None
        if clsname == 'Guake':
            g = args[0]
        elif getattr(args[0], 'get_guake', None):
            g = args[0].get_guake()
        elif getattr(args[0], 'get_notebook', None):
            g = args[0].get_notebook().guake
        elif getattr(args[0], 'guake', None):
            g = args[0].guake
        elif getattr(args[0], 'notebook', None):
            g = args[0].notebook.guake

        # Tada!
        if g and g.settings.general.get_boolean('save-tabs-when-changed'):
            g.save_tabs()

    return wrapper
327888
def as_alias_handler(alias_list):
    """"""
    list_ = list()
    for alias in alias_list:
        if alias.asname:
            list_.append(alias.asname)
        else:
            list_.append(alias.name)
    return list_
245397
function alias (obj, method) {
  switch (type(method)) {
    case 'object': return aliasByDictionary(clone(obj), method);
    case 'function': return aliasByFunction(clone(obj), method);
  }
}
970337
def install_aliases():
    
    if PY3:
        return
    # if hasattr(install_aliases, 'run_already'):
    #     return
    for (newmodname, newobjname, oldmodname, oldobjname) in MOVES:
        __import__(newmodname)
        # We look up the module in sys.modules because __import__ just returns the
        # top-level package:
        newmod = sys.modules[newmodname]
        # newmod.__future_module__ = True

        __import__(oldmodname)
        oldmod = sys.modules[oldmodname]

        obj = getattr(oldmod, oldobjname)
        setattr(newmod, newobjname, obj)

    # Hack for urllib so it appears to have the same structure on Py2 as on Py3
    import urllib
    from future.backports.urllib import request
    from future.backports.urllib import response
    from future.backports.urllib import parse
    from future.backports.urllib import error
    from future.backports.urllib import robotparser
    urllib.request = request
    urllib.response = response
    urllib.parse = parse
    urllib.error = error
    urllib.robotparser = robotparser
    sys.modules['urllib.request'] = request
    sys.modules['urllib.response'] = response
    sys.modules['urllib.parse'] = parse
    sys.modules['urllib.error'] = error
    sys.modules['urllib.robotparser'] = robotparser

    # Patch the test module so it appears to have the same structure on Py2 as on Py3
    try:
        import test
    except ImportError:
        pass
    try:
        from future.moves.test import support
    except ImportError:
        pass
    else:
        test.support = support
        sys.modules['test.support'] = support

    # Patch the dbm module so it appears to have the same structure on Py2 as on Py3
    try:
        import dbm
    except ImportError:
        pass
    else:
        from future.moves.dbm import dumb
        dbm.dumb = dumb
        sys.modules['dbm.dumb'] = dumb
        try:
            from future.moves.dbm import gnu
        except ImportError:
            pass
        else:
            dbm.gnu = gnu
            sys.modules['dbm.gnu'] = gnu
        try:
            from future.moves.dbm import ndbm
        except ImportError:
            pass
        else:
            dbm.ndbm = ndbm
            sys.modules['dbm.ndbm'] = ndbm
902939
def functionFactory(in_code, name, defaults, globals_, imports):
    """"""
    def generatedFunction():
        pass
    generatedFunction.__code__ = marshal.loads(in_code)
    generatedFunction.__name__ = name
    generatedFunction.__defaults = defaults
    generatedFunction.__globals__.update(pickle.loads(globals_))
    for key, value in imports.items():
        imported_module = __import__(value)
        scoop.logger.debug("Dynamically loaded module {0}".format(value))
        generatedFunction.__globals__.update({key: imported_module})
    return generatedFunction
128433
def list_aliases():
    '''
    
    '''
    ret = dict((alias, target) for alias, target, comment in __parse_aliases() if alias)
    return ret
1321189
def save_function_effect(module):
    
    for intr in module.values():
        if isinstance(intr, dict):  # Submodule case
            save_function_effect(intr)
        else:
            fe = FunctionEffects(intr)
            IntrinsicArgumentEffects[intr] = fe
            if isinstance(intr, intrinsic.Class):
                save_function_effect(intr.fields)
1350549
def recursive_repr(fillvalue='...'):
    ''

    def decorating_function(user_function):
        repr_running = set()

        def wrapper(self):
            key = id(self), get_ident()
            if key in repr_running:
                return fillvalue
            repr_running.add(key)
            try:
                result = user_function(self)
            finally:
                repr_running.discard(key)
            return result

        # Can't use functools.wraps() here because of bootstrap issues
        wrapper.__module__ = getattr(user_function, '__module__')
        wrapper.__doc__ = getattr(user_function, '__doc__')
        wrapper.__name__ = getattr(user_function, '__name__')
        wrapper.__annotations__ = getattr(user_function, '__annotations__', {})
        return wrapper

    return decorating_function
948639
def default(*args, **kwargs):
    
    default = kwargs.get('default', None)
    for arg in args:
        if arg:
            return arg
    return default
316196
def preserveName(f):
    
    def decorator(decorated):
        return copyfunction(decorated,
                            dict(name=f.__name__), dict(name=f.__name__))
    return decorator