Add 'registry' argument to update new request registry
authorThierry Florac <tflorac@ulthar.net>
Sun, 18 Feb 2018 12:55:04 +0100
changeset 137 a96fc19c0109
parent 136 e5a7e65ba12a
child 138 e7db8173ee0d
Add 'registry' argument to update new request registry
src/pyams_utils/request.py
--- a/src/pyams_utils/request.py	Sat Feb 17 15:53:31 2018 +0100
+++ b/src/pyams_utils/request.py	Sun Feb 18 12:55:04 2018 +0100
@@ -9,6 +9,7 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
+from pyams_utils.registry import get_global_registry
 
 __docformat__ = 'restructuredtext'
 
@@ -113,13 +114,17 @@
         return None
 
 
-def check_request(path='/', environ=None, base_url=None, headers=None, POST=None, **kw):
+def check_request(path='/', environ=None, base_url=None, headers=None, POST=None, registry=None, **kwargs):
     """Get current request, or create a new blank one if missing"""
     try:
         return get_request()
     except MissingRequestError:
-        request = Request.blank(path, environ, base_url, headers, POST, **kw)
-        request.registry = get_current_registry()
+        request = Request.blank(path, environ, base_url, headers, POST, **kwargs)
+        if registry is None:
+            registry = get_current_registry()
+            if registry is None:
+                registry = get_global_registry()
+        request.registry = registry
         return request