def url(pattern, handler, name=None, prefix='', **kwargs): if isinstance(handler, (list, tuple)) or hasattr(handler, 'urlpatterns'): urls = [] if hasattr(handler, 'urlpatterns'): handler = getattr(handler, 'urlpatterns', []) for route in handler: if isinstance(route, (list, tuple)): temp = [url(pattern + r.pattern, r.handler, r.name, **r.kwargs) for r in route] urls.extend(temp) else: u = Url(pattern+route.pattern, route.handler, route.name, **route.kwargs) urls.append(u) return urls elif isinstance(handler, str): if prefix.strip(): handler = prefix + '.' + handler handler = import_object(handler) return Url(pattern, handler, name, **kwargs) elif callable(handler): return Url(pattern, handler, name, **kwargs) else: raise TypeError('view must be a callable or a list/tuple in the case of include().')
def load_filter_class(self): """ :return: """ return [ import_object(backend) for backend in self.filter_backend_list if backend is not None ]
def get_hashers(): hashers = [] for hasher_path in settings.PASSWORD_HASHERS: hasher = import_object(hasher_path)() if not getattr(hasher, 'algorithm'): raise ImproperlyConfigured( "hasher doesn't specify an algorithm name: %s" % hasher_path) hashers.append(hasher) return hashers
def paginator(self): """ 分页处理实例对象,如没配置返回None,反之对应的实例 """ if not hasattr(self, '_paginator'): paginator = None if self.pagination_class is None else import_object( self.pagination_class)() setattr(self, "_paginator", paginator) return self._paginator
def get_parsers(): parsers = [] for parser_path in settings.PARSER_CLASSES: parser = import_object(parser_path)() if not getattr(parser, 'media_type'): raise ImproperlyConfigured( "parser没有定义media_type值: {parser_path}".format( parser_path=parser_path)) parsers.append(parser) return parsers
def url(pattern, handler, kwargs=None, name=None, prefix=''): """ 指定URL和处理程序之间的映射,即tornado.web.URLSpec """ if isinstance(handler, (list, tuple)): return [(pattern + p, h, k, n) for p, h, k, n in handler] elif hasattr(handler, 'urlpatterns'): return [(pattern + p, h, k, n) for p, h, k, n in getattr(handler, 'urlpatterns', [])] elif isinstance(handler, str): if prefix.strip(): handler = prefix + '.' + handler handler = import_object(handler) return pattern, handler, kwargs, name elif callable(handler): return pattern, handler, kwargs, name else: raise TypeError( 'view must be a callable or a list/tuple in the case of include().' )