spug.web.cxml
index
/home/mmuller/w/spug/web/cxml.py

Module for converting CXML documents to XML.

 
Modules
       
re
string
web.xmlo

 
Classes
       
exceptions.Exception(exceptions.BaseException)
web.cxml.ParseError
web.cxml.BadEscapeSeq
web.cxml.CXMLParser
web.cxml.CXMLConverter
web.cxml.ElementParser
web.cxml.ElementFactory
web.cxml.DefaultElementFactory
web.cxml.Token
web.cxml.Toker

 
class BadEscapeSeq(ParseError)
    Raised when a bad escape sequence (backslash followed by a character)
is encountered.
 
 
Method resolution order:
BadEscapeSeq
ParseError
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods inherited from ParseError:
__init__(self, token, *parms)
__str__(self)

Data descriptors inherited from ParseError:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object at 0x8140ce0>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message
exception message

 
class CXMLConverter(CXMLParser)
    Converts CXML directly to XML on an output stream.
 
  Methods defined here:
__init__(self, src, dst, srcName='<file>', initLineNum=1)
fixAttrVal(self, attrVal)
"Fixes" an attribute value by replacing all forbidden characters
with acceptable ones.
handleAttrDef(self, attr, val, srcName, lineNum)
handleAttrWS(self, val)
handleCDataEnd(self)
handleCDataStart(self)
handleCharData(self, data)
handleCommentEnd(self)
handleCommentStart(self)
handleContentStart(self)
handleElemEnd(self)
handleElemStart(self, elemName, srcName, lineNum)
handleEntityRef(self, val)
handlePIEnd(self)
handlePIStart(self)
handleSpecialData(self, data)

Methods inherited from CXMLParser:
fixCharData(self, tok)
Fixes character data by escaping markup start chars and unescaping
CXML escape sequences.
handleContentEnd(self)
Called when element content is finished.
parse(self)
parseAttrDef(self, attrName)
Parses an attribute definition through the following comma
or end paren.  Returns true if there are more attribute definitions
to come.
 
parms:
   attrName::
      [string]
parseElem(self, elemName)
parseElems(self, nested)
Parses all alements
 
parms:
   nested::
      [boolean] true if we are in a nested context - if not nested,
      a bare '}' raises an exception.
parseLiteral(self, begin, end, endTok)
Parse any of the special "literal" tags that contain no markup
(processing instructions, comments and CDATA).
 
parms:
   begin::
      [callable<>] function to call before content.
   end::
      [callable<>] function to call after content.
   endTag::
      [int] type of token signalling the end of the literal.

 
class CXMLParser
    Parses CXML.  This is an abstract base class.  Derived classes must
implement all "handle" methods.
 
  Methods defined here:
__init__(self, src, srcName='<file>', initLineNum=1)
parms:
   src::
      [file.read] source stream
   srcName::
      [string] source file name
   initLineNum::
      [int] initial line number
fixCharData(self, tok)
Fixes character data by escaping markup start chars and unescaping
CXML escape sequences.
handleAttrDef(self, attr, val, srcName, lineNum)
handleAttrWS(self, val)
Called for white space in an attribute list.
handleCDataEnd(self)
handleCDataStart(self)
handleCharData(self, data)
handleCommentEnd(self)
handleCommentStart(self)
handleContentEnd(self)
Called when element content is finished.
handleContentStart(self)
Called when element content is started.
handleElemEnd(self)
Called to terminate the current element.
handleElemStart(self, elemName, srcName, lineNum)
handleEntityRef(self, val)
handlePIEnd(self)
handlePIStart(self)
handleSpecialData(self, data)
This is called for content of a processing instruction, comment, 
or CData block.
parse(self)
parseAttrDef(self, attrName)
Parses an attribute definition through the following comma
or end paren.  Returns true if there are more attribute definitions
to come.
 
parms:
   attrName::
      [string]
parseElem(self, elemName)
parseElems(self, nested)
Parses all alements
 
parms:
   nested::
      [boolean] true if we are in a nested context - if not nested,
      a bare '}' raises an exception.
parseLiteral(self, begin, end, endTok)
Parse any of the special "literal" tags that contain no markup
(processing instructions, comments and CDATA).
 
parms:
   begin::
      [callable<>] function to call before content.
   end::
      [callable<>] function to call after content.
   endTag::
      [int] type of token signalling the end of the literal.

 
class DefaultElementFactory(ElementFactory)
    The most basic form of @ElementFactory, only creates 
@spug.web.xmlo.Element instances.
 
  Methods defined here:
makeElement(self, name, actualNS)
Implements @ElementFactory.makeElement()

 
class ElementFactory
    Abstract base class for element factories - used to create specific
@spug.web.xmlo.Element derived classes.
 
  Methods defined here:
makeElement(self, name, actualNS)
Creates and returns a new element object (@spug.web.xmlo.Element
derivative).
 
Must be implemented by derived class.
 
parms:
   name::
      [string or tuple<string, string>] new element name.
      If a tuple, this is the explicit namespace URL and the local 
      name.
   actualNS::
      [string or None] The actual namespace of the element.

 
class ElementParser(CXMLParser)
    Creates a @spug.web.xmlo.Element tree from the parsed CXML.
 
  Methods defined here:
__init__(self, src, elementFactory=<web.cxml.DefaultElementFactory instance at 0x402ab68c>, srcName='<file>', initLineNum=1)
parms:
   src::
      [file.read] source stream
   elementFactory::
      [@ElementFactory] factory used to create element objects.
   srcName::
      [string] source file or stream name
   initLineNum::
      [int] initial line number
getRootElem(self)
handleAttrDef(self, attr, val, srcName, lineNum)
handleCDataEnd(self)
handleCDataStart(self)
handleCharData(self, data)
handleContentStart(self)
Called when element content is started.
handleElemEnd(self)
Called to terminate the current element.
handleElemStart(self, elemName, srcName, lineNum)
handleEntityRef(self, val)
handleSpecialData(self, data)
This is called for content of a processing instruction, comment, 
or CData block.

Methods inherited from CXMLParser:
fixCharData(self, tok)
Fixes character data by escaping markup start chars and unescaping
CXML escape sequences.
handleAttrWS(self, val)
Called for white space in an attribute list.
handleCommentEnd(self)
handleCommentStart(self)
handleContentEnd(self)
Called when element content is finished.
handlePIEnd(self)
handlePIStart(self)
parse(self)
parseAttrDef(self, attrName)
Parses an attribute definition through the following comma
or end paren.  Returns true if there are more attribute definitions
to come.
 
parms:
   attrName::
      [string]
parseElem(self, elemName)
parseElems(self, nested)
Parses all alements
 
parms:
   nested::
      [boolean] true if we are in a nested context - if not nested,
      a bare '}' raises an exception.
parseLiteral(self, begin, end, endTok)
Parse any of the special "literal" tags that contain no markup
(processing instructions, comments and CDATA).
 
parms:
   begin::
      [callable<>] function to call before content.
   end::
      [callable<>] function to call after content.
   endTag::
      [int] type of token signalling the end of the literal.

 
class ParseError(exceptions.Exception)
    Public-vars:
   token::
      [@Token] token specifying the location of the error
 
 
Method resolution order:
ParseError
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, token, *parms)
__str__(self)

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object at 0x8140ce0>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message
exception message

 
class Token
     Methods defined here:
__init__(self, id, val, srcName, lineNum)
__str__(self)

 
class Toker
     Methods defined here:
__init__(self, src, srcName='<file>', initLineNum=1)
parms:
   src::
      [file.readline] source for tokenizer
   srcName::
      [string] source name
   initLineNum::
      [int] initial line number
__iter__(self)
next(self)

Data and other attributes defined here:
CDATA = 0
COMMA = 12
COMMENT = 15
DQSTRING = 7
END = -1
ENDCDATA = 18
ENDCOMMENT = 16
ENDPI = 14
ENTITYREF = 19
EQUALS = 4
EXPCDATA = 17
LCURL = 5
LPAREN = 2
NAME = 11
PI = 13
RCURL = 6
RPAREN = 3
SEMICOLON = 10
SQSTRING = 8
ST_CDATA = 0
ST_COMMENT = 3
ST_ENTITY = 5
ST_EXPCDATA = 4
ST_MARKUP = 1
ST_PI = 2
TAG = 1
WS = 9