Update URL Generator for compatibility with milla.Request and mark it deprecated
parent
2980b438da
commit
4c06340cea
|
@ -14,6 +14,10 @@ Contents:
|
|||
:maxdepth: 2
|
||||
|
||||
rationale
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
reference/index
|
||||
|
||||
*Milla* is released under the terms of the `Apache License, version 2.0`_.
|
||||
|
|
|
@ -26,6 +26,7 @@ import re
|
|||
import sys
|
||||
import urllib
|
||||
import urlparse
|
||||
import warnings
|
||||
|
||||
class Router(object):
|
||||
'''A dispatcher that maps arbitrary paths to controller callables
|
||||
|
@ -220,11 +221,20 @@ class Generator(object):
|
|||
A common pattern is to wrap this in a stub function::
|
||||
|
||||
url = Generator(request).generate
|
||||
|
||||
.. deprecated:: 0.2
|
||||
Use :py:meth:`milla.Request.relative_url` instead.
|
||||
'''
|
||||
|
||||
def __init__(self, request, path_only=True):
|
||||
self.request = request
|
||||
self.path_only = path_only
|
||||
warnings.warn(
|
||||
'Use of Generator is deprecated; '
|
||||
'use milla.Request.relative_url instead',
|
||||
DeprecationWarning,
|
||||
stacklevel=2
|
||||
)
|
||||
|
||||
def generate(self, *segments, **vars):
|
||||
'''Combines segments and the application's URL into a new URL
|
||||
|
@ -234,10 +244,7 @@ class Generator(object):
|
|||
while path.startswith('/'):
|
||||
path = path[1:]
|
||||
|
||||
url = self.request.relative_url(path, to_application=True)
|
||||
if self.path_only:
|
||||
split = urlparse.urlsplit(url)
|
||||
url = split.path
|
||||
if vars:
|
||||
url += '?' + urllib.urlencode(vars)
|
||||
return url
|
||||
return self.request.relative_url(path,
|
||||
to_application=True,
|
||||
path_only=self.path_only,
|
||||
**vars)
|
||||
|
|
Loading…
Reference in New Issue