曾与蒿藜同雨露,한때 잡초와 쑥과 함께 비와 이슬을 나누던 곳이 이제는 소나무와 삼나무와 함께 서리와 눈을 견뎌내고 있다.终随松柏到冰霜.かつては雑草やヨモギと共に雨や露を分かち合っていたが、今では松やヒノキと共に霜や雪に耐えている。曾与蒿藜同雨露,Once sharing rain and dew with weeds and wormwood, now enduring frost and snow with pines and cypresses.终随松柏到冰霜.曾与蒿藜同雨露한때 잡초와 쑥과 함께 비와 이슬을 나누던 곳이 이제는 소나무와 삼나무와 함께 서리와 눈을 견뎌내고 있다.,终随松柏到冰霜.譖セ荳手珍阯懷酔髮ィ髴イ�檎サ磯囂譚セ譟丞芦蜀ー髴�曾与蒿藜同雨露,鏇句笌钂胯棞鍚岄洦闇诧紝缁堥殢鏉炬煆鍒板啺闇�终随松柏到冰霜.曾与蒿藜同雨露,한때 잡초와 쑥과 함께 비와 이슬을 나누던 곳이 이제는 소나무와 삼나무와 함께 서리와 눈을 견뎌내고 있다.终随松柏到冰霜.曾与蒿藜同雨露,终随松柏到冰霜.
from __future__ import absolute_import
import re
try:
from django.urls import get_resolver
except ImportError:
from django.core.urlresolvers import get_resolver
class RouteResolver(object):
_optional_group_matcher = re.compile(r'\(\?\:([^\)]+)\)')
_named_group_matcher = re.compile(r'\(\?P<(\w+)>[^\)]+\)')
_non_named_group_matcher = re.compile(r'\([^\)]+\)')
# [foo|bar|baz]
_either_option_matcher = re.compile(r'\[([^\]]+)\|([^\]]+)\]')
_camel_re = re.compile(r'([A-Z]+)([a-z])')
_cache = {}
def _simplify(self, pattern):
r"""
Clean up urlpattern regexes into something readable by humans:
From:
> "^(?P<sport_slug>\w+)/athletes/(?P<athlete_slug>\w+)/$"
To:
> "{sport_slug}/athletes/{athlete_slug}/"
"""
# remove optional params
# TODO(dcramer): it'd be nice to change these into [%s] but it currently
# conflicts with the other rules because we're doing regexp matches
# rather than parsing tokens
result = self._optional_group_matcher.sub(lambda m: '%s' % m.group(1), pattern)
# handle named groups first
result = self._named_group_matcher.sub(lambda m: '{%s}' % m.group(1), result)
# handle non-named groups
result = self._non_named_group_matcher.sub('{var}', result)
# handle optional params
result = self._either_option_matcher.sub(lambda m: m.group(1), result)
# clean up any outstanding regex-y characters.
result = result.replace('^', '').replace('$', '') \
.replace('?', '').replace('//', '/').replace('\\', '')
return result
def _resolve(self, resolver, path, parents=None):
match = resolver.regex.search(path)
if not match:
return
if parents is None:
parents = [resolver]
elif resolver not in parents:
parents = parents + [resolver]
new_path = path[match.end():]
for pattern in resolver.url_patterns:
# this is an include()
if not pattern.callback:
match = self._resolve(pattern, new_path, parents)
if match:
return match
continue
elif not pattern.regex.search(new_path):
continue
try:
return self._cache[pattern]
except KeyError:
pass
prefix = ''.join(self._simplify(p.regex.pattern) for p in parents)
result = prefix + self._simplify(pattern.regex.pattern)
if not result.startswith('/'):
result = '/' + result
self._cache[pattern] = result
return result
def resolve(self, path, urlconf=None):
resolver = get_resolver(urlconf)
match = self._resolve(resolver, path)
return match or path