#NEWLINE# def _finalize_namespaces( self , ns_dict = None ) : #NEWLINE# #INDENT# 'Returns a dictionary of namespaces to be exported with an XML\n        document.\n\n        This loops over all the namespaces that were discovered and built\n        during the execution of ``collect()`` and\n        ``_parse_collected_classes()`` and attempts to merge them all.\n\n        Returns:\n            An ``alias: namespace`` dictionary containing all namespaces\n            required to be present on an exported document.\n\n        Raises:\n            .DuplicatePrefixError: If namespace prefix was mapped to more than\n                one namespace.\n\n        ' #NEWLINE# if ( not ns_dict ) : #NEWLINE# #INDENT# ns_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# user_namespaces = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( ns , alias ) in ns_dict . iteritems ( ) : #NEWLINE# #INDENT# user_namespaces [ alias ] = ns #NEWLINE# #UNINDENT# ns_dict = collections . defaultdict ( set ) #NEWLINE# id_alias = idgen . get_id_namespace_alias ( ) #NEWLINE# id_ns = idgen . get_id_namespace ( ) #NEWLINE# ns_dict [ id_alias ] . add ( id_ns ) #NEWLINE# collected_prefixed = dict ( self . _collected_namespaces . iteritems ( ) ) #NEWLINE# no_prefix = collected_prefixed . pop ( None , set ( ) ) #NEWLINE# collected_unprefixed = self . _resolve_unprefixed ( no_prefix ) #NEWLINE# self . _fix_example_namespace ( ) #NEWLINE# namespace_dicts = itertools . chain ( self . _BASELINE_NAMESPACES . iteritems ( ) , self . _input_namespaces . iteritems ( ) , collected_prefixed . iteritems ( ) , collected_unprefixed . iteritems ( ) , user_namespaces . iteritems ( ) ) #NEWLINE# for ( alias , ns ) in namespace_dicts : #NEWLINE# #INDENT# ns_dict [ alias ] . add ( ns ) #NEWLINE# #UNINDENT# self . _check_namespaces ( ns_dict ) #NEWLINE# flattened = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( alias , ns_set ) in ns_dict . iteritems ( ) : #NEWLINE# #INDENT# flattened [ alias ] = ns_set . pop ( ) #NEWLINE# #UNINDENT# return flattened