From de590816d8d06730d99499db9a068f8d0e2cd3f9 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 29 Jan 2020 09:12:11 +0000 Subject: [PATCH] [FIX] *: deprecated access to url_ utilities through werkzeug root In 0.15 accessing werkzeug.urls functions directly through werkzeug is deprecated, the shortcut will be removed in the eventual werkzeug 1.0. Fix existing uses of these shortcuts. Also cleanup some imports when they're not far from a werkzeug* import being altered. --- addons/auth_oauth/controllers/main.py | 6 +++--- addons/google_spreadsheet/models/google_drive.py | 2 +- addons/hr/models/hr_employee.py | 5 +---- .../wizard/hr_expense_sheet_register_payment.py | 2 +- addons/http_routing/models/ir_http.py | 8 +++++--- addons/l10n_ch/models/res_bank.py | 2 +- addons/mail/controllers/main.py | 5 +++-- addons/mail/models/mail_thread.py | 3 +-- addons/payment_ingenico/models/payment.py | 6 +++--- addons/transifex/models/ir_translation.py | 10 +++------- addons/web/controllers/main.py | 4 ++-- addons/web_editor/models/ir_attachment.py | 2 +- addons/website/controllers/main.py | 5 +++-- addons/website/models/res_partner.py | 11 +++-------- addons/website_crm_partner_assign/controllers/main.py | 4 ++-- addons/website_customer/controllers/main.py | 2 +- addons/website_event/models/event_event.py | 4 ++-- addons/website_membership/controllers/main.py | 2 +- odoo/addons/base/models/ir_ui_view.py | 4 ++-- odoo/addons/base/models/res_bank.py | 2 +- odoo/http.py | 2 +- 21 files changed, 41 insertions(+), 50 deletions(-) diff --git a/addons/auth_oauth/controllers/main.py b/addons/auth_oauth/controllers/main.py index 00eea3268b6..3d1a6b53af3 100644 --- a/addons/auth_oauth/controllers/main.py +++ b/addons/auth_oauth/controllers/main.py @@ -66,7 +66,7 @@ class OAuthLogin(Home): scope=provider['scope'], state=json.dumps(state), ) - provider['auth_link'] = "%s?%s" % (provider['auth_endpoint'], werkzeug.url_encode(params)) + provider['auth_link'] = "%s?%s" % (provider['auth_endpoint'], werkzeug.urls.url_encode(params)) return providers def get_state(self, provider): @@ -76,7 +76,7 @@ class OAuthLogin(Home): state = dict( d=request.session.db, p=provider['id'], - r=werkzeug.url_quote_plus(redirect), + r=werkzeug.urls.url_quote_plus(redirect), ) token = request.params.get('token') if token: @@ -134,7 +134,7 @@ class OAuthController(http.Controller): cr.commit() action = state.get('a') menu = state.get('m') - redirect = werkzeug.url_unquote_plus(state['r']) if state.get('r') else False + redirect = werkzeug.urls.url_unquote_plus(state['r']) if state.get('r') else False url = '/web' if redirect: url = redirect diff --git a/addons/google_spreadsheet/models/google_drive.py b/addons/google_spreadsheet/models/google_drive.py index f3c04608e72..0f4f830b673 100644 --- a/addons/google_spreadsheet/models/google_drive.py +++ b/addons/google_spreadsheet/models/google_drive.py @@ -74,7 +74,7 @@ class GoogleDrive(models.Model): try: req = requests.post( - 'https://spreadsheets.google.com/feeds/cells/%s/od6/private/full/batch?%s' % (spreadsheet_key, werkzeug.url_encode({'v': 3, 'access_token': access_token})), + 'https://spreadsheets.google.com/feeds/cells/%s/od6/private/full/batch?%s' % (spreadsheet_key, werkzeug.urls.url_encode({'v': 3, 'access_token': access_token})), data=request, headers={'content-type': 'application/atom+xml', 'If-Match': '*'}, timeout=TIMEOUT, diff --git a/addons/hr/models/hr_employee.py b/addons/hr/models/hr_employee.py index 0324babaf23..1fcdf4584ae 100644 --- a/addons/hr/models/hr_employee.py +++ b/addons/hr/models/hr_employee.py @@ -4,14 +4,11 @@ import base64 from random import choice from string import digits -import itertools -from werkzeug import url_encode -import pytz +from werkzeug.urls import url_encode from odoo import api, fields, models, _ from odoo.exceptions import ValidationError, AccessError from odoo.modules.module import get_module_resource -from odoo.addons.resource.models.resource_mixin import timezone_datetime class HrEmployeePrivate(models.Model): diff --git a/addons/hr_expense/wizard/hr_expense_sheet_register_payment.py b/addons/hr_expense/wizard/hr_expense_sheet_register_payment.py index c13fec1939f..0c7050b1d7a 100644 --- a/addons/hr_expense/wizard/hr_expense_sheet_register_payment.py +++ b/addons/hr_expense/wizard/hr_expense_sheet_register_payment.py @@ -3,7 +3,7 @@ from odoo import api, fields, models, _ from odoo.exceptions import UserError, ValidationError -from werkzeug import url_encode +from werkzeug.urls import url_encode class HrExpenseSheetRegisterPaymentWizard(models.TransientModel): diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py index de512bdcdd8..d4755f0b2b7 100644 --- a/addons/http_routing/models/ir_http.py +++ b/addons/http_routing/models/ir_http.py @@ -7,7 +7,9 @@ import os import re import traceback import unicodedata -import werkzeug +import werkzeug.exceptions +import werkzeug.routing +import werkzeug.urls # optional python-slugify import (https://github.com/un33k/python-slugify) try: @@ -550,8 +552,8 @@ class IrHttp(models.AbstractModel): return cls._handle_exception(e) if getattr(request, 'is_frontend_multilang', False) and request.httprequest.method in ('GET', 'HEAD'): - generated_path = werkzeug.url_unquote_plus(path) - current_path = werkzeug.url_unquote_plus(request.httprequest.path) + generated_path = werkzeug.urls.url_unquote_plus(path) + current_path = werkzeug.urls.url_unquote_plus(request.httprequest.path) if generated_path != current_path: if request.lang != cls._get_default_lang(): path = '/' + request.lang.url_code + path diff --git a/addons/l10n_ch/models/res_bank.py b/addons/l10n_ch/models/res_bank.py index 90dedc00b8f..5feb7dd6676 100644 --- a/addons/l10n_ch/models/res_bank.py +++ b/addons/l10n_ch/models/res_bank.py @@ -148,7 +148,7 @@ class ResPartnerBank(models.Model): ref_type, reference, communication) - qr_code_url = '/report/barcode/?type=%s&value=%s&width=%s&height=%s&humanreadable=1' % ('QR', werkzeug.url_quote_plus(qr_code_string), 256, 256) + qr_code_url = '/report/barcode/?type=%s&value=%s&width=%s&height=%s&humanreadable=1' % ('QR', werkzeug.urls.url_quote_plus(qr_code_string), 256, 256) return qr_code_url def validate_swiss_code_arguments(self, currency, debitor): diff --git a/addons/mail/controllers/main.py b/addons/mail/controllers/main.py index 243c16c9abd..4f99295b937 100644 --- a/addons/mail/controllers/main.py +++ b/addons/mail/controllers/main.py @@ -4,9 +4,10 @@ import base64 import logging import psycopg2 -import werkzeug +import werkzeug.utils +import werkzeug.wrappers -from werkzeug import url_encode +from werkzeug.urls import url_encode from odoo import api, http, registry, SUPERUSER_ID, _ from odoo.exceptions import AccessError diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 2e94ea0cf44..e033cab3b63 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -24,7 +24,6 @@ except ImportError: from collections import namedtuple from email.message import EmailMessage from lxml import etree -from werkzeug import url_encode from werkzeug import urls from odoo import _, api, exceptions, fields, models, tools, registry, SUPERUSER_ID @@ -2482,7 +2481,7 @@ class MailThread(models.AbstractModel): token = self._notify_encode_link(base_link, params) params['token'] = token - link = '%s?%s' % (base_link, url_encode(params)) + link = '%s?%s' % (base_link, urls.url_encode(params)) if self: link = self[0].get_base_url() + link diff --git a/addons/payment_ingenico/models/payment.py b/addons/payment_ingenico/models/payment.py index 0399ec68c46..2e719ce033c 100644 --- a/addons/payment_ingenico/models/payment.py +++ b/addons/payment_ingenico/models/payment.py @@ -9,7 +9,7 @@ from unicodedata import normalize import requests from lxml import etree, objectify -from werkzeug import urls, url_encode +from werkzeug import urls from odoo import api, fields, models, _ from odoo.addons.payment.models.payment_acquirer import ValidationError @@ -177,7 +177,7 @@ class PaymentAcquirerOgone(models.Model): 'DECLINEURL': urls.url_join(base_url, OgoneController._decline_url), 'EXCEPTIONURL': urls.url_join(base_url, OgoneController._exception_url), 'CANCELURL': urls.url_join(base_url, OgoneController._cancel_url), - 'PARAMPLUS': url_encode(param_plus), + 'PARAMPLUS': urls.url_encode(param_plus), } if self.save_token in ['ask', 'always']: temp_ogone_tx_values.update({ @@ -365,7 +365,7 @@ class PaymentTxOgone(models.Model): 'ECI': 9, # Recurring (from eCommerce) 'ALIAS': self.payment_token_id.acquirer_ref, 'RTIMEOUT': 30, - 'PARAMPLUS': url_encode(param_plus), + 'PARAMPLUS': urls.url_encode(param_plus), 'EMAIL': self.partner_id.email or '', 'CN': self.partner_id.name or '', } diff --git a/addons/transifex/models/ir_translation.py b/addons/transifex/models/ir_translation.py index ed1150f8d14..1f17fc47d3a 100644 --- a/addons/transifex/models/ir_translation.py +++ b/addons/transifex/models/ir_translation.py @@ -1,14 +1,10 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -try: - from configparser import ConfigParser -except ImportError: - # python2 import - from ConfigParser import ConfigParser +from configparser import ConfigParser from os.path import join as opj import os -import werkzeug +import werkzeug.urls import odoo from odoo import models, fields @@ -84,7 +80,7 @@ class IrTranslation(models.Model): 'project': project, 'lang': lang_code, 'module': translation.module, - 'src': "text:'" + werkzeug.url_quote_plus( + 'src': "text:'" + werkzeug.urls.url_quote_plus( translation.src[:50].replace("\n", "").replace("'", "") ) + "'", } diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 798077daf40..cdc43a07c6e 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -26,7 +26,7 @@ import werkzeug.utils import werkzeug.wrappers import werkzeug.wsgi from collections import OrderedDict, defaultdict, Counter -from werkzeug.urls import url_decode, iri_to_uri +from werkzeug.urls import url_encode, url_decode, iri_to_uri from lxml import etree import unicodedata @@ -1257,7 +1257,7 @@ class Session(http.Controller): 'state': json.dumps({'d': request.db, 'u': ICP.get_param('web.base.url')}), 'scope': 'userinfo', } - return 'https://accounts.odoo.com/oauth2/auth?' + werkzeug.url_encode(params) + return 'https://accounts.odoo.com/oauth2/auth?' + url_encode(params) @http.route('/web/session/destroy', type='json', auth="user") def destroy(self): diff --git a/addons/web_editor/models/ir_attachment.py b/addons/web_editor/models/ir_attachment.py index bd8c27165d2..7c8ff486ea6 100644 --- a/addons/web_editor/models/ir_attachment.py +++ b/addons/web_editor/models/ir_attachment.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from werkzeug import url_quote +from werkzeug.urls import url_quote from odoo import api, models, fields, tools diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index 687f49e919b..83c0df51ff8 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -7,6 +7,7 @@ import os import logging import pytz import requests +import werkzeug.urls import werkzeug.utils import werkzeug.wrappers @@ -51,9 +52,9 @@ class QueryURL(object): paths[key] = u"%s" % value elif value: if isinstance(value, list) or isinstance(value, set): - fragments.append(werkzeug.url_encode([(key, item) for item in value])) + fragments.append(werkzeug.urls.url_encode([(key, item) for item in value])) else: - fragments.append(werkzeug.url_encode([(key, value)])) + fragments.append(werkzeug.urls.url_encode([(key, value)])) for key in path_args: value = paths.get(key) if value is not None: diff --git a/addons/website/models/res_partner.py b/addons/website/models/res_partner.py index cc832f3d3f9..c75d7ea8c75 100644 --- a/addons/website/models/res_partner.py +++ b/addons/website/models/res_partner.py @@ -1,15 +1,10 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -import werkzeug +import werkzeug.urls from odoo import models, fields - -def urlplus(url, params): - return werkzeug.Href(url)(params or None) - - class Partner(models.Model): _name = 'res.partner' _inherit = ['res.partner', 'website.published.multi.mixin'] @@ -27,14 +22,14 @@ class Partner(models.Model): 'sensor': 'false', 'key': google_maps_api_key, } - return urlplus('//maps.googleapis.com/maps/api/staticmap', params) + return '//maps.googleapis.com/maps/api/staticmap?'+werkzeug.urls.url_encode(params) def google_map_link(self, zoom=10): params = { 'q': '%s, %s %s, %s' % (self.street or '', self.city or '', self.zip or '', self.country_id and self.country_id.display_name or ''), 'z': zoom, } - return urlplus('https://maps.google.com/maps', params) + return 'https://maps.google.com/maps' + werkzeug.urls.url_encode(params) def _get_name(self): name = super(Partner, self)._get_name() diff --git a/addons/website_crm_partner_assign/controllers/main.py b/addons/website_crm_partner_assign/controllers/main.py index 99422b03160..4be4cf83057 100644 --- a/addons/website_crm_partner_assign/controllers/main.py +++ b/addons/website_crm_partner_assign/controllers/main.py @@ -2,7 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. import datetime -import werkzeug +import werkzeug.urls from collections import OrderedDict from werkzeug.exceptions import NotFound @@ -308,7 +308,7 @@ class WebsiteCrmPartnerAssign(WebsitePartnerPage): 'google_map_partner_ids': google_map_partner_ids, 'pager': pager, 'searches': post, - 'search_path': "%s" % werkzeug.url_encode(post), + 'search_path': "%s" % werkzeug.urls.url_encode(post), 'google_maps_api_key': google_maps_api_key, } return request.render("website_crm_partner_assign.index", values, status=partners and 200 or 404) diff --git a/addons/website_customer/controllers/main.py b/addons/website_customer/controllers/main.py index 4a7a931297d..7ef94366be8 100644 --- a/addons/website_customer/controllers/main.py +++ b/addons/website_customer/controllers/main.py @@ -132,7 +132,7 @@ class WebsiteCustomer(http.Controller): 'google_map_partner_ids': google_map_partner_ids, 'pager': pager, 'post': post, - 'search_path': "?%s" % werkzeug.url_encode(post), + 'search_path': "?%s" % werkzeug.urls.url_encode(post), 'tag': tag, 'tags': tags, 'google_maps_api_key': google_maps_api_key, diff --git a/addons/website_event/models/event_event.py b/addons/website_event/models/event_event.py index 6a8f1fd8eeb..491b8b60b17 100644 --- a/addons/website_event/models/event_event.py +++ b/addons/website_event/models/event_event.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -import werkzeug +import werkzeug.urls import json from odoo import api, fields, models, _ @@ -147,7 +147,7 @@ class Event(models.Model): } if self.address_id: params.update(location=self.sudo().address_id.contact_address.replace('\n', ' ')) - encoded_params = werkzeug.url_encode(params) + encoded_params = werkzeug.urls.url_encode(params) google_url = GOOGLE_CALENDAR_URL + encoded_params iCal_url = '/event/%d/ics?%s' % (self.id, encoded_params) return {'google_url': google_url, 'iCal_url': iCal_url} diff --git a/addons/website_membership/controllers/main.py b/addons/website_membership/controllers/main.py index d9e8cbdd757..ac5c6a8e47b 100644 --- a/addons/website_membership/controllers/main.py +++ b/addons/website_membership/controllers/main.py @@ -155,7 +155,7 @@ class WebsiteMembership(http.Controller): 'google_map_partner_ids': google_map_partner_ids, 'pager': pager, 'post': post, - 'search': "?%s" % werkzeug.url_encode(post), + 'search': "?%s" % werkzeug.urls.url_encode(post), 'search_count': count_members, 'google_maps_api_key': google_maps_api_key, } diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py index f2662bc040c..73a4ea9cae1 100644 --- a/odoo/addons/base/models/ir_ui_view.py +++ b/odoo/addons/base/models/ir_ui_view.py @@ -16,7 +16,7 @@ import uuid from dateutil.relativedelta import relativedelta from difflib import HtmlDiff -import werkzeug +import werkzeug, werkzeug.urls from lxml import etree from lxml.etree import LxmlError from lxml.builder import E @@ -1595,7 +1595,7 @@ actual arch. debug=request.session.debug if request else '', test_mode_enabled=bool(config['test_enable'] or config['test_file']), json=json_scriptsafe, - quote_plus=werkzeug.url_quote_plus, + quote_plus=werkzeug.urls.url_quote_plus, time=time, datetime=datetime, relativedelta=relativedelta, diff --git a/odoo/addons/base/models/res_bank.py b/odoo/addons/base/models/res_bank.py index 4b212f5bb08..be7b8245ca8 100644 --- a/odoo/addons/base/models/res_bank.py +++ b/odoo/addons/base/models/res_bank.py @@ -132,7 +132,7 @@ class ResPartnerBank(models.Model): if comment: communication = (comment[:137] + '...') if len(comment) > 140 else comment qr_code_string = 'BCD\n001\n1\nSCT\n%s\n%s\n%s\nEUR%s\n\n\n%s' % (self.bank_bic or "", self.company_id.name, self.acc_number, amount, communication) - qr_code_url = '/report/barcode/?type=%s&value=%s&width=%s&height=%s&humanreadable=1' % ('QR', werkzeug.url_quote_plus(qr_code_string), 128, 128) + qr_code_url = '/report/barcode/?' + werkzeug.urls.url_encode({'type': 'QR', 'value': qr_code_string, 'width': 128, 'height': 128, 'humanreadable': 1}) return qr_code_url def _validate_qr_code_arguments(self): diff --git a/odoo/http.py b/odoo/http.py index 5164f29a042..4c0cf76005c 100644 --- a/odoo/http.py +++ b/odoo/http.py @@ -167,7 +167,7 @@ def local_redirect(path, query=None, keep_hash=False, code=303): if not query: query = {} if query: - url += '?' + werkzeug.url_encode(query) + url += '?' + urls.url_encode(query) return werkzeug.utils.redirect(url, code) def redirect_with_hash(url, code=303):