diff options
author | Fred Drake <fdrake@acm.org> | 2000-10-23 18:09:50 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2000-10-23 18:09:50 (GMT) |
commit | 16f6329e6153c4b92f2175a5560e372a762befe6 (patch) | |
tree | 4d3c2f0bfe8e827ed07df59a538fa1d93bb2acb1 /Lib/xml | |
parent | 098b55ab4427aa546a06973cecd5e18080b546fd (diff) | |
download | cpython-16f6329e6153c4b92f2175a5560e372a762befe6.zip cpython-16f6329e6153c4b92f2175a5560e372a762befe6.tar.gz cpython-16f6329e6153c4b92f2175a5560e372a762befe6.tar.bz2 |
Make reindent.py happy (lots of trailing whitespace removed).
Diffstat (limited to 'Lib/xml')
-rw-r--r-- | Lib/xml/__init__.py | 2 | ||||
-rw-r--r-- | Lib/xml/dom/minidom.py | 17 | ||||
-rw-r--r-- | Lib/xml/dom/pulldom.py | 24 | ||||
-rw-r--r-- | Lib/xml/sax/__init__.py | 10 | ||||
-rw-r--r-- | Lib/xml/sax/_exceptions.py | 4 | ||||
-rw-r--r-- | Lib/xml/sax/expatreader.py | 38 | ||||
-rw-r--r-- | Lib/xml/sax/handler.py | 42 | ||||
-rw-r--r-- | Lib/xml/sax/saxutils.py | 18 | ||||
-rw-r--r-- | Lib/xml/sax/xmlreader.py | 52 |
9 files changed, 103 insertions, 104 deletions
diff --git a/Lib/xml/__init__.py b/Lib/xml/__init__.py index 4302f8d..a38db2d 100644 --- a/Lib/xml/__init__.py +++ b/Lib/xml/__init__.py @@ -8,7 +8,7 @@ dom -- The W3C Document Object Model. This supports DOM Level 1 + parsers -- Python wrappers for XML parsers (currently only supports Expat). sax -- The Simple API for XML, developed by XML-Dev, led by David - Megginson and ported to Python by Lars Marius Garshol. This + Megginson and ported to Python by Lars Marius Garshol. This supports the SAX 2 API. """ diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py index 00bd4ca..6a72684 100644 --- a/Lib/xml/dom/minidom.py +++ b/Lib/xml/dom/minidom.py @@ -40,7 +40,7 @@ class Node: def __init__(self): self.childNodes = [] - if Node._debug: + if Node._debug: index = repr(id(self)) + repr(self.__class__) Node.allnodes[index] = repr(self.__dict__) if Node.debug is None: @@ -52,16 +52,16 @@ class Node: if key[0:2] == "__": raise AttributeError # getattr should never call getattr! - if self.__dict__.has_key("inGetAttr"): + if self.__dict__.has_key("inGetAttr"): del self.inGetAttr raise AttributeError, key prefix, attrname = key[:5], key[5:] if prefix == "_get_": self.inGetAttr = 1 - if hasattr(self, attrname): + if hasattr(self, attrname): del self.inGetAttr - return (lambda self=self, attrname=attrname: + return (lambda self=self, attrname=attrname: getattr(self, attrname)) else: del self.inGetAttr @@ -213,7 +213,7 @@ class AttributeList: def itemsNS(self): return map(lambda node: ((node.URI, node.localName), node.value), self._attrs.values()) - + def keys(self): return self._attrs.keys() @@ -229,7 +229,7 @@ class AttributeList: def __cmp__(self, other): if self._attrs is getattr(other, "_attrs", None): return 0 - else: + else: return cmp(id(self), id(other)) #FIXME: is it appropriate to return .value? @@ -324,7 +324,7 @@ class Element(Node): node.unlink() del self._attrs[node.name] del self._attrsNS[(node.namespaceURI, node.localName)] - + def getElementsByTagName(self, name): return _getElementsByTagNameHelper(self, name, []) @@ -337,7 +337,7 @@ class Element(Node): # undocumented def writexml(self, writer): writer.write("<" + self.tagName) - + a_names = self._get_attributes().keys() a_names.sort() @@ -473,4 +473,3 @@ def parse(*args, **kwargs): def parseString(*args, **kwargs): "Parse a file into a DOM from a string" return _doparse(pulldom.parseString, args, kwargs) - diff --git a/Lib/xml/dom/pulldom.py b/Lib/xml/dom/pulldom.py index 7374069..063f7e8 100644 --- a/Lib/xml/dom/pulldom.py +++ b/Lib/xml/dom/pulldom.py @@ -49,7 +49,7 @@ class PullDOM(xml.sax.ContentHandler): attr = self.document.createAttribute(a_localname) attr.value = value node.setAttributeNode(attr) - + parent = self.curNode node.parentNode = parent self.curNode = node @@ -72,7 +72,7 @@ class PullDOM(xml.sax.ContentHandler): attr = self.document.createAttribute(aname) attr.value = value node.setAttributeNode(attr) - + parent = self.curNode node.parentNode = parent self.curNode = node @@ -87,7 +87,7 @@ class PullDOM(xml.sax.ContentHandler): self.lastEvent = self.lastEvent[1] #self.events.append((END_ELEMENT, node)) self.curNode = node.parentNode - + def comment(self, s): node = self.document.createComment(s) parent = self.curNode @@ -98,7 +98,7 @@ class PullDOM(xml.sax.ContentHandler): def processingInstruction(self, target, data): node = self.document.createProcessingInstruction(target, data) - + parent = self.curNode node.parentNode = parent self.lastEvent[1] = [(PROCESSING_INSTRUCTION, node), None] @@ -142,9 +142,9 @@ class ErrorHandler: def warning(self, exception): print exception def error(self, exception): - raise exception + raise exception def fatalError(self, exception): - raise exception + raise exception class DOMEventStream: def __init__(self, stream, parser, bufsize): @@ -202,18 +202,18 @@ class SAX2DOM(PullDOM): def processingInstruction(self, target, data): PullDOM.processingInstruction(self, target, data) node = self.lastEvent[0][1] - node.parentNode.appendChild(node) + node.parentNode.appendChild(node) def ignorableWhitespace(self, chars): PullDOM.ignorableWhitespace(self, chars) node = self.lastEvent[0][1] - node.parentNode.appendChild(node) + node.parentNode.appendChild(node) def characters(self, chars): PullDOM.characters(self, chars) node = self.lastEvent[0][1] - node.parentNode.appendChild(node) - + node.parentNode.appendChild(node) + default_bufsize = (2 ** 14) - 20 def parse(stream_or_string, parser=None, bufsize=default_bufsize): @@ -221,7 +221,7 @@ def parse(stream_or_string, parser=None, bufsize=default_bufsize): stream = open(stream_or_string) else: stream = stream_or_string - if not parser: + if not parser: parser = xml.sax.make_parser() return DOMEventStream(stream, parser, bufsize) @@ -230,7 +230,7 @@ def parseString(string, parser=None): from cStringIO import StringIO except ImportError: from StringIO import StringIO - + bufsize = len(string) buf = StringIO(string) if not parser: diff --git a/Lib/xml/sax/__init__.py b/Lib/xml/sax/__init__.py index 447420e..0375e5d 100644 --- a/Lib/xml/sax/__init__.py +++ b/Lib/xml/sax/__init__.py @@ -37,7 +37,7 @@ def parseString(string, handler, errorHandler=ErrorHandler()): from cStringIO import StringIO except ImportError: from StringIO import StringIO - + if errorHandler is None: errorHandler = ErrorHandler() parser = make_parser() @@ -61,8 +61,8 @@ del os _key = "python.xml.sax.parser" if sys.platform[:4] == "java" and sys.registry.containsKey(_key): default_parser_list = string.split(sys.registry.getProperty(_key), ",") - - + + def make_parser(parser_list = []): """Creates and returns a SAX parser. @@ -85,8 +85,8 @@ def make_parser(parser_list = []): # so try the next one pass - raise SAXReaderNotAvailable("No parsers found", None) - + raise SAXReaderNotAvailable("No parsers found", None) + # --- Internal utility methods used by make_parser if sys.platform[ : 4] == "java": diff --git a/Lib/xml/sax/_exceptions.py b/Lib/xml/sax/_exceptions.py index 88ec8ca..1ea582f 100644 --- a/Lib/xml/sax/_exceptions.py +++ b/Lib/xml/sax/_exceptions.py @@ -42,7 +42,7 @@ class SAXException(Exception): # ===== SAXPARSEEXCEPTION ===== -class SAXParseException(SAXException): +class SAXParseException(SAXException): """Encapsulate an XML parse error or warning. This exception will include information for locating the error in @@ -62,7 +62,7 @@ class SAXParseException(SAXException): def getColumnNumber(self): """The column number of the end of the text where the exception - occurred.""" + occurred.""" return self._locator.getColumnNumber() def getLineNumber(self): diff --git a/Lib/xml/sax/expatreader.py b/Lib/xml/sax/expatreader.py index fed5e2d..d84931e 100644 --- a/Lib/xml/sax/expatreader.py +++ b/Lib/xml/sax/expatreader.py @@ -9,7 +9,7 @@ from xml.sax._exceptions import * try: from xml.parsers import expat except ImportError: - raise SAXReaderNotAvailable("expat not supported",None) + raise SAXReaderNotAvailable("expat not supported",None) from xml.sax import xmlreader, saxutils, handler AttributesImpl = xmlreader.AttributesImpl @@ -39,12 +39,12 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator): self._source = source self.reset() self._cont_handler.setDocumentLocator(self) - xmlreader.IncrementalParser.parse(self, source) + xmlreader.IncrementalParser.parse(self, source) def prepareParser(self, source): if source.getSystemId() != None: self._parser.SetBase(source.getSystemId()) - + def getFeature(self, name): if name == handler.feature_namespaces: return self._namespaces @@ -91,7 +91,7 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator): self.feed("", isFinal = 1) self._cont_handler.endDocument() self._parsing = 0 - + def reset(self): if self._namespaces: self._parser = expat.ParserCreate(None, " ") @@ -109,17 +109,17 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator): self._parser.NotationDeclHandler = self.notation_decl self._parser.StartNamespaceDeclHandler = self.start_namespace_decl self._parser.EndNamespaceDeclHandler = self.end_namespace_decl -# self._parser.CommentHandler = -# self._parser.StartCdataSectionHandler = -# self._parser.EndCdataSectionHandler = -# self._parser.DefaultHandler = -# self._parser.DefaultHandlerExpand = -# self._parser.NotStandaloneHandler = +# self._parser.CommentHandler = +# self._parser.StartCdataSectionHandler = +# self._parser.EndCdataSectionHandler = +# self._parser.DefaultHandler = +# self._parser.DefaultHandlerExpand = +# self._parser.NotStandaloneHandler = self._parser.ExternalEntityRefHandler = self.external_entity_ref self._parsing = 0 self._entity_stack = [] - + # Locator methods def getColumnNumber(self): @@ -133,7 +133,7 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator): def getSystemId(self): return self._source.getSystemId() - + # event handlers def start_element(self, name, attrs): self._cont_handler.startElement(name, AttributesImpl(attrs)) @@ -158,14 +158,14 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator): newattrs[apair] = value - self._cont_handler.startElementNS(pair, None, + self._cont_handler.startElementNS(pair, None, AttributesNSImpl(newattrs, {})) def end_element_ns(self, name): pair = string.split(name) if len(pair) == 1: pair = (None, name) - + self._cont_handler.endElementNS(pair, None) # this is not used (call directly to ContentHandler) @@ -181,7 +181,7 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator): def end_namespace_decl(self, prefix): self._cont_handler.endPrefixMapping(prefix) - + def unparsed_entity_decl(self, name, base, sysid, pubid, notation_name): self._dtd_handler.unparsedEntityDecl(name, pubid, sysid, notation_name) @@ -193,7 +193,7 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator): source = saxutils.prepare_input_source(source, self._source.getSystemId() or "") - + self._entity_stack.append((self._parser, self._source)) self._parser = self._parser.ExternalEntityParserCreate(context) self._source = source @@ -206,12 +206,12 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator): (self._parser, self._source) = self._entity_stack[-1] del self._entity_stack[-1] return 1 - + # --- - + def create_parser(*args, **kwargs): return apply(ExpatParser, args, kwargs) - + # --- if __name__ == "__main__": diff --git a/Lib/xml/sax/handler.py b/Lib/xml/sax/handler.py index cf266e9..aa08d99 100644 --- a/Lib/xml/sax/handler.py +++ b/Lib/xml/sax/handler.py @@ -38,10 +38,10 @@ class ErrorHandler: raise exception def warning(self, exception): - "Handle a warning." + "Handle a warning." print exception - + # ===== CONTENTHANDLER ===== class ContentHandler: @@ -53,7 +53,7 @@ class ContentHandler: def __init__(self): self._locator = None - + def setDocumentLocator(self, locator): """Called by the parser to give the application a locator for locating the origin of document events. @@ -71,22 +71,22 @@ class ContentHandler: character content that does not match an application's business rules). The information returned by the locator is probably not sufficient for use with a search engine. - + Note that the locator will return correct information only during the invocation of the events in this interface. The application should not attempt to use it at any other time.""" - self._locator = locator + self._locator = locator def startDocument(self): """Receive notification of the beginning of a document. - + The SAX parser will invoke this method only once, before any other methods in this interface or in DTDHandler (except for setDocumentLocator).""" def endDocument(self): """Receive notification of the end of a document. - + The SAX parser will invoke this method only once, and it will be the last method invoked during the parse. The parser shall not invoke this method until it has either abandoned parsing @@ -95,13 +95,13 @@ class ContentHandler: def startPrefixMapping(self, prefix, uri): """Begin the scope of a prefix-URI Namespace mapping. - + The information from this event is not necessary for normal Namespace processing: the SAX XML reader will automatically replace prefixes for element and attribute names when the http://xml.org/sax/features/namespaces feature is true (the default). - + There are cases, however, when applications need to use prefixes in character data or in attribute values, where they cannot safely be expanded automatically; the @@ -118,7 +118,7 @@ class ContentHandler: def endPrefixMapping(self, prefix): """End the scope of a prefix-URI mapping. - + See startPrefixMapping for details. This event will always occur after the corresponding endElement event, but the order of endPrefixMapping events is not otherwise guaranteed.""" @@ -151,10 +151,10 @@ class ContentHandler: The name parameter contains the name of the element type, just as with the startElementNS event.""" - + def characters(self, content): """Receive notification of character data. - + The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into @@ -164,24 +164,24 @@ class ContentHandler: def ignorableWhitespace(self, whitespace): """Receive notification of ignorable whitespace in element content. - + Validating Parsers must use this method to report each chunk of ignorable whitespace (see the W3C XML 1.0 recommendation, section 2.10): non-validating parsers may also use this method if they are capable of parsing and using content models. - + SAX parsers may return all contiguous whitespace in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information. - + The application must not attempt to read from the array outside of the specified range.""" def processingInstruction(self, target, data): """Receive notification of a processing instruction. - + The Parser will invoke this method once for each processing instruction found: note that processing instructions may occur before or after the main document element. @@ -192,7 +192,7 @@ class ContentHandler: def skippedEntity(self, name): """Receive notification of a skipped entity. - + The Parser will invoke this method once for each entity skipped. Non-validating processors may skip entities if they have not seen the declarations (because, for example, the @@ -202,7 +202,7 @@ class ContentHandler: http://xml.org/sax/features/external-parameter-entities properties.""" - + # ===== DTDHandler ===== class DTDHandler: @@ -217,16 +217,16 @@ class DTDHandler: def unparsedEntityDecl(self, name, publicId, systemId, ndata): "Handle an unparsed entity declaration event." - + # ===== ENTITYRESOLVER ===== - + class EntityResolver: """Basic interface for resolving entities. If you create an object implementing this interface, then register the object with your Parser, the parser will call the method in your object to resolve all external entities. Note that DefaultHandler implements this interface with the default behaviour.""" - + def resolveEntity(self, publicId, systemId): """Resolve the system identifier of an entity and return either the system identifier to read from as a string, or an InputSource diff --git a/Lib/xml/sax/saxutils.py b/Lib/xml/sax/saxutils.py index 1fb3743..5d784bd 100644 --- a/Lib/xml/sax/saxutils.py +++ b/Lib/xml/sax/saxutils.py @@ -12,7 +12,7 @@ _StringTypes = [types.StringType, types.UnicodeType] def escape(data, entities={}): """Escape &, <, and > in a string of data. - You can escape other strings of data by passing a dictionary as + You can escape other strings of data by passing a dictionary as the optional entities parameter. The keys and values must all be strings; each key will be replaced with its corresponding value. """ @@ -20,7 +20,7 @@ def escape(data, entities={}): data = data.replace("<", "<") data = data.replace(">", ">") for chars, entity in entities.items(): - data = data.replace(chars, entity) + data = data.replace(chars, entity) return data @@ -57,7 +57,7 @@ class XMLGenerator(handler.ContentHandler): for (name, value) in attrs.items(): self._out.write(' %s="%s"' % (name, escape(value))) self._out.write('>') - + def endElement(self, name): self._out.write('</%s>' % name) @@ -73,7 +73,7 @@ class XMLGenerator(handler.ContentHandler): for pair in self._undeclared_ns_maps: self._out.write(' xmlns:%s="%s"' % pair) self._undeclared_ns_maps = [] - + for (name, value) in attrs.items(): name = self._current_context[name[0]] + ":" + name[1] self._out.write(' %s="%s"' % (name, escape(value))) @@ -85,7 +85,7 @@ class XMLGenerator(handler.ContentHandler): else: name = self._current_context[name[0]] + ":" + name[1] self._out.write('</%s>' % name) - + def characters(self, content): self._out.write(escape(content)) @@ -107,7 +107,7 @@ class XMLFilterBase(xmlreader.XMLReader): def __init__(self, parent = None): xmlreader.XMLReader.__init__(self) self._parent = parent - + # ErrorHandler methods def error(self, exception): @@ -210,7 +210,7 @@ class XMLFilterBase(xmlreader.XMLReader): def prepare_input_source(source, base = ""): """This function takes an InputSource and an optional base URL and returns a fully resolved InputSource object ready for reading.""" - + if type(source) in _StringTypes: source = xmlreader.InputSource(source) elif hasattr(source, "read"): @@ -229,7 +229,7 @@ def prepare_input_source(source, base = ""): else: source.setSystemId(urlparse.urljoin(base, sysid)) f = urllib.urlopen(source.getSystemId()) - + source.setByteStream(f) - + return source diff --git a/Lib/xml/sax/xmlreader.py b/Lib/xml/sax/xmlreader.py index 7f31fc2..b336cb2 100644 --- a/Lib/xml/sax/xmlreader.py +++ b/Lib/xml/sax/xmlreader.py @@ -6,7 +6,7 @@ import handler # ===== XMLREADER ===== class XMLReader: - """Interface for reading an XML document using callbacks. + """Interface for reading an XML document using callbacks. XMLReader is the interface that an XML parser's SAX2 driver must implement. This interface allows an application to set and query @@ -17,7 +17,7 @@ class XMLReader: methods must not return until parsing is complete, and readers must wait for an event-handler callback to return before reporting the next event.""" - + def __init__(self): self._cont_handler = handler.ContentHandler() self._dtd_handler = handler.DTDHandler() @@ -35,11 +35,11 @@ class XMLReader: def setContentHandler(self, handler): "Registers a new object to receive document content events." self._cont_handler = handler - + def getDTDHandler(self): "Returns the current DTD handler." return self._dtd_handler - + def setDTDHandler(self, handler): "Register an object to receive basic DTD-related events." self._dtd_handler = handler @@ -47,7 +47,7 @@ class XMLReader: def getEntityResolver(self): "Returns the current EntityResolver." return self._ent_handler - + def setEntityResolver(self, resolver): "Register an object to resolve external entities." self._ent_handler = resolver @@ -55,20 +55,20 @@ class XMLReader: def getErrorHandler(self): "Returns the current ErrorHandler." return self._err_handler - + def setErrorHandler(self, handler): "Register an object to receive error-message events." self._err_handler = handler def setLocale(self, locale): - """Allow an application to set the locale for errors and warnings. - + """Allow an application to set the locale for errors and warnings. + SAX parsers are not required to provide localization for errors and warnings; if they cannot support the requested locale, however, they must throw a SAX exception. Applications may request a locale change in the middle of a parse.""" raise SAXNotSupportedException("Locale support not implemented") - + def getFeature(self, name): "Looks up and returns the state of a SAX2 feature." raise SAXNotRecognizedException("Feature '%s' not recognized" % name) @@ -112,7 +112,7 @@ class IncrementalParser(XMLReader): def parse(self, source): import saxutils source = saxutils.prepare_input_source(source) - + self.prepareParser(source) file = source.getByteStream() buffer = file.read(self._bufsize) @@ -121,7 +121,7 @@ class IncrementalParser(XMLReader): buffer = file.read(self._bufsize) self.close() - def feed(self, data): + def feed(self, data): """This method gives the raw XML data in the data parameter to the parser and makes it parse the data, emitting the corresponding events. It is allowed for XML constructs to be @@ -238,7 +238,7 @@ class InputSource: """Set the byte stream (a Python file-like object which does not perform byte-to-character conversion) for this input source. - + The SAX parser will ignore this if there is also a character stream specified, but it will use a byte stream in preference to opening a URI connection itself. @@ -249,16 +249,16 @@ class InputSource: def getByteStream(self): """Get the byte stream for this input source. - + The getEncoding method will return the character encoding for - this byte stream, or None if unknown.""" + this byte stream, or None if unknown.""" return self.__bytefile - + def setCharacterStream(self, charfile): """Set the character stream for this input source. (The stream must be a Python 1.6 Unicode-wrapped file-like that performs conversion to Unicode strings.) - + If there is a character stream specified, the SAX parser will ignore any byte stream and will not attempt to open a URI connection to the system identifier.""" @@ -267,11 +267,11 @@ class InputSource: def getCharacterStream(self): "Get the character stream for this input source." return self.__charfile - + # ===== ATTRIBUTESIMPL ===== class AttributesImpl: - + def __init__(self, attrs): """Non-NS-aware implementation. @@ -298,13 +298,13 @@ class AttributesImpl: def getQNameByName(self, name): if not self._attrs.has_key(name): raise KeyError - return name - + return name + def getNames(self): return self._attrs.keys() def getQNames(self): - return self._attrs.keys() + return self._attrs.keys() def __len__(self): return len(self._attrs) @@ -333,7 +333,7 @@ class AttributesImpl: # ===== ATTRIBUTESNSIMPL ===== class AttributesNSImpl(AttributesImpl): - + def __init__(self, attrs, qnames): """NS-aware implementation. @@ -346,25 +346,25 @@ class AttributesNSImpl(AttributesImpl): for (nsname, qname) in self._qnames.items(): if qname == name: return self._attrs[nsname] - + raise KeyError def getNameByQName(self, name): for (nsname, qname) in self._qnames.items(): if qname == name: return nsname - + raise KeyError def getQNameByName(self, name): return self._qnames[name] - + def getQNames(self): return self._qnames.values() def copy(self): return self.__class__(self._attrs, self._qnames) - + def _test(): XMLReader() |