diff --git a/Lib/test/test_pyexpat.py b/Lib/test/test_pyexpat.py index a0ba59008ec..b2b4dea0605 100644 --- a/Lib/test/test_pyexpat.py +++ b/Lib/test/test_pyexpat.py @@ -231,7 +231,7 @@ def test_parse_bytes(self): parser = expat.ParserCreate(namespace_separator='!') self._hookup_callbacks(parser, out) - parser.Parse(data, 1) + parser.Parse(data, True) operations = out.out self._verify_parse_output(operations) @@ -243,7 +243,7 @@ def test_parse_str(self): parser = expat.ParserCreate(namespace_separator='!') self._hookup_callbacks(parser, out) - parser.Parse(data.decode('iso-8859-1'), 1) + parser.Parse(data.decode('iso-8859-1'), True) operations = out.out self._verify_parse_output(operations) @@ -316,7 +316,7 @@ def collector(name, *args): L.append(name) p.StartElementHandler = collector p.EndElementHandler = collector - p.Parse(b" ", 1) + p.Parse(b" ", True) tag = L[0] self.assertEqual(len(L), 6) for entry in L: @@ -332,14 +332,14 @@ def __init__(self, parser): def ExternalEntityRefHandler(self, context, base, sysId, pubId): external_parser = self.parser.ExternalEntityParserCreate("") - self.parser_result = external_parser.Parse(b"", 1) + self.parser_result = external_parser.Parse(b"", True) return 1 parser = expat.ParserCreate(namespace_separator='!') parser.buffer_text = 1 out = ExternalOutputter(parser) parser.ExternalEntityRefHandler = out.ExternalEntityRefHandler - parser.Parse(data, 1) + parser.Parse(data, True) self.assertEqual(out.parser_result, 1) @@ -383,7 +383,7 @@ def test_default_to_disabled(self): def test_buffering_enabled(self): # Make sure buffering is turned on self.assertTrue(self.parser.buffer_text) - self.parser.Parse(b"123", 1) + self.parser.Parse(b"123", True) self.assertEqual(self.stuff, ['123'], "buffered text not properly collapsed") @@ -391,39 +391,39 @@ def test1(self): # XXX This test exposes more detail of Expat's text chunking than we # XXX like, but it tests what we need to concisely. self.setHandlers(["StartElementHandler"]) - self.parser.Parse(b"12\n34\n5", 1) + self.parser.Parse(b"12\n34\n5", True) self.assertEqual(self.stuff, ["", "1", "", "2", "\n", "3", "", "4\n5"], "buffering control not reacting as expected") def test2(self): - self.parser.Parse(b"1<2> \n 3", 1) + self.parser.Parse(b"1<2> \n 3", True) self.assertEqual(self.stuff, ["1<2> \n 3"], "buffered text not properly collapsed") def test3(self): self.setHandlers(["StartElementHandler"]) - self.parser.Parse(b"123", 1) + self.parser.Parse(b"123", True) self.assertEqual(self.stuff, ["", "1", "", "2", "", "3"], "buffered text not properly split") def test4(self): self.setHandlers(["StartElementHandler", "EndElementHandler"]) self.parser.CharacterDataHandler = None - self.parser.Parse(b"123", 1) + self.parser.Parse(b"123", True) self.assertEqual(self.stuff, ["", "", "", "", "", ""]) def test5(self): self.setHandlers(["StartElementHandler", "EndElementHandler"]) - self.parser.Parse(b"123", 1) + self.parser.Parse(b"123", True) self.assertEqual(self.stuff, ["", "1", "", "", "2", "", "", "3", ""]) def test6(self): self.setHandlers(["CommentHandler", "EndElementHandler", "StartElementHandler"]) - self.parser.Parse(b"12345 ", 1) + self.parser.Parse(b"12345 ", True) self.assertEqual(self.stuff, ["", "1", "", "", "2", "", "", "345", ""], "buffered text not properly split") @@ -431,7 +431,7 @@ def test6(self): def test7(self): self.setHandlers(["CommentHandler", "EndElementHandler", "StartElementHandler"]) - self.parser.Parse(b"12345 ", 1) + self.parser.Parse(b"12345 ", True) self.assertEqual(self.stuff, ["", "1", "", "", "2", "", "", "3", "", "4", "", "5", ""], @@ -451,7 +451,7 @@ def test_exception(self): parser = expat.ParserCreate() parser.StartElementHandler = self.StartElementHandler try: - parser.Parse(b"", 1) + parser.Parse(b"", True) self.fail() except RuntimeError as e: self.assertEqual(e.args[0], 'a', @@ -499,7 +499,7 @@ def test(self): ('e', 15, 3, 6), ('e', 17, 4, 1), ('e', 22, 5, 0)] xml = b'\n \n \n \n' - self.parser.Parse(xml, 1) + self.parser.Parse(xml, True) class sf1296433Test(unittest.TestCase): @@ -579,7 +579,7 @@ def test_disabling_buffer(self): # Parse one chunk of XML self.n = 0 - parser.Parse(xml1, 0) + parser.Parse(xml1, False) self.assertEqual(parser.buffer_size, 1024) self.assertEqual(self.n, 1) @@ -588,13 +588,13 @@ def test_disabling_buffer(self): self.assertFalse(parser.buffer_text) self.assertEqual(parser.buffer_size, 1024) for i in range(10): - parser.Parse(xml2, 0) + parser.Parse(xml2, False) self.assertEqual(self.n, 11) parser.buffer_text = 1 self.assertTrue(parser.buffer_text) self.assertEqual(parser.buffer_size, 1024) - parser.Parse(xml3, 1) + parser.Parse(xml3, True) self.assertEqual(self.n, 12) def counting_handler(self, text): @@ -621,10 +621,10 @@ def test_change_size_1(self): self.assertEqual(parser.buffer_size, 1024) self.n = 0 - parser.Parse(xml1, 0) + parser.Parse(xml1, False) parser.buffer_size *= 2 self.assertEqual(parser.buffer_size, 2048) - parser.Parse(xml2, 1) + parser.Parse(xml2, True) self.assertEqual(self.n, 2) def test_change_size_2(self): @@ -637,10 +637,10 @@ def test_change_size_2(self): self.assertEqual(parser.buffer_size, 2048) self.n=0 - parser.Parse(xml1, 0) + parser.Parse(xml1, False) parser.buffer_size = parser.buffer_size // 2 self.assertEqual(parser.buffer_size, 1024) - parser.Parse(xml2, 1) + parser.Parse(xml2, True) self.assertEqual(self.n, 4) class MalformedInputTest(unittest.TestCase): diff --git a/Lib/xml/dom/expatbuilder.py b/Lib/xml/dom/expatbuilder.py index 2bd835b0359..199c22d0af3 100644 --- a/Lib/xml/dom/expatbuilder.py +++ b/Lib/xml/dom/expatbuilder.py @@ -204,11 +204,11 @@ def parseFile(self, file): buffer = file.read(16*1024) if not buffer: break - parser.Parse(buffer, 0) + parser.Parse(buffer, False) if first_buffer and self.document.documentElement: self._setup_subset(buffer) first_buffer = False - parser.Parse("", True) + parser.Parse(b"", True) except ParseEscape: pass doc = self.document @@ -637,7 +637,7 @@ def parseString(self, string): nsattrs = self._getNSattrs() # get ns decls from node's ancestors document = _FRAGMENT_BUILDER_TEMPLATE % (ident, subset, nsattrs) try: - parser.Parse(document, 1) + parser.Parse(document, True) except: self.reset() raise @@ -697,7 +697,7 @@ def external_entity_ref_handler(self, context, base, systemId, publicId): self.fragment = self.document.createDocumentFragment() self.curNode = self.fragment try: - parser.Parse(self._source, 1) + parser.Parse(self._source, True) finally: self.curNode = old_cur_node self.document = old_document diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index beb2d68803a..e75200a1b8a 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -1710,14 +1710,14 @@ def _default(self, text): def feed(self, data): """Feed encoded data to parser.""" try: - self.parser.Parse(data, 0) + self.parser.Parse(data, False) except self._error as v: self._raiseerror(v) def close(self): """Finish feeding data to parser and return element structure.""" try: - self.parser.Parse("", 1) # end of data + self.parser.Parse(b"", True) # end of data except self._error as v: self._raiseerror(v) try: diff --git a/Lib/xml/sax/expatreader.py b/Lib/xml/sax/expatreader.py index 5066ffc2fa5..e334ac9fea0 100644 --- a/Lib/xml/sax/expatreader.py +++ b/Lib/xml/sax/expatreader.py @@ -93,7 +93,7 @@ def __init__(self, namespaceHandling=0, bufsize=2**16-20): self._parser = None self._namespaces = namespaceHandling self._lex_handler_prop = None - self._parsing = 0 + self._parsing = False self._entity_stack = [] self._external_ges = 0 self._interning = None @@ -203,10 +203,10 @@ def setProperty(self, name, value): # IncrementalParser methods - def feed(self, data, isFinal = 0): + def feed(self, data, isFinal=False): if not self._parsing: self.reset() - self._parsing = 1 + self._parsing = True self._cont_handler.startDocument() try: @@ -237,13 +237,13 @@ def close(self): # If we are completing an external entity, do nothing here return try: - self.feed("", isFinal = 1) + self.feed(b"", isFinal=True) self._cont_handler.endDocument() - self._parsing = 0 + self._parsing = False # break cycle created by expat handlers pointing to our methods self._parser = None finally: - self._parsing = 0 + self._parsing = False if self._parser is not None: # Keep ErrorColumnNumber and ErrorLineNumber after closing. parser = _ClosedParser() @@ -307,7 +307,7 @@ def reset(self): self._parser.SetParamEntityParsing( expat.XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE) - self._parsing = 0 + self._parsing = False self._entity_stack = [] # Locator methods diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py index 246ef27ffc2..b4b2941ea5b 100644 --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -442,7 +442,7 @@ def __init__(self, target): target.xml(encoding, None) def feed(self, data): - self._parser.Parse(data, 0) + self._parser.Parse(data, False) def close(self): try: