Test instances against the Response/Request classes from werkzeug
It should be allowed to use the base classes instead of the custom derived of Tryton. Closes #14765
This commit is contained in:
@@ -17,8 +17,8 @@ from werkzeug import exceptions
|
||||
from werkzeug.datastructures import Authorization
|
||||
from werkzeug.exceptions import abort
|
||||
from werkzeug.utils import redirect, send_file
|
||||
from werkzeug.wrappers import Request as _Request
|
||||
from werkzeug.wrappers import Response as _Response
|
||||
from werkzeug.wrappers import Request as BaseRequest
|
||||
from werkzeug.wrappers import Response as BaseResponse
|
||||
|
||||
from trytond import backend, config, security
|
||||
from trytond.exceptions import RateLimitException, UserError, UserWarning
|
||||
@@ -84,7 +84,7 @@ def remove_auth_cookies(response, database):
|
||||
remove_cookie(response, database, TRYTON_SESSION_COOKIE)
|
||||
|
||||
|
||||
class Request(_Request):
|
||||
class Request(BaseRequest):
|
||||
|
||||
view_args = None
|
||||
|
||||
@@ -204,7 +204,7 @@ class Request(_Request):
|
||||
}
|
||||
|
||||
|
||||
class Response(_Response):
|
||||
class Response(BaseResponse):
|
||||
|
||||
def get_json(self, force=False, silent=False):
|
||||
from .jsonrpc import JSONDecoder, json
|
||||
@@ -413,7 +413,7 @@ def user_application(name, json=True):
|
||||
response = func(request, *args, **kwargs)
|
||||
except (UserError, UserWarning) as e:
|
||||
raise JSONBadRequest(e)
|
||||
if not isinstance(response, Response) and json:
|
||||
if not isinstance(response, BaseResponse) and json:
|
||||
response = Response(json_.dumps(response, cls=JSONEncoder),
|
||||
content_type='application/json')
|
||||
return response
|
||||
|
||||
@@ -30,7 +30,7 @@ except ImportError:
|
||||
from trytond import backend, config, security
|
||||
from trytond.protocols.jsonrpc import JSONProtocol
|
||||
from trytond.protocols.wrappers import (
|
||||
HTTPStatus, Request, Response, abort, exceptions)
|
||||
BaseResponse, HTTPStatus, Request, Response, abort, exceptions)
|
||||
from trytond.protocols.xmlrpc import XMLProtocol
|
||||
from trytond.status import processing
|
||||
from trytond.tools import resolve, safe_join
|
||||
@@ -142,7 +142,7 @@ class TrytondWSGI(object):
|
||||
response = e
|
||||
for error_handler in self.error_handlers:
|
||||
rv = error_handler(self, request, e)
|
||||
if isinstance(rv, Response):
|
||||
if isinstance(rv, BaseResponse):
|
||||
response = rv
|
||||
return response
|
||||
|
||||
@@ -205,12 +205,13 @@ class TrytondWSGI(object):
|
||||
|
||||
with processing(request):
|
||||
data = self.dispatch_request(request)
|
||||
if not isinstance(data, (Response, exceptions.HTTPException)):
|
||||
if not isinstance(
|
||||
data, (BaseResponse, exceptions.HTTPException)):
|
||||
response = self.make_response(request, data)
|
||||
else:
|
||||
response = data
|
||||
|
||||
if origin and isinstance(response, Response):
|
||||
if origin and isinstance(response, BaseResponse):
|
||||
response.headers['Access-Control-Allow-Origin'] = origin
|
||||
response.headers['Vary'] = 'Origin'
|
||||
method = request.headers.get('Access-Control-Request-Method')
|
||||
|
||||
Reference in New Issue
Block a user