Package EasyExtend :: Package langlets :: Package p4d :: Module p4dbase :: Class P4D
[hide private]
[frames] | no frames]

Class P4D

object --+
         |
        P4D
Known Subclasses:

P4D objects are lazy wrappers around nested lists that store XML or P4D data.

Nested Classes [hide private]
  ListType
Class used to represent lists of P4D objects.
Instance Methods [hide private]
 
__init__(self, tree, parent=None)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
 
_remap(self)
 
__nonzero__(self)
 
update(self)
 
comment(self)
Seeks for single P4D comment object ( characterized by tag = '*' ) and returns its comment text.
 
CDATA(self)
Seeks for single P4D CDATA object ( characterized by tag = '**' ) and returns its CDATA text.
 
xmlstr(self, xml_declaration=False, strip_p4d=True, xmlprinter=<class 'EasyExtend.langlets.p4d.xmlutils.xmlprinter'>)
Creates XML string from current P4D object.
 
p4dstr(self, name='', p4d_kwd=True)
Creates P4D string from current P4D object.
 
search(self, filter_function)
Searches for elements in the children of this P4D node for which filter_function(Item) == True.
 
namespace(self, prefix=None)
 
attributes(self)
Returns all attributes of this P4D element.
str
attribute(self, name)
Attribute accessor of a given name for this P4D element.
 
content(self)
 
text(self)
Returns textual content of this P4D node.
 
first_child(self)
Returns the first child object of this P4D node.
 
children(self, tag=None)
Returns all child P4D nodes of this node.
 
get(self, tag)
Like child(tag) but doesn't raise an exception when child was not found.
 
child(self, tag)
Returns first child P4D node with a given tag.
 
__getattr__(self, tag)
 
__delitem__(self, name)
 
__setattr__(self, name, value)
x.__setattr__('name', value) <==> x.name = value
 
_create_attributes(self, attrs)
 
_extract_from_qname(self, name)
 
_lazy_child_access(self, i)
 
_attr_access(self, key)
 
next(self)
 
object_data(self)
Framework method.
 
__iter__(self)
 
__repr__(self)
repr(x)

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __str__

Class Methods [hide private]
 
from_p4dnode(cls, p4dnode)
Converts P4DNode object into P4D object.
 
eval(self, p4d_str)
Evaluates p4d_str in globals and locals.
 
from_xml(cls, xml_src)
Create P4D object from xml source string.
 
from_html(cls, html_src)
Create P4D object from html source string.
Class Variables [hide private]
  parser = None
  p4d_kwd = False
Properties [hide private]
  _attrs
  _children
  _content
  _idx
  _name
  _parent
  _tree
  tag

Inherited from object: __class__

Method Details [hide private]

__init__(self, tree, parent=None)
(Constructor)

 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Parameters:
  • tree - A tree is a nested list of elements of the kind [TAG, ATTR, CHILDREN, TEXT]. TAG and TEXT are strings, ATTR is a dict and CHILDREN is a list of elements having the same tree structure.
  • parent - the parent P4D object.
Overrides: object.__init__

from_xml(cls, xml_src)
Class Method

 

Create P4D object from xml source string.

Parameters:
  • xml_src - str or unicode object containing xml source.
Returns:
P4D object.

from_html(cls, html_src)
Class Method

 

Create P4D object from html source string.

Parameters:
  • html_src - str or unicode object containing html source.
Returns:
P4D object.

comment(self)

 

Seeks for single P4D comment object ( characterized by tag = '*' ) and returns its comment text.

Returns:
comment text.

CDATA(self)

 

Seeks for single P4D CDATA object ( characterized by tag = '**' ) and returns its CDATA text.

Returns:
CDATA text.

xmlstr(self, xml_declaration=False, strip_p4d=True, xmlprinter=<class 'EasyExtend.langlets.p4d.xmlutils.xmlprinter'>)

 

Creates XML string from current P4D object.

Parameters:
  • xml_declaration - xmlstr prints XML declaration header.
  • strip_p4d - xmlstr performs p4d:xxx -> xxx transformations for elements prefixed by p4d.
  • xmlprinter - optional xmlprinter object. Default is xmlutils.xmlprinter.

p4dstr(self, name='', p4d_kwd=True)

 

Creates P4D string from current P4D object.

Parameters:
  • name - adds assignment of P4D object to name so you don't have to write 'name = ...' yourself.
  • p4d_kwd - Adds `p4d:` prefix in cases where tag or attribute names are P4D keywords.

search(self, filter_function)

 

Searches for elements in the children of this P4D node for which filter_function(Item) == True.

Parameters:
  • filter_function - A function of a single parameter that returns an object of type bool.

attribute(self, name)

 

Attribute accessor of a given name for this P4D element.

Returns: str
attribute value.
Raises:
  • KeyError - if no attribute with the given name is available

    Corresponding P4D syntax:

       A.attribute('b') <==> A.@b
    

first_child(self)

 

Returns the first child object of this P4D node.

Raises:
  • IndexError - if no child element is available

children(self, tag=None)

 

Returns all child P4D nodes of this node.

Parameters:
  • tag - filters nodes according to tag value.
Returns:
P4DList object
Raises:
  • ValueError - if no child element is available with given tag.

    Corresponding P4D syntax:

       A.children('b') <==> A.b
    

get(self, tag)

 

Like child(tag) but doesn't raise an exception when child was not found.

Parameters:
  • tag - filters nodes according to tag value.

child(self, tag)

 

Returns first child P4D node with a given tag.

Parameters:
  • tag - filters nodes according to tag value.
Raises:
  • ValueError - if no child element is available with given tag.

__setattr__(self, name, value)

 

x.__setattr__('name', value) <==> x.name = value

Overrides: object.__setattr__
(inherited documentation)

object_data(self)

 

Framework method. Returns nested list passed to P4D constructor.

__repr__(self)
(Representation operator)

 

repr(x)

Overrides: object.__repr__
(inherited documentation)