Author: jmorliaguet
Date: Wed Jun 21 00:23:11 2006
New Revision: 3479

Modified:
   cpsskins/branches/paris-sprint-2006/locations/README.txt
   cpsskins/branches/paris-sprint-2006/locations/location.py
   cpsskins/branches/paris-sprint-2006/storage/locations.py

Log:

- paths are written as '/...' and stored as tuples internally



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    Wed Jun 21 
00:23:11 2006
@@ -125,13 +125,13 @@
 
     >>> from cpsskins.locations import Location
 
-    >>> l1 = Location(title=u'folder 1', path=(u'f1',), data=u'd1')
+    >>> l1 = Location(title=u'folder 1', path=u'/f1', data=u'd1')
     >>> l1
-    <Location 'folder 1' at f1>
+    <Location 'folder 1' at /f1>
 
-    >>> l2 = Location(title=u'folder 1/2', path=(u'f1', 'f2'), data=u'd1/2')
+    >>> l2 = Location(title=u'folder 1/2', path=u'/f1/f2', data=u'd1/2')
     >>> l2
-    <Location 'folder 1/2' at f1/f2>
+    <Location 'folder 1/2' at /f1/f2>
 
 to get the location's data, we call the location:
 
@@ -154,8 +154,8 @@
 
 if two locations have a same path, they are equal:
 
-    >>> lA = Location(title=u'A', path=(u'f1', u'f2'), data=u'A')
-    >>> lB = Location(title=u'B', path=(u'f1', u'f2'), data=u'B')
+    >>> lA = Location(title=u'A', path=u'/f1/f2', data=u'A')
+    >>> lB = Location(title=u'B', path=u'/f1/f2', data=u'B')
 
     >>> lA == lB
     True
@@ -172,31 +172,31 @@
 
     >>> from pprint import pprint
     >>> pprint(dict(locations))
-    {(u'', u'f1'): <Location 'folder 1' at f1>,
-     (u'', u'f1', 'f2'): <Location 'folder 1/2' at f1/f2>}
+    {(u'', u'', u'f1'): <Location 'folder 1' at /f1>,
+     (u'', u'', u'f1', u'f2'): <Location 'folder 1/2' at /f1/f2>}
 
 we can obtain the list of locations with:
 
     >>> locations.getPaths()
-    [(u'f1', 'f2'), (u'f1',)]
+    [(u'', u'f1'), (u'', u'f1', u'f2')]
 
 
-now we want to find the location of 'f1/f2/f3':
+now we want to find the location of '/f1/f2/f3':
 
-    >>> locations.find(u'f1/f2/f3')
-    <Location 'folder 1/2' at f1/f2>
+    >>> locations.find(u'/f1/f2/f3')
+    <Location 'folder 1/2' at /f1/f2>
 
-or get the location of 'f1/f2'
+or get the location of '/f1/f2'
 
-    >>> locations.find(u'f1/f2')
-    <Location 'folder 1/2' at f1/f2>
+    >>> locations.find(u'/f1/f2')
+    <Location 'folder 1/2' at /f1/f2>
 
-or 'f1':
+or '/f1':
 
-    >>> locations.find(u'f1')
-    <Location 'folder 1' at f1>
+    >>> locations.find(u'/f1')
+    <Location 'folder 1' at /f1>
 
-    >>> locations.find(u'f2') is None
+    >>> locations.find(u'/f2') is None
     True
 
 scopes
@@ -210,110 +210,110 @@
 By specifying a scope we can restrict the paths covered by a location, for
 instance:
 
-    >>> l3 = Location(title=u'C', path=(u'f1', u'f3'), data=u'C', scope=(0, 1))
+    >>> l3 = Location(title=u'C', path=u'/f1/f3', data=u'C', scope=(0, 1))
     >>> locations.add(l3)
 
     >>> l3
-    <Location 'C' at f1/f3>
+    <Location 'C' at /f1/f3>
 
-means that the 'l3' location has a scope covering f1/f3 and all immediate
-sublocation paths (f1/f3/...) but not (f1/f3/.../...)
+means that the 'l3' location has a scope covering /f1/f3 and all immediate
+sublocation paths (/f1/f3/...) but not (/f1/f3/.../...)
 
 
-    >>> locations.find(u'f1/f3')
-    <Location 'C' at f1/f3>
+    >>> locations.find(u'/f1/f3')
+    <Location 'C' at /f1/f3>
 
