4Suite API Documentation

Module amara.binderytools

Convenience functions for using the Amara bindery.
Classes:
Functions:
Globals:

Classes

class element_skeleton_rule(xpattern_rule_base)
An Amara bindery rule. Bindery rules allow developers to customize how XML documents are translated to Python objects.
This rule is pattern based.  Elements that match the pattern and their
children  will be bound as elements only, with no child character data
preserved.  Use this when you only care about the element structure and
want to save resources by not loading the character data.

The default pattern is '*', meaning all elements.

Methods

__init__(self, xpatterns=None)
Overrides: __init__ from class xpattern_rule_base
apply(self, binder)

Methods inherited from class xpattern_rule_base

Methods inherited from class object

__delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Members

event_type = 3
priority = 20

Members inherited from class xpattern_rule_base

Members inherited from class object

__class__
class omit_element_rule(xpattern_rule_base)
An Amara bindery rule. Bindery rules allow developers to customize how XML documents are translated to Python objects.
This rule is pattern based.  Elements that match the pattern will
be ignored and not bound to any object at all, saving memory.

There is no default pattern.  You must specify one.

Methods

apply(self, binder)

Methods inherited from class xpattern_rule_base

Methods inherited from class object

__delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Members

event_type = 3
priority = -40

Members inherited from class xpattern_rule_base

Members inherited from class object

__class__
class saxbind_chunker(amara.bindery.binder, amara.saxtools.sax2dom_chunker)
Note: Ignores nodes prior to the document element, such as PIs and text nodes. Collapses CDATA sections into plain text Only designed to work if you set the feature sax.handler.feature_namespaces to 1 on the parser you use.
xpatterns - list of XSLT Patterns.  Only portions of the
    tree within these patterns will be instantiated as DOM (as
    chunks fed to chunk_consumer in sequence)
    If None (the default, a DOM node will be created representing
    the entire tree.

prefixes - a dictionary of prefix -> namespace name mappings used to
    interpret XPatterns

chunk_consumer - a callable object taking an XML root object.  It will be
    invoked as each chunk is prepared.

Methods

__init__(self, xpatterns=None, prefixes=None, chunk_consumer=None, rules=None, event_hook=None)
Overrides: __init__ from class binder
characters(self, chars)
Overrides: characters from class binder
endDocument(self)
Overrides: endDocument from class binder
endElementNS(self, (ns, local), qname)
Overrides: endElementNS from class binder
startDocument(self)
#Overridden ContentHandler methods
Overrides: startDocument from class binder
startElementNS(self, (ns, local), qname, attribs)
Overrides: startElementNS from class binder

Methods inherited from class amara.bindery.binder

Methods inherited from class amara.pyxml_standins.LexicalHandler

Methods inherited from class object

__delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Methods inherited from class amara.saxtools.sax2dom_chunker

Methods inherited from class xml.sax.handler.ContentHandler

endElement, endPrefixMapping, ignorableWhitespace, setDocumentLocator, skippedEntity, startElement

Members inherited from class amara.bindery.binder

Members inherited from class object

__class__
class simple_string_element_rule(xpattern_rule_base)
An Amara bindery rule. Bindery rules allow developers to customize how XML documents are translated to Python objects.
This rule is pattern based.  Elements that match the pattern will
be bound as simple Python unicode objects, rather than full
element objects, saving memory.

There is no default pattern.  You must specify one.

Methods

apply(self, binder)

Methods inherited from class xpattern_rule_base

Methods inherited from class object

__delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Members

event_type = 3
priority = -30

Members inherited from class xpattern_rule_base

Members inherited from class object

__class__
class type_inference(xpattern_rule_base)
An Amara bindery rule. Bindery rules allow developers to customize how XML documents are translated to Python objects.
This rule is pattern based.  Children of elements that match
the pattern are checked to see if they could be a more specialized
type, such as int, float or date

The default pattern is '*', meaning all elements.

Methods

__init__(self, xpatterns=None)
Overrides: __init__ from class xpattern_rule_base
apply(self, binder)

Methods inherited from class xpattern_rule_base

Methods inherited from class object

__delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Members

event_type = 3
priority = 30

Members inherited from class xpattern_rule_base

Members inherited from class object

__class__
class ws_strip_element_rule(xpattern_rule_base, amara.bindery.default_element_rule)
An Amara bindery rule. Bindery rules allow developers to customize how XML documents are translated to Python objects.
This rule is pattern based.  Elements that match the pattern and
descendants will have text children stripped if they are pure whitespace.
In other words
<a> <b/> <c/> </a>
will end up with the same binding as
<a> <b/> <c/> </a>
but not
<a> <b/> x <c/> </a> <!-- ' x ' is not pure whitespace -->
Stripping whitespace saves memory and can simplify resulting bindings,
but be sure the whitespace doesn't have a significant meeaning in the
document.

The default pattern is '*', meaning all elements.

Methods

__init__(self, xpatterns=None)
Overrides: __init__ from class xpattern_rule_base
apply(self, binder)
Overrides: apply from class default_element_rule

Methods inherited from class xpattern_rule_base

Methods inherited from class object

__delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Members

event_type = 3
priority = -20

Members inherited from class xpattern_rule_base

Members inherited from class object

__class__
class xpattern_rule_base(object)

Methods

__init__(self, xpatterns)
Overrides: __init__ from class object
add_rule_hook(self, binder)
dom_match(self, node, binder)
match(self, binder)

Methods inherited from class object

__delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Members

__dict__ = <attribute '__dict__' of 'xpattern_rule_base' objects>
__weakref__ = <attribute '__weakref__' of 'xpattern_rule_base' objects>

Members inherited from class object

__class__

Functions

bind_file(fname, rules=None, binderobj=None, prefixes=None)
Create a binding from XML read from a file rules - a list of bindery rule objects to fine-tune the binding binderobj - optional binder object to control binding details, the default is None, in which case a binder object will be created prefixes - dictionary mapping prefixes to namespace URIs the default is None
bind_stream(stream, uri=None, rules=None, binderobj=None, prefixes=None)
Create a binding from XML retrieved from a file-like object rules - a list of bindery rule objects to fine-tune the binding binderobj - optional binder object to control binding details, the default is None, in which case a binder object will be created prefixes - dictionary mapping prefixes to namespace URIs the default is None
bind_string(st, uri=None, rules=None, binderobj=None, prefixes=None)
Create a binding from XML in string (NOT unicode) form rules - a list of bindery rule objects to fine-tune the binding binderobj - optional binder object to control binding details, the default is None, in which case a binder object will be created prefixes - dictionary mapping prefixes to namespace URIs the default is None
bind_uri(uri, rules=None, binderobj=None, prefixes=None)
Create a binding from XML retrieved from a URI rules - a list of bindery rule objects to fine-tune the binding binderobj - optional binder object to control binding details, the default is None, in which case a binder object will be created prefixes - dictionary mapping prefixes to namespace URIs the default is None
create_document(qname=None, ns=None, content=None, attributes=None, pubid=None, sysid=None, prefixes=None)
Create a document, with optional convenience arguments to create top-level information items qname - optional QName of the document element (which will be created) if QName is not given, no other arguments may be given ns - optional namespace of the document element content - optional Unicode that makes up text content to be set as the child of the document element pubid - optional public ID of the doctype (to be set on the document) sysid - optional system ID of the doctype (to be set on the document) prefixes - optional set of additional, preferred prefix/namespace mappings for the document to track
fixup_namespaces(node)
reduces namespace clutter in documents by looking for duplicate namespace declarations and preferring those set as document prefixes
infer_data_from_string(value)
pushbind(source, xpatterns, prefixes=None, rules=None, event_hook=None)
Generator that yields subtrees of Python object bindings from XML according to the given pattern. The patterns are must be XSLT patterns matching elements.
Example: for an xml document

XML = '<a> <b><c/></b> <b><c/></b> <b><c/></b> </a>'

pushbind('b', string=XML)
Will return a generator that yields the first, second and third b
element in turn as Python objects containing the full subtree.

Warning: this function uses threads and only works in Python distros
with threading support.

lookahead - how far ahead the SAX engine looks for events before waiting
for the user to request another subtree from the generator.  0 means
the SAX engine will just load and queue up object for
the entire file in the background.
quick_xml_scan(source, field, filter=None, display=None, **kwargs)
Scan through an XML file to extract the first occurrence of single field, without loading more of the file than needed to find the data field - a Uncode object representing an XSLT pattern filter - an optional XPath expression for filtering results from the pattern display - an optional XPath expression indicating what value to display, with the matching node from the pattern as the context

Globals

DATETIME_PAT = <_sre.SRE_Pattern object at 0x8377390>
Compiled regular expression objects
DEFAULT_URI = 'urn:bogus:unknown-resource-uri'
TIME_PAT = <_sre.SRE_Pattern object at 0x8377938>
Compiled regular expression objects