-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdk_types.py.ejs
More file actions
67 lines (59 loc) · 1.94 KB
/
pdk_types.py.ejs
File metadata and controls
67 lines (59 loc) · 1.94 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# THIS FILE WAS GENERATED BY `xtp-python-bindgen`. DO NOT EDIT.
from __future__ import annotations
from enum import Enum # noqa: F401
from typing import Optional, List # noqa: F401
from datetime import datetime # noqa: F401
from dataclasses import dataclass # noqa: F401
from dataclass_wizard import JSONWizard, skip_if_field, IS # noqa: F401
from dataclass_wizard.type_def import JSONObject
from base64 import b64encode, b64decode
<% Object.values(schema.schemas).forEach(schema => { %>
<% if (schema.enum) { %>
class <%- pythonTypeName(schema.name) %>(Enum):
<% schema.enum.forEach(variant => { -%>
<%- pythonTypeName(variant) %> = "<%- variant %>"
<% }) %>
<% } else { %>
@dataclass
class <%- pythonTypeName(schema.name) %>(JSONWizard):
<% schema.properties.forEach(p => { -%>
<% if (!p.nullable && p.required) {%>
<% if (p.description) { -%>
# <%- formatCommentBlock(p.description, "# ") %>
<% } -%>
<%- p.name %>: <%- toPythonType(p, p.required) %>
<% } %>
<% }) %>
<% schema.properties.forEach(p => { -%>
<% if (p.nullable && p.required) {%>
<% if (p.description) { -%>
# <%- formatCommentBlock(p.description, "# ") %>
<% } -%>
<%- p.name %>: <%- toPythonType(p, p.required) %>
<% } %>
<% }) %>
<% schema.properties.forEach(p => { -%>
<% if (!p.required) {%>
<% if (p.description) { -%>
# <%- formatCommentBlock(p.description, "# ") %>
<% } -%>
<%- p.name %>: <%- toPythonType(p, p.required) %> = skip_if_field(IS(None), default=None)
<% } %>
<% }) %>
@classmethod
def _pre_from_dict(cls, o: JSONObject) -> JSONObject:
<% schema.properties.forEach(p => { -%>
<% if (p.xtpType.kind === 'buffer') {%>
o['<%- p.name %>'] = b64decode(o['<%- p.name %>'])
<% } -%>
<% }) -%>
return o
def _pre_dict(self):
<% schema.properties.forEach(p => { -%>
<% if (p.xtpType.kind === 'buffer') {%>
self.<%- p.name %> = b64encode(self.<%- p.name %>).decode("utf-8")
<% } -%>
<% }) -%>
return
<% } %>
<% }); %>