-    >>> locations.find(u'f1/f3/f4')
-    <Location 'C' at f1/f3>
+    >>> locations.find(u'/f1/f3/f4')
+    <Location 'C' at /f1/f3>
 
-    >>> locations.find(u'f1/f3/f4/f5')
-    <Location 'folder 1' at f1>
+    >>> locations.find(u'/f1/f3/f4/f5')
+    <Location 'folder 1' at /f1>
 
-l4 has a scope covering 'f1/f4' and sublocations of level 1 and 2:
+l4 has a scope covering '/f1/f4' and sublocations of level 1 and 2:
 
-    >>> l4 = Location(title=u'D', path=(u'f1', u'f4'), data=u'D', scope=(0, 2))
+    >>> l4 = Location(title=u'D', path=u'/f1/f4', data=u'D', scope=(0, 2))
     >>> locations.add(l4)
 
-    >>> locations.find(u'f1/f4')
-    <Location 'D' at f1/f4>
+    >>> locations.find(u'/f1/f4')
+    <Location 'D' at /f1/f4>
 
-    >>> locations.find(u'f1/f4/f5')
-    <Location 'D' at f1/f4>
+    >>> locations.find(u'/f1/f4/f5')
+    <Location 'D' at /f1/f4>
 
-    >>> locations.find(u'f1/f4/f5/f6')
-    <Location 'D' at f1/f4>
+    >>> locations.find(u'/f1/f4/f5/f6')
+    <Location 'D' at /f1/f4>
 
-    >>> locations.find(u'f1/f4/f5/f6/f7')
-    <Location 'folder 1' at f1>
+    >>> locations.find(u'/f1/f4/f5/f6/f7')
+    <Location 'folder 1' at /f1>
 
-    >>> locations.find(u'f1/f4/f5/f6/f7/f8')
-    <Location 'folder 1' at f1>
+    >>> locations.find(u'/f1/f4/f5/f6/f7/f8')
+    <Location 'folder 1' at /f1>
 
-l5 has a scope covering the 'f1/f5' location's immediate sublocations only:
+l5 has a scope covering the '/f1/f5' location's immediate sublocations only:
 
-    >>> l5 = Location(title=u'E', path=(u'f1', u'f5'), data=u'E', scope=(1, 1))
+    >>> l5 = Location(title=u'E', path=u'/f1/f5', data=u'E', scope=(1, 1))
     >>> locations.add(l5)
 
-    >>> locations.find(u'f1/f5')
-    <Location 'folder 1' at f1>
+    >>> locations.find(u'/f1/f5')
+    <Location 'folder 1' at /f1>
 
-    >>> locations.find(u'f1/f5/f6')
-    <Location 'E' at f1/f5>
+    >>> locations.find(u'/f1/f5/f6')
+    <Location 'E' at /f1/f5>
 
-l6 has a scope covering the 'f1/f6' location's sublocations of level 2 or
+l6 has a scope covering the '/f1/f6' location's sublocations of level 2 or
 more:
 
-    >>> l6 = Location(title=u'F', path=(u'f1', u'f6'), data=u'F', scope=(2, 0))
+    >>> l6 = Location(title=u'F', path=u'/f1/f6', data=u'F', scope=(2, 0))
     >>> locations.add(l6)
 
-    >>> locations.find(u'f1/f6')
-    <Location 'folder 1' at f1>
+    >>> locations.find(u'/f1/f6')
+    <Location 'folder 1' at /f1>
 
-    >>> locations.find(u'f1/f6/f7')
-    <Location 'folder 1' at f1>
+    >>> locations.find(u'/f1/f6/f7')
+    <Location 'folder 1' at /f1>
 
-    >>> locations.find(u'f1/f6/f7/f8')
-    <Location 'F' at f1/f6>
+    >>> locations.find(u'/f1/f6/f7/f8')
+    <Location 'F' at /f1/f6>
 
-    >>> locations.find(u'f1/f6/f7/f8/f9')
-    <Location 'F' at f1/f6>
+    >>> locations.find(u'/f1/f6/f7/f8/f9')
+    <Location 'F' at /f1/f6>
 
