--- a/cubicweb/web/application.py Thu Oct 20 18:28:46 2016 +0200
+++ b/cubicweb/web/application.py Fri Oct 21 13:09:47 2016 +0200
@@ -20,13 +20,14 @@
__docformat__ = "restructuredtext en"
import contextlib
+from functools import wraps
import json
import sys
from time import clock, time
from contextlib import contextmanager
from warnings import warn
-from six import text_type, binary_type
+from six import PY2, text_type, binary_type
from six.moves import http_client
from rql import BadRQLQuery
@@ -47,6 +48,30 @@
SESSION_MANAGER = None
+def _deprecated_path_arg(func):
+ @wraps(func)
+ def wrapper(self, req, *args, **kwargs):
+ if args or 'path' in kwargs:
+ func_name = func.func_name if PY2 else func.__name__
+ warn('[3.24] path argument got removed from "%s" parameters' % func_name,
+ DeprecationWarning)
+ return func(self, req)
+ return wrapper
+
+
+def _deprecated_req_path_swapped(func):
+ @wraps(func)
+ def wrapper(self, req, *args, **kwargs):
+ if not isinstance(req, CubicWebRequestBase):
+ warn('[3.15] Application entry point arguments are now (req, path) '
+ 'not (path, req)', DeprecationWarning, 2)
+ path = req
+ req = args[0] if args else kwargs.pop('req')
+ args = (path, ) + args[1:]
+ return func(self, req, *args, **kwargs)
+ return wrapper
+
+
@contextmanager
def anonymized_request(req):
orig_cnx = req.cnx
@@ -198,7 +223,8 @@
# publish methods #########################################################
- def log_handle_request(self, req, path):
+ @_deprecated_path_arg
+ def log_handle_request(self, req):
"""wrapper around _publish to log all queries executed for a given
accessed path
"""
@@ -224,7 +250,7 @@
req.set_cnx = wrap_set_cnx(req.set_cnx)
try:
- return self.main_handle_request(req, path)
+ return self.main_handle_request(req)
finally:
cnx = req.cnx
if cnx:
@@ -240,20 +266,17 @@
except Exception:
self.exception('error while logging queries')
- def main_handle_request(self, req, path):
- """Process an http request
+ @_deprecated_req_path_swapped
+ @_deprecated_path_arg
+ def main_handle_request(self, req):
+ """Process an HTTP request `req`
- Arguments are:
- - a Request object
- - path of the request object
+ :type req: `web.Request`
+ :param req: the request object
It returns the content of the http response. HTTP header and status are
set on the Request object.
"""
- if not isinstance(req, CubicWebRequestBase):
- warn('[3.15] Application entry point arguments are now (req, path) '
- 'not (path, req)', DeprecationWarning, 2)
- req, path = path, req
if req.authmode == 'http':
# activate realm-based auth
realm = self.vreg.config['realm']
@@ -280,7 +303,7 @@
try:
# Try to generate the actual request content
with cnx:
- content = self.core_handle(req, path)
+ content = self.core_handle(req)
# Handle user log-out
except LogOut as ex:
# When authentification is handled by cookie the code that
@@ -329,24 +352,23 @@
assert isinstance(content, binary_type)
return content
- def core_handle(self, req, path):
- """method called by the main publisher to process <path>
+ @_deprecated_path_arg
+ def core_handle(self, req):
+ """method called by the main publisher to process <req> relative path
should return a string containing the resulting page or raise a
`NotFound` exception
- :type path: str
- :param path: the path part of the url to publish
-
:type req: `web.Request`
:param req: the request object
:rtype: str
:return: the result of the pusblished url
"""
+ path = req.relative_path(False)
# don't log form values they may contains sensitive information
- self.debug('publish "%s" (%s, form params: %s)',
- path, req.session.sessionid, list(req.form))
+ self.debug('publish "%s" (%s, form params: %s)', path,
+ req.session.sessionid, list(req.form))
# remove user callbacks on a new request (except for json controllers
# to avoid callbacks being unregistered before they could be called)
tstart = clock()
@@ -423,7 +445,7 @@
except Exception:
pass # ignore rollback error at this point
self.add_undo_link_to_msg(req)
- self.debug('query %s executed in %s sec', req.relative_path(), clock() - tstart)
+ self.debug('query %s executed in %s sec', path, clock() - tstart)
return result
# Error handlers