Exemplo n.º 1
0
    def test_xml_fromstring(self):
        'xml_fromstring=False does not convert types'
        x2j_convert = self.check_data(xmljson.Parker(xml_fromstring=True))
        x2j_strings = self.check_data(xmljson.Parker(xml_fromstring=str))
        x2j_convert('1', '<root>1</root>')
        x2j_strings('"1"', '<root>1</root>')
        x2j_convert('true', '<root>true</root>')
        x2j_strings('"true"', '<root>true</root>')

        j2x_convert = self.check_etree(xmljson.Parker(xml_tostring=True))
        j2x_strings = self.check_etree(xmljson.Parker(xml_tostring=str))
        j2x_convert(True, '<true/>')
        j2x_strings(True, '<True/>')
        j2x_convert(False, '<false/>')
        j2x_strings(False, '<False/>')
Exemplo n.º 2
0
    def test_cli(self):
        dialects = [
            xmljson.Abdera(),
            xmljson.BadgerFish(),
            xmljson.Cobra(),
            xmljson.GData(),
            xmljson.Parker(),
            xmljson.Yahoo()
        ]

        for dialect in dialects:
            for path in [
                    'abdera-1.xml', 'abdera-2.xml', 'abdera-3.xml',
                    'abdera-4.xml'
            ]:
                in_file = io.open(os.path.join(_folder, path),
                                  encoding='utf-8')
                out_file = openwrite(self.tmp)
                main(in_file, out_file, dialect)
                in_file = io.open(os.path.join(_folder, path),
                                  encoding='utf-8')
                out_file = io.open(self.tmp, encoding='utf-8')
                with closing(in_file), closing(out_file):
                    self.assertEqual(json.load(out_file),
                                     dialect.data(parse(in_file).getroot()))
Exemplo n.º 3
0
def xmllocalprefix(npa, nxx):
    """
    get list of NPA-NXXes local to given NPA-NXX from localcallingguide.com
    :param npa:
    :param nxx:
    :return:
    """
    url = "https://www.localcallingguide.com/xmllocalprefix.php"
    params = {'npa': npa, 'nxx': nxx}
    response = requests.get(url, params=params)
    data = xmljson.Parker(dict_type=dict).data(ET.fromstring(response.text))
    return [
        '{npa}{nxx}'.format(npa=prefix['npa'], nxx=prefix['nxx'])
        for prefix in data['lca-data']['prefix']
    ]