Author: jmorliaguet Date: Sun Jun 18 11:33:43 2006 New Revision: 3448 Modified: cpsskins/branches/paris-sprint-2006/locations/README.txt cpsskins/branches/paris-sprint-2006/locations/__init__.py cpsskins/branches/paris-sprint-2006/locations/interfaces.py cpsskins/branches/paris-sprint-2006/locations/location.py
Log: - API / doc test updates Modified: cpsskins/branches/paris-sprint-2006/locations/README.txt ============================================================================== --- cpsskins/branches/paris-sprint-2006/locations/README.txt (original) +++ cpsskins/branches/paris-sprint-2006/locations/README.txt Sun Jun 18 11:33:43 2006 @@ -118,3 +118,48 @@ its scope covers the location context. The rule's data can then be associated to the location context. +Implementation +-------------- + +We create 2 locations: + + >>> from cpsskins.locations import Location + + >>> l1 = Location(name=u'folder 1', path=(u'f1',), data=u'd1') + >>> l1 + <Location at: /f1 ('folder 1')> + + >>> l2 = Location(name=u'folder 1/2', path=(u'f1', 'f2'), data=u'd1/2') + >>> l2 + <Location at: /f1/f2 ('folder 1/2')> + +to get the location's data, we call the location: + + >>> l1() + u'd1' + + >>> l2() + u'd1/2' + +the two locations can be compared: + + >>> l1 == l2 + False + + >>> l1 > l2 + True + + >>> l2 < l1 + True + +if two locations have a same path, they are equal: + + >>> lA = Location(name=u'A', path=(u'f1', u'f2'), data=u'A') + >>> lB = Location(name=u'B', path=(u'f1', u'f2'), data=u'B') + + >>> lA == lB + True + + + + Modified: cpsskins/branches/paris-sprint-2006/locations/__init__.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/locations/__init__.py (original) +++ cpsskins/branches/paris-sprint-2006/locations/__init__.py Sun Jun 18 11:33:43 2006 @@ -17,3 +17,7 @@ """ __docformat__ = "reStructuredText" +from zope.deferredimport import defineFrom + +defineFrom('cpsskins.locations.location', 'Location') + Modified: cpsskins/branches/paris-sprint-2006/locations/interfaces.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/locations/interfaces.py (original) +++ cpsskins/branches/paris-sprint-2006/locations/interfaces.py Sun Jun 18 11:33:43 2006 @@ -35,3 +35,7 @@ title=u"Data", ) + scope = Tuple( + title=u"Scope", + ) + Modified: cpsskins/branches/paris-sprint-2006/locations/location.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/locations/location.py (original) +++ cpsskins/branches/paris-sprint-2006/locations/location.py Sun Jun 18 11:33:43 2006 @@ -24,28 +24,42 @@ from cpsskins.locations.interfaces import ILocation class Location(object): - """A location""" + """A location + """ implements(ILocation) - def __init__(self, name=u'', path=(), data=u''): + def __init__(self, name=u'', path=(), data=u'', scope=()): self.name = name self.path = path self.data = data + self.scope = scope def __repr__(self): - return "<Location %s>" % str(self) + return "<Location at: /%s ('%s')>" % (str(self), self.name) + + def __call__(self): + return self.data def __str__(self): return u'/'.join(self.path) def __gt__(self, other): - raise NotImplementedError + path = self.path + other_path = other.path + if len(path) >= len(other_path): + return False + i = 0 + for p in path: + if other_path[i] != p: + return False + i += 1 + return True def __lt__(self, other): - raise NotImplementedError + return other > self def __eq__(self, other): - raise NotImplementedError + return self.path == other.path LocationFactory = Factory(Location) -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins