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