-    >>> locations.find(u'f1/f6/f7/f8/f9/f10')
-    <Location 'F' at f1/f6>
+    >>> locations.find(u'/f1/f6/f7/f8/f9/f10')
+    <Location 'F' at /f1/f6>
 
 namespaces
 ..........
 
 Namespaces can be created by specifying a location root:
 
-    >>> l7 = Location(title=u'G', path=(u'f1',), data=u'G', root=u'pages')
+    >>> l7 = Location(title=u'G', path=u'/f1', data=u'G', root=u'pages')
     >>> locations.add(l7)
 
-    >>> locations.find(u'f1', root=u'pages')
-    <Location 'G' at f1 for 'pages'>
+    >>> locations.find(u'/f1', root=u'pages')
+    <Location 'G' at /f1 for 'pages'>
 
-    >>> l8 = Location(title=u'H', path=(u'f1',), data=u'H', root=u'engines')
+    >>> l8 = Location(title=u'H', path=u'/f1', data=u'H', root=u'engines')
     >>> locations.add(l8)
 
-    >>> locations.find(u'f1', root=u'engines')
-    <Location 'H' at f1 for 'engines'>
+    >>> locations.find(u'/f1', root=u'engines')
+    <Location 'H' at /f1 for 'engines'>
 
 we get the list of location paths with:
 
     >>> locations.getPaths(u'pages')
-    [(u'f1',)]
+    [(u'', u'f1')]
 
 or with:
 
     >>> locations.getPaths(u'engines')
-    [(u'f1',)]
+    [(u'', u'f1')]
 
 
 to obtain all the paths we use:
 
     >>> locations.getAllPaths() # doctest: +NORMALIZE_WHITESPACE
-    [(u'f1', 'f2'), (u'f1', u'f3'), (u'f1',), (u'f1', u'f4'), (u'f1', u'f5'),
-    (u'f1', u'f6')]
+    [(u'', u'f1'), (u'', u'f1', u'f6'), (u'', u'f1', u'f2'),
+     (u'', u'f1', u'f3'), (u'', u'f1', u'f4'), (u'', u'f1', u'f5')]
 
 finally we remove the locations:
 

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   Wed Jun 21 
00:23:11 2006
@@ -28,15 +28,15 @@
     """
     implements(ILocation)
 
-    def __init__(self, title=u'', path=(), data=u'', scope=(0, 0), root=u''):
+    def __init__(self, title=u'', path=u'', data=u'', scope=(0, 0), root=u''):
         self.title = title
-        self.path = path
         self.data = data
         self.scope = scope
         self.root = root
+        self.path = path
 
     def __repr__(self):
-        path = str(self)
+        path = self.path
         if self.root:
             path = u"%s for '%s'" % (path, self.root)
         return "<Location '%s' at %s>" % (self.title, path)
@@ -45,11 +45,11 @@
         return self.data
 
     def __str__(self):
-        return u'/'.join(self.path)
+        return self.path
 
     def __gt__(self, other):
-        path = self.path
-        other_path = other.path
+        path = self._path_tuple
+        other_path = other._path_tuple
         if len(path) >= len(other_path):
             return False
         i = 0
@@ -63,7 +63,15 @@
         return other > self
 
     def __eq__(self, other):
-        return self.path == other.path
+        return self._path_tuple == other._path_tuple
+
+    def getPath(self):
+        return u'/'.join(self._path_tuple)
+
+    def setPath(self, path):
+        self._path_tuple = tuple(path.split(u'/'))
+
+    path = property(getPath, setPath)
 
 LocationFactory = Factory(Location)
 

Modified: cpsskins/branches/paris-sprint-2006/storage/locations.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/storage/locations.py    (original)
+++ cpsskins/branches/paris-sprint-2006/storage/locations.py    Wed Jun 21 
00:23:11 2006
@@ -49,7 +49,7 @@
     implements(ILocationStorage)
 
     def add(self, location, name=u''):
-        key = (location.root,) + location.path
+        key = (location.root,) + location._path_tuple
         if key in self:
             del self[key]
         self[key] = location
@@ -58,7 +58,7 @@
         if not isinstance(locations, (list, tuple)):
             locations = [locations]
         for location in locations:
-            key = (location.root,) + location.path
+            key = (location.root,) + location._path_tuple
             if key not in self:
                 continue
             del self[key]
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to