~ubuntu-branches/ubuntu/natty/python3.1/natty-security

« back to all changes in this revision

Viewing changes to Lib/test/test_sax.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-11-14 01:12:15 UTC
  • mfrom: (1.4.3 upstream) (2.1.20 sid)
  • Revision ID: james.westby@ubuntu.com-20101114011215-ggan17jck7sxjlir
Tags: 3.1.3~rc1-1
* Python 3.1.3 release candidate 1.
  - Issue #10221: dict.pop(k) now has a key error message that includes the
    missing key (same message d[k] returns for missing keys).
  - Issue #5437: A preallocated MemoryError instance should not hold
    traceback data (including local variables caught in the stack trace)
    alive infinitely.
  - Issue #10077: Fix logging of site module errors at startup.
  - Issue #10186: Fix the SyntaxError caret when the offset is equal
    to the length of the offending line.
  - Issue #9713, #10114: Parser functions (eg. PyParser_ASTFromFile) expects
    filenames encoded to the filesystem encoding with surrogateescape error
    handler (to support undecodable bytes), instead of UTF-8 in strict mode.
  - Issue #9997: Don't let the name "top" have special significance in scope
    resolution.
  - Issue #10068: Global objects which have reference cycles with
    their module's dict are now cleared again.
  - Issue #4471: Properly shutdown socket in IMAP.shutdown().
  - Fix IMAP.login() to work properly.
  - Issue #10126: Fix distutils' test_build when Python was built with
    --enable-shared.
  - Fix typo in one sdist option (medata-check).
  - Issue #9199: Fix incorrect use of distutils.cmd.Command.announce.
  - Issue #1718574: Fix options that were supposed to accept arguments but did
    not in build_clib.
  - Issue #9281: Prevent race condition with mkdir in distutils.
  - Issue #10229: Fix caching error in gettext.
  - Issue #10252: Close file objects in a timely manner in distutils code and
    tests.
  - Issue #10311: The signal module now restores errno before returning from
    its low-level signal handler.
  - The keyword only restriction for the places argument in
    unittest.TestCase.assert[Not]AlmostEqual methods has been removed.
  - Issue 6706: asyncore accept() method no longer raises
    EWOULDBLOCK/ECONNABORTED on incomplete connection attempt but returns
    None instead.
  - Issue #10266: uu.decode didn't close in_file explicitly when it was given
    as a filename.
  - Issue #10246: uu.encode didn't close file objects explicitly when
    filenames were given to it.
  - Issue #10253: FileIO leaks a file descriptor when trying to open a file
    for append that isn't seekable.
  - Issue #5027: The standard ``xml`` namespace is now understood by
    xml.sax.saxutils.XMLGenerator as being bound to
    http://www.w3.org/XML/1998/namespace.
  - Issue #5117: Case normalization was needed on ntpath.relpath(). And
    fixed root directory issue on posixpath.relpath(). (Ported working fixes
    from ntpath)
  - Issue #10041: The signature of optional arguments in socket.makefile()
    didn't match that of io.open(), and they also didn't get forwarded
    properly to TextIOWrapper in text mode.
  - Issue #6612: Fix site and sysconfig to catch os.getcwd() error, eg. if the
    current directory was deleted.
  - Issue #9054: Fix a crash occurring when using the pyexpat module
    with expat version 2.0.1.
* Move the Makefile into the -min package, required by sysconfig.
  Addresses: #603237.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# regression test for SAX 2.0            -*- coding: iso-8859-1 -*-
2
 
# $Id: test_sax.py 66203 2008-09-04 02:22:52Z benjamin.peterson $
 
1
# regression test for SAX 2.0
 
2
# $Id: test_sax.py 85862 2010-10-27 18:54:06Z antoine.pitrou $
3
3
 
4
4
from xml.sax import make_parser, ContentHandler, \
5
5
                    SAXException, SAXReaderNotAvailable, SAXParseException
11
11
from xml.sax.saxutils import XMLGenerator, escape, unescape, quoteattr, \
12
12
                             XMLFilterBase
13
13
from xml.sax.expatreader import create_parser
 
14
from xml.sax.handler import feature_namespaces
14
15
from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl
15
16
from io import StringIO
16
17
from test.support import findfile, run_unittest
106
107
                          "<Donald Duck & Co>")
107
108
 
108
109
    def test_escape_extra(self):
109
 
        self.assertEquals(escape("Hei p� deg", {"�" : "å"}),
 
110
        self.assertEquals(escape("Hei på deg", {"å" : "å"}),
110
111
                          "Hei på deg")
111
112
 
112
113
    # ===== unescape
118
119
                          "<Donald Duck & Co>")
119
120
 
120
121
    def test_unescape_extra(self):
121
 
        self.assertEquals(unescape("Hei p� deg", {"�" : "&aring;"}),
 
122
        self.assertEquals(unescape("Hei på deg", {"å" : "&aring;"}),
122
123
                          "Hei p&aring; deg")
123
124
 
124
125
    def test_unescape_amp_extra(self):
288
289
        self.assertEquals(result.getvalue(),
289
290
            start+'<my:a xmlns:my="qux" b="c"></my:a>')
290
291
 
 
292
    def test_5027_1(self):
 
293
        # The xml prefix (as in xml:lang below) is reserved and bound by
 
294
        # definition to http://www.w3.org/XML/1998/namespace.  XMLGenerator had
 
295
        # a bug whereby a KeyError is thrown because this namespace is missing
 
296
        # from a dictionary.
 
297
        #
 
298
        # This test demonstrates the bug by parsing a document.
 
299
        test_xml = StringIO(
 
300
            '<?xml version="1.0"?>'
 
301
            '<a:g1 xmlns:a="http://example.com/ns">'
 
302
             '<a:g2 xml:lang="en">Hello</a:g2>'
 
303
            '</a:g1>')
 
304
 
 
305
        parser = make_parser()
 
306
        parser.setFeature(feature_namespaces, True)
 
307
        result = StringIO()
 
308
        gen = XMLGenerator(result)
 
309
        parser.setContentHandler(gen)
 
310
        parser.parse(test_xml)
 
311
 
 
312
        self.assertEquals(result.getvalue(),
 
313
                          start + (
 
314
                          '<a:g1 xmlns:a="http://example.com/ns">'
 
315
                           '<a:g2 xml:lang="en">Hello</a:g2>'
 
316
                          '</a:g1>'))
 
317
 
 
318
    def test_5027_2(self):
 
319
        # The xml prefix (as in xml:lang below) is reserved and bound by
 
320
        # definition to http://www.w3.org/XML/1998/namespace.  XMLGenerator had
 
321
        # a bug whereby a KeyError is thrown because this namespace is missing
 
322
        # from a dictionary.
 
323
        #
 
324
        # This test demonstrates the bug by direct manipulation of the
 
325
        # XMLGenerator.
 
326
        result = StringIO()
 
327
        gen = XMLGenerator(result)
 
328
 
 
329
        gen.startDocument()
 
330
        gen.startPrefixMapping('a', 'http://example.com/ns')
 
331
        gen.startElementNS(('http://example.com/ns', 'g1'), 'g1', {})
 
332
        lang_attr = {('http://www.w3.org/XML/1998/namespace', 'lang'): 'en'}
 
333
        gen.startElementNS(('http://example.com/ns', 'g2'), 'g2', lang_attr)
 
334
        gen.characters('Hello')
 
335
        gen.endElementNS(('http://example.com/ns', 'g2'), 'g2')
 
336
        gen.endElementNS(('http://example.com/ns', 'g1'), 'g1')
 
337
        gen.endPrefixMapping('a')
 
338
        gen.endDocument()
 
339
 
 
340
        self.assertEquals(result.getvalue(),
 
341
                          start + (
 
342
                          '<a:g1 xmlns:a="http://example.com/ns">'
 
343
                           '<a:g2 xml:lang="en">Hello</a:g2>'
 
344
                          '</a:g1>'))
 
345
 
291
346
 
292
347
class XMLFilterBaseTest(unittest.TestCase):
293
348
    def test_filter_basic(self):