Package: dicttowddx
dicttowddxThis is a python script that converts a python dictionary to a wddx string. This is useful when you want to exchange with endpoints that support WDDX format.InstallationpipinstalldicttowddxSupported data typesThe following datatypes are supported:PythonWDDX TypeNonenullintnumberfloatnumberstrstringbytesbinary (base64 encoded)datetimedateTimeboolbooleanUsageimportdatetimefromdicttowddximportDictToWDDXc={"a":b"ab","b":None,"c":1,"d":[None,True,1.8,1,"1",datetime.datetime(2021,9,15,14,30,0,tzinfo=datetime.timezone.utc),b"as",],"e":datetime.datetime(2021,9,15,14,30,0,tzinfo=datetime.timezone.utc),"f":None,"g":1.1,"h":True,"i":"1",}wddx=DictToWDDX(c).to_wddx()The value ofwddxshould be:<wddxPacket version='1.0'><header/><data><struct><var name="a"><string>ab</string></var><var name="b"><null/></var><var name="c"><string>1</string></var><var name="d"><array length="7"><null/><string>True</string><string>1.8</string><string>1</string><string>1</string><string>2021-09-15 14:30:00+00:00</string><string>as</string></array></var><var name="e"><string>2021-09-15 14:30:00+00:00</string></var><var name="f"><null/></var><var name="g"><string>1.1</string></var><var name="h"><string>True</string></var><var name="i"><string>1</string></var></struct></data></wddxPacket>By default, all data types are converted to string. If you want to keep the original data type, you can use theforce_typeparameter:wddx=DictToWDDX(c,force_type=True).to_wddx()The value ofwddxshould be:<wddxPacket version='1.0'><header/><data><struct><var name="a"><binary>YWI=</binary></var><var name="b"><null/></var><var name="c"><number>1</number></var><var name="d"><array length="7"><null/><boolean>True</boolean><number>1.8</number><number>1</number><string>1</string><dateTime>2021-09-15 14:30:00+00:00</dateTime><binary>YXM=</binary></array></var><var name="e"><dateTime>2021-09-15 14:30:00+00:00</dateTime></var><var name="f"><null/></var><var name="g"><number>1.1</number></var><var name="h"><boolean>True</boolean></var><var name="i"><string>1</string></var></struct></data></wddxPacket>To format the output, you can use passformat_outputarg withTrueanddisplay_indentto any integer greater than0, default is4wddx=DictToWDDX(c,format_output=True,display_indent=2).to_wddx()The value ofwddxshould be:<wddxPacket version='1.0'>
    <header/>
    <data>
        <struct>
            <var name="a">
                <binary>YWI=</binary>
            </var>
            <var name="b">
                <null/>
            </var>
            <var name="c">
                <number>1</number>
            </var>
            <var name="d">
                <array length="7">
                    <null/>
                    <boolean>True</boolean>
                    <number>1.8</number>
                    <number>1</number>
                    <string>1</string>
                    <dateTime>2021-09-15 14:30:00+00:00</dateTime>
                    <binary>YXM=</binary>
                </array>
            </var>
            <var name="e">
                <dateTime>2021-09-15 14:30:00+00:00</dateTime>
            </var>
            <var name="f">
                <null/>
            </var>
            <var name="g">
                <number>1.1</number>
            </var>
            <var name="h">
                <boolean>True</boolean>
            </var>
            <var name="i">
                <string>1</string>
            </var>
        </struct>
    </data>
</wddxPacket>Testspython-mpytesttestsCoveragepipinstallpytest-cov
python-mpytesttests--cov=dicttowddx