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
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 |
|
__init__(initlist, factory)
Initialize the pending collection.
Source code in xsdata/formats/dataclass/parsers/utils.py
36 37 38 39 |
|
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
41 42 43 44 45 46 47 |
|
ParserUtils
Random parser util functions.
Source code in xsdata/formats/dataclass/parsers/utils.py
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 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 |
|
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
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
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
71 72 73 74 75 76 77 78 79 80 81 82 |
|
parse_var(meta, var, config, value, ns_map=None, default=None, types=None, tokens_factory=None, format=None)
classmethod
Convert a value to a python primitive type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
meta | XmlMeta | The xml meta instance | required |
var | XmlVar | The xml var instance | required |
config | ParserConfig | The parser config instance | required |
value | Any | A primitive value or a list of primitive values | required |
ns_map | Optional[dict] | The element namespace prefix-URI map | None |
default | Any | Override the var default value | None |
types | Optional[Sequence[type]] | Override the var types | None |
tokens_factory | Optional[Callable] | Override the var tokens factory | None |
format | Optional[str] | Override the var format | None |
Returns:
Type | Description |
---|---|
Any | The converted value or values. |
Source code in xsdata/formats/dataclass/parsers/utils.py
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 |
|
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
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 |
|
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
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
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
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
|
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
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
validate_fixed_value(meta, var, value)
classmethod
Validate if the parsed value matches the fixed value.
Special cases - float nans are never equal in python - strings with whitespaces, need trimming - comparing raw str values
Source code in xsdata/formats/dataclass/parsers/utils.py
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 |
|