Goulib.markup module

simple HTML/XML generation (forked from markup)

Goulib.markup.cgiprint(line='', unbuff=True, line_end='\r\n')[source]
Print to the stdout. :param line: string to print, followed by line_end :param unbuff: boolean, True to flush the buffer after every write. :param line_end: string to print after each line. By default this is

, which is the standard specified by the RFC for http headers.

Goulib.markup.style_dict2str(style)[source]
Goulib.markup.style_str2dict(style)[source]
Goulib.markup.tag(tag, between, **kwargs)[source]

generate full tag.

class Goulib.markup.element(tag, case='lower', parent=None)[source]

Bases: object

This class handles the addition of a new element.

__init__(tag, case='lower', parent=None)[source]
__call__(*args, **kwargs)[source]
render(t, single, args, **kwargs)[source]

Append the actual tags to content.

close()[source]

Append a closing tag unless element has only opening tag.

open(**kwargs)[source]

Append an opening tag.

__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

class Goulib.markup.page(mode='strict_html', case='lower', onetags=None, twotags=None, separator='n', class_=None)[source]

Bases: object

This is our main class representing a document. Elements are added as attributes of an instance of this class.

Stuff that effects the whole document.

Parameters:mode – string. can be either:
  • ‘strict_html’ for HTML 4.01 (default)
  • ‘html’ alias for ‘strict_html’
  • ‘loose_html’ to allow some deprecated elements
  • ‘xml’ to allow arbitrary elements
Parameters:case – string. can be either:
  • ‘lower’ element names will be printed in lower case (default)
  • ‘upper’ they will be printed in upper case
  • ‘given’ element names will be printed as they are given
Parameters:
  • onetags – list or tuple of valid elements with opening tags only
  • twotags – list or tuple of valid elements with both opening and closing tags

these two keyword arguments may be used to select the set of valid elements in ‘xml’ mode invalid elements will raise appropriate exceptions

Parameters:
  • separator – string to place between added elements, defaults to newline
  • class – a class that will be added to every element if defined
__init__(mode='strict_html', case='lower', onetags=None, twotags=None, separator='\n', class_=None)[source]

Stuff that effects the whole document.

Parameters:mode – string. can be either:
  • ‘strict_html’ for HTML 4.01 (default)
  • ‘html’ alias for ‘strict_html’
  • ‘loose_html’ to allow some deprecated elements
  • ‘xml’ to allow arbitrary elements
Parameters:case – string. can be either:
  • ‘lower’ element names will be printed in lower case (default)
  • ‘upper’ they will be printed in upper case
  • ‘given’ element names will be printed as they are given
Parameters:
  • onetags – list or tuple of valid elements with opening tags only
  • twotags – list or tuple of valid elements with both opening and closing tags

these two keyword arguments may be used to select the set of valid elements in ‘xml’ mode invalid elements will raise appropriate exceptions

Parameters:
  • separator – string to place between added elements, defaults to newline
  • class – a class that will be added to every element if defined
__getattr__(attr)[source]
__str__()[source]
__call__(escape=False)[source]

Return the document as a string.

escape – False print normally
True replace < and > by &lt; and &gt;
the default escape sequences in most browsers
add(text)[source]

This is an alias to addcontent.

addfooter(text)[source]

Add some text to the bottom of the document

addheader(text)[source]

Add some text to the top of the document

addcontent(text)[source]

Add some text to the main part of the document

init(lang='en', css=None, metainfo=None, title=None, header=None, footer=None, charset=None, encoding=None, doctype=None, bodyattrs=None, script=None, base=None)[source]

This method is used for complete documents with appropriate doctype, encoding, title, etc information. For an /XML snippet omit this method.

lang – language, usually a two character string, will appear
as <html lang=’en’> in html mode (ignored in xml mode)
css – Cascading Style Sheet filename as a string or a list of
strings for multiple css files (ignored in xml mode)
metainfo – a dictionary in the form { ‘name’:’content’ } to be inserted
into meta element(s) as <meta name=’name’ content=’content’> (ignored in xml mode)

base – set the <base href=”…”> tag in <head>

