Cédric Krier pushed to branch branch/default at Tryton / Tryton


Commits:
a22c4cd5 by Cédric Krier at 2023-01-14T11:43:51+01:00
Use standard functools.wraps instead of wrapt
- - - - -


2 changed files:

- trytond/setup.py
- trytond/trytond/wsgi.py


Changes:

=====================================
trytond/setup.py
=====================================
@@ -141,7 +141,6 @@
         'polib',
         'python-sql >= 1.3',
         'werkzeug',
-        'wrapt',
         'passlib >= 1.7.0',
         'pytz;python_version<"3.9"',
         ],


=====================================
trytond/trytond/wsgi.py
=====================================
@@ -8,6 +8,7 @@
 import sys
 import traceback
 import urllib.parse
+from functools import wraps
 
 from werkzeug.routing import BaseConverter, Map, Rule
 
@@ -25,8 +26,6 @@
 except ImportError:
     from werkzeug.wsgi import SharedDataMiddleware
 
-import wrapt
-
 from trytond.config import config
 from trytond.protocols.jsonrpc import JSONProtocol
 from trytond.protocols.wrappers import (
@@ -69,17 +68,18 @@
         self.error_handlers.append(handler)
         return handler
 
-    @wrapt.decorator
-    def auth_required(self, wrapped, instance, args, kwargs):
-        request = args[0]
-        if request.user_id:
-            return wrapped(*args, **kwargs)
-        else:
-            headers = {}
-            if request.headers.get('X-Requested-With') != 'XMLHttpRequest':
-                headers['WWW-Authenticate'] = 'Basic realm="Tryton"'
-            response = Response(None, http.client.UNAUTHORIZED, headers)
-            abort(http.client.UNAUTHORIZED, response=response)
+    def auth_required(self, func):
+        @wraps(func)
+        def wrapper(request, *args, **kwargs):
+            if request.user_id:
+                return func(request, *args, **kwargs)
+            else:
+                headers = {}
+                if request.headers.get('X-Requested-With') != 'XMLHttpRequest':
+                    headers['WWW-Authenticate'] = 'Basic realm="Tryton"'
+                response = Response(None, http.client.UNAUTHORIZED, headers)
+                abort(http.client.UNAUTHORIZED, response=response)
+        return wrapper
 
     def check_request_size(self, request, size=None):
         if request.method not in {'POST', 'PUT', 'PATCH'}:



View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/a22c4cd5d9b2fc2f495aad8b05b265184f232b7b

-- 
View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/a22c4cd5d9b2fc2f495aad8b05b265184f232b7b
You're receiving this email because of your account on foss.heptapod.net.


Reply via email to