How to use the xmltodict.unparse function in xmltodict

To help you get started, we’ve selected a few xmltodict examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github martinblech / xmltodict / tests / test_dicttoxml.py View on Github external
def test_simple_cdata(self):
        obj = {'a': 'b'}
        self.assertEqual(obj, parse(unparse(obj)))
        self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
github jxtech / wechatpy / tests / test_fields.py View on Github external
def assertXMLEqual(self, expected, xml):
        expected = xmltodict.unparse(xmltodict.parse(expected))
        xml = xmltodict.unparse(xmltodict.parse(xml))
        self.assertEqual(expected, xml)
github project-generator / project_generator / project_generator / tools / uvision.py View on Github external
def _generate_uvmpw_file(self):
        uvmpw_dic = xmltodict.parse(open(self.uvmpw_file, "rb"))
        uvmpw_dic['ProjectWorkspace']['project'] = []

        for project in self.workspace['projects']:
            # We check how far is project from root and workspace. IF they dont match,
            # get relpath for project and inject it into workspace
            path_project = os.path.dirname(project['files']['uvproj'])
            path_workspace = os.path.dirname(self.workspace['settings']['path'] + '\\')
            destination = os.path.join(os.path.relpath(self.env_settings.root, path_project), project['files']['uvproj'])
            if path_project != path_workspace:
                destination = os.path.join(os.path.relpath(self.env_settings.root, path_workspace), project['files']['uvproj'])
            uvmpw_dic['ProjectWorkspace']['project'].append({'PathAndName': destination})

        # generate the file
        uvmpw_xml = xmltodict.unparse(uvmpw_dic, pretty=True)
        project_path, uvmpw = self.gen_file_raw(uvmpw_xml, '%s.uvmpw' % self.workspace['settings']['name'], self.workspace['settings']['path'])
        return project_path, uvmpw
github rackerlabs / mimic / mimic / rest / noit_api.py View on Github external
def get_all_checks(self, request):
        """
        Return the current configuration and state of all checks.
        """
        request.setHeader(b"content-type", b"application/xml")
        return xmltodict.unparse(get_all_checks())
github osmc / osmc / package / mediacenter-addon-osmc / src / script.module.osmcsetting.networking / resources / lib / osmc_advset_editor.py View on Github external
def write_advancedsettings(self, loc, dictionary):
		''' Writes the supplied dictionary back to the advancedsettings.xml file '''

		if not dictionary.get('advancedsettings', None):

			self.log('Empty dictionary passed to advancedsettings file writer. Preventing write, backing up and removing file.')

			subprocess.call(['sudo', 'cp', loc, loc.replace('advancedsettings.xml', 'advancedsettings_backup.xml')])

			subprocess.call(['sudo', 'rm', '-f', loc])

			return

		with open(loc, 'w') as f:
			xmltodict.unparse(  input_dict = dictionary, 
								output = f, 
								pretty = True)
github alibaba / ansible-provider-docs / lib / ansible / plugins / connection / winrm.py View on Github external
def _winrm_send_input(self, protocol, shell_id, command_id, stdin, eof=False):
        rq = {'env:Envelope': protocol._get_soap_header(
            resource_uri='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd',
            action='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Send',
            shell_id=shell_id)}
        stream = rq['env:Envelope'].setdefault('env:Body', {}).setdefault('rsp:Send', {})\
            .setdefault('rsp:Stream', {})
        stream['@Name'] = 'stdin'
        stream['@CommandId'] = command_id
        stream['#text'] = base64.b64encode(to_bytes(stdin))
        if eof:
            stream['@End'] = 'true'
        protocol.send_message(xmltodict.unparse(rq))
github gil9red / SimplePyScripts / XML / XML_to_dict__xmltodict__examples / dict_to_xml__unparse__real_example.py View on Github external
for i, item in enumerate(items, 1):
    root['person' + str(i)] = item

my_dict = {
    'root': root
}
# my_dict = {
#     'root': {
#         'person1': {"first_name": "Ivan", "last_name": "Ivanov", "city": "Moscow"},
#         'person2': {"first_name": "Sergey", "last_name": "Sidorov", "city": "Sochi"},
#     }
# }

# Параметр full_document=False убирает из XML строку "
github opps / opps / opps / views / generic / xml_views.py View on Github external
def __init__(self, obj='', mimetype="application/xml", *args, **kwargs):
        content = xmltodict.unparse(obj)
        super(XMLResponse, self).__init__(content, mimetype, *args, **kwargs)
github ZhuPeng / trackupdates / trackupdates / utils.py View on Github external
def json2xml(j):
    x = xmltodict.unparse({'json': j})
    logger.debug('json2xml: %s', x.encode('utf-8'))
    return x
github sid5432 / pyOTDR / pyOTDR / dump.py View on Github external
def tofile(results, logfile, format='JSON'):
    """ 
    dump results to file (specifiled by file handle logfile)
    """
    
    if format == 'JSON':
        json.dump(results, logfile, sort_keys=True, indent=8, separators=(',',': '))
    elif format == 'XML':
        newresults = replace_keys(results) 
        res = xmltodict.unparse(newresults, pretty=True)
        logfile.write(res)
    else:
        raise ValueError('Format has to be JSON or XML')