mirror of
https://github.com/python/cpython.git
synced 2025-09-05 00:11:10 +00:00
(merge 3.2) Issue #12451: pydoc.synopsis() now reads the encoding cookie if
available, to read the Python script from the right encoding.
This commit is contained in:
commit
319672e8a6
3 changed files with 20 additions and 5 deletions
|
@ -51,16 +51,17 @@ Richard Chamberlain, for the first implementation of textdoc.
|
||||||
# the current directory is changed with os.chdir(), an incorrect
|
# the current directory is changed with os.chdir(), an incorrect
|
||||||
# path will be displayed.
|
# path will be displayed.
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import builtins
|
import builtins
|
||||||
import imp
|
import imp
|
||||||
import io
|
|
||||||
import inspect
|
import inspect
|
||||||
|
import io
|
||||||
|
import os
|
||||||
import pkgutil
|
import pkgutil
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import tokenize
|
||||||
import warnings
|
import warnings
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from reprlib import Repr
|
from reprlib import Repr
|
||||||
|
@ -221,7 +222,7 @@ def synopsis(filename, cache={}):
|
||||||
if lastupdate < mtime:
|
if lastupdate < mtime:
|
||||||
info = inspect.getmoduleinfo(filename)
|
info = inspect.getmoduleinfo(filename)
|
||||||
try:
|
try:
|
||||||
file = open(filename)
|
file = tokenize.open(filename)
|
||||||
except IOError:
|
except IOError:
|
||||||
# module can't be opened, so skip it
|
# module can't be opened, so skip it
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -16,7 +16,7 @@ from io import StringIO
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from test.support import TESTFN, forget, rmtree, EnvironmentVarGuard, \
|
from test.support import TESTFN, forget, rmtree, EnvironmentVarGuard, \
|
||||||
reap_children, captured_output, captured_stdout
|
reap_children, captured_output, captured_stdout, unlink
|
||||||
|
|
||||||
from test import pydoc_mod
|
from test import pydoc_mod
|
||||||
|
|
||||||
|
@ -395,6 +395,17 @@ class PydocDocTest(unittest.TestCase):
|
||||||
self.assertIn('_replace', helptext)
|
self.assertIn('_replace', helptext)
|
||||||
self.assertIn('_asdict', helptext)
|
self.assertIn('_asdict', helptext)
|
||||||
|
|
||||||
|
def test_synopsis(self):
|
||||||
|
self.addCleanup(unlink, TESTFN)
|
||||||
|
for encoding in ('ISO-8859-1', 'UTF-8'):
|
||||||
|
with open(TESTFN, 'w', encoding=encoding) as script:
|
||||||
|
if encoding != 'UTF-8':
|
||||||
|
print('#coding: {}'.format(encoding), file=script)
|
||||||
|
print('"""line 1: h\xe9', file=script)
|
||||||
|
print('line 2: hi"""', file=script)
|
||||||
|
synopsis = pydoc.synopsis(TESTFN, {})
|
||||||
|
self.assertEqual(synopsis, 'line 1: h\xe9')
|
||||||
|
|
||||||
|
|
||||||
class TestDescriptions(unittest.TestCase):
|
class TestDescriptions(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
@ -200,6 +200,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #12451: pydoc.synopsis() now reads the encoding cookie if available,
|
||||||
|
to read the Python script from the right encoding.
|
||||||
|
|
||||||
- Issue #12451: distutils now opens the setup script in binary mode to read the
|
- Issue #12451: distutils now opens the setup script in binary mode to read the
|
||||||
encoding cookie, instead of opening it in UTF-8.
|
encoding cookie, instead of opening it in UTF-8.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue