[Commits] (grant) Fix Bug 1013 (Nested XML syntax alternative) r=lisa

commits at osafoundation.org commits at osafoundation.org
Thu Feb 24 14:00:48 PST 2005


Commit by: grant
Modified files:
chandler/Chandler-project.wpr 1.37 1.38
chandler/application/Parcel.py 1.49 1.50
chandler/application/tests/TestAnonymous.py None 1.1
chandler/application/tests/__init__.py 1.4 1.5
chandler/application/tests/testparcels/anonymous/parcel.xml None 1.1

Log message:
Fix Bug 1013 (Nested XML syntax alternative) r=lisa

- In Parcel.py, allow the creation of Items from XML elements without
  having the "itsName" attribute set:

  1. Instead of relying on itsName, to know when to create an Item, the
     parcel loader checks to see if a given XML element & namespace point
     to a Kind.

  2. If you leave off itsName from a top-level Parcel element, you get
     the name implied by their place in the repository. As before, it's
     an error if you mis-specify a Parcel's itsName.

  3. If you leave off itsName from any other Item, it gets added to the
     repository with a name of None. This means the repository auto-generates
     a name from the Item's UUID.

- Added a couple of unit tests.


ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/Chandler-project.wpr.diff?r1=text&tr1=1.37&r2=text&tr2=1.38
http://cvs.osafoundation.org/index.cgi/chandler/application/Parcel.py.diff?r1=text&tr1=1.49&r2=text&tr2=1.50
http://cvs.osafoundation.org/index.cgi/chandler/application/tests/TestAnonymous.py?rev=1.1&content-type=text/vnd.viewcvs-markup
http://cvs.osafoundation.org/index.cgi/chandler/application/tests/__init__.py.diff?r1=text&tr1=1.4&r2=text&tr2=1.5
http://cvs.osafoundation.org/index.cgi/chandler/application/tests/testparcels/anonymous/parcel.xml?rev=1.1&content-type=text/vnd.viewcvs-markup

Index: chandler/Chandler-project.wpr
diff -u chandler/Chandler-project.wpr:1.37 chandler/Chandler-project.wpr:1.38
--- chandler/Chandler-project.wpr:1.37	Tue Feb 22 20:21:20 2005
+++ chandler/Chandler-project.wpr	Thu Feb 24 14:00:45 2005
@@ -23,6 +23,7 @@
                   loc('application/preferencesMetadata.xml'),
                   loc('application/tests/ParcelLoaderTestCase.py'),
                   loc('application/tests/TestAllParcels.py'),
+                  loc('application/tests/TestAnonymous.py'),
                   loc('application/tests/TestAttributes.py'),
                   loc('application/tests/TestBogusItsName.py'),
                   loc('application/tests/TestCircular.py'),
@@ -43,6 +44,7 @@
                   loc('application/tests/dependencyparcels/depB/parcel.xml'),
                   loc('application/tests/itemparcels/items/parcel.xml'),
                   loc('application/tests/itemparcels/super/parcel.xml'),
+                  loc('application/tests/testparcels/anonymous/parcel.xml'),
                   loc('application/tests/testparcels/attributes/parcel.xml'),
                   loc('application/tests/testparcels/circular/calendar/parcel.xml'),
                   loc('application/tests/testparcels/circular/contact/parcel.xml'),

Index: chandler/application/Parcel.py
diff -u chandler/application/Parcel.py:1.49 chandler/application/Parcel.py:1.50
--- chandler/application/Parcel.py:1.49	Tue Feb 22 20:21:19 2005
+++ chandler/application/Parcel.py	Thu Feb 24 14:00:46 2005
@@ -901,6 +901,9 @@
         currentItem = None
         currentValue = None
 
+        # Find the kind represented by the tag (uri, local). The
+        # parser has already mapped the prefix to the namespace (uri).
+        kind = self.findItem(uri, local, self.locator.getLineNumber())
         nameString = None
         if attrs.has_key((None, 'itemName')):
             print "Deprecation warning: 'itemName' should be 'itsName' at", \
