def set_mapping(self, mapping): # First, record the namespace and prefix, if necessary. xml_ns = mapping.configuration.get_option(XML_NAMESPACE_OPTION) if not xml_ns is None: xml_prefix = mapping.configuration.get_option(XML_PREFIX_OPTION) if not xml_prefix is None: ns = self.__ns_map.get(xml_prefix) if ns is None: # New prefix - register. self.__ns_map[xml_prefix] = xml_ns elif xml_ns != ns: raise ValueError('Prefix "%s" is already registered for ' 'namespace %s.' % (xml_prefix, ns)) # Make sure we rebuild the lookup. if not self.__ns_lookup is None: self.__ns_lookup = None MappingRegistry.set_mapping(self, mapping)
def __init__(self): MappingRegistry.__init__(self) self.__ns_map = self.__class__.NS_MAP.copy() self.__ns_lookup = None