[Checkins] SVN: z3c.pt/trunk/ Wrap 'sys.modules' dictionary in an 'opaque' dictionary class, such that the representation string does not list all loaded modules.
Malthe Borch
mborch at gmail.com
Mon May 11 02:54:43 EDT 2009
Log message for revision 99833:
Wrap 'sys.modules' dictionary in an 'opaque' dictionary class, such that the representation string does not list all loaded modules.
Changed:
U z3c.pt/trunk/CHANGES.txt
U z3c.pt/trunk/src/z3c/pt/pagetemplate.py
-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt 2009-05-11 06:51:33 UTC (rev 99832)
+++ z3c.pt/trunk/CHANGES.txt 2009-05-11 06:54:42 UTC (rev 99833)
@@ -1,6 +1,10 @@
Changelog
---------
+- Wrap ``sys.modules`` dictionary in an "opaque" dictionary class,
+ such that the representation string does not list all loaded
+ modules. [malthe]
+
1.0b15 (2009/04/24)
~~~~~~~~~~~~~~~~~~~
Modified: z3c.pt/trunk/src/z3c/pt/pagetemplate.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/pagetemplate.py 2009-05-11 06:51:33 UTC (rev 99832)
+++ z3c.pt/trunk/src/z3c/pt/pagetemplate.py 2009-05-11 06:54:42 UTC (rev 99833)
@@ -20,6 +20,18 @@
_marker = object()
_expr_cache = {}
+class opaque_dict(dict):
+ def __new__(cls, dictionary):
+ inst = dict.__new__(cls)
+ inst.__getitem__ = dictionary.__getitem__
+ inst.__len__ = dictionary.__len__
+ return inst
+
+ def __repr__(self):
+ return "{...} (%d entries)" % len(self)
+
+sys_modules = opaque_dict(sys.modules)
+
def evaluate_expression(pragma, expr):
key = "%s(%s)" % (pragma, expr)
try:
@@ -118,7 +130,7 @@
path=evaluate_path,
exists=evaluate_exists,
nothing=None,
- modules=sys.modules)
+ modules=sys_modules)
class BaseTemplateFile(BaseTemplate, template.PageTemplateFile):
"""If ``filename`` is a relative path, the module path of the
@@ -200,7 +212,7 @@
exists=evaluate_exists,
options=kwargs,
nothing=None,
- modules=sys.modules)
+ modules=sys_modules)
def __call__(self, _ob=None, context=None, request=None, **kwargs):
kwargs.setdefault('context', context)
More information about the Checkins
mailing list