def add_alternate_formats(self, filename):
        """Add phone number alternate format metadata retrieved from XML"""
        with open(filename, "r") as infile:
            xtree = etree.parse(infile)
        self.alt_territory = {}  # country_code to XAlternateTerritory
        xterritories = xtree.find(TOP_XPATH)
        for xterritory in xterritories:
            if xterritory.tag == TERRITORY_TAG:
                terrobj = XAlternateTerritory(xterritory)
                id = str(terrobj.country_code)
                if id in self.alt_territory:
                    raise Exception("Duplicate entry for %s" % id)
                self.alt_territory[id] = terrobj
            else:
                raise Exception("Unexpected element %s found" % xterritory.tag)
def add_alternate_formats ( self , filename ) : with open ( filename , "r" ) as infile : xtree = etree . parse ( infile ) self . alt_territory = { } xterritories = xtree . find ( TOP_XPATH ) for xterritory in xterritories : if xterritory . tag == TERRITORY_TAG : terrobj = XAlternateTerritory ( xterritory ) id = str ( terrobj . country_code ) if id in self . alt_territory : raise Exception ( "Duplicate entry for %s" % id ) self . alt_territory [ id ] = terrobj else : raise Exception ( "Unexpected element %s found" % xterritory . tag )
Add phone number alternate format metadata retrieved from XML