xmlstream
index
/home/kalfa/debian/mypackages/jabber.py/jabber.py-0.5.0/jabber/xmlstream.py

xmlstream.py provides simple functionality for implementing
XML stream based network protocols. It is used as a  base
for jabber.py.
 
xmlstream.py manages the network connectivity and xml parsing
of the stream. When a complete 'protocol element' ( meaning a
complete child of the xmlstreams root ) is parsed the dipatch
method is called with a 'Node' instance of this structure.
The Node class is a very simple XML DOM like class for
manipulating XML documents or 'protocol elements' in this
case.

 
Modules
       
debug
debug
re
socket
sys
time
_xmlplus

 
Classes
       
Node
NodeBuilder
Stream
Client
Server
error

 
class Client(Stream)
    
Method resolution order:
Client
Stream
NodeBuilder

Methods defined here:
__init__(self, host, port, namespace, debug=['always'], log=None, sock=None, id=None, connection=1, hostIP=None, proxy=None)
connect(self)
Attempt to connect to specified host
getSocket(self)

Methods inherited from Stream:
disconnect(self)
Close the stream and socket
disconnectHandler(self, conn)
Called when a Network Error or disconnection occurs.
Designed to be overidden
disconnected(self, conn)
Called when a Network Error or disconnection occurs.
getIncomingID(self)
Returns the streams ID
getOutgoingID(self)
Returns the streams ID
log(self, data, inout='')
Logs data to the specified filehandle. Data is time stamped
and prefixed with inout
process(self, timeout=0)
Receives incoming data (if any) and processes it.
Waits for data no more than timeout seconds.
read(self)
Reads incoming data. Blocks until done. Calls disconnected(self) if appropriate.
timestampLog(self, timestamp)
Enable or disable the showing of a timestamp in the log.
By default, timestamping is enabled.
write(self, raw_data)
Writes raw outgoing data. Blocks until done.
If supplied data is not unicode string, ENCODING
is used for convertion. Avoid this!
Always send your data as a unicode string.

Methods inherited from NodeBuilder:
DEBUG(self, dup1, dup2=None)
dispatch(self, dom)
getDom(self)
handle_data(self, data)
XML Parser callback
unknown_endtag(self, tag)
XML Parser callback
unknown_starttag(self, tag, attrs)
XML Parser callback

 
class Node
    A simple XML DOM like class
 
  Methods defined here:
__init__(self, tag=None, parent=None, attrs={}, payload=[], node=None)
__str__(self)
getAttr(self, key)
Get a value for the nodes named attribute.
getChildren(self)
Returns a nodes children
getData(self)
Return the nodes textual data
getDataAsParts(self)
Return the node data as an array
getName(self)
Set the nodes tag name.
getNamespace(self)
Returns the nodes namespace.
getParent(self)
return the nodes parent node.
getTag(self, name, index=None)
Returns a child node with tag name. Returns None
if not found.
getTags(self, name)
Like getTag but returns a list with matching child nodes
insertData(self, data)
Set the nodes textual data
insertNode(self, node)
Add a child node to the node
insertTag(self, name=None, attrs={}, payload=[], node=None)
Add a child tag of name 'name' to the node.
 
Returns the newly created node.
insertXML(self, xml_str)
Add raw xml as a child of the node
putAttr(self, key, val)
Add a name/value attribute to the node.
putData(self, data)
Set the nodes textual data
removeTag(self, tag)
Pops out specified child and returns it.
setName(self, val)
Set the nodes tag name.
setNamespace(self, namespace)
Set the nodes namespace.
setParent(self, node)
Set the nodes parent node.

 
class NodeBuilder
    builds a 'minidom' from data parsed to it. Primarily for insertXML
method of Node
 
  Methods defined here:
DEBUG(self, dup1, dup2=None)
__init__(self, data=None)
dispatch(self, dom)
getDom(self)
handle_data(self, data)
XML Parser callback
unknown_endtag(self, tag)
XML Parser callback
unknown_starttag(self, tag, attrs)
XML Parser callback

 
class Server
     Methods defined here:
__init__(self, maxclients=10)
now(self)
serve(self)

 
class Stream(NodeBuilder)
    Extention of NodeBuilder class. Handles stream of XML stanzas.
Calls dispatch method for every child of root node
(stream:stream for jabber stream).
attributes _read, _write and _reader must be set by external entity
 
  Methods defined here:
__init__(self, namespace, debug=['always'], log=None, id=None, timestampLog=1)
connect(self)
disconnect(self)
Close the stream and socket
disconnectHandler(self, conn)
Called when a Network Error or disconnection occurs.
Designed to be overidden
disconnected(self, conn)
Called when a Network Error or disconnection occurs.
getIncomingID(self)
Returns the streams ID
getOutgoingID(self)
Returns the streams ID
log(self, data, inout='')
Logs data to the specified filehandle. Data is time stamped
and prefixed with inout
process(self, timeout=0)
Receives incoming data (if any) and processes it.
Waits for data no more than timeout seconds.
read(self)
Reads incoming data. Blocks until done. Calls disconnected(self) if appropriate.
timestampLog(self, timestamp)
Enable or disable the showing of a timestamp in the log.
By default, timestamping is enabled.
write(self, raw_data)
Writes raw outgoing data. Blocks until done.
If supplied data is not unicode string, ENCODING
is used for convertion. Avoid this!
Always send your data as a unicode string.

Methods inherited from NodeBuilder:
DEBUG(self, dup1, dup2=None)
dispatch(self, dom)
getDom(self)
handle_data(self, data)
XML Parser callback
unknown_endtag(self, tag)
XML Parser callback
unknown_starttag(self, tag, attrs)
XML Parser callback

 
class error
     Methods defined here:
__init__(self, value)
__str__(self)

 
Functions
       
XMLescape(txt)
Escape XML entities
XMLunescape(txt)
Unescape XML entities
select(...)
select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)
 
Wait until one or more file descriptors are ready for some kind of I/O.
The first three arguments are lists of file descriptors to be waited for:
rlist -- wait until ready for reading
wlist -- wait until ready for writing
xlist -- wait for an ``exceptional condition''
If only one kind of condition is required, pass [] for the other lists.
A file descriptor is either a socket or file object, or a small integer
gotten from a fileno() method call on one of those.
 
The optional 4th argument specifies a timeout in seconds; it may be
a floating point number to specify fractions of seconds.  If it is absent
or None, the call will never time out.
 
The return value is a tuple of three lists corresponding to the first three
arguments; each contains the subset of the corresponding file descriptors
that are ready.
 
*** IMPORTANT NOTICE ***
On Windows, only sockets are supported; on Unix, all file descriptors.

 
Data
        BLOCK_SIZE = 1024
DBG_ALWAYS = 'always'
DBG_CONN_ERROR = 'conn-error'
DBG_INIT = 'init'
DBG_XML = ['xml-parse', 'xml-raw']
DBG_XML_PARSE = 'xml-parse'
DBG_XML_RAW = 'xml-raw'
ENCODING = 'utf-8'
False = 0
STDIO = 0
TCP = 1
TCP_SSL = 2
True = 1
VERSION = '0.5'