def get_module_routes(module_name, custom_routes=None, exclusions=None,<EOL>arg_pattern=r'<STR_LIT>'):
def has_method(module, cls_name, method_name):<EOL><INDENT>return all([<EOL>method_name in vars(getattr(module, cls_name)),<EOL>is_method(reduce(getattr, [module, cls_name, method_name]))<EOL>])<EOL><DEDENT>def yield_args(module, cls_name, method_name):<EOL><INDENT>"""<STR_LIT>"""<EOL>wrapped_method = reduce(getattr, [module, cls_name, method_name])<EOL>method = extract_method(wrapped_method)<EOL>argspec_args = getattr(method, "<STR_LIT>",<EOL>inspect.getargspec(method).args)<EOL>return [a for a in argspec_args if a not in ["<STR_LIT>"]]<EOL><DEDENT>def generate_auto_route(module, module_name, cls_name, method_name, url_name):<EOL><INDENT>"""<STR_LIT>"""<EOL>def get_handler_name():<EOL><INDENT>"""<STR_LIT>"""<EOL>if url_name == "<STR_LIT>":<EOL><INDENT>if cls_name.lower().endswith('<STR_LIT>'):<EOL><INDENT>return cls_name.lower().replace('<STR_LIT>', '<STR_LIT>', <NUM_LIT:1>)<EOL><DEDENT>return cls_name.lower()<EOL><DEDENT>else:<EOL><INDENT>return url_name<EOL><DEDENT><DEDENT>def get_arg_route():<EOL><INDENT>"""<STR_LIT>"""<EOL>if yield_args(module, cls_name, method_name):<EOL><INDENT>return "<STR_LIT>".format("<STR_LIT:/>".join(<EOL>[arg_pattern.format(argname) for argname<EOL>in yield_args(module, cls_name, method_name)]<EOL>))<EOL><DEDENT>return r"<STR_LIT>"<EOL><DEDENT>return "<STR_LIT>".format(<EOL>"<STR_LIT:/>".join(module_name.split("<STR_LIT:.>")[<NUM_LIT:1>:]),<EOL>get_handler_name(),<EOL>get_arg_route()<EOL>)<EOL><DEDENT>if not custom_routes:<EOL><INDENT>custom_routes = []<EOL><DEDENT>if not exclusions:<EOL><INDENT>exclusions = []<EOL><DEDENT>module = importlib.import_module(module_name)<EOL>custom_routes_s = [c.__name__ for r, c in custom_routes]<EOL>rhs = {cls_name: cls for (cls_name, cls) in<EOL>inspect.getmembers(module, inspect.isclass)}<EOL>auto_routes = list(chain(*[<EOL>list(set(chain(*[<EOL>[<EOL>(<EOL>generate_auto_route(<EOL>module, module_name, cls_name, method_name, url_name<EOL>),<EOL>getattr(module, cls_name)<EOL>) for url_name in getattr(module, cls_name).__url_names__<EOL>] + [<EOL>(<EOL>url,<EOL>getattr(module, cls_name)<EOL>) for url in getattr(module, cls_name).__urls__<EOL>]<EOL>for method_name in HTTP_METHODS if has_method(<EOL>module, cls_name, method_name)<EOL>])))<EOL>for cls_name, cls in rhs.items()<EOL>if is_handler_subclass(cls)<EOL>and cls_name not in (custom_routes_s + exclusions)<EOL>]))<EOL>routes = auto_routes + custom_routes<EOL>return routes<EOL>
Create and return routes for module_name

    Routes are (url, RequestHandler) tuples

    :returns: list of routes for ``module_name`` with respect to ``exclusions``
        and ``custom_routes``. Returned routes are with URLs formatted such
        that they are forward-slash-separated by module/class level
        and end with the lowercase name of the RequestHandler (it will also
        remove 'handler' from the end of the name of the handler).
        For example, a requesthandler with the name
        ``helloworld.api.HelloWorldHandler`` would be assigned the url
        ``/api/helloworld``.
        Additionally, if a method has extra arguments aside from ``self`` in
        its signature, routes with URL patterns will be generated to
        match ``r"(?P<{}>[a-zA-Z0-9_\-]+)".format(argname)`` for each
        argument. The aforementioned regex will match ONLY values
        with alphanumeric, hyphen and underscore characters. You can provide
        your own pattern by setting a ``arg_pattern`` param.
    :rtype: [(url, RequestHandler), ... ]
    :type  module_name: str
    :param module_name: Name of the module to get routes for
    :type  custom_routes: [(str, RequestHandler), ... ]
    :param custom_routes: List of routes that have custom URLs and therefore
        should be automagically generated
    :type  exclusions: [str, str, ...]
    :param exclusions: List of RequestHandler names that routes should not be
        generated for
    :type  arg_pattern: str
    :param arg_pattern: Default pattern for extra arguments of any method