Commit a70f9026 authored by Denis Laxalde's avatar Denis Laxalde
Browse files

Drop most deprecated code in cubicweb.web

This includes both Python and JavaScript code. Most code has been
deprecated since a very long time (versions 3.1x mostly, more than 5
years ago, and a few things until 3.24).

There are still a few deprecated things, most of which are actually used
within cubicweb (or in cubes we depend on for tests). I don't know what
to do with these...

Removed a couple of unused imports along the way.

Changelog entry will come in a later changeset.
parent e651d5f24cb5
......@@ -23,7 +23,6 @@ publisher to get a full CubicWeb web application
from cubicweb import _
from six.moves.urllib.parse import quote as urlquote
from logilab.common.deprecation import deprecated
from cubicweb.web._exceptions import *
from cubicweb.utils import json_dumps
......
......@@ -19,14 +19,13 @@
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 PY2, text_type, binary_type
from six import text_type, binary_type
from six.moves import http_client
from rql import BadRQLQuery
......@@ -40,40 +39,12 @@ from cubicweb.web import cors
from cubicweb.web import (
LOGGER, StatusResponse, DirectResponse, Redirect, NotFound, LogOut,
RemoteCallFailed, InvalidSession, RequestError, PublishException)
from cubicweb.web.request import CubicWebRequestBase
# make session manager available through a global variable so the debug view can
# print information about web session
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)
path = args[0] if args else kwargs['path']
assert path == req.relative_path(False), \
'mismatching path, {0} vs {1}'.format(path, req.relative_path(False))
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):
from cubicweb.web.views.authentication import Session
......@@ -227,7 +198,6 @@ class CubicWebPublisher(object):
# publish methods #########################################################
@_deprecated_path_arg
def log_handle_request(self, req):
"""wrapper around _publish to log all queries executed for a given
accessed path
......@@ -273,8 +243,6 @@ class CubicWebPublisher(object):
except Exception:
self.exception('error while logging queries')
@_deprecated_req_path_swapped
@_deprecated_path_arg
def main_handle_request(self, req):
"""Process an HTTP request `req`
......@@ -352,7 +320,6 @@ class CubicWebPublisher(object):
assert isinstance(content, binary_type)
return content
@_deprecated_path_arg
def core_handle(self, req):
"""method called by the main publisher to process <req> relative path
......
......@@ -23,7 +23,7 @@ from cubicweb import _
from six import add_metaclass
from logilab.mtconverter import xml_escape
from logilab.common.deprecation import class_deprecated, class_renamed
from logilab.common.deprecation import class_deprecated
from cubicweb import Unauthorized, role as get_role
from cubicweb.schema import display_name
......@@ -33,7 +33,6 @@ from cubicweb.web.htmlwidgets import (BoxLink, BoxWidget, SideBoxWidget,
RawBoxItem)
from cubicweb.web.action import UnregisteredAction
from cubicweb.web.component import (
AjaxEditRelationCtxComponent,
EditRelationMixIn,
Separator,
)
......@@ -195,8 +194,3 @@ class EditRelationBoxTemplate(EditRelationMixIn, EntityBoxTemplate):
label = super(EditRelationBoxTemplate, self).box_item(
entity, etarget, rql, label)
return RawBoxItem(label, liclass=u'invisible')
AjaxEditRelationBoxTemplate = class_renamed(
'AjaxEditRelationBoxTemplate', AjaxEditRelationCtxComponent,
'[3.10] AjaxEditRelationBoxTemplate has been renamed to AjaxEditRelationCtxComponent (%(cls)s)')
......@@ -23,7 +23,6 @@ from six import PY2
from logilab.mtconverter import xml_escape
from logilab.common.registry import yes
from logilab.common.deprecation import deprecated
from cubicweb.appobject import AppObject
from cubicweb.mail import format_mail
......@@ -106,12 +105,6 @@ class Controller(AppObject):
if not self._edited_entity:
self._edited_entity = entity
@deprecated('[3.18] call view.set_http_cache_headers then '
'.is_client_cache_valid() method and return instead')
def validate_cache(self, view):
view.set_http_cache_headers()
self._cw.validate_cache()
def sendmail(self, recipient, subject, body):
senderemail = self._cw.user.cw_adapt_to('IEmailable').get_email()
msg = format_mail({'email' : senderemail,
......
......@@ -473,19 +473,8 @@ function _loadDynamicFragments(node) {
}
// else: rebuild full url by fetching cubicweb:rql, cubicweb:vid, etc.
var rql = $fragment.attr('cubicweb:rql');
var items = $fragment.attr('cubicweb:vid').split('&');
var vid = items[0];
var vid = $fragment.attr('cubicweb:vid');
var extraparams = {};
// case where vid='myvid&param1=val1&param2=val2': this is a deprecated abuse-case
if (items.length > 1) {
cw.log("[3.5] you're using extraargs in cubicweb:vid " +
"attribute, this is deprecated, consider using " +
"loadurl instead");
for (var j = 1; j < items.length; j++) {
var keyvalue = items[j].split('=');
extraparams[keyvalue[0]] = keyvalue[1];
}
}
var actrql = $fragment.attr('cubicweb:actualrql');
if (actrql) {
extraparams['actualrql'] = actrql;
......@@ -679,23 +668,6 @@ function triggerLoad(divid) {
jQuery('#lazy-' + divid).trigger('load_' + divid);
}
/* DEPRECATED *****************************************************************/
// still used in cwo and keyword cubes at least
reloadComponent = cw.utils.deprecatedFunction(
'[3.9] reloadComponent() is deprecated, use loadxhtml instead',
function(compid, rql, registry, nodeid, extraargs) {
registry = registry || 'components';
rql = rql || '';
nodeid = nodeid || (compid + 'Component');
extraargs = extraargs || {};
var node = cw.jqNode(nodeid);
return node.loadxhtml(AJAX_BASE_URL, ajaxFuncArgs('component', null, compid,
rql, registry, extraargs));
}
);
function remoteExec(fname /* ... */) {
setProgressCursor();
var props = {
......
......@@ -18,12 +18,3 @@ function map(func, array) {
}
return result;
}
// skm cube still uses this
getNodeAttribute = cw.utils.deprecatedFunction(
'[3.9] getNodeAttribute(node, attr) is deprecated, use $(node).attr(attr)',
function(node, attribute) {
return $(node).attr(attribute);
}
);
......@@ -9,17 +9,6 @@ jQuery.extend(cw.htmlhelpers, {
});
/**
* .. function:: baseuri()
*
* returns the document's baseURI.
*/
baseuri = cw.utils.deprecatedFunction(
"[3.20] baseuri() is deprecated, use BASE_URL instead",
function () {
return BASE_URL;
});
/**
* .. function:: setProgressCursor()
*
......
......@@ -426,15 +426,6 @@ function IFRAME(params) {
// backward compat
CubicWeb = cw;
jQuery.extend(cw, {
require: cw.utils.deprecatedFunction(
'[3.9] CubicWeb.require() is not used anymore',
function(module) {}),
provide: cw.utils.deprecatedFunction(
'[3.9] CubicWeb.provide() is not used anymore',
function(module) {})
});
jQuery(document).ready(function() {
$(cw).trigger('server-response', [false, document]);
});
......@@ -63,7 +63,6 @@ from logilab.mtconverter import xml_escape
from logilab.common.graph import has_path
from logilab.common.decorators import cached, cachedproperty
from logilab.common.date import datetime2ticks, ustrftime, ticks2datetime
from logilab.common.deprecation import deprecated
from logilab.common.registry import yes
from rql import nodes, utils
......@@ -89,12 +88,6 @@ def get_facet(req, facetid, select, filtered_variable):
return req.vreg['facets'].object_by_id(facetid, req, select=select,
filtered_variable=filtered_variable)
@deprecated('[3.13] filter_hiddens moved to cubicweb.web.views.facets with '
'slightly modified prototype')
def filter_hiddens(w, baserql, **kwargs):
from cubicweb.web.views.facets import filter_hiddens
return filter_hiddens(w, baserql, wdgs=kwargs.pop('facets'), **kwargs)
## rqlst manipulation functions used by facets ################################
......@@ -164,15 +157,6 @@ def prepare_select(select, filtered_variable):
# global tree config: DISTINCT, LIMIT, OFFSET
select.set_distinct(True)
@deprecated('[3.13] use init_facets instead')
def prepare_facets_rqlst(rqlst, args=None):
assert len(rqlst.children) == 1, 'FIXME: union not yet supported'
select = rqlst.children[0]
filtered_variable = get_filtered_variable(select)
baserql = select.as_string(args)
prepare_select(select, filtered_variable)
return filtered_variable, baserql
def prepare_vocabulary_select(select, filtered_variable, rtype, role,
select_target_entity=True):
"""prepare a syntax tree to generate a filter vocabulary rql using the given
......@@ -370,11 +354,6 @@ def _get_var(select, varname, varmap):
return var
_prepare_vocabulary_rqlst = deprecated('[3.13] renamed prepare_vocabulary_select')(
prepare_vocabulary_select)
_cleanup_rqlst = deprecated('[3.13] renamed to cleanup_select')(cleanup_select)
## base facet classes ##########################################################
class AbstractFacet(AppObject):
......@@ -479,11 +458,6 @@ class AbstractFacet(AppObject):
def wdgclass(self):
raise NotImplementedError
@property
@deprecated('[3.13] renamed .select')
def rqlst(self):
return self.select
class VocabularyFacet(AbstractFacet):
"""This abstract class extend :class:`AbstractFacet` to use the
......
......@@ -23,7 +23,6 @@ from warnings import warn
from six import add_metaclass
from logilab.common.decorators import iclassmethod
from logilab.common.deprecation import deprecated
from cubicweb.appobject import AppObject
from cubicweb.view import NOINDEX, NOFOLLOW
......
......@@ -34,7 +34,6 @@ from six.moves.http_cookies import SimpleCookie
from rql.utils import rqlvar_maker
from logilab.common.decorators import cached
from logilab.common.deprecation import deprecated
from cubicweb import AuthenticationError
from cubicweb.req import RequestSessionBase
......@@ -162,16 +161,6 @@ class _CubicWebRequestBase(RequestSessionBase):
self.html_headers.define_var('pageid', pid, override=False)
self.pageid = pid
def _get_json_request(self):
warn('[3.15] self._cw.json_request is deprecated, use self._cw.ajax_request instead',
DeprecationWarning, stacklevel=2)
return self.ajax_request
def _set_json_request(self, value):
warn('[3.15] self._cw.json_request is deprecated, use self._cw.ajax_request instead',
DeprecationWarning, stacklevel=2)
self.ajax_request = value
json_request = property(_get_json_request, _set_json_request)
@property
def authmode(self):
"""Authentification mode of the instance
......@@ -696,15 +685,6 @@ class _CubicWebRequestBase(RequestSessionBase):
# XXX replace by False once validate_cache bw compat method is dropped
return None
@deprecated('[3.18] use .is_client_cache_valid() method instead')
def validate_cache(self):
"""raise a `StatusResponse` exception if a cached page along the way
exists and is still usable.
"""
status_code = self.is_client_cache_valid()
if status_code is not None:
raise StatusResponse(status_code)
# abstract methods to override according to the web front-end #############
def http_method(self):
......@@ -812,26 +792,13 @@ class _CubicWebRequestBase(RequestSessionBase):
values = _parse_accept_header(accepteds, value_parser, value_sort_key)
return (raw_value for (raw_value, parsed_value, score) in values)
@deprecated('[3.17] demote_to_html is deprecated as we always serve html')
def demote_to_html(self):
"""helper method to dynamically set request content type to text/html
The global doctype and xmldec must also be changed otherwise the browser
will display '<[' at the beginning of the page
"""
pass
# xml doctype #############################################################
def set_doctype(self, doctype, reset_xmldecl=None):
def set_doctype(self, doctype):
"""helper method to dynamically change page doctype
:param doctype: the new doctype, e.g. '<!DOCTYPE html>'
"""
if reset_xmldecl is not None:
warn('[3.17] reset_xmldecl is deprecated as we only serve html',
DeprecationWarning, stacklevel=2)
self.main_stream.set_doctype(doctype)
# page data management ####################################################
......@@ -878,16 +845,6 @@ class _CubicWebRequestBase(RequestSessionBase):
useragent = self.useragent()
return useragent and 'MSIE' in useragent
@deprecated('[3.17] xhtml_browser is deprecated (xhtml is no longer served)')
def xhtml_browser(self):
"""return True if the browser is considered as xhtml compatible.
If the instance is configured to always return text/html and not
application/xhtml+xml, this method will always return False, even though
this is semantically different
"""
return False
def html_content_type(self):
return 'text/html'
......
......@@ -760,18 +760,6 @@ class ApplicationTC(CubicWebTC):
req.form['rql'] = 'rql:Any OV1, X WHERE X custom_workflow OV1?'
self.app_handle_request(req)
def test_handle_deprecation(self):
"""Test deprecation warning for *_handle methods."""
with self.admin_access.web_request(url='foo') as req:
with self.assertWarns(DeprecationWarning) as cm:
self.app.core_handle(req, 'foo')
self.assertIn('path argument got removed from "core_handle"',
str(cm.warning))
with self.assertWarns(DeprecationWarning) as cm:
self.app.main_handle_request('foo', req)
self.assertIn('entry point arguments are now (req, path)',
str(cm.warning))
if __name__ == '__main__':
unittest_main()
......@@ -25,7 +25,6 @@ from six.moves.urllib.parse import urlsplit, urlunsplit, urljoin, parse_qs
import lxml
from logilab.common.testlib import unittest_main
from logilab.common.decorators import monkeypatch
from cubicweb import Binary, NoSelectableObject, ValidationError, transaction as tx
from cubicweb.schema import RRQLExpression
......@@ -37,7 +36,6 @@ from cubicweb.utils import json_dumps
from cubicweb.uilib import rql_for_eid
from cubicweb.web import Redirect, RemoteCallFailed, http_headers, formfields as ff
from cubicweb.web.views.autoform import get_pending_inserts, get_pending_deletes
from cubicweb.web.views.basecontrollers import JSonController, xhtmlize, jsonize
from cubicweb.web.views.ajaxcontroller import ajaxfunc, AjaxFunction
from cubicweb.server.session import Connection
from cubicweb.server.hook import Hook, Operation
......@@ -760,8 +758,8 @@ class EditControllerTC(CubicWebTC):
with self.admin_access.web_request(url='edit') as req:
p = self.create_user(req, u"doe")
# do not try to skip 'primary_email' for this test
old_skips = p.__class__.skip_copy_for
p.__class__.skip_copy_for = ()
old_skips = p.__class__.cw_skip_copy_for
p.__class__.cw_skip_copy_for = ()
try:
e = req.create_entity('EmailAddress', address=u'doe@doe.com')
req.execute('SET P use_email E, P primary_email E WHERE P eid %(p)s, E eid %(e)s',
......@@ -786,7 +784,7 @@ class EditControllerTC(CubicWebTC):
rset = req.execute('CWUser P WHERE P surname "Boom"')
self.assertEqual(len(rset), 0)
finally:
p.__class__.skip_copy_for = old_skips
p.__class__.cw_skip_copy_for = old_skips
def test_regr_inlined_forms(self):
with self.admin_access.web_request() as req:
......@@ -1020,64 +1018,6 @@ class AjaxControllerTC(CubicWebTC):
self.assertEqual(cm.exception.reason, 'no foo method')
class JSonControllerTC(AjaxControllerTC):
# NOTE: this class performs the same tests as AjaxController but with
# deprecated 'json' controller (i.e. check backward compatibility)
tested_controller = 'json'
def setUp(self):
super(JSonControllerTC, self).setUp()
self.exposed_remote_funcs = [fname for fname in dir(JSonController)
if fname.startswith('js_')]
def tearDown(self):
super(JSonControllerTC, self).tearDown()
for funcname in dir(JSonController):
# remove functions added dynamically during tests
if funcname.startswith('js_') and funcname not in self.exposed_remote_funcs:
delattr(JSonController, funcname)
def test_monkeypatch_jsoncontroller(self):
with self.assertRaises(RemoteCallFailed):
with self.remote_calling('foo'):
pass
@monkeypatch(JSonController)
def js_foo(self):
return u'hello'
with self.remote_calling('foo') as (res, _):
self.assertEqual(res, b'hello')
def test_monkeypatch_jsoncontroller_xhtmlize(self):
with self.assertRaises(RemoteCallFailed):
with self.remote_calling('foo'):
pass
@monkeypatch(JSonController)
@xhtmlize
def js_foo(self):
return u'hello'
with self.remote_calling('foo') as (res, _):
self.assertEqual(b'<div>hello</div>', res)
def test_monkeypatch_jsoncontroller_jsonize(self):
with self.assertRaises(RemoteCallFailed):
with self.remote_calling('foo'):
pass
@monkeypatch(JSonController)
@jsonize
def js_foo(self):
return 12
with self.remote_calling('foo') as (res, _):
self.assertEqual(res, b'12')
def test_monkeypatch_jsoncontroller_stdfunc(self):
@monkeypatch(JSonController)
@jsonize
def js_reledit_form(self):
return 12
with self.remote_calling('reledit_form') as (res, _):
self.assertEqual(res, b'12')
class UndoControllerTC(CubicWebTC):
def setUp(self):
......
......@@ -19,15 +19,10 @@
import os
import sys
import tempfile
from six import add_metaclass
from rql import nodes
from logilab.mtconverter import xml_escape
from logilab.common.deprecation import class_deprecated
def need_table_view(rset, schema):
......@@ -126,23 +121,3 @@ def add_etype_button(req, etype, csscls='addButton right', **urlkwargs):
return u'<a href="%s" class="%s">%s</a>' % (
xml_escape(url), csscls, req.__('New %s' % etype))
return u''
@add_metaclass(class_deprecated)
class TmpFileViewMixin(object):
__deprecation_warning__ = '[3.18] %(cls)s is deprecated'
binary = True
content_type = 'application/octet-stream'
cache_max_age = 60*60*2 # stay in http cache for 2 hours by default
def call(self):
self.cell_call()
def cell_call(self, row=0, col=0):
self.cw_row, self.cw_col = row, col # in case one needs it
fd, tmpfile = tempfile.mkstemp('.png')
os.close(fd)
self._generate(tmpfile)
self.w(open(tmpfile, 'rb').read())
os.unlink(tmpfile)
......@@ -71,7 +71,6 @@ from six.moves import http_client
from logilab.common.date import strptime
from logilab.common.registry import yes
from logilab.common.deprecation import deprecated
from cubicweb import ObjectNotFound, NoSelectableObject, ValidationError
from cubicweb.appobject import AppObject
......@@ -444,16 +443,6 @@ def unload_page_data(self):
"""remove user's session data associated to current pageid"""
self._cw.session.data.pop(self._cw.pageid, None)
@ajaxfunc(output_type='json')
@deprecated("[3.13] use jQuery.cookie(cookiename, cookievalue, {path: '/'}) in js land instead")
def set_cookie(self, cookiename, cookievalue):
"""generates the Set-Cookie HTTP reponse header corresponding
to `cookiename` / `cookievalue`.
"""
cookiename, cookievalue = str(cookiename), str(cookievalue)
self._cw.set_cookie(cookiename, cookievalue)
@ajaxfunc
def delete_relation(self, rtype, subjeid, objeid):
......
......@@ -19,60 +19,18 @@
object to handle publication.
"""
from cubicweb import _
from warnings import warn
from six import text_type
from six.moves import http_client
from logilab.common.deprecation import deprecated
from cubicweb import (NoSelectableObject, ObjectNotFound, ValidationError,
AuthenticationError, UndoTransactionException,
Forbidden)
from cubicweb.utils import json_dumps
from cubicweb.predicates import (authenticated_user, anonymous_user,
match_form_params)
from cubicweb.web import Redirect, RemoteCallFailed
from cubicweb.web.controller import Controller, append_url_params
from cubicweb.web import Redirect
from cubicweb.web.controller import Controller
from cubicweb.web.views import vid_from_rset
import cubicweb.transaction as tx
@deprecated('[3.15] jsonize is deprecated, use AjaxFunction appobjects instead')
def jsonize(func):
"""decorator to sets correct content_type and calls `json_dumps` on
results
"""
def wrapper(self, *args, **kwargs):
self._cw.set_content_type('application/json')
return json_dumps(func(self, *args, **kwargs))
wrapper.__name__ = func.__name__
return wrapper
@deprecated('[3.15] xhtmlize is deprecated, use AjaxFunction appobjects instead')