utils
xsdata.formats.dataclass.parsers.utils
PendingCollection
Bases: UserList
An iterable implementation of parsed values.
The values are parsed individually in the end we need to convert it to a tuple or a list based on the mutability setting of the data class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
initlist | Optional[Iterable] | An initial list of values or None | required |
factory | Optional[Callable] | A callable factory for the values when the node parse has finished. | required |
Source code in xsdata/formats/dataclass/parsers/utils.py
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 |
|
evaluate()
Evaluate the values factory and return the result.
Returns:
Type | Description |
---|---|
Iterable[Any] | A list or tuple or set of values |
Source code in xsdata/formats/dataclass/parsers/utils.py
28 29 30 31 32 33 34 |
|
ParserUtils
Random parser util functions.
Source code in xsdata/formats/dataclass/parsers/utils.py
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 |
|
xsi_type(attrs, ns_map)
classmethod
Parse the xsi:type attribute value if present.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attrs | Dict | The element attributes | required |
ns_map | Dict | The element namespace prefix-URI map | required |
Returns:
Type | Description |
---|---|
Optional[str] | The xsi:type attribute value or None |
Source code in xsdata/formats/dataclass/parsers/utils.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
xsi_nil(attrs)
classmethod
Return whether xsi:nil attribute value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attrs | Dict | The element attributes | required |
Returns:
Type | Description |
---|---|
Optional[bool] | The bool value or None if it doesn't exist. |
Source code in xsdata/formats/dataclass/parsers/utils.py
58 59 60 61 62 63 64 65 66 67 68 69 |
|
parse_value(value, types, default=None, ns_map=None, tokens_factory=None, format=None)
classmethod
Convert a value to a python primitive type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value | Any | A primitive value or a list of primitive values | required |
types | Sequence[Type] | An iterable of types to try to convert the value | required |
default | Optional[Any] | The default value/factory if the given is None | None |
ns_map | Optional[Dict] | The element namespace prefix-URI map | None |
tokens_factory | Optional[Callable] | A callable factory for the converted values if the element is derived from xs:NMTOKENS | None |
format | Optional[str] | The format argument for base64/hex values or dates. | None |
Returns:
Type | Description |
---|---|
Any | The converted value or values. |
Source code in xsdata/formats/dataclass/parsers/utils.py
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 |
|
normalize_content(value)
classmethod
Normalize element text or tail content.
If content is just whitespace return None, otherwise preserve the original content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value | Optional[str] | The element content | required |
Returns:
Type | Description |
---|---|
Optional[str] | The normalized content |
Source code in xsdata/formats/dataclass/parsers/utils.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
parse_any_attributes(attrs, ns_map)
classmethod
Parse attributes with qname support.
Example
{"foo": "bar", "xsi:type": "my:type"} -> {"foo": "bar", "xsi:type" "{http://someuri.com}type"}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attrs | Dict[str, str] | The element attributes | required |
ns_map | Dict[Optional[str], str] | The element namespace prefix-URI map | required |
Returns:
Type | Description |
---|---|
Dict[str, str] | The parsed attributes with expanded namespace prefixes |
Source code in xsdata/formats/dataclass/parsers/utils.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
parse_any_attribute(value, ns_map)
classmethod
Expand the value with the full namespace if it has a prefix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value | str | The attr value | required |
ns_map | Dict | The element namespace prefix-URI map | required |
Returns:
Type | Description |
---|---|
str | The expanded value. |
Source code in xsdata/formats/dataclass/parsers/utils.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|