File: generate_uaerrors.py

package info (click to toggle)
python-opcua 0.98.11-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 45,296 kB
  • sloc: xml: 579,866; cs: 124,455; python: 56,857; makefile: 164; sh: 37
file content (28 lines) | stat: -rw-r--r-- 769 bytes parent folder | download | duplicates (2)
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
28
from textwrap import dedent
from generate_statuscode import status_codes
from string import Template

if __name__ == "__main__":
    codes = status_codes()

    with open("../opcua/ua/uaerrors/_auto.py", "w") as f:
        preamble = """\
        #AUTOGENERATED!!!

        from opcua.ua.uaerrors import UaStatusCodeError
        

        """

        f.write(dedent(preamble))

        for name, code, _ in codes:
            # skip non-bad because they should not be thrown as exceptions
            if not name.startswith("Bad"):
                continue

            template = Template(dedent("""\
            class $name(UaStatusCodeError):
                code = $code
            """))
            print(template.safe_substitute(name=name, code=code), file=f)