any2any.base¶
Casts¶
- class any2any.base.Cast(**settings)¶
Base class for all casts. This class is virtual, and all subclasses must implement Cast.call().
Available Settings :
- from_¶
type. The type to cast from. If not given, the type of the input is used.
- to¶
type. The type to cast to.
- mm_to_cast¶
dict. {<mm>: <cast>}. A dictionary mapping a metamorphosis to a cast instance.
- extra_mm_to_cast¶
dict. {<mm>: <cast>}. Overrides mm_to_cast as a dictionary update.
- from_wrapped¶
type. A subclass of any2any.utils.WrappedObject. If provided, will cause from_ to be automatically wrapped.
- to_wrapped¶
type. A subclass of any2any.utils.WrappedObject. If provided, will cause to to be automatically wrapped.
- logs¶
bool. If True, the cast writes debug informations to the logger.
Members :
- call(inpt)¶
Virtual method. Casts inpt.
- cast_for(mm)¶
Picks in mm_to_cast a cast suitable for mm, customizes it with calling cast’s settings, and finally returns it.
- set_debug_on()¶
Set debug mode: all debug logs will be printed on stderr.
- set_debug_off()¶
Toggle debug mode off.
- class any2any.base.CastStack(**settings)¶
A cast provided for convenience. CastStack doesn’t do anything else than looking for a suitable cast with Cast.cast_for() and calling it. It is therefore very useful for just stacking a bunch of casts, and then casting different types of input. For example :
>>> cast = CastStack(mm_to_cast={ ... Mm(from_any=int): my_int_cast, ... Mm(from_any=str): my_str_cast, ... }) >>> cast('a string') 'other string' >>> cast(1234) 12345
- call(inpt, from_=None, to=None) = <unbound method CastStack.call>¶
Settings¶
- class any2any.base.Setting(default=None)¶
Base class for all setting types.
- customize(cast, value)¶
This method handles customization of the setting’s value.
- get(cast)¶
Gets and returns the setting’s value from cast.
- inherits(setting)¶
When overriding a setting, this is called on the new setting to take into account the parent setting.
- init(cast, value)¶
This method handles initialization of the setting’s value.
- set(cast, value)¶
Sets the setting’s value on cast.