prettytypo package¶
Subpackages¶
Submodules¶
prettytypo.state_stack module¶
- class prettytypo.state_stack.StateDefault(name=None, stack=None)[исходный код]¶
Базовые классы: object
Default State
Use this class as mixin for you own states.
Параметры: Raises: TypeError – if container is not a collection or stack is not a StateStack
- real_name¶
str
name with what it will be registered in :class:.`StateStack`
- init_name¶
str
name that has been given in constructor
- container¶
type
type of chunks and results. It must be a collection
- followers¶
list of str
list of eventual next states (by name)
- stack¶
-
stack that construct this instance
- done¶
bool
is state done for pop from stack?
- __call__(chunk)[исходный код]¶
Call wrapper
This wrapper test chunk type and provide it to call(). If call() return True, store chunk to result.
Параметры: chunk¶ – chunk of data Raises: TypeError – if chunk is not a container type
- back(state)[исходный код]¶
This method is called when children state has poped
Redefine this method to modify and store result of child.
Параметры: state¶ – child state
- call(_)[исходный код]¶
Main method for state
Redefine this method to modify result.
Параметры: chunk¶ – chunk of data Результат: store this chunk to result? Тип результата: bool
- classmethod cond(chunk, state)[исходный код]¶
Condition to push this state
Redefine this class method to provide auto push this state from other, that contains this in followers.
Параметры: Результат: push this state to stack?
Тип результата: bool
- container¶
псевдоним класса list
- end()[исходный код]¶
This method is called when done is True
Redefine this method to modify result before it will be passed to parent state.
- followers = []¶
- real_name = 'default'¶
- class prettytypo.state_stack.StateSet[исходный код]¶
Базовые классы: object
Set of states types
This is same as dict with test of values and default item.
- __getitem__(name)[исходный код]¶
Get state class by StateDefault.real_name
Параметры: name¶ – StateDefault.real_name Результат: state class if there is or StateDefault Тип результата: StateClass
- __len__()[исходный код]¶
Length of state classes
- __setitem__(name, value)[исходный код]¶
Store state class by StateDefault.real_name
Параметры: - name¶ – StateDefault.real_name
- value¶ – state class to store
- class prettytypo.state_stack.StateStack[исходный код]¶
Базовые классы: object
Stack of states
This is a main state machine realization.
- __call__(chunk)[исходный код]¶
Main method of machine
At start test StateDefault.cond() for every state in StateDefault.followers of current and for first True this state is pushed to stack and then chunk provided to its StateDefault.__call__(). If no StateDefault.cond() has return True, chunk provided to StateDefault.__call__() of current.
After test is current StateDefault.done and pop() if True.
Параметры: chunk¶ – chunk of data Raises: LookupError – if stack is empty
- __len__()[исходный код]¶
Length of stack
- current[исходный код]¶
The head of stack
- pop()[исходный код]¶
Pop state from stack
State is poped from stack. Then called StateDefault.end() of it. Finally, if stack is not empty, the poped state provided to StateDefault.back() of stack head.
- push(name)[исходный код]¶
Push state in stack
Get the state class by real_name from registered or StateDefault if there isn’t. Initiate this state with name as StateDefault.init_name and self as StateDefault.stack.
Параметры: name¶ – StateDefault.real_name
- register(state_class)[исходный код]¶
Register a state in machine
Параметры: state_class¶ – state implementation class to register Raises: TypeError – if state_class is not subclass of StateDefault
Module contents¶
Typograph for LaTeX.