Python django.core.urlresolvers 模块,RegexURLPattern() 实例源码

我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用django.core.urlresolvers.RegexURLPattern()

项目:driveboardapp    作者:nortd    | 项目源码 | 文件源码
def find_url_callbacks(urls_module):
    if isinstance(urls_module, list):
        urlpatterns = urls_module
        hid_list = []
    else:
        urlpatterns = urls_module.urlpatterns
        hid_list = [urls_module.__name__]
    for pattern in urlpatterns:
        if isinstance(pattern, RegexURLPattern):
            hid_list.append(pattern.callback.__module__)
        elif isinstance(pattern, RegexURLResolver):
            hid_list += find_url_callbacks(pattern.urlconf_module)
    return hid_list


# Add templatetags and context processors for each installed app.
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def check_resolver(resolver):
    """
    Recursively check the resolver.
    """
    from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
    warnings = []
    for pattern in resolver.url_patterns:
        if isinstance(pattern, RegexURLResolver):
            warnings.extend(check_include_trailing_dollar(pattern))
            # Check resolver recursively
            warnings.extend(check_resolver(pattern))
        elif isinstance(pattern, RegexURLPattern):
            warnings.extend(check_pattern_name(pattern))

        warnings.extend(check_pattern_startswith_slash(pattern))

    return warnings
项目:baya    作者:counsyl    | 项目源码 | 文件源码
def decorate_url_pattern(self, pattern, *args, **kwargs):
        """Decorate a RegexURLPattern or RegexURLResolver.

        Args:
            resolve_fn: Either RegexURLPattern or RegexURLResolver, from
                django.core.urlresolvers

        This decorates the callback for a url after it gets resolved with
        self.decorate_method.
        """
        resolve_fn = pattern.resolve

        @functools.wraps(resolve_fn)
        def patch_resolve(path):
            result = resolve_fn(path)
            if result:
                result.func = self.decorate_method(
                    result.func, *args, **kwargs)
            return result
        pattern.resolve = patch_resolve
        return pattern
项目:baya    作者:counsyl    | 项目源码 | 文件源码
def decorate_url_pattern(self, pattern, *args, **kwargs):
        """Decorate a RegexURLPattern or RegexURLResolver.

        Args:
            resolve_fn: Either RegexURLPattern or RegexURLResolver, from
                django.core.urlresolvers

        This decorates the callback for a url after it gets resolved with
        self.decorate_method.
        """
        resolve_fn = pattern.resolve

        @functools.wraps(resolve_fn)
        def patch_resolve(path):
            result = resolve_fn(path)
            if result:
                result.func = self.decorate_method(
                    result.func, *args, **kwargs)
            return result
        pattern.resolve = patch_resolve
        return pattern
项目:wanblog    作者:wanzifa    | 项目源码 | 文件源码
def check_resolver(resolver):
    """
    Recursively check the resolver.
    """
    from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
    warnings = []
    for pattern in resolver.url_patterns:
        if isinstance(pattern, RegexURLResolver):
            warnings.extend(check_include_trailing_dollar(pattern))
            # Check resolver recursively
            warnings.extend(check_resolver(pattern))
        elif isinstance(pattern, RegexURLPattern):
            warnings.extend(check_pattern_name(pattern))

        warnings.extend(check_pattern_startswith_slash(pattern))

    return warnings
项目:tabmaster    作者:NicolasMinghetti    | 项目源码 | 文件源码
def check_resolver(resolver):
    """
    Recursively check the resolver.
    """
    from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
    warnings = []
    for pattern in resolver.url_patterns:
        if isinstance(pattern, RegexURLResolver):
            warnings.extend(check_include_trailing_dollar(pattern))
            # Check resolver recursively
            warnings.extend(check_resolver(pattern))
        elif isinstance(pattern, RegexURLPattern):
            warnings.extend(check_pattern_name(pattern))

        warnings.extend(check_pattern_startswith_slash(pattern))

    return warnings
项目:logo-gen    作者:jellene4eva    | 项目源码 | 文件源码
def check_resolver(resolver):
    """
    Recursively check the resolver.
    """
    from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
    warnings = []
    for pattern in resolver.url_patterns:
        if isinstance(pattern, RegexURLResolver):
            warnings.extend(check_include_trailing_dollar(pattern))
            # Check resolver recursively
            warnings.extend(check_resolver(pattern))
        elif isinstance(pattern, RegexURLPattern):
            warnings.extend(check_pattern_name(pattern))

        warnings.extend(check_pattern_startswith_slash(pattern))

    return warnings
项目:gmail_scanner    作者:brandonhub    | 项目源码 | 文件源码
def check_resolver(resolver):
    """
    Recursively check the resolver.
    """
    from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
    warnings = []
    for pattern in resolver.url_patterns:
        if isinstance(pattern, RegexURLResolver):
            warnings.extend(check_include_trailing_dollar(pattern))
            # Check resolver recursively
            warnings.extend(check_resolver(pattern))
        elif isinstance(pattern, RegexURLPattern):
            warnings.extend(check_pattern_name(pattern))

        warnings.extend(check_pattern_startswith_slash(pattern))

    return warnings
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def check_resolver(resolver):
    """
    Recursively check the resolver.
    """
    from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
    warnings = []
    for pattern in resolver.url_patterns:
        if isinstance(pattern, RegexURLResolver):
            warnings.extend(check_include_trailing_dollar(pattern))
            # Check resolver recursively
            warnings.extend(check_resolver(pattern))
        elif isinstance(pattern, RegexURLPattern):
            warnings.extend(check_pattern_name(pattern))

        warnings.extend(check_pattern_startswith_slash(pattern))

    return warnings
项目:django-next-train    作者:bitpixdigital    | 项目源码 | 文件源码
def check_resolver(resolver):
    """
    Recursively check the resolver.
    """
    from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
    warnings = []
    for pattern in resolver.url_patterns:
        if isinstance(pattern, RegexURLResolver):
            warnings.extend(check_include_trailing_dollar(pattern))
            # Check resolver recursively
            warnings.extend(check_resolver(pattern))
        elif isinstance(pattern, RegexURLPattern):
            warnings.extend(check_pattern_name(pattern))

        warnings.extend(check_pattern_startswith_slash(pattern))

    return warnings
项目:mac-package-build    作者:persepolisdm    | 项目源码 | 文件源码
def find_url_callbacks(urls_module):
    if isinstance(urls_module, list):
        urlpatterns = urls_module
        hid_list = []
    else:
        urlpatterns = urls_module.urlpatterns
        hid_list = [urls_module.__name__]
    for pattern in urlpatterns:
        if isinstance(pattern, RegexURLPattern):
            hid_list.append(pattern.callback.__module__)
        elif isinstance(pattern, RegexURLResolver):
            hid_list += find_url_callbacks(pattern.urlconf_module)
    return hid_list


# Add templatetags and context processors for each installed app.
项目:DjangoZeroToHero    作者:RayParra    | 项目源码 | 文件源码
def check_resolver(resolver):
    """
    Recursively check the resolver.
    """
    from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
    warnings = []
    for pattern in resolver.url_patterns:
        if isinstance(pattern, RegexURLResolver):
            warnings.extend(check_include_trailing_dollar(pattern))
            # Check resolver recursively
            warnings.extend(check_resolver(pattern))
        elif isinstance(pattern, RegexURLPattern):
            warnings.extend(check_pattern_name(pattern))

        warnings.extend(check_pattern_startswith_slash(pattern))

    return warnings
项目:Roboism    作者:markroxor    | 项目源码 | 文件源码
def check_resolver(resolver):
    """
    Recursively check the resolver.
    """
    from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
    warnings = []
    for pattern in resolver.url_patterns:
        if isinstance(pattern, RegexURLResolver):
            warnings.extend(check_include_trailing_dollar(pattern))
            # Check resolver recursively
            warnings.extend(check_resolver(pattern))
        elif isinstance(pattern, RegexURLPattern):
            warnings.extend(check_pattern_name(pattern))

        warnings.extend(check_pattern_startswith_slash(pattern))

    return warnings
