potc.translate.trans¶
Translator¶
-
class
potc.translate.trans.
Translator
(extend_rules=None)[source]¶ - Overview:
Common translator for the common translation cases.
This class is based on
BlankTranslator
, contains all the rules from the installed plugins. It is the best choice for being used directly.
-
__init__
(extend_rules=None)[source]¶ - Overview:
Constructor of
Translator
.- Arguments:
extend_rules: Rules for base translator.
-
transobj
(obj) → potc.translate.trans.ObjectTranslation¶ - Overview:
Do translation to the given object
obj
.- Arguments:
obj: Object to be translated.
- Returns:
result (
ObjectTranslation
): Result of object translation.
-
transvars
(vars_: Mapping[str, Any], reformat=None, isort: bool = True) → potc.translate.trans.VarsTranslation¶ - Overview:
Do translation to the given variables
vars_
, and create a runnable code.- Arguments:
vars_ (
Mapping[str, Any]
): Variables to be translated.- reformat: Reformatter for the final source code, default is
None
which means do not reformat the code.
- reformat: Reformatter for the final source code, default is
isort (
bool
): Sort the import statements, default isTrue
.
- Returns:
result (
VarsTranslation
): Result of vars translation.
TranslationFailed¶
ObjectTranslation¶
-
class
potc.translate.trans.
ObjectTranslation
(code: str, addon: potc.fixture.addons.Addons, trace: str)[source]¶ - Overview:
Result of object translation.
-
__init__
(code: str, addon: potc.fixture.addons.Addons, trace: str)[source]¶ - Overview:
Constructor of
ObjectTranslation
.- Arguments:
code (
str
): String translated code.addon (
Addons
): Addon object for this translation.trace (
str
): Rule name for the translated object.
-
__iter__
()[source]¶ - Overview:
Iterate this object.
- Examples::
>>> ot = ObjectTranslation(cc, aa, tt) >>> c, a, t = ot >>> assert c is cc >>> assert a is aa >>> assert t is tt
-
property
addon
¶ - Overview:
Addon object for this translation.
-
property
code
¶ - Overview:
String translated code.
-
property
imports
¶ - Overview:
Import statements of this translation.
-
property
trace
¶ - Overview:
Rule name for the translated object.
VarsTranslation¶
-
class
potc.translate.trans.
VarsTranslation
(code: str, addons: Mapping[str, potc.fixture.addons.Addons])[source]¶ - Overview:
Result of vars translation.
-
__init__
(code: str, addons: Mapping[str, potc.fixture.addons.Addons])[source]¶ - Overview:
Constructor of
VarsTranslation
.- Arguments:
code (
str
): String translated code.addons (
Mapping[str, Addons]
): Addon objects for the sub translations.
-
__iter__
()[source]¶ - Overview:
Iterate this object.
- Examples::
>>> ot = VarsTranslation(cc, aa) >>> c, a = ot >>> assert c is cc >>> assert a is aa
-
property
addons
¶ - Overview:
Addon objects for the sub translations.
-
property
code
¶ - Overview:
String translated code.
BaseTranslator¶
-
class
potc.translate.trans.
BaseTranslator
(extend_rules=None)[source]¶ - Overview:
Base translator for the common translation cases.
This class is based on
_AbstractTranslator
, contains only system-leveled and default object-leveled translation rules.
-
__init__
(extend_rules=None)[source]¶ - Overview:
Constructor of
BaseTranslator
.- Arguments:
extend_rules: Rules for base translator.
-
transobj
(obj) → potc.translate.trans.ObjectTranslation¶ - Overview:
Do translation to the given object
obj
.- Arguments:
obj: Object to be translated.
- Returns:
result (
ObjectTranslation
): Result of object translation.
-
transvars
(vars_: Mapping[str, Any], reformat=None, isort: bool = True) → potc.translate.trans.VarsTranslation¶ - Overview:
Do translation to the given variables
vars_
, and create a runnable code.- Arguments:
vars_ (
Mapping[str, Any]
): Variables to be translated.- reformat: Reformatter for the final source code, default is
None
which means do not reformat the code.
- reformat: Reformatter for the final source code, default is
isort (
bool
): Sort the import statements, default isTrue
.
- Returns:
result (
VarsTranslation
): Result of vars translation.
BlankTranslator¶
-
class
potc.translate.trans.
BlankTranslator
(extend_rules=None)[source]¶ - Overview:
Blank translator for the common translation cases.
This class is based on
BaseTranslator
, contains all the native rules in this project. May be the best choice for DIY and testings.
Note
The rules from the plugins will be not be here, and will certainly not be applied when translation is processed.
-
__init__
(extend_rules=None)[source]¶ - Overview:
Constructor of
BlankTranslator
.- Arguments:
extend_rules: Rules for base translator.
-
transobj
(obj) → potc.translate.trans.ObjectTranslation¶ - Overview:
Do translation to the given object
obj
.- Arguments:
obj: Object to be translated.
- Returns:
result (
ObjectTranslation
): Result of object translation.
-
transvars
(vars_: Mapping[str, Any], reformat=None, isort: bool = True) → potc.translate.trans.VarsTranslation¶ - Overview:
Do translation to the given variables
vars_
, and create a runnable code.- Arguments:
vars_ (
Mapping[str, Any]
): Variables to be translated.- reformat: Reformatter for the final source code, default is
None
which means do not reformat the code.
- reformat: Reformatter for the final source code, default is
isort (
bool
): Sort the import statements, default isTrue
.
- Returns:
result (
VarsTranslation
): Result of vars translation.
autotrans¶
-
potc.translate.trans.
autotrans
(trans: Union[potc.translate.trans.BaseTranslator, Type[potc.translate.trans.BaseTranslator], list, tuple]) → potc.translate.trans.BaseTranslator[source]¶ - Overview:
Turn the given object
trans
to aBaseTranslator
instance.- Arguments:
trans (
Union[BaseTranslator, Type[BaseTranslator], list, tuple]
): Any object to be transformed toBaseTranslator
instance.
- Returns:
translator (
BaseTranslator
): Translator instance which can be directly used.