module xmlhelper.xml_tree_node
¶
Short summary¶
module pyrsslocal.xmlhelper.xml_tree_node
parsing XML
Classes¶
class |
truncated documentation |
---|---|
Defines a node containing a dictionary. |
Methods¶
method |
truncated documentation |
---|---|
Concatenates every information. |
|
usual |
|
Adopts a table built on anoher object. |
|
Builds _othercount when not present. |
|
some checking |
|
Collapses together all fields having the same name in the member other. |
|
Converts all types into lists. |
|
Replaces all values in the object. |
|
logs an object from the root if not already done |
|
Transfers values to the object self.table. |
|
Adds the content of the node itself (and all included nodes). |
|
private: change names attributes. |
|
Gets a copy. |
|
Enumerates all nodes sharing the same name: tag. |
|
Finds all nodes depending on a regular expression. |
|
Gets all values associated to a given field name. |
|
Gets all values associated to a list of fields (must come together in a single node, not in self.other). |
|
Concatenates every information. |
|
Returns True if it only contains text. |
|
Iterator on the nodes. |
|
Moves all objects to other. |
|
Changes the value of a field. |
|
Strips the buffer. |
Documentation¶
parsing XML
- class pyrsslocal.xmlhelper.xml_tree_node.XMLHandlerDictNode(father, name, level, root=False)¶
Bases:
dict
Defines a node containing a dictionary.
attribute
meaning
father
ancestor
name
name of the section (tag)
buffer
value or content of the section
level
level in the hierarchy
other
included sections
- Parameters:
father – father
name – node name
level – could be infered but still
root – is it the root
- __cmp__(other)¶
- __iadd__(other)¶
Concatenates every information.
- Parameters:
other – other value to concatenate
- Returns:
self
- __init__(father, name, level, root=False)¶
- Parameters:
father – father
name – node name
level – could be infered but still
root – is it the root
- __lt__(other)¶
Return self<value.
- __str__()¶
usual
- _adopt_table(tbl, exception)¶
Adopts a table built on anoher object.
- Parameters:
tbl – same kind of node but including members: - table - conversion_table
exception – if True, raises an exception, log otherwise
Warning
The method could change the object itself if it does not fit.
Warning
The method adds members ‘conversion_table’, ‘add_root_id’
- _build_othercount()¶
Builds _othercount when not present.
- _check_(add_root_id)¶
some checking
- _collapse(use_list)¶
Collapses together all fields having the same name in the member other.
Warning
it should be called after iadd
- _convert_into_list()¶
Converts all types into lists.
- _guess_type(tolerance=0.01, utf8=False)¶
Replaces all values in the object.
- Parameters:
tolerance –
guess_type_list()
utf8 – if True, all types are str
Warning
it should be called after _collapse
- _log_error()¶
logs an object from the root if not already done
- _transfer_to_object(root=True, exception=True)¶
Transfers values to the object self.table.
- Parameters:
root – if True, it is the root
exception – if True, raise ValueError
- Returns:
the value, dictionary of dictionary of list sometimes…
Warning
We assume fid is the key.
Warning
If root.add_root_id is True, is assumes column root_id is root.add_root_id
- add_xml_content(content)¶
Adds the content of the node itself (and all included nodes).
- apply_change_names(change_names)¶
private: change names attributes.
- Parameters:
change_names – { oldname : newname }
- copy()¶
Gets a copy.
- enumerate_on_tag(tag, recursive=False)¶
Enumerates all nodes sharing the same name: tag.
- Parameters:
tag – node name to enumerate on
recursive – if True, looks into node (name == tag) if there are sub-node with the same name
- Returns:
enumeration on node
- find_node(li)¶
- Parameters:
li – list of names
- Returns:
a list of nodes which correspond to the list of names
- find_node_regex(regex)¶
Finds all nodes depending on a regular expression.
- Parameters:
regex – regular expression
- Returns:
list of
[ (node, value) ]
- find_node_value(li)¶
- Parameters:
li – list of names
- Returns:
a list of values
- get_full_name()¶
- Returns:
the list of self.name from all parents
- get_root()¶
- Returns:
the root of the node
- get_values(field)¶
Gets all values associated to a given field name.
- Parameters:
field – field name
- Returns:
list of [ key, value ]
- get_values_group(fields, nb=1)¶
Gets all values associated to a list of fields (must come together in a single node, not in self.other).
- Parameters:
fields – fields name (list or dictionary)
nb – at least nb fields must be filled
- Returns:
list of dictionaries
- get_xml_content()¶
- Returns:
self.xmlcontent
- get_xml_output()¶
- Returns:
an XML output (all lines terminated by end_of_line
- iadd(other, use_list, collapse)¶
Concatenates every information.
- Parameters:
other – other value to concatenate
use_list – use a list or not
collapse – collapse all information
- Returns:
self
- is_text_only()¶
Returns True if it only contains text.
- iterfields()¶
Iterator on the nodes.
- rearrange(debug=False)¶
Moves all objects to other.
- set(i, v)¶
Changes the value of a field.
- Parameters:
i – field
v – new value
- strip()¶
Strips the buffer.