xsdata.formats.converter module¶
-
class
xsdata.formats.converter.Converter[source]¶ Bases:
objectAbstract converter class.
-
abstract
deserialize(value, **kwargs)[source]¶ Convert any type to the converter dedicated type.
- Raises
ConverterError – if converter fails with and expected ValueError
- Parameters
- Return type
-
abstract
-
class
xsdata.formats.converter.ConverterAdapter(registry=<factory>)[source]¶ Bases:
object-
registry: Dict[Type, xsdata.formats.converter.Converter]¶
-
deserialize(value, types, **kwargs)[source]¶ Attempt to convert a any value to one of the given types.
If all attempts fail return the value input value and issue a warning.
-
serialize(value, **kwargs)[source]¶ Convert the given value to string, ignore None values.
If the value is a list assume the value is a list of tokens.
-
register_converter(data_type, func)[source]¶ Register a callable or converter for the given data type.
Callables will be wrapped in a
xsdata.formats.converter.ProxyConverter
-
type_converter(data_type)[source]¶ Get a suitable converter for given data type.
Try the parent type if the original doesn’t exist, fall back to str and issue a warning if no converter matches.
-
-
class
xsdata.formats.converter.BoolConverter[source]¶ Bases:
xsdata.formats.converter.Converter-
deserialize(value, **kwargs)[source]¶ Convert any type to the converter dedicated type.
- Raises
ConverterError – if converter fails with and expected ValueError
- Parameters
- Return type
-
-
class
xsdata.formats.converter.IntConverter[source]¶ Bases:
xsdata.formats.converter.Converter-
deserialize(value, **kwargs)[source]¶ Convert any type to the converter dedicated type.
- Raises
ConverterError – if converter fails with and expected ValueError
- Parameters
- Return type
-
-
class
xsdata.formats.converter.StrConverter[source]¶ Bases:
xsdata.formats.converter.Converter-
deserialize(value, **kwargs)[source]¶ Convert any type to the converter dedicated type.
- Raises
ConverterError – if converter fails with and expected ValueError
- Parameters
- Return type
-
-
class
xsdata.formats.converter.FloatConverter[source]¶ Bases:
xsdata.formats.converter.Converter-
deserialize(value, **kwargs)[source]¶ Convert any type to the converter dedicated type.
- Raises
ConverterError – if converter fails with and expected ValueError
- Parameters
- Return type
-
-
class
xsdata.formats.converter.DecimalConverter[source]¶ Bases:
xsdata.formats.converter.Converter-
deserialize(value, **kwargs)[source]¶ Convert any type to the converter dedicated type.
- Raises
ConverterError – if converter fails with and expected ValueError
- Parameters
- Return type
-
-
class
xsdata.formats.converter.QNameConverter[source]¶ Bases:
xsdata.formats.converter.Converter-
deserialize(value, ns_map=None, **kwargs)[source]¶ Convert namespace prefixed strings, or fully qualified strings to QNames.
- examples:
xs:string -> QName(“http://www.w3.org/2001/XMLSchema”, “string”)
{foo}bar -> QName(“foo”, “bar”
-
serialize(value, ns_map=None, **kwargs)[source]¶ Convert a QName instance to string either with a namespace prefix if a prefix-URI namespaces mapping is provided or to a fully qualified name with the namespace.
- examples:
QName(“http://www.w3.org/2001/XMLSchema”, “int”) & ns_map -> xs:int
QName(“foo, “bar”) -> {foo}bar
-
-
class
xsdata.formats.converter.LxmlQNameConverter[source]¶ Bases:
xsdata.formats.converter.Converter-
deserialize(value, ns_map=None, **kwargs)[source]¶ Convert namespace prefixed strings, or fully qualified strings to QNames.
- examples:
xs:string -> QName(“http://www.w3.org/2001/XMLSchema”, “string”)
{foo}bar -> QName(“foo”, “bar”
-
serialize(value, ns_map=None, **kwargs)[source]¶ Convert a QName instance to string either with a namespace prefix if a prefix-URI namespaces mapping is provided or to a fully qualified name with the namespace.
- examples:
QName(“http://www.w3.org/2001/XMLSchema”, “int”) & ns_map -> xs:int
QName(“foo, “bar”) -> {foo}bar
-
-
class
xsdata.formats.converter.EnumConverter[source]¶
-
class
xsdata.formats.converter.ProxyConverter(func)[source]¶ Bases:
xsdata.formats.converter.Converter- Parameters
func (
Callable) – the callable to convert from string
-
func: Callable¶
-
deserialize(value, **kwargs)[source]¶ Convert any type to the converter dedicated type.
- Raises
ConverterError – if converter fails with and expected ValueError
- Parameters
- Return type