Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e6c910e9
Commit
e6c910e9
authored
Jun 30, 2011
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #12451: pydoc.synopsis() now reads the encoding cookie if available, to
read the Python script from the right encoding.
parent
dc9b1ea0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
5 deletions
+20
-5
Lib/pydoc.py
Lib/pydoc.py
+5
-4
Lib/test/test_pydoc.py
Lib/test/test_pydoc.py
+12
-1
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/pydoc.py
View file @
e6c910e9
...
...
@@ -57,16 +57,17 @@ Richard Chamberlain, for the first implementation of textdoc.
# the current directory is changed with os.chdir(), an incorrect
# path will be displayed.
import
os
import
sys
import
builtins
import
imp
import
io
import
inspect
import
io
import
os
import
pkgutil
import
platform
import
re
import
sys
import
time
import
tokenize
import
warnings
from
collections
import
deque
from
reprlib
import
Repr
...
...
@@ -227,7 +228,7 @@ def synopsis(filename, cache={}):
if
lastupdate
<
mtime
:
info
=
inspect
.
getmoduleinfo
(
filename
)
try
:
file
=
open
(
filename
)
file
=
tokenize
.
open
(
filename
)
except
IOError
:
# module can't be opened, so skip it
return
None
...
...
Lib/test/test_pydoc.py
View file @
e6c910e9
...
...
@@ -16,7 +16,7 @@ from io import StringIO
from
collections
import
namedtuple
from
contextlib
import
contextmanager
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
...
...
@@ -389,6 +389,17 @@ class PydocDocTest(unittest.TestCase):
self
.
assertIn
(
'_replace'
,
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
):
...
...
Misc/NEWS
View file @
e6c910e9
...
...
@@ -25,6 +25,9 @@ Core and Builtins
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
encoding cookie, instead of opening it in UTF-8.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment