⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 saxlib.py

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 PY
📖 第 1 页 / 共 2 页
字号:
"""
This module contains the core classes of version 2.0 of SAX for Python.
This file provides only default classes with absolutely minimum
functionality, from which drivers and applications can be subclassed.

Many of these classes are empty and are included only as documentation
of the interfaces.

$Id$
"""

version = '2.0beta'

# A number of interfaces used to live in saxlib, but are now in
# various other modules for Python 2 compatibility. If nobody uses
# them here any longer, the references can be removed

from handler import ErrorHandler, ContentHandler, DTDHandler, EntityResolver
from xmlreader import XMLReader, InputSource, Locator, IncrementalParser
from _exceptions import *

from handler import \
     feature_namespaces,\
     feature_namespace_prefixes,\
     feature_string_interning,\
     feature_validation,\
     feature_external_ges,\
     feature_external_pes,\
     all_features,\
     property_lexical_handler,\
     property_declaration_handler,\
     property_dom_node,\
     property_xml_string,\
     all_properties

#============================================================================
#
# MAIN INTERFACES
#
#============================================================================

# ===== XMLFILTER =====

class XMLFilter(XMLReader):
    """Interface for a SAX2 parser filter.

    A parser filter is an XMLReader that gets its events from another
    XMLReader (which may in turn also be a filter) rather than from a
    primary source like a document or other non-SAX data source.
    Filters can modify a stream of events before passing it on to its
    handlers."""

    def __init__(self, parent = None):
        """Creates a filter instance, allowing applications to set the
        parent on instantiation."""
        XMLReader.__init__(self)
        self._parent = parent

    def setParent(self, parent):
        """Sets the parent XMLReader of this filter. The argument may
        not be None."""
        self._parent = parent

    def getParent(self):
        "Returns the parent of this filter."
        return self._parent

# ===== ATTRIBUTES =====

class Attributes:
    """Interface for a list of XML attributes.

    Contains a list of XML attributes, accessible by name."""

    def getLength(self):
        "Returns the number of attributes in the list."
        raise NotImplementedError("This method must be implemented!")

    def getType(self, name):
        "Returns the type of the attribute with the given name."
        raise NotImplementedError("This method must be implemented!")

    def getValue(self, name):
        "Returns the value of the attribute with the given name."
        raise NotImplementedError("This method must be implemented!")

    def getValueByQName(self, name):
        """Returns the value of the attribute with the given raw (or
        qualified) name."""
        raise NotImplementedError("This method must be implemented!")

    def getNameByQName(self, name):
        """Returns the namespace name of the attribute with the given
        raw (or qualified) name."""
        raise NotImplementedError("This method must be implemented!")

    def getNames(self):
        """Returns a list of the names of all attributes
        in the list."""
        raise NotImplementedError("This method must be implemented!")

    def getQNames(self):
        """Returns a list of the raw qualified names of all attributes
        in the list."""
        raise NotImplementedError("This method must be implemented!")

    def __len__(self):
        "Alias for getLength."
        raise NotImplementedError("This method must be implemented!")

    def __getitem__(self, name):
        "Alias for getValue."
        raise NotImplementedError("This method must be implemented!")

    def keys(self):
        "Returns a list of the attribute names in the list."
        raise NotImplementedError("This method must be implemented!")

    def has_key(self, name):
        "True if the attribute is in the list, false otherwise."
        raise NotImplementedError("This method must be implemented!")

    def get(self, name, alternative=None):
        """Return the value associated with attribute name; if it is not
        available, then return the alternative."""
        raise NotImplementedError("This method must be implemented!")

    def copy(self):
        "Return a copy of the Attributes object."
        raise NotImplementedError("This method must be implemented!")

    def items(self):
        "Return a list of (attribute_name, value) pairs."
        raise NotImplementedError("This method must be implemented!")

    def values(self):
        "Return a list of all attribute values."
        raise NotImplementedError("This method must be implemented!")


#============================================================================
#
# HANDLER INTERFACES
#
#============================================================================


# ===== DECLHANDLER =====

class DeclHandler:
    """Optional SAX2 handler for DTD declaration events.

    Note that some DTD declarations are already reported through the
    DTDHandler interface. All events reported to this handler will
    occur between the startDTD and endDTD events of the
    LexicalHandler.

    To se the DeclHandler for an XMLReader, use the setProperty method
    with the identifier http://xml.org/sax/handlers/DeclHandler."""

    def attributeDecl(self, elem_name, attr_name, type, value_def, value):
        """Report an attribute type declaration.

        Only the first declaration will be reported. The type will be
        one of the strings "CDATA", "ID", "IDREF", "IDREFS",
        "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", or "NOTATION", or
        a list of names (in the case of enumerated definitions).

        elem_name is the element type name, attr_name the attribute
        type name, type a string representing the attribute type,
        value_def a string representing the default declaration
        ('#IMPLIED', '#REQUIRED', '#FIXED' or None). value is a string
        representing the attribute's default value, or None if there
        is none."""

    def elementDecl(self, elem_name, content_model):
        """Report an element type declaration.

        Only the first declaration will be reported.

        content_model is the string 'EMPTY', the string 'ANY' or the content
        model structure represented as tuple (separator, tokens, modifier)
        where separator is the separator in the token list (that is, '|' or
        ','), tokens is the list of tokens (element type names or tuples
        representing parentheses) and modifier is the quantity modifier
        ('*', '?' or '+')."""

    def internalEntityDecl(self, name, value):
        """Report an internal entity declaration.

        Only the first declaration of an entity will be reported.

        name is the name of the entity. If it is a parameter entity,
        the name will begin with '%'. value is the replacement text of
        the entity."""

    def externalEntityDecl(self, name, public_id, system_id):
        """Report a parsed entity declaration. (Unparsed entities are
        reported to the DTDHandler.)

        Only the first declaration for each entity will be reported.

        name is the name of the entity. If it is a parameter entity,
        the name will begin with '%'. public_id and system_id are the
        public and system identifiers of the entity. public_id will be
        None if none were declared."""



# ===== LEXICALHANDLER =====

class LexicalHandler:
    """Optional SAX2 handler for lexical events.

    This handler is used to obtain lexical information about an XML
    document, that is, information about how the document was encoded

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -