You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
5.1 KiB

Merged revisions 69576,69579-69580,69589,69619-69620,69633,69703-69704,69728-69730 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r69576 | georg.brandl | 2009-02-13 04:56:50 -0600 (Fri, 13 Feb 2009) | 1 line #1661108: note that urlsafe encoded string can contain "=". ........ r69579 | georg.brandl | 2009-02-13 05:06:59 -0600 (Fri, 13 Feb 2009) | 2 lines Fix warnings GCC emits where the argument of PyErr_Format is a single variable. ........ r69580 | georg.brandl | 2009-02-13 05:10:04 -0600 (Fri, 13 Feb 2009) | 2 lines Fix warnings GCC emits where the argument of PyErr_Format is a single variable. ........ r69589 | martin.v.loewis | 2009-02-13 14:11:34 -0600 (Fri, 13 Feb 2009) | 2 lines Move amd64 properties further to the top, so that they override the linker options correctly. ........ r69619 | benjamin.peterson | 2009-02-14 11:00:51 -0600 (Sat, 14 Feb 2009) | 1 line this needn't be a shebang line ........ r69620 | georg.brandl | 2009-02-14 11:01:36 -0600 (Sat, 14 Feb 2009) | 1 line #5179: don't leak PIPE fds when child execution fails. ........ r69633 | hirokazu.yamamoto | 2009-02-15 03:19:48 -0600 (Sun, 15 Feb 2009) | 1 line Fixed typo. ........ r69703 | raymond.hettinger | 2009-02-16 16:42:54 -0600 (Mon, 16 Feb 2009) | 3 lines Issue 5229: Documentation for super() neglects to say what super() actually does ........ r69704 | raymond.hettinger | 2009-02-16 17:00:25 -0600 (Mon, 16 Feb 2009) | 1 line Add explanation for super(type1, type2). ........ r69728 | georg.brandl | 2009-02-17 18:22:55 -0600 (Tue, 17 Feb 2009) | 2 lines #5297: fix example. ........ r69729 | georg.brandl | 2009-02-17 18:25:13 -0600 (Tue, 17 Feb 2009) | 2 lines #5296: sequence -> iterable. ........ r69730 | georg.brandl | 2009-02-17 18:31:36 -0600 (Tue, 17 Feb 2009) | 2 lines #5268: mention VMSError. ........
17 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
Merged revisions 73004,73439,73496,73509,73529,73564,73576-73577,73595-73596,73605 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r73004 | jeffrey.yasskin | 2009-05-28 22:44:31 -0500 (Thu, 28 May 2009) | 5 lines Fix nearly all compilation warnings under Apple gcc-4.0. Tested with OPT="-g -Wall -Wstrict-prototypes -Werror" in both --with-pydebug mode and --without. There's still a batch of non-prototype warnings in Xlib.h that I don't know how to fix. ........ r73439 | benjamin.peterson | 2009-06-15 19:29:31 -0500 (Mon, 15 Jun 2009) | 1 line don't mask encoding errors when decoding a string #6289 ........ r73496 | vinay.sajip | 2009-06-21 12:37:27 -0500 (Sun, 21 Jun 2009) | 1 line Issue #6314: logging.basicConfig() performs extra checks on the "level" argument. ........ r73509 | amaury.forgeotdarc | 2009-06-22 14:33:48 -0500 (Mon, 22 Jun 2009) | 2 lines #4490 Fix sample code run by "python -m xml.sax.xmlreader" ........ r73529 | r.david.murray | 2009-06-23 13:02:46 -0500 (Tue, 23 Jun 2009) | 4 lines Fix issue 5230 by having pydoc's safeimport check to see if the import error was thrown from itself in order to decide if the module can't be found. Thanks to Lucas Prado Melo for collaborating on the fix and tests. ........ r73564 | amaury.forgeotdarc | 2009-06-25 17:29:29 -0500 (Thu, 25 Jun 2009) | 6 lines #2016 Fix a crash in function call when the **kwargs dictionary is mutated during the function call setup. This even gives a slight speedup, probably because tuple allocation is faster than PyMem_NEW. ........ r73576 | benjamin.peterson | 2009-06-26 18:37:06 -0500 (Fri, 26 Jun 2009) | 1 line document is_declared_global() ........ r73577 | benjamin.peterson | 2009-06-27 09:16:23 -0500 (Sat, 27 Jun 2009) | 1 line link to extensive generator docs in the reference manual ........ r73595 | ezio.melotti | 2009-06-27 18:45:39 -0500 (Sat, 27 Jun 2009) | 1 line stmt and setup can contain multiple statements, see #5896 ........ r73596 | ezio.melotti | 2009-06-27 19:07:45 -0500 (Sat, 27 Jun 2009) | 1 line Fixed a wrong apostrophe ........ r73605 | georg.brandl | 2009-06-28 07:10:18 -0500 (Sun, 28 Jun 2009) | 1 line Remove stray pychecker directive. ........
17 years ago
Merged revisions 73004,73439,73496,73509,73529,73564,73576-73577,73595-73596,73605 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r73004 | jeffrey.yasskin | 2009-05-28 22:44:31 -0500 (Thu, 28 May 2009) | 5 lines Fix nearly all compilation warnings under Apple gcc-4.0. Tested with OPT="-g -Wall -Wstrict-prototypes -Werror" in both --with-pydebug mode and --without. There's still a batch of non-prototype warnings in Xlib.h that I don't know how to fix. ........ r73439 | benjamin.peterson | 2009-06-15 19:29:31 -0500 (Mon, 15 Jun 2009) | 1 line don't mask encoding errors when decoding a string #6289 ........ r73496 | vinay.sajip | 2009-06-21 12:37:27 -0500 (Sun, 21 Jun 2009) | 1 line Issue #6314: logging.basicConfig() performs extra checks on the "level" argument. ........ r73509 | amaury.forgeotdarc | 2009-06-22 14:33:48 -0500 (Mon, 22 Jun 2009) | 2 lines #4490 Fix sample code run by "python -m xml.sax.xmlreader" ........ r73529 | r.david.murray | 2009-06-23 13:02:46 -0500 (Tue, 23 Jun 2009) | 4 lines Fix issue 5230 by having pydoc's safeimport check to see if the import error was thrown from itself in order to decide if the module can't be found. Thanks to Lucas Prado Melo for collaborating on the fix and tests. ........ r73564 | amaury.forgeotdarc | 2009-06-25 17:29:29 -0500 (Thu, 25 Jun 2009) | 6 lines #2016 Fix a crash in function call when the **kwargs dictionary is mutated during the function call setup. This even gives a slight speedup, probably because tuple allocation is faster than PyMem_NEW. ........ r73576 | benjamin.peterson | 2009-06-26 18:37:06 -0500 (Fri, 26 Jun 2009) | 1 line document is_declared_global() ........ r73577 | benjamin.peterson | 2009-06-27 09:16:23 -0500 (Sat, 27 Jun 2009) | 1 line link to extensive generator docs in the reference manual ........ r73595 | ezio.melotti | 2009-06-27 18:45:39 -0500 (Sat, 27 Jun 2009) | 1 line stmt and setup can contain multiple statements, see #5896 ........ r73596 | ezio.melotti | 2009-06-27 19:07:45 -0500 (Sat, 27 Jun 2009) | 1 line Fixed a wrong apostrophe ........ r73605 | georg.brandl | 2009-06-28 07:10:18 -0500 (Sun, 28 Jun 2009) | 1 line Remove stray pychecker directive. ........
17 years ago
Merged revisions 73004,73439,73496,73509,73529,73564,73576-73577,73595-73596,73605 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r73004 | jeffrey.yasskin | 2009-05-28 22:44:31 -0500 (Thu, 28 May 2009) | 5 lines Fix nearly all compilation warnings under Apple gcc-4.0. Tested with OPT="-g -Wall -Wstrict-prototypes -Werror" in both --with-pydebug mode and --without. There's still a batch of non-prototype warnings in Xlib.h that I don't know how to fix. ........ r73439 | benjamin.peterson | 2009-06-15 19:29:31 -0500 (Mon, 15 Jun 2009) | 1 line don't mask encoding errors when decoding a string #6289 ........ r73496 | vinay.sajip | 2009-06-21 12:37:27 -0500 (Sun, 21 Jun 2009) | 1 line Issue #6314: logging.basicConfig() performs extra checks on the "level" argument. ........ r73509 | amaury.forgeotdarc | 2009-06-22 14:33:48 -0500 (Mon, 22 Jun 2009) | 2 lines #4490 Fix sample code run by "python -m xml.sax.xmlreader" ........ r73529 | r.david.murray | 2009-06-23 13:02:46 -0500 (Tue, 23 Jun 2009) | 4 lines Fix issue 5230 by having pydoc's safeimport check to see if the import error was thrown from itself in order to decide if the module can't be found. Thanks to Lucas Prado Melo for collaborating on the fix and tests. ........ r73564 | amaury.forgeotdarc | 2009-06-25 17:29:29 -0500 (Thu, 25 Jun 2009) | 6 lines #2016 Fix a crash in function call when the **kwargs dictionary is mutated during the function call setup. This even gives a slight speedup, probably because tuple allocation is faster than PyMem_NEW. ........ r73576 | benjamin.peterson | 2009-06-26 18:37:06 -0500 (Fri, 26 Jun 2009) | 1 line document is_declared_global() ........ r73577 | benjamin.peterson | 2009-06-27 09:16:23 -0500 (Sat, 27 Jun 2009) | 1 line link to extensive generator docs in the reference manual ........ r73595 | ezio.melotti | 2009-06-27 18:45:39 -0500 (Sat, 27 Jun 2009) | 1 line stmt and setup can contain multiple statements, see #5896 ........ r73596 | ezio.melotti | 2009-06-27 19:07:45 -0500 (Sat, 27 Jun 2009) | 1 line Fixed a wrong apostrophe ........ r73605 | georg.brandl | 2009-06-28 07:10:18 -0500 (Sun, 28 Jun 2009) | 1 line Remove stray pychecker directive. ........
17 years ago
  1. # -*- coding: koi8-r -*-
  2. import unittest
  3. from test.support import TESTFN, unlink, unload, rmtree
  4. import importlib
  5. import os
  6. import sys
  7. import subprocess
  8. class SourceEncodingTest(unittest.TestCase):
  9. def test_pep263(self):
  10. self.assertEqual(
  11. "�����".encode("utf-8"),
  12. b'\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd'
  13. )
  14. self.assertEqual(
  15. "\".encode("utf-8"),
  16. b'\\\xd0\x9f'
  17. )
  18. def test_compilestring(self):
  19. # see #1882
  20. c = compile(b"\n# coding: utf-8\nu = '\xc3\xb3'\n", "dummy", "exec")
  21. d = {}
  22. exec(c, d)
  23. self.assertEqual(d['u'], '\xf3')
  24. def test_issue2301(self):
  25. try:
  26. compile(b"# coding: cp932\nprint '\x94\x4e'", "dummy", "exec")
  27. except SyntaxError as v:
  28. self.assertEqual(v.text, "print '\u5e74'\n")
  29. else:
  30. self.fail()
  31. def test_issue4626(self):
  32. c = compile("# coding=latin-1\n\u00c6 = '\u00c6'", "dummy", "exec")
  33. d = {}
  34. exec(c, d)
  35. self.assertEqual(d['\xc6'], '\xc6')
  36. def test_issue3297(self):
  37. c = compile("a, b = '\U0001010F', '\\U0001010F'", "dummy", "exec")
  38. d = {}
  39. exec(c, d)
  40. self.assertEqual(d['a'], d['b'])
  41. self.assertEqual(len(d['a']), len(d['b']))
  42. self.assertEqual(ascii(d['a']), ascii(d['b']))
  43. def test_issue7820(self):
  44. # Ensure that check_bom() restores all bytes in the right order if
  45. # check_bom() fails in pydebug mode: a buffer starts with the first
  46. # byte of a valid BOM, but next bytes are different
  47. # one byte in common with the UTF-16-LE BOM
  48. self.assertRaises(SyntaxError, eval, b'\xff\x20')
  49. # two bytes in common with the UTF-8 BOM
  50. self.assertRaises(SyntaxError, eval, b'\xef\xbb\x20')
  51. def test_20731(self):
  52. sub = subprocess.Popen([sys.executable,
  53. os.path.join(os.path.dirname(__file__),
  54. 'coding20731.py')],
  55. stderr=subprocess.PIPE)
  56. err = sub.communicate()[1]
  57. self.assertEqual(sub.returncode, 0)
  58. self.assertNotIn(b'SyntaxError', err)
  59. def test_error_message(self):
  60. compile(b'# -*- coding: iso-8859-15 -*-\n', 'dummy', 'exec')
  61. compile(b'\xef\xbb\xbf\n', 'dummy', 'exec')
  62. compile(b'\xef\xbb\xbf# -*- coding: utf-8 -*-\n', 'dummy', 'exec')
  63. with self.assertRaisesRegex(SyntaxError, 'fake'):
  64. compile(b'# -*- coding: fake -*-\n', 'dummy', 'exec')
  65. with self.assertRaisesRegex(SyntaxError, 'iso-8859-15'):
  66. compile(b'\xef\xbb\xbf# -*- coding: iso-8859-15 -*-\n',
  67. 'dummy', 'exec')
  68. with self.assertRaisesRegex(SyntaxError, 'BOM'):
  69. compile(b'\xef\xbb\xbf# -*- coding: iso-8859-15 -*-\n',
  70. 'dummy', 'exec')
  71. with self.assertRaisesRegex(SyntaxError, 'fake'):
  72. compile(b'\xef\xbb\xbf# -*- coding: fake -*-\n', 'dummy', 'exec')
  73. with self.assertRaisesRegex(SyntaxError, 'BOM'):
  74. compile(b'\xef\xbb\xbf# -*- coding: fake -*-\n', 'dummy', 'exec')
  75. def test_bad_coding(self):
  76. module_name = 'bad_coding'
  77. self.verify_bad_module(module_name)
  78. def test_bad_coding2(self):
  79. module_name = 'bad_coding2'
  80. self.verify_bad_module(module_name)
  81. def verify_bad_module(self, module_name):
  82. self.assertRaises(SyntaxError, __import__, 'test.' + module_name)
  83. path = os.path.dirname(__file__)
  84. filename = os.path.join(path, module_name + '.py')
  85. with open(filename, "rb") as fp:
  86. bytes = fp.read()
  87. self.assertRaises(SyntaxError, compile, bytes, filename, 'exec')
  88. def test_exec_valid_coding(self):
  89. d = {}
  90. exec(b'# coding: cp949\na = "\xaa\xa7"\n', d)
  91. self.assertEqual(d['a'], '\u3047')
  92. def test_file_parse(self):
  93. # issue1134: all encodings outside latin-1 and utf-8 fail on
  94. # multiline strings and long lines (>512 columns)
  95. unload(TESTFN)
  96. filename = TESTFN + ".py"
  97. f = open(filename, "w", encoding="cp1252")
  98. sys.path.insert(0, os.curdir)
  99. try:
  100. with f:
  101. f.write("# -*- coding: cp1252 -*-\n")
  102. f.write("'''A short string\n")
  103. f.write("'''\n")
  104. f.write("'A very long string %s'\n" % ("X" * 1000))
  105. importlib.invalidate_caches()
  106. __import__(TESTFN)
  107. finally:
  108. del sys.path[0]
  109. unlink(filename)
  110. unlink(filename + "c")
  111. unlink(filename + "o")
  112. unload(TESTFN)
  113. rmtree('__pycache__')
  114. def test_error_from_string(self):
  115. # See http://bugs.python.org/issue6289
  116. input = "# coding: ascii\n\N{SNOWMAN}".encode('utf-8')
  117. with self.assertRaises(SyntaxError) as c:
  118. compile(input, "<string>", "exec")
  119. expected = "'ascii' codec can't decode byte 0xe2 in position 16: " \
  120. "ordinal not in range(128)"
  121. self.assertTrue(c.exception.args[0].startswith(expected),
  122. msg=c.exception.args[0])
  123. if __name__ == "__main__":
  124. unittest.main()