Skip to content

Commit

Permalink
remove redirect_to and url_for-like args to @https
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
pjenvey committed Jan 19, 2010
1 parent 7cd556a commit b91b2e4
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 82 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Pylons Changelog
* WARNING: Removed Buffet options, setup, and legacy render/render_response
function from pylons.templating. This also means config no longer accepts
the add_template_engine option.
* WARNING: Removed legacy redirect_to function.
* WARNING: @https decorator no longer accepts url_for-like arguments.

0.10 (**branch**)
* redirect_to is now deprecated, use redirect(url(*args, **kwargs)) instead.
Expand Down
25 changes: 1 addition & 24 deletions pylons/controllers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Functions available:
:func:`abort`, :func:`forward`, :func:`etag_cache`,
:func:`mimetype`, :func:`redirect`, and :func:`redirect_to`
:func:`mimetype` and :func:`redirect`
"""
import base64
import binascii
Expand All @@ -26,7 +26,6 @@
except ImportError:
import sha as sha1

from routes import url_for
from webob import Request as WebObRequest
from webob import Response as WebObResponse
from webob.exc import status_map
Expand Down Expand Up @@ -202,25 +201,3 @@ def redirect(url, code=302):
log.debug("Generating %s redirect" % code)
exc = status_map[code]
raise exc(location=url).exception


def redirect_to(*args, **kargs):
"""Raises a redirect exception to the URL resolved by Routes'
url_for function
Optionally, a _code variable may be passed with the status code of
the redirect, i.e.::
redirect_to(controller='home', action='index', _code=303)
.. warning::
This function is deprecated. Pass the result of :func:`url` to
:func:`redirect` instead.
"""
import warnings
warnings.warn('redirect_to is deprecated, use redirect(url(*args, '
'**kwargs)) instead.', DeprecationWarning, 2)
code = kargs.pop('_code', 302)
return redirect(url_for(*args, **kargs), code)
26 changes: 4 additions & 22 deletions pylons/decorators/secure.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def authenticate_form(func, *args, **kwargs):
abort(403, detail=csrf_detected_message)
authenticate_form = decorator(authenticate_form)

def https(*redirect_args, **redirect_kwargs):
def https(url_or_callable):
"""Decorator to redirect to the SSL version of a page if not
currently using HTTPS. Apply this decorator to controller methods
(actions).
Expand Down Expand Up @@ -78,13 +78,6 @@ def login(self):
def get(self):
do_secure()
.. warning::
Arguments as would be passed to the
:func:`url_for`/:func:`redirect_to` functions are
deprecated. Explicitly specify the url or a callable returning
the url instead.
"""
def wrapper(func, *args, **kwargs):
"""Decorator Wrapper function"""
Expand All @@ -95,21 +88,10 @@ def wrapper(func, *args, **kwargs):
# don't allow POSTs (raises an exception)
abort(405, headers=[('Allow', 'GET')])

# ensure https
if not redirect_args or redirect_kwargs:
from routes import url_for
import warnings
url_doc = (not redirect_args and 'url.current()' or
'url(*args, **kwargs)')
msg = ('Calling https with url_for args is deprecated, use '
'https(lambda: %s) instead' % url_doc)
warnings.warn(msg, DeprecationWarning, 2)
redirect_kwargs['protocol'] = 'https'
url = url_for(*redirect_args, **redirect_kwargs)
if callable(url_or_callable):
url = url_or_callable()
else:
url = redirect_args[0]
if callable(url):
url = url()
url = url_or_callable
# Ensure an https scheme, which also needs a host
parts = urlparse.urlparse(url)
url = urlparse.urlunparse(('https', parts[1] or request.host) +
Expand Down
1 change: 0 additions & 1 deletion tests/test_units/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import pylons
from pylons.controllers import WSGIController
from pylons.controllers.util import redirect_to

from __init__ import TestWSGIController, SetupCacheGlobal, ControllerWrap, TestMiddleware

Expand Down
32 changes: 0 additions & 32 deletions tests/test_units/test_decorator_https.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ def index(self):
return 'index page'
index = https('/pylons')(index)

def login(self):
return 'login page'
login = https(controller='auth', action='login')(login)

def login2(self):
return 'login2 page'
login2 = https(lambda: url(controller='auth', action='login'))(login2)
Expand All @@ -27,10 +23,6 @@ def secure(self):
return 'secure page'
secure = https(lambda: url.current())(secure)

def get(self):
return 'get page'
get = https()(get)

class TestHttpsDecorator(TestWSGIController):
def setUp(self):
TestWSGIController.setUp(self)
Expand Down Expand Up @@ -62,18 +54,6 @@ def test_https_disallows_post(self):
self.environ['pylons.routes_dict']['action'] = 'index'
response = self.app.post('/index', status=405)

def test_https_url_for_kwargs(self):
self.environ['pylons.routes_dict']['action'] = 'login'

response = self.app.get('/login', status=302)
assert response.header_dict.get('location') == \
'https://localhost/auth/login'

self.environ['wsgi.url_scheme'] = 'https'
response = self.app.get('/login', status=200)
assert 'location' not in response.header_dict
assert 'login page' in response

def test_https_callable(self):
self.environ['pylons.routes_dict']['action'] = 'login2'

Expand All @@ -97,15 +77,3 @@ def test_https_callable_current(self):
response = self.app.get('/secure', status=200)
assert 'location' not in response.header_dict
assert 'secure page' in response

def test_https_redirect_to_self(self):
self.environ['pylons.routes_dict']['action'] = 'get'

response = self.app.get('/get', status=302)
assert response.header_dict.get('location') == \
'https://localhost/get'

self.environ['wsgi.url_scheme'] = 'https'
response = self.app.get('/get', status=200)
assert 'location' not in response.header_dict
assert 'get page' in response
2 changes: 1 addition & 1 deletion tests/test_webapps/filestotest/base_with_xmlrpc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pylons import tmpl_context as c, app_globals, cache, request, session
from pylons.controllers import WSGIController, XMLRPCController
from pylons.controllers.util import abort, redirect_to, etag_cache
from pylons.controllers.util import abort, etag_cache, redirect
from pylons.decorators import jsonify, validate
from pylons.templating import render_mako as render
from pylons.i18n import N_, _, ungettext
Expand Down
2 changes: 1 addition & 1 deletion tests/test_webapps/filestotest/controller_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pylons.decorators import rest
from pylons.i18n import _, get_lang, set_lang, LanguageError
from pylons.templating import render_mako, render_genshi, render_jinja2
from pylons.controllers.util import abort, redirect_to
from pylons.controllers.util import abort, redirect

class SampleController(BaseController):
def index(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_webapps/filestotest/controller_sqlatest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pylons.i18n import _, get_lang, set_lang, LanguageError
from pylons.templating import render_mako, render_genshi, \
render_jinja2
from pylons.controllers.util import abort, redirect_to, url_for
from pylons.controllers.util import abort, redirect

class SampleController(BaseController):
def index(self):
Expand Down

0 comments on commit b91b2e4

Please sign in to comment.