[Zope-Checkins] CVS: Zope3/lib/python/Zope/Security - Checker.py:1.1.2.8 Proxy.py:1.1.2.15 RestrictedInterpreter.py:1.1.2.4

Jim Fulton jim@zope.com
Tue, 23 Apr 2002 11:06:47 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Security
In directory cvs.zope.org:/tmp/cvs-serv4165/lib/python/Zope/Security

Modified Files:
      Tag: SecurityProxy-branch
	Checker.py Proxy.py RestrictedInterpreter.py 
Log Message:
Refactored Zope.Security.Proxy names.

Zope.Security.Proxy.Proxy is the Proxy type.

Zope.Security.Proxy.ProxyFactory is the factory that selects a checker
and creates a proxy for an object. 

This thing introduces an odd dependency on the Checker module. Maybe
the ProxyFactory should only be in the Checker module.

Zope.Security.Proxy.getObject is a function that gets the object
proxied by a proxy.

Zope.Security.Proxy.getChecker is a function that gets the checker
used by a proxy.



=== Zope3/lib/python/Zope/Security/Checker.py 1.1.2.7 => 1.1.2.8 ===
 from Zope.Exceptions import Unauthorized, Forbidden, DuplicationError
 from Interface.IInterface import IInterface
-from _Proxy import _Proxy
+from _Proxy import _Proxy as Proxy
 from types import InstanceType, ClassType, FunctionType, MethodType, ModuleType
 from ISecurityProxyFactory import ISecurityProxyFactory
 # XXX SecurityManagement needs to move out of App
@@ -10,7 +10,7 @@
 # Marker for public attributes
 CheckerPublic = object()
 
-def Proxy(object, checker=None):
+def ProxyFactory(object, checker=None):
     """Factory function that creats a proxy for an object
 
     The proxy checker is looked up if not provided.
@@ -23,13 +23,13 @@
 
     else:
         # Maybe someone passed us a proxy and a checker
-        if type(object) is _Proxy:
+        if type(object) is Proxy:
             # XXX should we keep the existing proxy or create a new one.
             return object
 
-    return _Proxy(object, checker)
+    return Proxy(object, checker)
 
-Proxy.__implements__ = ISecurityProxyFactory
+ProxyFactory.__implements__ = ISecurityProxyFactory
 
 class Checker:
 
@@ -88,7 +88,11 @@
     def proxy(self, value):
         'See Zope.Security.IChecker.IChecker'
         # Now we need to create a proxy
-        return Proxy(value)
+        checker = selectChecker(value)
+        if checker is None:
+            return value
+
+        return Proxy(value, checker)
 
     #
     ############################################################
@@ -243,7 +247,7 @@
     str: NoProxy,
     unicode: NoProxy,
     InstanceType: _instanceChecker,
-    _Proxy: NoProxy,
+    Proxy: NoProxy,
     ClassType: _classChecker,
     FunctionType: _callableChecker,
     MethodType: _callableChecker,


=== Zope3/lib/python/Zope/Security/Proxy.py 1.1.2.14 => 1.1.2.15 ===
 """
 
-from Checker import Proxy
+from _Proxy import getObject, getChecker
+from _Proxy import _Proxy as Proxy
+from Checker import ProxyFactory
 


=== Zope3/lib/python/Zope/Security/RestrictedInterpreter.py 1.1.2.3 => 1.1.2.4 ===
 
-from Zope.Security.Proxy import Proxy
+from Zope.Security.Proxy import ProxyFactory
 
 class RestrictedInterpreter:
 
@@ -29,8 +29,8 @@
         import __builtin__
         for k, v in __builtin__.__dict__.iteritems():
             if k not in self.nok_builtin_names:
-                self.builtins[k] = Proxy(v, self.checker)
-        self.builtins['__import__'] = Proxy(self.ri_import)
+                self.builtins[k] = ProxyFactory(v, self.checker)
+        self.builtins['__import__'] = ProxyFactory(self.ri_import)
 
     def ri_import(self, name, globals, locals, fromlist):
         # XXX handle fromlist