xsdata.formats.converter module¶
-
class
xsdata.formats.converter.
Converter
[source]¶ Bases:
object
Abstract converter class.
-
abstract
from_string
(value, **kwargs)[source]¶ Convert from string.
- 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]¶
-
from_string
(value, types, **kwargs)[source]¶ Attempt to convert a string to one of the given types.
If the input is not a string return the input value. If all attempts fail return the value input value and issue a warning.
-
to_string
(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
-
from_string
(value, **kwargs)[source]¶ Convert from string.
- Raises
ConverterError – if converter fails with and expected ValueError
- Parameters
- Return type
-
-
class
xsdata.formats.converter.
IntConverter
[source]¶ Bases:
xsdata.formats.converter.Converter
-
from_string
(value, **kwargs)[source]¶ Convert from string.
- Raises
ConverterError – if converter fails with and expected ValueError
- Parameters
- Return type
-
-
class
xsdata.formats.converter.
StrConverter
[source]¶ Bases:
xsdata.formats.converter.Converter
-
from_string
(value, **kwargs)[source]¶ Convert from string.
- Raises
ConverterError – if converter fails with and expected ValueError
- Parameters
- Return type
-
-
class
xsdata.formats.converter.
FloatConverter
[source]¶ Bases:
xsdata.formats.converter.Converter
-
from_string
(value, **kwargs)[source]¶ Convert from string.
- Raises
ConverterError – if converter fails with and expected ValueError
- Parameters
- Return type
-
-
class
xsdata.formats.converter.
DecimalConverter
[source]¶ Bases:
xsdata.formats.converter.Converter
-
from_string
(value, **kwargs)[source]¶ Convert from string.
- Raises
ConverterError – if converter fails with and expected ValueError
- Parameters
- Return type
-
-
class
xsdata.formats.converter.
QNameConverter
[source]¶ Bases:
xsdata.formats.converter.Converter
-
from_string
(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”
-
to_string
(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
-
from_string
(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”
-
to_string
(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¶
-
from_string
(value, **kwargs)[source]¶ Convert from string.
- Raises
ConverterError – if converter fails with and expected ValueError
- Parameters
- Return type