diff options
author | Ben Bangert <ben@groovie.org> | 2010-02-20 14:04:48 -0500 |
---|---|---|
committer | Ben Bangert <ben@groovie.org> | 2010-02-20 14:04:48 -0500 |
commit | d1d1742903fa5ca24ef848a6ae895303f2661b2a (patch) | |
tree | 9057bbdf8d227c659c6a4f02369b7c329e18dc1d /routes | |
parent | fd0942df2c68f604504807f7143e2bd063613ccf (diff) | |
download | routes-d1d1742903fa5ca24ef848a6ae895303f2661b2a.tar.gz |
Increase unit tests and add more explicit use of the mapper for matching.
--HG--
branch : trunk
Diffstat (limited to 'routes')
-rw-r--r-- | routes/mapper.py | 25 | ||||
-rw-r--r-- | routes/util.py | 8 |
2 files changed, 17 insertions, 16 deletions
diff --git a/routes/mapper.py b/routes/mapper.py index 60ecf0a..298680c 100644 --- a/routes/mapper.py +++ b/routes/mapper.py @@ -594,7 +594,7 @@ class Mapper(SubMapperParent): self._master_regexp = re.compile(regexp) self._created_regs = True - def _match(self, url): + def _match(self, url, environ): """Internal Route matcher Matches a URL against a route, and returns a tuple of the match @@ -622,7 +622,7 @@ class Mapper(SubMapperParent): else: return (None, None, matchlog) - environ = self.environ + environ = environ or self.environ sub_domains = self.sub_domains sub_domains_ignore = self.sub_domains_ignore domain_match = self.domain_match @@ -647,7 +647,7 @@ class Mapper(SubMapperParent): return (match, route, matchlog) return (None, None, matchlog) - def match(self, url): + def match(self, url=None, environ=None): """Match a URL against against one of the routes contained. Will return None if no valid match is found. @@ -657,18 +657,20 @@ class Mapper(SubMapperParent): resultdict = m.match('/joe/sixpack') """ - if not url: - raise RoutesException('No URL provided, the minimum URL necessary' - ' to match is "/".') + if not url and not environ: + raise RoutesException('URL or environ must be provided') - result = self._match(url) + if not url: + url = environ['PATH_INFO'] + + result = self._match(url, environ) if self.debug: return result[0], result[1], result[2] if isinstance(result[0], dict) or result[0]: return result[0] return None - def routematch(self, url): + def routematch(self, url=None, environ=None): """Match a URL against against one of the routes contained. Will return None if no valid match is found, otherwise a @@ -679,7 +681,12 @@ class Mapper(SubMapperParent): resultdict, route_obj = m.match('/joe/sixpack') """ - result = self._match(url) + if not url and not environ: + raise RoutesException('URL or environ must be provided') + + if not url: + url = environ['PATH_INFO'] + result = self._match(url, environ) if self.debug: return result[0], result[1], result[2] if isinstance(result[0], dict) or result[0]: diff --git a/routes/util.py b/routes/util.py index c38c43b..fe77c82 100644 --- a/routes/util.py +++ b/routes/util.py @@ -192,8 +192,6 @@ def url_for(*args, **kargs): for key in ['anchor', 'host', 'protocol']: if kargs.get(key): del kargs[key] - if kargs.has_key(key+'_'): - kargs[key] = kargs.pop(key+'_') config = request_config() route = None static = False @@ -336,8 +334,6 @@ class URLGenerator(object): for key in ['anchor', 'host', 'protocol']: if kargs.get(key): del kargs[key] - if kargs.has_key(key+'_'): - kargs[key] = kargs.pop(key+'_') route = None use_current = '_use_current' in kargs and kargs.pop('_use_current') @@ -345,7 +341,7 @@ class URLGenerator(object): static = False encoding = self.mapper.encoding url = '' - + more_args = len(args) > 0 if more_args: route = self.mapper._routenames.get(args[0]) @@ -353,7 +349,6 @@ class URLGenerator(object): if not route and more_args: static = True url = args[0] - if url.startswith('/') and self.environ.get('SCRIPT_NAME'): url = self.environ.get('SCRIPT_NAME') + url @@ -383,7 +378,6 @@ class URLGenerator(object): # If this route has a filter, apply it if route.filter: newargs = route.filter(newargs) - if not route.static or (route.static and not route.external): # Handle sub-domains newargs = _subdomain_check(newargs, self.mapper, |