Commit 9ef37bd4 authored by Fred Drake's avatar Fred Drake

Factory:

- remove methods that aren't needed
- rename "resolved" to "instance" for readability
parent 097a940b
############################################################################## ##############################################################################
# #
# Copyright (c) 2002, 2003 Zope Corporation and Contributors. # Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # This software is subject to the provisions of the Zope Public License,
...@@ -41,27 +41,18 @@ class Factory: ...@@ -41,27 +41,18 @@ class Factory:
def __init__(self, class_path, callback, *args, **kw): def __init__(self, class_path, callback, *args, **kw):
self.class_path = class_path self.class_path = class_path
self.callback = callback self.callback = callback
self.setArgs(list(args), kw) self.args = args
self.resolved = _marker self.kw = kw
self.instance = _marker
def __repr__(self): def __repr__(self):
return ('<Factory instance for class "%s" with positional args "%s" ' return ('<Factory instance for class "%s" with positional args "%s" '
'and keword args "%s"' % (self.class_path, self.args, self.kw)) 'and keword args "%s"' % (self.class_path, self.args, self.kw))
__str__ = __repr__
def __call__(self): def __call__(self):
if self.resolved is _marker: if self.instance is _marker:
package = importer(self.class_path) constructor = importer(self.class_path)
inst = package(*self.args, **self.kw) self.instance = constructor(*self.args, **self.kw)
if self.callback: if self.callback is not None:
self.callback(inst) self.callback(self.instance)
self.resolved = inst return self.instance
return self.resolved
def setArgs(self, args, kw):
self.args = args
self.kw = kw
def getArgs(self):
return (self.args, self.kw)
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