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
| @@ -555,10 +555,12 @@ DOM = DOM() | |||||
| class Collection(UserDict): | class Collection(UserDict): | ||||
| """Helper class for maintaining ordered named collections.""" | """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) | UserDict.__init__(self) | ||||
| self.parent = weakref.ref(parent) | self.parent = weakref.ref(parent) | ||||
| self.list = [] | self.list = [] | ||||
| self._func = key | |||||
| def __getitem__(self, key): | def __getitem__(self, key): | ||||
| if type(key) is type(1): | if type(key) is type(1): | ||||
| @@ -571,10 +573,10 @@ class Collection(UserDict): | |||||
| self.data[key] = item | self.data[key] = item | ||||
| def keys(self): | def keys(self): | ||||
| return map(lambda i: i.name, self.list) | |||||
| return map(lambda i: self._func(i), self.list) | |||||
| def items(self): | 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): | def values(self): | ||||
| return self.list | return self.list | ||||
| @@ -718,14 +718,15 @@ class XMLSchema(XMLSchemaComponent): | |||||
| """ | """ | ||||
| self.targetNamespace = None | self.targetNamespace = None | ||||
| XMLSchemaComponent.__init__(self, parent) | 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._imported_schemas = {} | ||||
| self._included_schemas = {} | self._included_schemas = {} | ||||