Back to index

plone3  3.1.7
general.py
Go to the documentation of this file.
00001 from interfaces import ITestObject
00002 from zope.interface import alsoProvides as mark
00003 
00004 def dummy(kdict, name='dummy', iface=ITestObject, bases=(object,)):
00005     """ factory for dummies """
00006     obj = type(name, bases, kdict)()
00007     mark(obj, iface)
00008     return obj 
00009 
00010 def getToolByName(context, tool_name):
00011     """
00012     acquisition faker
00013     """
00014     return getattr(context, tool_name)
00015 
00016 portal_path = "/path_to/portal"
00017 
00018 class portal_url(object):
00019     def __init__(self, portal_path=portal_path):
00020         self.portal_path=portal_path
00021         
00022     def getPortalPath(self):
00023         return self.portal_path
00024 
00025 _marker = object()
00026 class pdo(dict):
00027     """
00028     pseudo data object....masquerades as a brain
00029     """
00030 
00031     def __init__(self, **kwargs):
00032         self.update(kwargs)
00033 
00034     def __getattr__(self, key):
00035         ret = self.get(key, _marker)
00036         if not ret is _marker:
00037             return ret
00038         raise AttributeError
00039 
00040     def getPath(self):
00041         return portal_path + "/%s" %self.getId
00042     
00043     def getObject(self):
00044         self.UID = lambda : self.UID
00045         return self