Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../xml/sax
File: handler.py
"""
[0] Fix | Delete
This module contains the core classes of version 2.0 of SAX for Python.
[1] Fix | Delete
This file provides only default classes with absolutely minimum
[2] Fix | Delete
functionality, from which drivers and applications can be subclassed.
[3] Fix | Delete
[4] Fix | Delete
Many of these classes are empty and are included only as documentation
[5] Fix | Delete
of the interfaces.
[6] Fix | Delete
[7] Fix | Delete
$Id$
[8] Fix | Delete
"""
[9] Fix | Delete
[10] Fix | Delete
version = '2.0beta'
[11] Fix | Delete
[12] Fix | Delete
#============================================================================
[13] Fix | Delete
#
[14] Fix | Delete
# HANDLER INTERFACES
[15] Fix | Delete
#
[16] Fix | Delete
#============================================================================
[17] Fix | Delete
[18] Fix | Delete
# ===== ERRORHANDLER =====
[19] Fix | Delete
[20] Fix | Delete
class ErrorHandler:
[21] Fix | Delete
"""Basic interface for SAX error handlers.
[22] Fix | Delete
[23] Fix | Delete
If you create an object that implements this interface, then
[24] Fix | Delete
register the object with your XMLReader, the parser will call the
[25] Fix | Delete
methods in your object to report all warnings and errors. There
[26] Fix | Delete
are three levels of errors available: warnings, (possibly)
[27] Fix | Delete
recoverable errors, and unrecoverable errors. All methods take a
[28] Fix | Delete
SAXParseException as the only parameter."""
[29] Fix | Delete
[30] Fix | Delete
def error(self, exception):
[31] Fix | Delete
"Handle a recoverable error."
[32] Fix | Delete
raise exception
[33] Fix | Delete
[34] Fix | Delete
def fatalError(self, exception):
[35] Fix | Delete
"Handle a non-recoverable error."
[36] Fix | Delete
raise exception
[37] Fix | Delete
[38] Fix | Delete
def warning(self, exception):
[39] Fix | Delete
"Handle a warning."
[40] Fix | Delete
print exception
[41] Fix | Delete
[42] Fix | Delete
[43] Fix | Delete
# ===== CONTENTHANDLER =====
[44] Fix | Delete
[45] Fix | Delete
class ContentHandler:
[46] Fix | Delete
"""Interface for receiving logical document content events.
[47] Fix | Delete
[48] Fix | Delete
This is the main callback interface in SAX, and the one most
[49] Fix | Delete
important to applications. The order of events in this interface
[50] Fix | Delete
mirrors the order of the information in the document."""
[51] Fix | Delete
[52] Fix | Delete
def __init__(self):
[53] Fix | Delete
self._locator = None
[54] Fix | Delete
[55] Fix | Delete
def setDocumentLocator(self, locator):
[56] Fix | Delete
"""Called by the parser to give the application a locator for
[57] Fix | Delete
locating the origin of document events.
[58] Fix | Delete
[59] Fix | Delete
SAX parsers are strongly encouraged (though not absolutely
[60] Fix | Delete
required) to supply a locator: if it does so, it must supply
[61] Fix | Delete
the locator to the application by invoking this method before
[62] Fix | Delete
invoking any of the other methods in the DocumentHandler
[63] Fix | Delete
interface.
[64] Fix | Delete
[65] Fix | Delete
The locator allows the application to determine the end
[66] Fix | Delete
position of any document-related event, even if the parser is
[67] Fix | Delete
not reporting an error. Typically, the application will use
[68] Fix | Delete
this information for reporting its own errors (such as
[69] Fix | Delete
character content that does not match an application's
[70] Fix | Delete
business rules). The information returned by the locator is
[71] Fix | Delete
probably not sufficient for use with a search engine.
[72] Fix | Delete
[73] Fix | Delete
Note that the locator will return correct information only
[74] Fix | Delete
during the invocation of the events in this interface. The
[75] Fix | Delete
application should not attempt to use it at any other time."""
[76] Fix | Delete
self._locator = locator
[77] Fix | Delete
[78] Fix | Delete
def startDocument(self):
[79] Fix | Delete
"""Receive notification of the beginning of a document.
[80] Fix | Delete
[81] Fix | Delete
The SAX parser will invoke this method only once, before any
[82] Fix | Delete
other methods in this interface or in DTDHandler (except for
[83] Fix | Delete
setDocumentLocator)."""
[84] Fix | Delete
[85] Fix | Delete
def endDocument(self):
[86] Fix | Delete
"""Receive notification of the end of a document.
[87] Fix | Delete
[88] Fix | Delete
The SAX parser will invoke this method only once, and it will
[89] Fix | Delete
be the last method invoked during the parse. The parser shall
[90] Fix | Delete
not invoke this method until it has either abandoned parsing
[91] Fix | Delete
(because of an unrecoverable error) or reached the end of
[92] Fix | Delete
input."""
[93] Fix | Delete
[94] Fix | Delete
def startPrefixMapping(self, prefix, uri):
[95] Fix | Delete
"""Begin the scope of a prefix-URI Namespace mapping.
[96] Fix | Delete
[97] Fix | Delete
The information from this event is not necessary for normal
[98] Fix | Delete
Namespace processing: the SAX XML reader will automatically
[99] Fix | Delete
replace prefixes for element and attribute names when the
[100] Fix | Delete
http://xml.org/sax/features/namespaces feature is true (the
[101] Fix | Delete
default).
[102] Fix | Delete
[103] Fix | Delete
There are cases, however, when applications need to use
[104] Fix | Delete
prefixes in character data or in attribute values, where they
[105] Fix | Delete
cannot safely be expanded automatically; the
[106] Fix | Delete
start/endPrefixMapping event supplies the information to the
[107] Fix | Delete
application to expand prefixes in those contexts itself, if
[108] Fix | Delete
necessary.
[109] Fix | Delete
[110] Fix | Delete
Note that start/endPrefixMapping events are not guaranteed to
[111] Fix | Delete
be properly nested relative to each-other: all
[112] Fix | Delete
startPrefixMapping events will occur before the corresponding
[113] Fix | Delete
startElement event, and all endPrefixMapping events will occur
[114] Fix | Delete
after the corresponding endElement event, but their order is
[115] Fix | Delete
not guaranteed."""
[116] Fix | Delete
[117] Fix | Delete
def endPrefixMapping(self, prefix):
[118] Fix | Delete
"""End the scope of a prefix-URI mapping.
[119] Fix | Delete
[120] Fix | Delete
See startPrefixMapping for details. This event will always
[121] Fix | Delete
occur after the corresponding endElement event, but the order
[122] Fix | Delete
of endPrefixMapping events is not otherwise guaranteed."""
[123] Fix | Delete
[124] Fix | Delete
def startElement(self, name, attrs):
[125] Fix | Delete
"""Signals the start of an element in non-namespace mode.
[126] Fix | Delete
[127] Fix | Delete
The name parameter contains the raw XML 1.0 name of the
[128] Fix | Delete
element type as a string and the attrs parameter holds an
[129] Fix | Delete
instance of the Attributes class containing the attributes of
[130] Fix | Delete
the element."""
[131] Fix | Delete
[132] Fix | Delete
def endElement(self, name):
[133] Fix | Delete
"""Signals the end of an element in non-namespace mode.
[134] Fix | Delete
[135] Fix | Delete
The name parameter contains the name of the element type, just
[136] Fix | Delete
as with the startElement event."""
[137] Fix | Delete
[138] Fix | Delete
def startElementNS(self, name, qname, attrs):
[139] Fix | Delete
"""Signals the start of an element in namespace mode.
[140] Fix | Delete
[141] Fix | Delete
The name parameter contains the name of the element type as a
[142] Fix | Delete
(uri, localname) tuple, the qname parameter the raw XML 1.0
[143] Fix | Delete
name used in the source document, and the attrs parameter
[144] Fix | Delete
holds an instance of the Attributes class containing the
[145] Fix | Delete
attributes of the element.
[146] Fix | Delete
[147] Fix | Delete
The uri part of the name tuple is None for elements which have
[148] Fix | Delete
no namespace."""
[149] Fix | Delete
[150] Fix | Delete
def endElementNS(self, name, qname):
[151] Fix | Delete
"""Signals the end of an element in namespace mode.
[152] Fix | Delete
[153] Fix | Delete
The name parameter contains the name of the element type, just
[154] Fix | Delete
as with the startElementNS event."""
[155] Fix | Delete
[156] Fix | Delete
def characters(self, content):
[157] Fix | Delete
"""Receive notification of character data.
[158] Fix | Delete
[159] Fix | Delete
The Parser will call this method to report each chunk of
[160] Fix | Delete
character data. SAX parsers may return all contiguous
[161] Fix | Delete
character data in a single chunk, or they may split it into
[162] Fix | Delete
several chunks; however, all of the characters in any single
[163] Fix | Delete
event must come from the same external entity so that the
[164] Fix | Delete
Locator provides useful information."""
[165] Fix | Delete
[166] Fix | Delete
def ignorableWhitespace(self, whitespace):
[167] Fix | Delete
"""Receive notification of ignorable whitespace in element content.
[168] Fix | Delete
[169] Fix | Delete
Validating Parsers must use this method to report each chunk
[170] Fix | Delete
of ignorable whitespace (see the W3C XML 1.0 recommendation,
[171] Fix | Delete
section 2.10): non-validating parsers may also use this method
[172] Fix | Delete
if they are capable of parsing and using content models.
[173] Fix | Delete
[174] Fix | Delete
SAX parsers may return all contiguous whitespace in a single
[175] Fix | Delete
chunk, or they may split it into several chunks; however, all
[176] Fix | Delete
of the characters in any single event must come from the same
[177] Fix | Delete
external entity, so that the Locator provides useful
[178] Fix | Delete
information."""
[179] Fix | Delete
[180] Fix | Delete
def processingInstruction(self, target, data):
[181] Fix | Delete
"""Receive notification of a processing instruction.
[182] Fix | Delete
[183] Fix | Delete
The Parser will invoke this method once for each processing
[184] Fix | Delete
instruction found: note that processing instructions may occur
[185] Fix | Delete
before or after the main document element.
[186] Fix | Delete
[187] Fix | Delete
A SAX parser should never report an XML declaration (XML 1.0,
[188] Fix | Delete
section 2.8) or a text declaration (XML 1.0, section 4.3.1)
[189] Fix | Delete
using this method."""
[190] Fix | Delete
[191] Fix | Delete
def skippedEntity(self, name):
[192] Fix | Delete
"""Receive notification of a skipped entity.
[193] Fix | Delete
[194] Fix | Delete
The Parser will invoke this method once for each entity
[195] Fix | Delete
skipped. Non-validating processors may skip entities if they
[196] Fix | Delete
have not seen the declarations (because, for example, the
[197] Fix | Delete
entity was declared in an external DTD subset). All processors
[198] Fix | Delete
may skip external entities, depending on the values of the
[199] Fix | Delete
http://xml.org/sax/features/external-general-entities and the
[200] Fix | Delete
http://xml.org/sax/features/external-parameter-entities
[201] Fix | Delete
properties."""
[202] Fix | Delete
[203] Fix | Delete
[204] Fix | Delete
# ===== DTDHandler =====
[205] Fix | Delete
[206] Fix | Delete
class DTDHandler:
[207] Fix | Delete
"""Handle DTD events.
[208] Fix | Delete
[209] Fix | Delete
This interface specifies only those DTD events required for basic
[210] Fix | Delete
parsing (unparsed entities and attributes)."""
[211] Fix | Delete
[212] Fix | Delete
def notationDecl(self, name, publicId, systemId):
[213] Fix | Delete
"Handle a notation declaration event."
[214] Fix | Delete
[215] Fix | Delete
def unparsedEntityDecl(self, name, publicId, systemId, ndata):
[216] Fix | Delete
"Handle an unparsed entity declaration event."
[217] Fix | Delete
[218] Fix | Delete
[219] Fix | Delete
# ===== ENTITYRESOLVER =====
[220] Fix | Delete
[221] Fix | Delete
class EntityResolver:
[222] Fix | Delete
"""Basic interface for resolving entities. If you create an object
[223] Fix | Delete
implementing this interface, then register the object with your
[224] Fix | Delete
Parser, the parser will call the method in your object to
[225] Fix | Delete
resolve all external entities. Note that DefaultHandler implements
[226] Fix | Delete
this interface with the default behaviour."""
[227] Fix | Delete
[228] Fix | Delete
def resolveEntity(self, publicId, systemId):
[229] Fix | Delete
"""Resolve the system identifier of an entity and return either
[230] Fix | Delete
the system identifier to read from as a string, or an InputSource
[231] Fix | Delete
to read from."""
[232] Fix | Delete
return systemId
[233] Fix | Delete
[234] Fix | Delete
[235] Fix | Delete
#============================================================================
[236] Fix | Delete
#
[237] Fix | Delete
# CORE FEATURES
[238] Fix | Delete
#
[239] Fix | Delete
#============================================================================
[240] Fix | Delete
[241] Fix | Delete
feature_namespaces = "http://xml.org/sax/features/namespaces"
[242] Fix | Delete
# true: Perform Namespace processing (default).
[243] Fix | Delete
# false: Optionally do not perform Namespace processing
[244] Fix | Delete
# (implies namespace-prefixes).
[245] Fix | Delete
# access: (parsing) read-only; (not parsing) read/write
[246] Fix | Delete
[247] Fix | Delete
feature_namespace_prefixes = "http://xml.org/sax/features/namespace-prefixes"
[248] Fix | Delete
# true: Report the original prefixed names and attributes used for Namespace
[249] Fix | Delete
# declarations.
[250] Fix | Delete
# false: Do not report attributes used for Namespace declarations, and
[251] Fix | Delete
# optionally do not report original prefixed names (default).
[252] Fix | Delete
# access: (parsing) read-only; (not parsing) read/write
[253] Fix | Delete
[254] Fix | Delete
feature_string_interning = "http://xml.org/sax/features/string-interning"
[255] Fix | Delete
# true: All element names, prefixes, attribute names, Namespace URIs, and
[256] Fix | Delete
# local names are interned using the built-in intern function.
[257] Fix | Delete
# false: Names are not necessarily interned, although they may be (default).
[258] Fix | Delete
# access: (parsing) read-only; (not parsing) read/write
[259] Fix | Delete
[260] Fix | Delete
feature_validation = "http://xml.org/sax/features/validation"
[261] Fix | Delete
# true: Report all validation errors (implies external-general-entities and
[262] Fix | Delete
# external-parameter-entities).
[263] Fix | Delete
# false: Do not report validation errors.
[264] Fix | Delete
# access: (parsing) read-only; (not parsing) read/write
[265] Fix | Delete
[266] Fix | Delete
feature_external_ges = "http://xml.org/sax/features/external-general-entities"
[267] Fix | Delete
# true: Include all external general (text) entities.
[268] Fix | Delete
# false: Do not include external general entities.
[269] Fix | Delete
# access: (parsing) read-only; (not parsing) read/write
[270] Fix | Delete
[271] Fix | Delete
feature_external_pes = "http://xml.org/sax/features/external-parameter-entities"
[272] Fix | Delete
# true: Include all external parameter entities, including the external
[273] Fix | Delete
# DTD subset.
[274] Fix | Delete
# false: Do not include any external parameter entities, even the external
[275] Fix | Delete
# DTD subset.
[276] Fix | Delete
# access: (parsing) read-only; (not parsing) read/write
[277] Fix | Delete
[278] Fix | Delete
all_features = [feature_namespaces,
[279] Fix | Delete
feature_namespace_prefixes,
[280] Fix | Delete
feature_string_interning,
[281] Fix | Delete
feature_validation,
[282] Fix | Delete
feature_external_ges,
[283] Fix | Delete
feature_external_pes]
[284] Fix | Delete
[285] Fix | Delete
[286] Fix | Delete
#============================================================================
[287] Fix | Delete
#
[288] Fix | Delete
# CORE PROPERTIES
[289] Fix | Delete
#
[290] Fix | Delete
#============================================================================
[291] Fix | Delete
[292] Fix | Delete
property_lexical_handler = "http://xml.org/sax/properties/lexical-handler"
[293] Fix | Delete
# data type: xml.sax.sax2lib.LexicalHandler
[294] Fix | Delete
# description: An optional extension handler for lexical events like comments.
[295] Fix | Delete
# access: read/write
[296] Fix | Delete
[297] Fix | Delete
property_declaration_handler = "http://xml.org/sax/properties/declaration-handler"
[298] Fix | Delete
# data type: xml.sax.sax2lib.DeclHandler
[299] Fix | Delete
# description: An optional extension handler for DTD-related events other
[300] Fix | Delete
# than notations and unparsed entities.
[301] Fix | Delete
# access: read/write
[302] Fix | Delete
[303] Fix | Delete
property_dom_node = "http://xml.org/sax/properties/dom-node"
[304] Fix | Delete
# data type: org.w3c.dom.Node
[305] Fix | Delete
# description: When parsing, the current DOM node being visited if this is
[306] Fix | Delete
# a DOM iterator; when not parsing, the root DOM node for
[307] Fix | Delete
# iteration.
[308] Fix | Delete
# access: (parsing) read-only; (not parsing) read/write
[309] Fix | Delete
[310] Fix | Delete
property_xml_string = "http://xml.org/sax/properties/xml-string"
[311] Fix | Delete
# data type: String
[312] Fix | Delete
# description: The literal string of characters that was the source for
[313] Fix | Delete
# the current event.
[314] Fix | Delete
# access: read-only
[315] Fix | Delete
[316] Fix | Delete
property_encoding = "http://www.python.org/sax/properties/encoding"
[317] Fix | Delete
# data type: String
[318] Fix | Delete
# description: The name of the encoding to assume for input data.
[319] Fix | Delete
# access: write: set the encoding, e.g. established by a higher-level
[320] Fix | Delete
# protocol. May change during parsing (e.g. after
[321] Fix | Delete
# processing a META tag)
[322] Fix | Delete
# read: return the current encoding (possibly established through
[323] Fix | Delete
# auto-detection.
[324] Fix | Delete
# initial value: UTF-8
[325] Fix | Delete
#
[326] Fix | Delete
[327] Fix | Delete
property_interning_dict = "http://www.python.org/sax/properties/interning-dict"
[328] Fix | Delete
# data type: Dictionary
[329] Fix | Delete
# description: The dictionary used to intern common strings in the document
[330] Fix | Delete
# access: write: Request that the parser uses a specific dictionary, to
[331] Fix | Delete
# allow interning across different documents
[332] Fix | Delete
# read: return the current interning dictionary, or None
[333] Fix | Delete
#
[334] Fix | Delete
[335] Fix | Delete
all_properties = [property_lexical_handler,
[336] Fix | Delete
property_dom_node,
[337] Fix | Delete
property_declaration_handler,
[338] Fix | Delete
property_xml_string,
[339] Fix | Delete
property_encoding,
[340] Fix | Delete
property_interning_dict]
[341] Fix | Delete
[342] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function