@@ -909,8 +912,8 @@
         elif attrs.has_key((None, 'itsName')):
             nameString = attrs.getValue((None, 'itsName'))
             
-        if nameString:
-            # If it has an item name, it's an item
+        
+        if kind and kind.itsKind.itsUUID == self.manager.kindUUID:
             element = 'Item'
 
             if attrs.has_key((None, 'itemClass')):
@@ -918,25 +921,23 @@
             else:
                 classString = None
 
-            # Find the kind represented by the tag (uri, local). The
-            # parser has already mapped the prefix to the namespace (uri).
-            kind = self.findItem(uri, local, self.locator.getLineNumber())
-            if kind is None:
-                explanation = "Kind doesn't exist: %s:%s" % (uri, local)
-                self.saveExplanation(explanation)
-                raise ParcelException(explanation)
-
             # If we have the document root, use the parcel parent.
             # Otherwise, the currentItem is the parent.
             parent = self.__getCurrentItem()
             if parent is None:
                 parent = self.parcelParent
+                lastComponent = self.repoPath.split('/')[-1]
+
+                # A top-level anonymous Parcel item has an implicit
+                # itsName of lastComponent here.
+                if nameString is None:
+                    nameString = lastComponent
                 # <http://bugzilla.osafoundation.org/show_bug.cgi?id=2495>
                 # Make sure that the top-level parcel's itsName
                 # actually matches where it's going in the repository.
                 # Otherwise, it's possible to run into an infinite
                 # recursion here.
-                if self.repoPath.split('/')[-1] != nameString:
+                elif nameString != lastComponent:
                     explanation = "Parcel's itsName '%s' doesn't match last component of repository path '%s'" % \
                                 (nameString, self.repoPath)
                     self.saveExplanation(explanation)
@@ -961,6 +962,19 @@
                                                   nameString, classString)
                     self.itemsCreated.append(currentItem)
 
+        elif nameString:
+            
+            # We have an itsName, but for some reason we can't figure out
+            # the Kind of this item. Either it doesn't exist...
+            if kind is None:
+                explanation = "Kind doesn't exist: %s:%s" % (uri, local)
+            # ... or it isn't a Kind at all.
+            else:
+                explanation = "Expected a kind: %s:%s" % (uri, local)
+                
+            self.saveExplanation(explanation)
+            raise ParcelException(explanation)
+
         elif len(self.elementStack) > 0 and \
              self.elementStack[-1].elementType == 'Ignore':
             # If we're ignoring the current item, ignore its attributes, etc
@@ -1223,7 +1237,13 @@
 
         value = rawValue
         
-        if type(value) in (unicode, str):
+        # If we have a Kind, we should create a new Item that's
+        # an anonymous child of item.
+        if valueType.itsKind.itsUUID == self.manager.kindUUID:
+            
+            value = valueType.newItem(None, item)
+        
+        elif type(value) in (unicode, str):
             try:
                 value = valueType.makeValue(value)
             except Exception, e:

Index: chandler/application/tests/__init__.py
diff -u chandler/application/tests/__init__.py:1.4 chandler/application/tests/__init__.py:1.5
--- chandler/application/tests/__init__.py:1.4	Tue Feb 22 20:21:20 2005
+++ chandler/application/tests/__init__.py	Thu Feb 24 14:00:46 2005
@@ -8,8 +8,8 @@
 __all__ = [
     'TestAllParcels', 'TestAttributes', 'TestCircular', 'TestClasses', 
     'TestClouds', 'TestCollections', 'TestCopying', 'TestDependency',
-    'TestItems', 'TestKindAndItem', 'TestLocalAttrs', 'TestParcelErrors',
-    'TestParcelLoader','TestUuidOf', 'TestParcelPerf'
+    'TestItems', 'TestKindAndItem', 'TestLocalAttrs', 'TestParcelLoader',
+    'TestUuidOf', 'TestParcelPerf'
 ]
 
 def suite():



More information about the Commits mailing list