mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Updated to new *NS signatures (patch 101573).
This commit is contained in:
parent
1258049de0
commit
f43cf31f4a
1 changed files with 25 additions and 25 deletions
|
@ -16,9 +16,9 @@ pyexpat.__version__ == '1.5'.
|
||||||
|
|
||||||
version = "0.20"
|
version = "0.20"
|
||||||
|
|
||||||
|
from xml.sax._exceptions import *
|
||||||
from xml.parsers import expat
|
from xml.parsers import expat
|
||||||
from xml.sax import xmlreader
|
from xml.sax import xmlreader
|
||||||
import xml.sax
|
|
||||||
|
|
||||||
# --- ExpatParser
|
# --- ExpatParser
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
|
||||||
self._parser = None
|
self._parser = None
|
||||||
self._namespaces = namespaceHandling
|
self._namespaces = namespaceHandling
|
||||||
self._parsing = 0
|
self._parsing = 0
|
||||||
|
self._attrs = xmlreader.AttributesImpl({}, {})
|
||||||
|
|
||||||
# XMLReader methods
|
# XMLReader methods
|
||||||
|
|
||||||
|
@ -47,8 +48,7 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
|
||||||
xmlreader.IncrementalParser.parse(self, stream)
|
xmlreader.IncrementalParser.parse(self, stream)
|
||||||
except expat.error:
|
except expat.error:
|
||||||
error_code = self._parser.ErrorCode
|
error_code = self._parser.ErrorCode
|
||||||
raise xml.sax.SAXParseException(expat.ErrorString(error_code),
|
raise SAXParseException(expat.ErrorString(error_code), None, self)
|
||||||
None, self)
|
|
||||||
|
|
||||||
self._cont_handler.endDocument()
|
self._cont_handler.endDocument()
|
||||||
|
|
||||||
|
@ -59,19 +59,23 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
|
||||||
self._parser.SetBase(self._source)
|
self._parser.SetBase(self._source)
|
||||||
|
|
||||||
def getFeature(self, name):
|
def getFeature(self, name):
|
||||||
"Looks up and returns the state of a SAX2 feature."
|
if name == feature_namespaces:
|
||||||
|
return self._namespaces
|
||||||
raise SAXNotRecognizedException("Feature '%s' not recognized" % name)
|
raise SAXNotRecognizedException("Feature '%s' not recognized" % name)
|
||||||
|
|
||||||
def setFeature(self, name, state):
|
def setFeature(self, name, state):
|
||||||
"Sets the state of a SAX2 feature."
|
if self._parsing:
|
||||||
raise SAXNotRecognizedException("Feature '%s' not recognized" % name)
|
raise SAXNotSupportedException("Cannot set features while parsing")
|
||||||
|
if name == feature_namespaces:
|
||||||
|
self._namespaces = state
|
||||||
|
else:
|
||||||
|
raise SAXNotRecognizedException("Feature '%s' not recognized" %
|
||||||
|
name)
|
||||||
|
|
||||||
def getProperty(self, name):
|
def getProperty(self, name):
|
||||||
"Looks up and returns the value of a SAX2 property."
|
|
||||||
raise SAXNotRecognizedException("Property '%s' not recognized" % name)
|
raise SAXNotRecognizedException("Property '%s' not recognized" % name)
|
||||||
|
|
||||||
def setProperty(self, name, value):
|
def setProperty(self, name, value):
|
||||||
"Sets the value of a SAX2 property."
|
|
||||||
raise SAXNotRecognizedException("Property '%s' not recognized" % name)
|
raise SAXNotRecognizedException("Property '%s' not recognized" % name)
|
||||||
|
|
||||||
# IncrementalParser methods
|
# IncrementalParser methods
|
||||||
|
@ -81,8 +85,10 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
|
||||||
self._parsing = 1
|
self._parsing = 1
|
||||||
self.reset()
|
self.reset()
|
||||||
self._cont_handler.startDocument()
|
self._cont_handler.startDocument()
|
||||||
# FIXME: error checking and endDocument()
|
|
||||||
self._parser.Parse(data, 0)
|
if not self._parser.Parse(data, 0):
|
||||||
|
msg = pyexpat.ErrorString(self._parser.ErrorCode)
|
||||||
|
raise SAXParseException(msg, None, self)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if self._parsing:
|
if self._parsing:
|
||||||
|
@ -131,36 +137,30 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
|
||||||
|
|
||||||
# event handlers
|
# event handlers
|
||||||
def start_element(self, name, attrs):
|
def start_element(self, name, attrs):
|
||||||
self._cont_handler.startElement(name, name,
|
self._cont_handler.startElement(name, self._attrs)
|
||||||
xmlreader.AttributesImpl(attrs, attrs))
|
|
||||||
|
|
||||||
def end_element(self, name):
|
def end_element(self, name):
|
||||||
self._cont_handler.endElement(name, name)
|
self._cont_handler.endElement(name)
|
||||||
|
|
||||||
def start_element_ns(self, name, attrs):
|
def start_element_ns(self, name, attrs):
|
||||||
pair = name.split()
|
pair = name.split()
|
||||||
if len(pair) == 1:
|
if len(pair) == 1:
|
||||||
tup = (None, name)
|
pair = (None, name)
|
||||||
else:
|
|
||||||
tup = pair
|
|
||||||
|
|
||||||
self._cont_handler.startElement(tup, None,
|
self._cont_handler.startElementNS(pair, None, self._attrs)
|
||||||
xmlreader.AttributesImpl(attrs, None))
|
|
||||||
|
|
||||||
def end_element_ns(self, name):
|
def end_element_ns(self, name):
|
||||||
pair = name.split()
|
pair = name.split()
|
||||||
if len(pair) == 1:
|
if len(pair) == 1:
|
||||||
name = (None, name, None)
|
name = (None, name)
|
||||||
else:
|
|
||||||
name = pair + [None] # prefix is not implemented yet!
|
|
||||||
|
|
||||||
self._cont_handler.endElement(name, None)
|
self._cont_handler.endElementNS(pair, None)
|
||||||
|
|
||||||
# this is not used
|
# this is not used (call directly to ContentHandler)
|
||||||
def processing_instruction(self, target, data):
|
def processing_instruction(self, target, data):
|
||||||
self._cont_handler.processingInstruction(target, data)
|
self._cont_handler.processingInstruction(target, data)
|
||||||
|
|
||||||
# this is not used
|
# this is not used (call directly to ContentHandler)
|
||||||
def character_data(self, data):
|
def character_data(self, data):
|
||||||
self._cont_handler.characters(data)
|
self._cont_handler.characters(data)
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
|
||||||
self._dtd_handler.notationDecl(name, pubid, sysid)
|
self._dtd_handler.notationDecl(name, pubid, sysid)
|
||||||
|
|
||||||
def external_entity_ref(self, context, base, sysid, pubid):
|
def external_entity_ref(self, context, base, sysid, pubid):
|
||||||
assert 0 # not implemented
|
raise NotImplementedError()
|
||||||
source = self._ent_handler.resolveEntity(pubid, sysid)
|
source = self._ent_handler.resolveEntity(pubid, sysid)
|
||||||
source = saxutils.prepare_input_source(source)
|
source = saxutils.prepare_input_source(source)
|
||||||
# FIXME: create new parser, stack self._source and self._parser
|
# FIXME: create new parser, stack self._source and self._parser
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue