Python django.core.urlresolvers.RegexURLResolver() Examples

The following are 7 code examples of django.core.urlresolvers.RegexURLResolver(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.core.urlresolvers , or try the search function .
Example #1
Source File: test_route.py    From baobab with GNU General Public License v3.0 6 votes vote down vote up
def test_01_nb_of_route(self):
        urls = ApiUrls.get_urls()
        # check the nb of defined ressources should be the same as the
        # number of route + 1 done by tastypie
        self.assertEqual(len(urls), self.nb_route + 1)
        self.assertTrue(isinstance(urls.pop(0), RegexURLPattern))

        event_url = urls.pop(0)
        self.assertTrue(isinstance(event_url, RegexURLResolver))
        # XXX depend on the version of tastypie: only use one or both method:
        #     prepend_urls/override_urls
        self.assertIn(len(event_url.url_patterns),
                      [self.nb_route_for_event, self.nb_route_for_event + 2])

        for url in urls:
            self.assertTrue(isinstance(url, RegexURLResolver))
            self.assertEqual(len(url.url_patterns),
                             self.nb_default_route_by_ressource) 
Example #2
Source File: api_docs.py    From django-rest-framework-docs with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def get_all_view_names(self, urlpatterns, parent_regex=''):
        for pattern in urlpatterns:
            if isinstance(pattern, RegexURLResolver):
                regex = '' if pattern._regex == "^" else pattern._regex
                self.get_all_view_names(urlpatterns=pattern.url_patterns, parent_regex=parent_regex + regex)
            elif isinstance(pattern, RegexURLPattern) and self._is_drf_view(pattern) and not self._is_format_endpoint(pattern):
                api_endpoint = ApiEndpoint(pattern, parent_regex, self.drf_router)
                self.endpoints.append(api_endpoint) 
Example #3
Source File: patch_resolvers.py    From gro-api with GNU General Public License v2.0 5 votes vote down vote up
def inner_get_resolver(urlconf, layout):
    # Loading this upon module import causes problems, so we're going to be
    # lazy about it
    from ..gro_api.urls import get_current_urls

    return urlresolvers.RegexURLResolver(
        r'^/', FakeURLConfModule(get_current_urls())
    ) 
Example #4
Source File: patch_resolvers.py    From gro-api with GNU General Public License v2.0 5 votes vote down vote up
def outer_get_resolver(urlconf):
    return inner_get_resolver(urlconf, system_layout.current_value)

# Monkey patching `django.core.urlresolvers.get_resolver` doesn't completely
# solve the problem in Django 1.8.3 because
# `django.core.handlers.base.BaseHandler` creates a new
# `django.core.urlresolvers.RegexURLResolver` on every request. This is
# addressed by ticket #14200 (https://code.djangoproject.com/ticket/14200).
# A patch for this problem has been written and accepted, and should appear in
# the next Django release. Until then, we essentially apply the accepted patch
# ourselves by monkey patching `BaseHandler.get_response`. 
Example #5
Source File: resolver.py    From django-telegram-bot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, conf):
        self.resolver = RegexURLResolver(r'^', conf) 
Example #6
Source File: bot.py    From permabots with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def handle_message(self, message, bot_service):
        """
        Process incoming message generating a response to the sender.
        
        :param message: Generic message received from provider
        :param bot_service: Service Integration
        :type bot_service: IntegrationBot :class:`IntegrationBot <permabots.models.bot.IntegrationBot>`

        .. note:: Message content will be extracted by IntegrationBot
        """
        urlpatterns = []
        state_context = {}
        chat_state = bot_service.get_chat_state(message)
        for handler in caching.get_or_set_related(self, 'handlers', 'response', 'request', 'target_state'):
            if handler.enabled:
                source_states = caching.get_or_set_related(handler, 'source_states')
                if chat_state:
                    state_context = chat_state.ctx
                if not source_states or (chat_state and chat_state.state in source_states):
                        urlpatterns.append(handler.urlpattern())
                    
        resolver = RegexURLResolver(r'^', urlpatterns)
        try:
            resolver_match = resolver.resolve(bot_service.message_text(message))
        except Resolver404:
            logger.warning("Handler not found for %s" % message)
        else:
            callback, callback_args, callback_kwargs = resolver_match
            logger.debug("Calling callback:%s for message %s with %s" % 
                         (callback, message, callback_kwargs))
            text, keyboard, target_state, context = callback(self, message=message, service=bot_service.identity, 
                                                             state_context=state_context, **callback_kwargs)
            if target_state:
                self.update_chat_state(bot_service, message, chat_state, target_state, context)
            keyboard = bot_service.build_keyboard(keyboard)
            bot_service.send_message(bot_service.get_chat_id(message), text, keyboard, message) 
Example #7
Source File: django-import-finder.py    From ConTroll_Remote_Access_Trojan with Apache License 2.0 5 votes vote down vote up
def find_url_callbacks(urls_module):
    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