Skip to content
This repository has been archived by the owner on Oct 4, 2022. It is now read-only.
/ pyxb Public archive
forked from pabigot/pyxb

Commit

Permalink
structures: support recording class-unique name for component
Browse files Browse the repository at this point in the history
This allows us to identify the name that was used in a parent class when
it gets overridden in a restricting class.
  • Loading branch information
pabigot committed May 20, 2017
1 parent 92db87f commit c69fff3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions pyxb/binding/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,7 @@ def _SetNameWithAccessors (component, container, is_plural, binding_module, nsm,
assert component._scope() == container
assert component.nameInBinding() is None, 'Use %s but binding name %s for %s' % (use_map['use'], component.nameInBinding(), component.expandedName())
component.setNameInBinding(use_map['use'])
component.setUniqueNameInBinding(use_map['id'])
key_name = six.u('%s_%s_%s') % (six.text_type(nsm.namespace()), container.nameInBinding(), component.expandedName())
use_map['key'] = utility.PrepareIdentifier(key_name, class_unique, private=True)
use_map['qname'] = six.text_type(component.expandedName())
Expand Down
19 changes: 16 additions & 3 deletions pyxb/xmlschema/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def _clearNamespaceContext (self):
# represent them, so need a binding-level name.
__nameInBinding = None

# The public unique name by which this component is referenced within the
# binding class (as opposed to the binding module).
__uniqueNameInBinding = None

# The schema component that owns this. If C{None}, the component is owned
# directly by the schema.
__owner = None
Expand Down Expand Up @@ -241,6 +245,7 @@ def _resetClone_csc (self, **kw):
assert self.__cloneSource is not None
owner = kw['owner']
self.__nameInBinding = None
self.__uniqueNameInBinding = None
self.__owner = owner
assert not (isinstance(self, ComplexTypeDefinition) and isinstance(owner, Schema))
self.__ownedComponents = set()
Expand Down Expand Up @@ -304,8 +309,7 @@ def bestNCName (self):
return None

def nameInBinding (self):
"""Return the name by which this component is known in the generated
binding.
"""Return the name by which this component is known in the binding module.
@note: To support builtin datatypes, type definitions with an
associated L{pythonSupport<SimpleTypeDefinition.pythonSupport>} class
Expand All @@ -314,6 +318,10 @@ def nameInBinding (self):
with a language keyword, this should be fine."""
return self.__nameInBinding

def uniqueNameInBinding (self):
"""Return the name by which this component is known in the binding class."""
return self.__uniqueNameInBinding

def hasBinding (self):
"""Return C{True} iff this is a component which has a user-visible
Python construct which serves as its binding.
Expand All @@ -324,10 +332,15 @@ def hasBinding (self):
return self.isTypeDefinition() or (isinstance(self, ElementDeclaration) and self._scopeIsGlobal())

def setNameInBinding (self, name_in_binding):
"""Set the name by which this component shall be known in the XSD binding."""
"""Set the name by which this component shall be known in the binding module."""
self.__nameInBinding = name_in_binding
return self

def setUniqueNameInBinding (self, unique_name):
"""Set the name by which this component shall be known in the binding class."""
self.__uniqueNameInBinding = unique_name
return self

def _updateFromOther_csc (self, other):
"""Override fields in this instance with those from the other.
Expand Down

0 comments on commit c69fff3

Please sign in to comment.