| 501 | |
| 502 | |
| 503 | class URLResolver: |
| 504 | def __init__( |
| 505 | self, pattern, urlconf_name, default_kwargs=None, app_name=None, namespace=None |
| 506 | ): |
| 507 | self.pattern = pattern |
| 508 | # urlconf_name is the dotted Python path to the module defining |
| 509 | # urlpatterns. It may also be an object with an urlpatterns attribute |
| 510 | # or urlpatterns itself. |
| 511 | self.urlconf_name = urlconf_name |
| 512 | self.callback = None |
| 513 | self.default_kwargs = default_kwargs or {} |
| 514 | self.namespace = namespace |
| 515 | self.app_name = app_name |
| 516 | self._reverse_dict = {} |
| 517 | self._namespace_dict = {} |
| 518 | self._app_dict = {} |
| 519 | # set of dotted paths to all functions and classes that are used in |
| 520 | # urlpatterns |
| 521 | self._callback_strs = set() |
| 522 | self._populated = False |
| 523 | self._local = Local() |
| 524 | |
| 525 | def __repr__(self): |
| 526 | if isinstance(self.urlconf_name, list) and self.urlconf_name: |
| 527 | # Don't bother to output the whole list, it can be huge |
| 528 | urlconf_repr = "<%s list>" % self.urlconf_name[0].__class__.__name__ |
| 529 | else: |
| 530 | urlconf_repr = repr(self.urlconf_name) |
| 531 | return "<%s %s (%s:%s) %s>" % ( |
| 532 | self.__class__.__name__, |
| 533 | urlconf_repr, |
| 534 | self.app_name, |
| 535 | self.namespace, |
| 536 | self.pattern.describe(), |
| 537 | ) |
| 538 | |
| 539 | def check(self): |
| 540 | messages = [] |
| 541 | for pattern in self.url_patterns: |
| 542 | messages.extend(check_resolver(pattern)) |
| 543 | return messages or self.pattern.check() |
| 544 | |
| 545 | def _populate(self): |
| 546 | # Short-circuit if called recursively in this thread to prevent |
| 547 | # infinite recursion. Concurrent threads may call this at the same |
| 548 | # time and will need to continue, so set 'populating' on a |
| 549 | # thread-local variable. |
| 550 | if getattr(self._local, "populating", False): |
| 551 | return |
| 552 | try: |
| 553 | self._local.populating = True |
| 554 | lookups = MultiValueDict() |
| 555 | namespaces = {} |
| 556 | apps = {} |
| 557 | language_code = get_language() |
| 558 | for url_pattern in reversed(self.url_patterns): |
| 559 | p_pattern = url_pattern.pattern.regex.pattern |
| 560 | p_pattern = p_pattern.removeprefix("^") |
no outgoing calls
searching dependent graphs…