# ``twisted`.`words`.`protocols`.`irc`.`_FormattingParser``

class documentation

`class _FormattingParser(_CommandDispatcherMixin): (source)`

View In Hierarchy

A finite-state machine that parses formatted IRC text.

Currently handled formatting includes: bold, reverse, underline, mIRC color codes and the ability to remove all current formatting.

See Also
http://www.mirc.co.uk/help/color.txt

Method | `__init__` | Undocumented
Method | `complete` | Flush the current buffer and return the final parsed result.
Method | `emit` | Add the currently parsed input to the result.
Method | `process` | Handle input.
Method | `state_COLOR_BACKGROUND` | Handle the background color state.
Method | `state_COLOR_FOREGROUND` | Handle the foreground color state.
Method | `state_TEXT` | Handle the "text" state.
Class Variable | `prefix` | Undocumented
Instance Variable | `background` | Current background color attribute, or `None`.
Instance Variable | `foreground` | Current foreground color attribute, or `None`.
Instance Variable | `state` | Current state of the finite-state machine.
Class Variable | `_formatCodes` | Mapping of format code values to names.
Instance Variable | `_attrs` | Set of the applicable formatting states (bold, underline, etc.) for the current `_buffer`, these are applied to `_buffer` when calling `emit`.
Instance Variable | `_buffer` | Buffer, containing the text content, of the formatting sequence currently being parsed, the buffer is used as the content for `_attrs` before being added to `_result` and emptied upon calling `emit`.
Instance Variable | `_result` | Current parse result.

Inherited from `_CommandDispatcherMixin`:

Method | `dispatch` | Perform actual command dispatch.

def __init__(self): (source)

Undocumented

def complete(self): (source)
Flush the current buffer and return the final parsed result.

Returns
Structured text and attributes.

def emit(self): (source)
Add the currently parsed input to the result.
def process(self, ch): (source)
Handle input.

Parameters
ch:`str` | A single character of input to process

def state_COLOR_BACKGROUND(self, ch): (source)

Handle the background color state.

Background colors can consist of up to two digits and must occur after a foreground color and must be preceded by a ,. Any non-digit character is treated as invalid input and results in the state being set to "text".

Parameters
ch | The character being processed.

def state_COLOR_FOREGROUND(self, ch): (source)

Handle the foreground color state.

Foreground colors can consist of up to two digits and may optionally end in a ,. Any non-digit or non-comma characters are treated as invalid input and result in the state being reset to "text".

Parameters
ch | The character being processed.

def state_TEXT(self, ch): (source)

Handle the "text" state.

Along with regular text, single token formatting codes are handled in this state too.

Parameters
ch | The character being processed.

prefix: `str` = (source)
overrides `twisted.words.protocols.irc._CommandDispatcherMixin.prefix`

Undocumented

background: `_BackgroundColorAttr` = (source)
Current background color attribute, or `None`.
foreground: `_ForegroundColorAttr` = (source)
Current foreground color attribute, or `None`.
state: `str` = (source)
Current state of the finite-state machine.
_formatCodes: `dict` mapping `str` to `str` = (source)
Mapping of format code values to names.
_attrs: `set` = (source)
Set of the applicable formatting states (bold, underline, etc.) for the current `_buffer`, these are applied to `_buffer` when calling `emit`.
_buffer: `str` = (source)
Buffer, containing the text content, of the formatting sequence currently being parsed, the buffer is used as the content for `_attrs` before being added to `_result` and emptied upon calling `emit`.
_result = (source)
Current parse result.