Commit 9d6c0b16 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

add unrestricted_contextmanager.

parent 2155dbf5
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
# #
############################################################################## ##############################################################################
from contextlib import contextmanager
from AccessControl.User import UnrestrictedUser from AccessControl.User import UnrestrictedUser
from AccessControl.SpecialUsers import system from AccessControl.SpecialUsers import system
from AccessControl.SecurityManagement import getSecurityManager, \ from AccessControl.SecurityManagement import getSecurityManager, \
...@@ -69,6 +70,17 @@ def UnrestrictedMethod(function): ...@@ -69,6 +70,17 @@ def UnrestrictedMethod(function):
def unrestricted_apply(function, args=(), kw={}): # XXX-JPS: naming def unrestricted_apply(function, args=(), kw={}): # XXX-JPS: naming
"""Function to bypass all security checks """Function to bypass all security checks
This function is as dangerous as 'UnrestrictedMethod' decorator. Read its
docstring for more information. Never use this, until you are 100% certain
that you have no other way.
"""
with unrestricted_contextmanager():
return apply(function, args, kw)
@contextmanager
def unrestricted_contextmanager():
"""Function to bypass all security checks
This function is as dangerous as 'UnrestrictedMethod' decorator. Read its This function is as dangerous as 'UnrestrictedMethod' decorator. Read its
docstring for more information. Never use this, until you are 100% certain docstring for more information. Never use this, until you are 100% certain
that you have no other way. that you have no other way.
...@@ -99,7 +111,7 @@ def unrestricted_apply(function, args=(), kw={}): # XXX-JPS: naming ...@@ -99,7 +111,7 @@ def unrestricted_apply(function, args=(), kw={}): # XXX-JPS: naming
role_list, user.getDomains()).__of__(uf) role_list, user.getDomains()).__of__(uf)
newSecurityManager(None, super_user) newSecurityManager(None, super_user)
try: try:
return apply(function, args, kw) yield
finally: finally:
# Make sure that the original user is back. # Make sure that the original user is back.
setSecurityManager(security_manager) setSecurityManager(security_manager)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment