Package g4ds :: Module messagewrapper :: Class GenericWrapper
[show private | hide private]
[frames | no frames]

Class GenericWrapper

Known Subclasses:
ControlMessageWrapper, MessageWrapper, PolicyFileWrapper, RoutingTableWrapper

Wrapper for generic functionality.

Wrapping for things like an action and data.
Method Summary
  __init__(self)
Yet empty constructor.
String and String unwrapActionAndData(self, rootnode, message, decodeHex)
Unwraps a messge as assembled with wrapActionAndData before.
  unwrapArgsAndDatas(self, rootname, message)
Extracts actions and data.
  wrapActionAndData(self, rootnode, action, data, encodeHex)
Comparable with a function call.
  wrapArgsAndDatas(self, root, args, datas)
Wraps a message with one root element, several args and several cdatas.
String _decodeHex(self, message, decompress)
Inverse function for _encodeHex.
String _encodeHex(self, message, compress)
Replaces the function _replaceCdata, which was not really a nice and sober solution for the nested CData sections problem.
String _replaceCdata(self, message)
Replaces CData section keywords by pre-defined substitutes.
String _unReplaceCdata(self, message)
Inverse function of _replaceCdata

Method Details

__init__(self)
(Constructor)

Yet empty constructor.

unwrapActionAndData(self, rootnode, message, decodeHex=0)

Unwraps a messge as assembled with wrapActionAndData before.
Parameters:
rootnode - Name of the rootnode inside the message
           (type=String)
message - XML message
           (type=String)
decodeHex - Was the message hex encoded when assembled? Decode it with this parameter
           (type=Boolean)
Returns:
The action and the data extracted from the XML fragment
           (type=String and String)

unwrapArgsAndDatas(self, rootname, message)

Extracts actions and data.

wrapActionAndData(self, rootnode, action, data, encodeHex=0)

Comparable with a function call.

Action is wrapped as a text node, data in a CDATA section.
Parameters:
rootnode - Name of the root node to create
           (type=String)
action - Name of the action in string representation
           (type=String)
data - Any data to be wrapped (may even be binary data)
           (type=String)
encodeHex - Shall the data be hex encoded before put into the CDATA section
           (type=Boolean)

wrapArgsAndDatas(self, root, args=None, datas=None)

Wraps a message with one root element, several args and several cdatas.

_decodeHex(self, message, decompress=1)

Inverse function for _encodeHex. This way replaces _unReplaceCdata.

Converts a hex code string back into its original real data. Two characters of hex code will represented one character in the output; hence, the given message must have a lenght of an even number.

Due to size constraint with the multiple wrappings compression was put into place. Check the explanaitions in _encodeHex for further details. Control decompression with the parameter decompress. By default, decompression is switched on.
Parameters:
message - String of pairs of hex values exactly as produced by _encodeHex
           (type=String)
decompress - Is the data inside the hex encoded area gzib compressed
           (type=Boolean)
Returns:
Original String - half the length of the passed string.
           (type=String)

_encodeHex(self, message, compress=1)

Replaces the function _replaceCdata, which was not really a nice and sober solution for the nested CData sections problem.

CData sections in XML documents must not be nested. Before any new CData section is created, this function should be invoked for "encoding" the data to put into the CData section. The encoded version of the message will be a string of hex values, each character in the source string is prepresented by two characters in the return string.

A problem arised when using this approach due to the multiple wrappings for single messages. The messages have significantly blown up in size and could not be transmitted properly. To overcome these problems, compressing has been put in place. This way, before the data is hex encoded it will be compressed using the zlib python libraries. The oposite procedure was put in place for _decodeHex - this way, it's totally transparent to the calling application. Control the use of compression with the parameter compress; by default compression is enabled now.
Parameters:
message - XML String, in which shall be encoded
           (type=String)
compress - Shall the data be gzip compressed before hex encoding
           (type=Boolean)
Returns:
A string of hex values representing the ASCII numbers of the source string
           (type=String)

_replaceCdata(self, message)

Replaces CData section keywords by pre-defined substitutes.

CData sections in XML documents must not be nested. Before any new CData section is created, this function should be invoked for "encoding" inner CData section and substituting the indicator beginning and end strings.

It can now also handle nested, nested, ... CData sections.
Parameters:
message - XML String, in which the CDATA sections shall be replaced.
           (type=String)
Returns:
XML String, in which the CDATA sections are replaced. (Be careful - this is not a valid XML String anymore. However, it should be inside a CDATA section afterwards, which makes it a valid XML string again.)
           (type=String)

Note: DEPRECATED. Use _encodeHex and _decodeHex instead.

_unReplaceCdata(self, message)

Inverse function of _replaceCdata

Ones, CDATA section keywords have been replaced, there must be a way to get them back. That's exactly what this function is doing. Of course, nested CDATA sections are supported in here as well.
Parameters:
message - XML String, in which the CDATA sections shall be recovered
           (type=String)
Returns:
XML String, in which CDATA sections have been recovered
           (type=String)

Note: DEPRECATED. Use _encodeHex and _decodeHex instead.


Generated by Epydoc 2.0 on Sat Oct 22 22:52:46 2005 http://epydoc.sf.net