builders
xsdata.formats.dataclass.models.builders
ClassMeta
The binding model combined metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element_name_generator | Callable | The element name generator | required |
attribute_name_generator | Callable | The attribute name generator | required |
qname | str | The namespace qualified name of the class | required |
local_name | str | The name of the element this class represents | required |
nillable | bool | Specifies whether this class supports nillable content | required |
namespace | Optional[str] | The class namespace | required |
target_qname | Optional[str] | The class target namespace qualified name | required |
Source code in xsdata/formats/dataclass/models/builders.py
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 |
|
__init__(element_name_generator, attribute_name_generator, qname, local_name, nillable, namespace, target_qname)
Initialize class meta.
Source code in xsdata/formats/dataclass/models/builders.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
XmlMetaBuilder
Binding class metadata builder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
class_type | ClassType | The supported class type, e.g. dataclass, attr, pydantic | required |
element_name_generator | Callable | The default element name generator | required |
attribute_name_generator | Callable | The default attribute name generator | required |
globalns | Optional[dict[str, Callable]] | The global namespace | None |
Source code in xsdata/formats/dataclass/models/builders.py
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 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
|
__init__(class_type, element_name_generator, attribute_name_generator, globalns=None)
Initialize the builder.
Source code in xsdata/formats/dataclass/models/builders.py
100 101 102 103 104 105 106 107 108 109 110 111 |
|
build(clazz, parent_namespace)
Build the binding metadata for a dataclass and its fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clazz | type | The target class | required |
parent_namespace | Optional[str] | The parent class namespace | required |
Returns:
Type | Description |
---|---|
XmlMeta | The binding metadata instance. |
Source code in xsdata/formats/dataclass/models/builders.py
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 |
|
build_vars(clazz, namespace, element_name_generator, attribute_name_generator)
Build the binding metadata for the given dataclass fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clazz | type | The target class | required |
namespace | Optional[str] | The target class namespace | required |
element_name_generator | Callable | The class element name generator | required |
attribute_name_generator | Callable | The class attribute name generator | required |
Yields:
Type | Description |
---|---|
XmlVar | An iterator of the field binding metadata instances. |
Source code in xsdata/formats/dataclass/models/builders.py
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 209 210 211 212 213 214 215 |
|
build_class_meta(clazz, parent_namespace=None)
Build the class meta options and merge with the defaults.
The class metaclass is not inheritable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clazz | Any | The target class | required |
parent_namespace | Optional[str] | The parent class namespace | None |
Returns:
Type | Description |
---|---|
ClassMeta | A class meta instance. |
Source code in xsdata/formats/dataclass/models/builders.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|
find_declared_class(clazz, name)
classmethod
Find the user class that matches the name.
Todo: Honestly I have no idea why we needed this.
Source code in xsdata/formats/dataclass/models/builders.py
264 265 266 267 268 269 270 271 272 273 274 275 |
|
is_inner_class(clazz)
classmethod
Return whether the given type is nested inside another type.
Source code in xsdata/formats/dataclass/models/builders.py
277 278 279 280 |
|
target_namespace(module, meta)
classmethod
The target namespace this class metadata was defined in.
Source code in xsdata/formats/dataclass/models/builders.py
282 283 284 285 286 287 288 289 290 291 292 293 |
|
default_xml_type(clazz)
Return the default xml type for the fields of the given dataclass.
If a class has fields with no xml type defined, attempt to figure it from the rest of the fields. It's either a text or an element field.
Todo hacks like this are so unnecessary...
Source code in xsdata/formats/dataclass/models/builders.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
|
XmlVarBuilder
Binding class field metadata builder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
class_type | ClassType | The supported class type, e.g. dataclass, attr, pydantic | required |
default_xml_type | str | The default xml type of this class fields | required |
element_name_generator | Callable | The element name generator | return_input |
attribute_name_generator | Callable | The attribute name generator | return_input |
Attributes:
Name | Type | Description |
---|---|---|
index | The index of the next var |
Source code in xsdata/formats/dataclass/models/builders.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 |
|
__init__(class_type, default_xml_type, element_name_generator=return_input, attribute_name_generator=return_input)
Initialize the builder.
Source code in xsdata/formats/dataclass/models/builders.py
341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
build(model, name, type_hint, metadata, init, parent_namespace, default_value, globalns, parent_factory=None)
Build the binding metadata for a class field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model | type | The model class | required |
name | str | The model field name | required |
type_hint | Any | The typing annotations of the field | required |
metadata | Mapping[str, Any] | The field metadata mapping | required |
init | bool | Specify whether this field can be initialized | required |
parent_namespace | Optional[str] | The class namespace | required |
default_value | Any | The field default value or factory | required |
globalns | Any | Python's global namespace | required |
parent_factory | Optional[Callable] | The value factory | None |
Returns:
Type | Description |
---|---|
Optional[XmlVar] | The field binding metadata instance. |
Source code in xsdata/formats/dataclass/models/builders.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
|
build_choices(model, name, choices, factory, globalns, parent_namespace)
Build the binding metadata for a compound dataclass field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model | type | The model class | required |
name | str | The model field name | required |
choices | list[dict] | The list of choice metadata | required |
factory | Optional[Callable] | The compound field values factory | required |
globalns | Any | Python's global namespace | required |
parent_namespace | Optional[str] | The class namespace | required |
Yields:
Type | Description |
---|---|
XmlVar | An iterator of field choice binding metadata instance. |
Source code in xsdata/formats/dataclass/models/builders.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
|
build_local_name(xml_type, name)
Transform the name for serialization by the target xml type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml_type | str | The xml type: element, attribute, ... | required |
name | str | The field name | required |
Returns:
Type | Description |
---|---|
str | The name to use for serialization. |
Source code in xsdata/formats/dataclass/models/builders.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
|
resolve_namespaces(xml_type, namespace, parent_namespace)
classmethod
Resolve a fields supported namespaces.
Only elements and wildcards are allowed to inherit the parent namespace if the given namespace is empty.
In case of wildcard try to decode the ##any, ##other, ##local,
target.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml_type | Optional[str] | The xml type (Text|Element(s)|Attribute(s)|Wildcard) | required |
namespace | Optional[str] | The field namespace | required |
parent_namespace | Optional[str] | The parent namespace | required |
Returns:
Type | Description |
---|---|
tuple[str, ...] | A tuple of supported namespaces. |
Source code in xsdata/formats/dataclass/models/builders.py
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 |
|
is_any_type(types, xml_type)
classmethod
Return whether the given xml type supports generic values.
Source code in xsdata/formats/dataclass/models/builders.py
574 575 576 577 578 579 580 |
|
is_typing_supported(types)
Validate all types are registered in the converter.
Source code in xsdata/formats/dataclass/models/builders.py
582 583 584 585 586 587 588 589 590 591 592 |
|