File size: 693 Bytes
37c29c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Remi Serra 202407

import base64
import xml.dom.minidom


def decode_b64_string_to_pretty_xml(encoded_string):
    # split
    split = encoded_string.split(",")
    if len(split) > 1:
        encoded = split[1]
    else:
        encoded = encoded_string
    # decode
    decoded_xml = base64.b64decode(encoded).decode("utf-8")

    # pretify XML
    dom = xml.dom.minidom.parseString(decoded_xml)
    pretty_xml_as_string = dom.toprettyxml(indent="", newl="")
    return pretty_xml_as_string


def encode_svg_xml_to_b64_string(svg_xml):
    xml_b64 = base64.b64encode(svg_xml.encode("utf-8")).decode("utf-8")
    # print(f"encode_svg_xml_to_b64_string:xml_b64:{xml_b64}")
    return xml_b64