Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python2..../xml/sax
File: __init__.py
"""Simple API for XML (SAX) implementation for Python.
[0] Fix | Delete
[1] Fix | Delete
This module provides an implementation of the SAX 2 interface;
[2] Fix | Delete
information about the Java version of the interface can be found at
[3] Fix | Delete
http://www.megginson.com/SAX/. The Python version of the interface is
[4] Fix | Delete
documented at <...>.
[5] Fix | Delete
[6] Fix | Delete
This package contains the following modules:
[7] Fix | Delete
[8] Fix | Delete
handler -- Base classes and constants which define the SAX 2 API for
[9] Fix | Delete
the 'client-side' of SAX for Python.
[10] Fix | Delete
[11] Fix | Delete
saxutils -- Implementation of the convenience classes commonly used to
[12] Fix | Delete
work with SAX.
[13] Fix | Delete
[14] Fix | Delete
xmlreader -- Base classes and constants which define the SAX 2 API for
[15] Fix | Delete
the parsers used with SAX for Python.
[16] Fix | Delete
[17] Fix | Delete
expatreader -- Driver that allows use of the Expat parser with SAX.
[18] Fix | Delete
"""
[19] Fix | Delete
[20] Fix | Delete
from xmlreader import InputSource
[21] Fix | Delete
from handler import ContentHandler, ErrorHandler
[22] Fix | Delete
from _exceptions import SAXException, SAXNotRecognizedException, \
[23] Fix | Delete
SAXParseException, SAXNotSupportedException, \
[24] Fix | Delete
SAXReaderNotAvailable
[25] Fix | Delete
[26] Fix | Delete
[27] Fix | Delete
def parse(source, handler, errorHandler=ErrorHandler()):
[28] Fix | Delete
parser = make_parser()
[29] Fix | Delete
parser.setContentHandler(handler)
[30] Fix | Delete
parser.setErrorHandler(errorHandler)
[31] Fix | Delete
parser.parse(source)
[32] Fix | Delete
[33] Fix | Delete
def parseString(string, handler, errorHandler=ErrorHandler()):
[34] Fix | Delete
try:
[35] Fix | Delete
from cStringIO import StringIO
[36] Fix | Delete
except ImportError:
[37] Fix | Delete
from StringIO import StringIO
[38] Fix | Delete
[39] Fix | Delete
if errorHandler is None:
[40] Fix | Delete
errorHandler = ErrorHandler()
[41] Fix | Delete
parser = make_parser()
[42] Fix | Delete
parser.setContentHandler(handler)
[43] Fix | Delete
parser.setErrorHandler(errorHandler)
[44] Fix | Delete
[45] Fix | Delete
inpsrc = InputSource()
[46] Fix | Delete
inpsrc.setByteStream(StringIO(string))
[47] Fix | Delete
parser.parse(inpsrc)
[48] Fix | Delete
[49] Fix | Delete
# this is the parser list used by the make_parser function if no
[50] Fix | Delete
# alternatives are given as parameters to the function
[51] Fix | Delete
[52] Fix | Delete
default_parser_list = ["xml.sax.expatreader"]
[53] Fix | Delete
[54] Fix | Delete
# tell modulefinder that importing sax potentially imports expatreader
[55] Fix | Delete
_false = 0
[56] Fix | Delete
if _false:
[57] Fix | Delete
import xml.sax.expatreader
[58] Fix | Delete
[59] Fix | Delete
import os, sys
[60] Fix | Delete
if not sys.flags.ignore_environment and "PY_SAX_PARSER" in os.environ:
[61] Fix | Delete
default_parser_list = os.environ["PY_SAX_PARSER"].split(",")
[62] Fix | Delete
del os
[63] Fix | Delete
[64] Fix | Delete
_key = "python.xml.sax.parser"
[65] Fix | Delete
if sys.platform[:4] == "java" and sys.registry.containsKey(_key):
[66] Fix | Delete
default_parser_list = sys.registry.getProperty(_key).split(",")
[67] Fix | Delete
[68] Fix | Delete
[69] Fix | Delete
def make_parser(parser_list = []):
[70] Fix | Delete
"""Creates and returns a SAX parser.
[71] Fix | Delete
[72] Fix | Delete
Creates the first parser it is able to instantiate of the ones
[73] Fix | Delete
given in the list created by doing parser_list +
[74] Fix | Delete
default_parser_list. The lists must contain the names of Python
[75] Fix | Delete
modules containing both a SAX parser and a create_parser function."""
[76] Fix | Delete
[77] Fix | Delete
for parser_name in parser_list + default_parser_list:
[78] Fix | Delete
try:
[79] Fix | Delete
return _create_parser(parser_name)
[80] Fix | Delete
except ImportError,e:
[81] Fix | Delete
import sys
[82] Fix | Delete
if parser_name in sys.modules:
[83] Fix | Delete
# The parser module was found, but importing it
[84] Fix | Delete
# failed unexpectedly, pass this exception through
[85] Fix | Delete
raise
[86] Fix | Delete
except SAXReaderNotAvailable:
[87] Fix | Delete
# The parser module detected that it won't work properly,
[88] Fix | Delete
# so try the next one
[89] Fix | Delete
pass
[90] Fix | Delete
[91] Fix | Delete
raise SAXReaderNotAvailable("No parsers found", None)
[92] Fix | Delete
[93] Fix | Delete
# --- Internal utility methods used by make_parser
[94] Fix | Delete
[95] Fix | Delete
if sys.platform[ : 4] == "java":
[96] Fix | Delete
def _create_parser(parser_name):
[97] Fix | Delete
from org.python.core import imp
[98] Fix | Delete
drv_module = imp.importName(parser_name, 0, globals())
[99] Fix | Delete
return drv_module.create_parser()
[100] Fix | Delete
[101] Fix | Delete
else:
[102] Fix | Delete
def _create_parser(parser_name):
[103] Fix | Delete
drv_module = __import__(parser_name,{},{},['create_parser'])
[104] Fix | Delete
return drv_module.create_parser()
[105] Fix | Delete
[106] Fix | Delete
del sys
[107] Fix | Delete
[108] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function