-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
427 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
==================== | ||
Dataclasses Features | ||
==================== | ||
|
||
By default xsdata with generate | ||
`dataclasses <https://docs.python.org/3/library/dataclasses.html>`_ with the default | ||
features on but you can use a :ref:`generator config <Generator Config>` to toggle | ||
almost all of them. | ||
|
||
|
||
.. literalinclude:: /../tests/fixtures/stripe/.xsdata.xml | ||
:language: xml | ||
:lines: 2-6 | ||
|
||
|
||
.. tab:: Frozen Model | ||
|
||
The code generator will use tuples instead of lists as well. | ||
|
||
.. literalinclude:: /../tests/fixtures/stripe/models/balance.py | ||
:language: python | ||
:lines: 93-128 | ||
|
||
.. tab:: Frozen Bindings | ||
|
||
.. testcode:: | ||
|
||
import pprint | ||
from tests import fixtures_dir | ||
from tests.fixtures.stripe.models import Balance | ||
from xsdata.formats.dataclass.parsers import JsonParser | ||
|
||
xml_path = fixtures_dir.joinpath("stripe/samples/balance.json") | ||
parser = JsonParser() | ||
root = parser.from_path(xml_path, Balance) | ||
pprint.pprint(root.pending) | ||
|
||
.. testoutput:: | ||
|
||
(Pending(amount=835408472, currency='usd', source_types=SourceTypes(bank_account=0, card=835408472)), | ||
Pending(amount=-22251, currency='eur', source_types=SourceTypes(bank_account=0, card=-22251))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Config xmlns="http://pypi.org/project/xsdata" version="21.6"> | ||
<Output maxLineLength="79"> | ||
<Package>tests.fixtures.stripe.models.balance</Package> | ||
<Format repr="true" eq="true" order="true" unsafeHash="false" frozen="true">dataclasses</Format> | ||
<Structure>single-package</Structure> | ||
<DocstringStyle>reStructuredText</DocstringStyle> | ||
<RelativeImports>true</RelativeImports> | ||
<CompoundFields>false</CompoundFields> | ||
</Output> | ||
<Conventions> | ||
<ClassName case="pascalCase" safePrefix="type"/> | ||
<FieldName case="snakeCase" safePrefix="value"/> | ||
<ConstantName case="screamingSnakeCase" safePrefix="value"/> | ||
<ModuleName case="snakeCase" safePrefix="mod"/> | ||
<PackageName case="snakeCase" safePrefix="pkg"/> | ||
</Conventions> | ||
<Aliases> | ||
</Aliases> | ||
</Config> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from .balance import ( | ||
Available, | ||
Balance, | ||
ConnectReserved, | ||
Pending, | ||
SourceTypes, | ||
) | ||
|
||
__all__ = [ | ||
"Available", | ||
"Balance", | ||
"ConnectReserved", | ||
"Pending", | ||
"SourceTypes", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
from dataclasses import dataclass, field | ||
from typing import Optional, Tuple | ||
|
||
|
||
@dataclass(order=True, frozen=True) | ||
class ConnectReserved: | ||
class Meta: | ||
name = "connect_reserved" | ||
|
||
amount: Optional[int] = field( | ||
default=None, | ||
metadata={ | ||
"type": "Element", | ||
} | ||
) | ||
currency: Optional[str] = field( | ||
default=None, | ||
metadata={ | ||
"type": "Element", | ||
} | ||
) | ||
|
||
|
||
@dataclass(order=True, frozen=True) | ||
class SourceTypes: | ||
class Meta: | ||
name = "source_types" | ||
|
||
bank_account: Optional[int] = field( | ||
default=None, | ||
metadata={ | ||
"type": "Element", | ||
} | ||
) | ||
card: Optional[int] = field( | ||
default=None, | ||
metadata={ | ||
"type": "Element", | ||
} | ||
) | ||
|
||
|
||
@dataclass(order=True, frozen=True) | ||
class Available: | ||
class Meta: | ||
name = "available" | ||
|
||
amount: Optional[int] = field( | ||
default=None, | ||
metadata={ | ||
"type": "Element", | ||
} | ||
) | ||
currency: Optional[str] = field( | ||
default=None, | ||
metadata={ | ||
"type": "Element", | ||
} | ||
) | ||
source_types: Optional[SourceTypes] = field( | ||
default=None, | ||
metadata={ | ||
"type": "Element", | ||
} | ||
) | ||
|
||
|
||
@dataclass(order=True, frozen=True) | ||
class Pending: | ||
class Meta: | ||
name = "pending" | ||
|
||
amount: Optional[int] = field( | ||
default=None, | ||
metadata={ | ||
"type": "Element", | ||
} | ||
) | ||
currency: Optional[str] = field( | ||
default=None, | ||
metadata={ | ||
"type": "Element", | ||
} | ||
) | ||
source_types: Optional[SourceTypes] = field( | ||
default=None, | ||
metadata={ | ||
"type": "Element", | ||
} | ||
) | ||
|
||
|
||
@dataclass(order=True, frozen=True) | ||
class Balance: | ||
class Meta: | ||
name = "balance" | ||
|
||
object_value: Optional[str] = field( | ||
default=None, | ||
metadata={ | ||
"name": "object", | ||
"type": "Element", | ||
} | ||
) | ||
available: Tuple[Available, ...] = field( | ||
default_factory=tuple, | ||
metadata={ | ||
"type": "Element", | ||
} | ||
) | ||
connect_reserved: Tuple[ConnectReserved, ...] = field( | ||
default_factory=tuple, | ||
metadata={ | ||
"type": "Element", | ||
} | ||
) | ||
livemode: Optional[bool] = field( | ||
default=None, | ||
metadata={ | ||
"type": "Element", | ||
} | ||
) | ||
pending: Tuple[Pending, ...] = field( | ||
default_factory=tuple, | ||
metadata={ | ||
"type": "Element", | ||
} | ||
) |
Oops, something went wrong.