diff --git a/Utility.py b/Utility.py index bad8210..ac409b6 100755 --- a/Utility.py +++ b/Utility.py @@ -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 diff --git a/XMLSchema.py b/XMLSchema.py index 7777bec..712efa1 100755 --- a/XMLSchema.py +++ b/XMLSchema.py @@ -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 = {}