项目:baya    作者:counsyl    | 项目源码 | 文件源码
def __call__(self, fn, *args, **kwargs):
        """Delegate the decoration to the appropriate method."""
        if isinstance(fn, functools.partial) and not hasattr(fn, '__module__'):
            raise ValueError(
                'Cannot decorate a bare functools.partial view.  '
                'You must invoke functools.update_wrapper(partial_view, '
                'full_view) first.')
        if not isinstance(fn, type) and isinstance(fn, collections.Callable):
            return self.decorate_method(fn, *args, **kwargs)
        elif isinstance(fn, tuple):
            # Must be an include('my_app.urls') we're decorating
            return self.decorate_include(fn, *args, **kwargs)
        elif isinstance(fn, (RegexURLPattern, RegexURLResolver)):
            return self.decorate_url_pattern(fn, *args, **kwargs)
        elif isinstance(fn, type) and issubclass(fn, BaseModelAdmin):
            if issubclass(fn, InlineModelAdmin):
                raise TypeError("Cannot decorate Inlines. See "
                                "baya.admin.options.BayaInline instead.")
            return self.decorate_admin(fn, *args, **kwargs)
        elif isinstance(fn, six.string_types):
            raise TypeError("Cannot decorate string-path to view: %s." % fn)
        else:
            # You'll probably only get here if you're trying to decorate
            # a class-based view
            raise TypeError(
                "Invalid type for requires decorator (%s). "
                "You cannot decorate class-based views. Decorate "
                "the URL or the as_view method instead." % type(fn))
项目:baya    作者:counsyl    | 项目源码 | 文件源码
def __call__(self, fn, *args, **kwargs):
        """Delegate the decoration to the appropriate method."""
        if isinstance(fn, functools.partial) and not hasattr(fn, '__module__'):
            raise ValueError(
                'Cannot decorate a bare functools.partial view.  '
                'You must invoke functools.update_wrapper(partial_view, '
                'full_view) first.')
        if not isinstance(fn, type) and isinstance(fn, collections.Callable):
            return self.decorate_method(fn, *args, **kwargs)
        elif isinstance(fn, tuple):
            # Must be an include('my_app.urls') we're decorating
            return self.decorate_include(fn, *args, **kwargs)
        elif isinstance(fn, (RegexURLPattern, RegexURLResolver)):
            return self.decorate_url_pattern(fn, *args, **kwargs)
        elif isinstance(fn, type) and issubclass(fn, BaseModelAdmin):
            if issubclass(fn, InlineModelAdmin):
                raise TypeError("Cannot decorate Inlines. See "
                                "baya.admin.options.BayaInline instead.")
            return self.decorate_admin(fn, *args, **kwargs)
        elif isinstance(fn, six.string_types):
            raise TypeError("Cannot decorate string-path to view: %s." % fn)
        else:
            # You'll probably only get here if you're trying to decorate
            # a class-based view
            raise TypeError(
                "Invalid type for requires decorator (%s). "
                "You cannot decorate class-based views. Decorate "
                "the URL or the as_view method instead." % type(fn))
项目:volla    作者:sgrowe    | 项目源码 | 文件源码
def test_returns_regex_url_pattern_if_passed_view_func(self):
        view = Mock()
        resolver = simple_url('/home-page/', view, sentinel.kwargs, sentinel.name)
        self.assertIsInstance(resolver, RegexURLPattern)
项目:djangorestframework-blueprint    作者:odoku    | 项目源码 | 文件源码
def get_views(urlpatterns, base=''):
    views = OrderedDict()
    for pattern in urlpatterns:
        if isinstance(pattern, RegexURLResolver):
            views.update(get_views(
                urlpatterns=pattern.url_patterns,
                base=base + pattern.regex.pattern,
            ))
        elif isinstance(pattern, RegexURLPattern):
            url = base + pattern.regex.pattern
            url = URL_PARAMETER_PATTERN.sub('{\g<param>}', simplify_regex(url))
            views[url] = pattern.callback
    return views