[Checkins] SVN: megrok.trails/trunk/src/megrok/trails/components.py Began adjusting Trails so that the constructor for an object can be
Brandon Rhodes
brandon at rhodesmill.org
Wed Aug 20 21:28:34 EDT 2008
Log message for revision 90045:
Began adjusting Trails so that the constructor for an object can be
different from its actual class.
Changed:
U megrok.trails/trunk/src/megrok/trails/components.py
-=-
Modified: megrok.trails/trunk/src/megrok/trails/components.py
===================================================================
--- megrok.trails/trunk/src/megrok/trails/components.py 2008-08-20 21:46:20 UTC (rev 90044)
+++ megrok.trails/trunk/src/megrok/trails/components.py 2008-08-21 01:28:33 UTC (rev 90045)
@@ -86,14 +86,20 @@
to result in URLs like '/account/brandon'.
"""
- def __init__(self, spec, cls):
+ def __init__(self, spec, constructor, cls=None):
"""Create a Trail to an object.
- Calls should look like: Trail('/account/:username', Account)
+ Calls should look like one of:
+ Trail('/account/:username', Account) # if Account(3) returns it
+ Trail('/account/:username', lookup_account, Account)
+
"""
self.spec = spec
self.parts = spec.strip('/').split('/')
+ if cls is None:
+ cls = constructor
+ self.constructor = constructor
self.cls = cls
tf = TrailAbsoluteURLFactory(self)
provideAdapter(tf, (cls, IHTTPRequest), IAbsoluteURL)
@@ -123,7 +129,7 @@
result[part[1:]] = name
elif part != name:
return None
- return self.cls(**result)
+ return self.constructor(**result)
def url(self, obj, request):
"""Return the URL of an object as defined by this Trail.
More information about the Checkins
mailing list