Browse Source

----------------------------------------------------------------------

Modified Files:
 	Utility.py -- Added a parameter to Collection class constructor,
		'name' is the default attribute used for keys but one
                 can specify whatever key they want.

        XMLSchema.py -- Used the above parameter to make Collection
		instances use the appropriate 'attribute' as key.

 ----------------------------------------------------------------------
main
Joshua Boverhof 21 years ago
parent
commit
68e882aa70
2 changed files with 14 additions and 11 deletions
  1. +5
    -3
      Utility.py
  2. +9
    -8
      XMLSchema.py

+ 5
- 3
Utility.py View File

@@ -555,10 +555,12 @@ DOM = DOM()

class Collection(UserDict):
"""Helper class for maintaining ordered named collections."""
def __init__(self, parent):
default = lambda k: k.name
def __init__(self, parent, key=Collection.default):
UserDict.__init__(self)
self.parent = weakref.ref(parent)
self.list = []
self._func = key

def __getitem__(self, key):
if type(key) is type(1):
@@ -571,10 +573,10 @@ class Collection(UserDict):
self.data[key] = item

def keys(self):
return map(lambda i: i.name, self.list)
return map(lambda i: self._func(i), self.list)

def items(self):
return map(lambda i: (i.name, i), self.list)
return map(lambda i: (self._func(i), i), self.list)

def values(self):
return self.list


+ 9
- 8
XMLSchema.py View File

@@ -718,14 +718,15 @@ class XMLSchema(XMLSchemaComponent):
"""
self.targetNamespace = None
XMLSchemaComponent.__init__(self, parent)
self.includes = Collection(self)
self.imports = Collection(self)
self.elements = Collection(self)
self.types = Collection(self)
self.attr_decl = Collection(self)
self.attr_groups = Collection(self)
self.model_groups = Collection(self)
self.notations = Collection(self)
f = lambda k: k.attributes['name']
self.includes = Collection(self, key=f)
self.imports = Collection(self, key=f)
self.elements = Collection(self, key=f)
self.types = Collection(self, key=f)
self.attr_decl = Collection(self, key=f)
self.attr_groups = Collection(self, key=f)
self.model_groups = Collection(self, key=f)
self.notations = Collection(self, key=f)

self._imported_schemas = {}
self._included_schemas = {}


Loading…
Cancel
Save