code
xsdata.formats.dataclass.serializers.code
PycodeSerializer
dataclass
Pycode serializer for data class instances.
Generate python pretty representation code from a model instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context | XmlContext | The models context instance | XmlContext() |
Source code in xsdata/formats/dataclass/serializers/code.py
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 |
|
render(obj, var_name='obj')
Serialize the input model instance to python representation string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | object | The input model instance to serialize | required |
var_name | str | The var name to assign the model instance | 'obj' |
Returns:
Type | Description |
---|---|
str | The serialized representation string. |
Source code in xsdata/formats/dataclass/serializers/code.py
29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
write(out, obj, var_name)
Write the given object to the output text stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out | TextIO | The output text stream | required |
obj | Any | The input model instance to serialize | required |
var_name | str | The var name to assign the model instance | required |
Source code in xsdata/formats/dataclass/serializers/code.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
build_imports(types)
classmethod
Build a list of imports from the given types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
types | set[type] | A set of types | required |
Returns:
Type | Description |
---|---|
str | The |
Source code in xsdata/formats/dataclass/serializers/code.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
repr_object(obj, level, types)
Write the given object as repr code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | Any | The input object to serialize | required |
level | int | The current object level | required |
types | set[type] | The parent object types | required |
Yields:
Type | Description |
---|---|
str | An iterator of the representation strings. |
Source code in xsdata/formats/dataclass/serializers/code.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
repr_array(obj, level, types)
Convert an iterable object to repr code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | Union[list, set, tuple] | A list, set, tuple instance | required |
level | int | The current object level | required |
types | set[type] | The parent object types | required |
Yields:
Type | Description |
---|---|
str | An iterator of the representation strings. |
Source code in xsdata/formats/dataclass/serializers/code.py
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 |
|
repr_mapping(obj, level, types)
Convert a map object to repr code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | Mapping | A map instance | required |
level | int | The current object level | required |
types | set[type] | The parent object types | required |
Yields:
Type | Description |
---|---|
str | An iterator of the representation strings. |
Source code in xsdata/formats/dataclass/serializers/code.py
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 |
|
repr_model(obj, level, types)
Convert a data model instance to repr code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | Any | A map instance | required |
level | int | The current object level | required |
types | set[type] | The parent object types | required |
Yields:
Type | Description |
---|---|
str | An iterator of the representation strings. |
Source code in xsdata/formats/dataclass/serializers/code.py
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 |
|