GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — PolyXML/benchmarks/python/models.py at main · polyxml/PolyXML

Expand file tree

/

models.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
208 lines (163 loc) · 6.46 KB
/

models.py

Copy path

File metadata and controls

208 lines (163 loc) · 6.46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
"""Data models for PolyXML, xsdata, and pydantic-xml comparative benchmarks."""
from dataclasses import dataclass, field
from pydantic import BaseModel, Field
# -----------------------------------------------------------------------------
# 1. PolyXML Models (Dataclass & Pydantic v2)
# -----------------------------------------------------------------------------
@dataclass
class PolySensor:
id: int = field(metadata={"type": "Attribute"})
temp: float = field(metadata={"type": "Element"})
status: str = field(metadata={"type": "Element"})
active: bool = field(metadata={"type": "Element"})
@dataclass
class PolyCatalogItem:
id: int = field(metadata={"type": "Attribute"})
name: str = field(metadata={"type": "Element"})
price: float = field(metadata={"type": "Element"})
@dataclass
class PolyCatalog:
items: list[PolyCatalogItem] = field(metadata={"type": "Element", "name": "item"})
@dataclass
class PolyOrderItem:
id: int = field(metadata={"type": "Attribute"})
qty: int = field(metadata={"type": "Attribute"})
name: str = field(metadata={"type": "Element"})
price: float = field(metadata={"type": "Element"})
available: bool = field(metadata={"type": "Element"})
@dataclass
class PolyOrder:
id: str = field(metadata={"type": "Attribute"})
customer: str = field(metadata={"type": "Element"})
items: list[PolyOrderItem] = field(metadata={"type": "Element", "name": "item"})
class PydanticSensor(BaseModel):
id: int = Field(..., json_schema_extra={"type": "Attribute"})
temp: float = Field(..., json_schema_extra={"type": "Element"})
status: str = Field(..., json_schema_extra={"type": "Element"})
active: bool = Field(..., json_schema_extra={"type": "Element"})
class PydanticCatalogItem(BaseModel):
id: int = Field(..., json_schema_extra={"type": "Attribute"})
name: str = Field(..., json_schema_extra={"type": "Element"})
price: float = Field(..., json_schema_extra={"type": "Element"})
class PydanticCatalog(BaseModel):
items: list[PydanticCatalogItem] = Field(
..., json_schema_extra={"type": "Element", "name": "item"}
)
# -----------------------------------------------------------------------------
# 2. xsdata Models
# -----------------------------------------------------------------------------
try:
from xsdata.formats.dataclass.parsers import XmlParser as XsXmlParser
from xsdata.formats.dataclass.serializers import XmlSerializer as XsXmlSerializer
HAS_XSDATA = True
@dataclass
class XsSensor:
id: int = field(metadata={"type": "Attribute"})
temp: float = field(metadata={"type": "Element"})
status: str = field(metadata={"type": "Element"})
active: bool = field(metadata={"type": "Element"})
@dataclass
class XsCatalogItem:
id: int = field(metadata={"type": "Attribute"})
name: str = field(metadata={"type": "Element"})
price: float = field(metadata={"type": "Element"})
@dataclass
class XsCatalog:
item: list[XsCatalogItem] = field(
default_factory=list, metadata={"type": "Element"}
)
@dataclass
class XsOrderItem:
id: int = field(metadata={"type": "Attribute"})
qty: int = field(metadata={"type": "Attribute"})
name: str = field(metadata={"type": "Element"})
price: float = field(metadata={"type": "Element"})
available: bool = field(metadata={"type": "Element"})
@dataclass
class XsOrder:
id: str = field(metadata={"type": "Attribute"})
customer: str = field(metadata={"type": "Element"})
items: list[XsOrderItem] = field(
default_factory=list, metadata={"type": "Element", "name": "item"}
)
except ImportError:
HAS_XSDATA = False
XsXmlParser = None # type: ignore
XsXmlSerializer = None # type: ignore
XsSensor = None # type: ignore
XsCatalogItem = None # type: ignore
XsCatalog = None # type: ignore
XsOrderItem = None # type: ignore
XsOrder = None # type: ignore
# -----------------------------------------------------------------------------
# 3. pydantic-xml Models
# -----------------------------------------------------------------------------
try:
from pydantic_xml import BaseXmlModel, attr, element
HAS_PXML = True
class PxmlSensor(BaseXmlModel, tag="Sensor"):
id: int = attr()
temp: float = element()
status: str = element()
active: bool = element()
class PxmlCatalogItem(BaseXmlModel, tag="item"):
id: int = attr()
name: str = element()
price: float = element()
class PxmlCatalog(BaseXmlModel, tag="Catalog"):
items: list[PxmlCatalogItem] = element(tag="item", default_factory=list)
except ImportError:
HAS_PXML = False
PxmlSensor = None # type: ignore
PxmlCatalogItem = None # type: ignore
PxmlCatalog = None # type: ignore
# -----------------------------------------------------------------------------
# 4. declxml Processors
# -----------------------------------------------------------------------------
try:
import declxml as xml_decl
HAS_DECLXML = True
DECLXML_SENSOR_PROC = xml_decl.dictionary(
"Sensor",
[
xml_decl.integer(".", attribute="id"),
xml_decl.floating_point("temp"),
xml_decl.string("status"),
xml_decl.boolean("active"),
],
)
DECLXML_CATALOG_ITEM_PROC = xml_decl.dictionary(
"item",
[
xml_decl.integer(".", attribute="id"),
xml_decl.string("name"),
xml_decl.floating_point("price"),
],
)
DECLXML_CATALOG_PROC = xml_decl.dictionary(
"Catalog",
[xml_decl.array(DECLXML_CATALOG_ITEM_PROC, alias="item")],
)
DECLXML_ORDER_ITEM_PROC = xml_decl.dictionary(
"item",
[
xml_decl.integer(".", attribute="id"),
xml_decl.integer(".", attribute="qty"),
xml_decl.string("name"),
xml_decl.floating_point("price"),
xml_decl.boolean("available"),
],
)
DECLXML_ORDER_PROC = xml_decl.dictionary(
"Order",
[
xml_decl.string(".", attribute="id"),
xml_decl.string("customer"),
xml_decl.array(DECLXML_ORDER_ITEM_PROC, alias="items"),
],
)
except ImportError:
HAS_DECLXML = False
DECLXML_SENSOR_PROC = None # type: ignore
DECLXML_CATALOG_PROC = None # type: ignore
DECLXML_ORDER_PROC = None # type: ignore
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.