bodyattrs –a dictionary in the form { ‘key’:’value’, … } which will be added
as attributes of the <body> element as <body key=’value’ … > (ignored in xml mode)
script – dictionary containing src:type pairs, <script type=’text/type’ src=src></script>
or a list of [ ‘src1’, ‘src2’, … ] in which case ‘javascript’ is assumed for all
title – the title of the document as a string to be inserted into
a title element as <title>my title</title> (ignored in xml mode)
header – some text to be inserted right after the <body> element
(ignored in xml mode)
footer – some text to be inserted right before the </body> element
(ignored in xml mode)
charset – a string defining the character set, will be inserted into a
<meta http-equiv=’Content-Type’ content=’text/html; charset=myset’> element (ignored in xml mode)
encoding – a string defining the encoding, will be put into to first line of
the document as <?xml version=‘1.0’ encoding=’myencoding’ ?> in xml mode (ignored in html mode)
doctype – the document type string, defaults to
<!DOCTYPE HTML PUBLIC ‘-//W3C//DTD HTML 4.01 Transitional//EN’> in html mode (ignored in xml mode)
css(filelist)[source]

This convenience function is only useful for html. It adds css stylesheet(s) to the document via the <link> element.

metainfo(mydict)[source]

This convenience function is only useful for html. It adds meta information via the <meta> element, the argument is a dictionary of the form { ‘name’:’content’ }.

scripts(mydict)[source]

Only useful in html, mydict is dictionary of src:type pairs or a list of script sources [ ‘src1’, ‘src2’, … ] in which case ‘javascript’ is assumed for type. Will be rendered as <script type=’text/type’ src=src></script>

__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

Goulib.markup.escape(text, newline=False)[source]

Escape special html characters.

Goulib.markup.unescape(text)[source]

Inverse of escape.

class Goulib.markup.dummy[source]

Bases: object

A dummy class for attaching attributes.

__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__init__

Initialize self. See help(type(self)) for accurate signature.

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

class Goulib.markup.russell[source]

Bases: object

A dummy class that contains anything.

__contains__(item)[source]
__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__init__

Initialize self. See help(type(self)) for accurate signature.

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

exception Goulib.markup.MarkupError[source]

Bases: Exception

All our exceptions subclass this.

__str__()[source]
__cause__

exception cause

__class__

alias of type

__context__

exception context

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__init__

Initialize self. See help(type(self)) for accurate signature.

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()
__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__setstate__()
__sizeof__() → int

size of object in memory, in bytes

__suppress_context__
__traceback__
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception Goulib.markup.ClosingError(tag)[source]

Bases: Goulib.markup.MarkupError

__init__(tag)[source]
__cause__

exception cause

__class__

alias of type

__context__

exception context

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()
__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__setstate__()
__sizeof__() → int

size of object in memory, in bytes

__str__()
__suppress_context__
__traceback__
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception Goulib.markup.OpeningError(tag)[source]

Bases: Goulib.markup.MarkupError

__init__(tag)[source]
__cause__

exception cause

__class__

alias of type

__context__

exception context

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()
__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__setstate__()
__sizeof__() → int

size of object in memory, in bytes

__str__()
__suppress_context__
__traceback__
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception Goulib.markup.ArgumentError(tag)[source]

Bases: Goulib.markup.MarkupError

__init__(tag)[source]
__cause__

exception cause

__class__

alias of type

__context__

exception context

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()
__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__setstate__()
__sizeof__() → int

size of object in memory, in bytes

__str__()
__suppress_context__
__traceback__
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception Goulib.markup.InvalidElementError(tag, mode)[source]

Bases: Goulib.markup.MarkupError

__cause__

exception cause

__class__

alias of type

__context__

exception context

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__init__(tag, mode)[source]
__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()
__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__setstate__()
__sizeof__() → int

size of object in memory, in bytes

__str__()
__suppress_context__
__traceback__
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception Goulib.markup.DeprecationError(tag)[source]

Bases: Goulib.markup.MarkupError

__cause__

exception cause

__class__

alias of type

__context__

exception context

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()
__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__setstate__()
__sizeof__() → int

size of object in memory, in bytes

__str__()
__suppress_context__
__traceback__
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

__init__(tag)[source]
exception Goulib.markup.ModeError(mode)[source]

Bases: Goulib.markup.MarkupError

__cause__

exception cause

__class__

alias of type

__context__

exception context

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()
__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__setstate__()
__sizeof__() → int

size of object in memory, in bytes

__str__()
__suppress_context__
__traceback__
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

__init__(mode)[source]
exception Goulib.markup.CustomizationError[source]

Bases: Goulib.markup.MarkupError

__cause__

exception cause

__class__

alias of type

__context__

exception context

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()
__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__setstate__()
__sizeof__() → int

size of object in memory, in bytes

__str__()
__suppress_context__
__traceback__
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

__init__()[source]