disambiguate_choices
xsdata.codegen.handlers.disambiguate_choices
DisambiguateChoices
Bases: RelativeHandlerInterface
Process choices with the same types and disambiguate them.
Essentially, this handler creates intermediate simple and complex types to ensure not two elements in a compound field can have the same type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
container | ContainerInterface | The class container instance | required |
Attributes:
Name | Type | Description |
---|---|---|
unnest_classes | Specifies whether to create intermediate inner or outer classes. |
Source code in xsdata/codegen/handlers/disambiguate_choices.py
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 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 |
|
process(target)
Process the given class attrs if they contain choices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target | Class | The target class instance | required |
Source code in xsdata/codegen/handlers/disambiguate_choices.py
33 34 35 36 37 38 39 40 41 |
|
process_compound_field(target, attr)
Process a compound field.
A compound field can be created by a mixed wildcard with explicit children, or because we enabled the configuration to group repeatable choices.
Steps
- Merge choices derived from xs:any elements
- Find ambiguous choices and create intermediate classes
- Reset the attr types if it's not a mixed wildcard.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target | Class | The target class instance | required |
attr | Attr | An attr instance that contains choices | required |
Source code in xsdata/codegen/handlers/disambiguate_choices.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
merge_wildcard_choices(attr)
classmethod
Merge choices derived from xs:any elements.
It's a compound field it doesn't make sense to have multiple wildcard choices. Merge them together.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr | Attr | The attr instance that contains choices | required |
Source code in xsdata/codegen/handlers/disambiguate_choices.py
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 |
|
find_ambiguous_choices(attr)
classmethod
Find choices with the same types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr | Attr | The attr instance with the choices. | required |
Yields:
Type | Description |
---|---|
Attr | An iterator of the ambiguous choices, except wildcards. |
Source code in xsdata/codegen/handlers/disambiguate_choices.py
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 |
|
disambiguate_choice(target, choice)
Create intermediate class for the given choice.
Scenarios
- Choice is derived from xs:anyType
- Choice is derived from a xs:anySimpleType
- Choice is a reference to xs:complexType or element
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target | Class | The target class instance | required |
choice | Attr | The ambiguous choice attr instance | required |
Source code in xsdata/codegen/handlers/disambiguate_choices.py
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 |
|
is_simple_type(choice)
Return whether the choice attr is a simple type reference.
Source code in xsdata/codegen/handlers/disambiguate_choices.py
177 178 179 180 181 182 183 |
|
create_ref_class(source, choice, inner)
Create an intermediate class for the given choice.
If the reference class is going to be inner, ensure the class name is unique, otherwise we will still end-up with ambiguous choices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source | Class | The source class instance | required |
choice | Attr | The ambiguous choice attr instance | required |
inner | bool | Specifies if the reference class will be inner | required |
Source code in xsdata/codegen/handlers/disambiguate_choices.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
next_available_name(parent, name)
classmethod
Find the next available name for an inner class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent | Class | The parent class instance | required |
name | str | The name of the inner class | required |
Returns:
Type | Description |
---|---|
str | The next available class name by adding a integer suffix. |
Source code in xsdata/codegen/handlers/disambiguate_choices.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
add_any_type_value(reference, choice)
classmethod
Add a simple any type content value attr to the reference class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reference | Class | The reference class instance | required |
choice | Attr | The source choice attr instance | required |
Source code in xsdata/codegen/handlers/disambiguate_choices.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
add_simple_type_value(reference, choice)
classmethod
Add a simple type content value attr to the reference class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reference | Class | The reference class instance | required |
choice | Attr | The source choice attr instance | required |
Source code in xsdata/codegen/handlers/disambiguate_choices.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
|
add_extension(reference, choice)
classmethod
Add an extension to the reference class from the choice type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reference | Class | The reference class instance | required |
choice | Attr | The source choice attr instance | required |
Source code in xsdata/codegen/handlers/disambiguate_choices.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
|