creoleparser.core

class creoleparser.core.Parser(dialect, method='xhtml', strip_whitespace=False, encoding='utf-8')
__init__(dialect, method='xhtml', strip_whitespace=False, encoding='utf-8')

Constructor for Parser objects

Parameters:
dialect

Usually created using creoleparser.dialects.create_dialect()

method

This value is passed to Genshies Steam.render(). Possible values include xhtml, html, xml, and text.

strip_whitespace

This value is passed to Genshies Steam.render().

encoding

This value is passed to Genshies Steam.render().

generate(text, element_store=None, context='block', environ=None)

Returns a Genshi Stream.

Parameters:
text

The text to be parsed.

context

This is useful for marco development where (for example) supression of paragraph tags is desired. Can be ‘inline’, ‘block’, or a list of WikiElement objects (use with caution).

element_store

Internal dictionary that’s passed around a lot ;)

environ

This can be any type of object. It will be passed to macro_func unchanged (for a description of macro_func, see create_dialect()).

render(text, element_store=None, context='block', environ=None, **kwargs)

Returns the final output string (e.g., xhtml). See generate() for named parameter descriptions.

Left over keyword arguments (kwargs) will be passed to Genshi’s Stream.render() method, overriding the corresponding attributes of the Parser object. For more infomation on Streams, see the Genshi documentation.

__call__(text, **kwargs)
Wrapper for the render method. Returns final output string.
class creoleparser.core.ArgParser(dialect, convert_implicit_lists=True, key_func=None, illegal_keys=(), convert_unicode_keys=True)

Creates a callable object for parsing macro argument strings

>>> from dialects import creepy20_base
>>> my_parser = ArgParser(dialect=creepy20_base())
>>> my_parser(" one two foo='three' boo='four' ")
(['one', 'two'], {'foo': 'three', 'boo': 'four'})

A parser returns a two-tuple, the first item being a list of positional arguments and the second a dictionary of keyword arguments. Argument values are either strings or lists.

__init__(dialect, convert_implicit_lists=True, key_func=None, illegal_keys=(), convert_unicode_keys=True)

Constructor for ArgParser objects

Parameters:
convert_unicode_keys

If True, keys will be converted using str(key) before being added to the output dictionary. This allows the dictionary to be safely passed to functions using the special ** form (i.e., func(**kwargs)).

dialect

Usually created using creepy10_base() or creepy20_base()

convert_implicit_lists

If True, all implicit lists will be converted to strings using ' '.join(list). “Implicit” lists are created when positional arguments follow keyword arguments (see creepy10_base()).

illegal_keys

A tuple of keys that will be post-fixed with an underscore if found during parsing.

key_func

If supplied, this function will be used to transform the names of keyword arguments. It must accept a single positional argument. For example, this can be used to make keywords case insensitive:

>>> from string import lower
>>> from dialects import creepy20_base
>>> my_parser = ArgParser(dialect=creepy20_base(),key_func=lower)
>>> my_parser(" Foo='one' ")
([], {'foo': 'one'})
__call__(arg_string, **kwargs)

Parses the arg_string returning a two-tuple

Keyword arguments (kwargs) can be used to override the corresponding attributes of the ArgParser object (see above). However, the dialect attribute cannot be overridden.

Previous topic

creoleparser.dialects

This Page