def load_routers(all_apps):
    "load-time post-processing of routers"

    for app in routers:
        # initialize apps with routers that aren't present,
        # on behalf of unit tests
        if app not in all_apps:
            all_apps.append(app)
            router = Storage(routers.BASE)   # new copy
            if app != 'BASE':
                keys = set(routers[app]).intersection(ROUTER_BASE_KEYS)
                if keys:
                    raise SyntaxError("BASE-only key(s) %s in router '%s'" % (
                        tuple(keys), app))
            router.update(routers[app])
            routers[app] = router
        router = routers[app]
        keys = set(router).difference(ROUTER_KEYS)
        if keys:
            raise SyntaxError("unknown key(s) %s in router '%s'" % (
                tuple(keys), app))
        if not router.controllers:
            router.controllers = set()
        elif not isinstance(router.controllers, str):
            router.controllers = set(router.controllers)
        if router.languages:
            router.languages = set(router.languages)
        else:
            router.languages = set()
        if router.functions:
            if isinstance(router.functions, (set, tuple, list)):
                functions = set(router.functions)
                if isinstance(router.default_function, str):
                    functions.add(
                        router.default_function)  # legacy compatibility
                router.functions = {router.default_controller: functions}
            for controller in router.functions:
                router.functions[controller] = set(
                    router.functions[controller])
        else:
            router.functions = dict()
        if app != 'BASE':
            for base_only in ROUTER_BASE_KEYS:
                router.pop(base_only, None)
            if 'domain' in router:
                routers.BASE.domains[router.domain] = app
            if isinstance(router.controllers, str) and router.controllers == 'DEFAULT':
                router.controllers = set()
                if isdir(abspath('applications', app)):
                    cpath = abspath('applications', app, 'controllers')
                    for cname in os.listdir(cpath):
                        if isfile(abspath(cpath, cname)) and cname.endswith('.py'):
                            router.controllers.add(cname[:-3])
            if router.controllers:
                router.controllers.add('static')
                router.controllers.add(router.default_controller)

    if isinstance(routers.BASE.applications, str) and routers.BASE.applications == 'ALL':
        routers.BASE.applications = list(all_apps)
    if routers.BASE.applications:
        routers.BASE.applications = set(routers.BASE.applications)
    else:
        routers.BASE.applications = set()

    for app in routers.keys():
        # set router name
        router = routers[app]
        router.name = app
        # compile URL validation patterns
        router._acfe_match = re.compile(router.acfe_match)
        router._file_match = re.compile(router.file_match)
        if router.args_match:
            router._args_match = re.compile(router.args_match)
        # convert path_prefix to a list of path elements
        if router.path_prefix:
            if isinstance(router.path_prefix, str):
                router.path_prefix = router.path_prefix.strip('/').split('/')

    #  rewrite BASE.domains as tuples
    #
    #      key:   'domain[:port]' -> (domain, port)
    #      value: 'application[/controller] -> (application, controller)
    #      (port and controller may be None)
    #
    domains = dict()
    if routers.BASE.domains:
        for (d, a) in routers.BASE.domains.iteritems():
            (domain, app) = (d.strip(':'), a.strip('/'))
            if ':' in domain:
                (domain, port) = domain.split(':')
            else:
                port = None
            if app in '/':
                (app, ctlr) = app.split('/', 1)
            else:
                ctlr = None
            if ctlr and '/' in ctlr:
                (ctlr, fcn) = ctlr.split('/')
            else:
                fcn = None
            if app not in all_apps and app not in routers:
                raise SyntaxError("unknown app '%s' in domains" % app)
            domains[(domain, port)] = (app, ctlr, fcn)
    routers.BASE.domains = domains
dataset/ETHPy150Open uwdata/termite-visualizations/web2py/gluon/rewrite.py/load_routers/swapped operands of `in`