~kernevil/ubuntu/saucy/pylons/fix-useless-import

« back to all changes in this revision

Viewing changes to pylons/decorators/secure.py

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ożarowski
  • Date: 2011-08-02 21:17:36 UTC
  • mfrom: (1.2.3 upstream) (10.1.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20110802211736-ejqil9b3yqgxt6lr
Tags: 1.0-2
* Add ipython_0.11_compatibility patch (thanks to Julian Taylor)
* Add build-arch and build-indep targets to debian/rules 
* Switch from dh_pysupport to dh_python2
* Source format changed to 3.0 (quilt)
* Standards-Version bumped to 3.9.2 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
    import webhelpers.html.secure_form as secure_form
8
8
except ImportError:
9
9
    import webhelpers.pylonslib.secure_form as secure_form
10
 
    
11
10
 
12
11
from pylons.controllers.util import abort, redirect
13
12
from pylons.decorators.util import get_pylons
50
49
        abort(403, detail=csrf_detected_message)
51
50
 
52
51
 
53
 
def https(*redirect_args, **redirect_kwargs):
 
52
def https(url_or_callable=None):
54
53
    """Decorator to redirect to the SSL version of a page if not
55
54
    currently using HTTPS. Apply this decorator to controller methods
56
55
    (actions).
84
83
        def get(self):
85
84
            do_secure()
86
85
 
87
 
    .. warning::
88
 
 
89
 
        Arguments as would be passed to the
90
 
        :func:`url_for`/:func:`redirect_to` functions are
91
 
        deprecated. Explicitly specify the url or a callable returning
92
 
        the url instead.
93
 
 
94
86
    """
95
87
    def wrapper(func, *args, **kwargs):
96
88
        """Decorator Wrapper function"""
101
93
            # don't allow POSTs (raises an exception)
102
94
            abort(405, headers=[('Allow', 'GET')])
103
95
 
104
 
        if redirect_kwargs:
105
 
            # XXX: not a foolproof check for url_for arguments, but the
106
 
            # best we can do
107
 
            import warnings
108
 
            from routes import url_for
109
 
            warnings.warn('Calling https with url_for args is deprecated, use '
110
 
                          'https(lambda: url(*args, **kwargs)) instead',
111
 
                          DeprecationWarning, 2)
112
 
            redirect_kwargs['protocol'] = 'https'
113
 
            url = url_for(*redirect_args, **redirect_kwargs)
114
 
        elif not redirect_args:
 
96
        if url_or_callable is None:
115
97
            url = request.url
 
98
        elif callable(url_or_callable):
 
99
            url = url_or_callable()
116
100
        else:
117
 
            url = redirect_args[0]
118
 
            if callable(url):
119
 
                url = url()
 
101
            url = url_or_callable
120
102
        # Ensure an https scheme, which also needs a host
121
103
        parts = urlparse.urlparse(url)
122
104
        url = urlparse.urlunparse(('https', parts[1] or request.host) +