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
f6a5ed98
Commit
f6a5ed98
authored
Jun 11, 2006
by
Greg Ward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug #1498146: fix optparse to handle Unicode strings in option help,
description, and epilog.
parent
747a36b2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
7 deletions
+48
-7
Lib/optparse.py
Lib/optparse.py
+11
-6
Lib/test/test_optparse.py
Lib/test/test_optparse.py
+34
-1
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/optparse.py
View file @
f6a5ed98
...
...
@@ -16,7 +16,7 @@ For support, use the optik-users@lists.sourceforge.net mailing list
# Python developers: please do not make changes to this file, since
# it is automatically generated from the Optik source code.
__version__
=
"1.5.1"
__version__
=
"1.5.1
+
"
__all__
=
[
'Option'
,
'SUPPRESS_HELP'
,
...
...
@@ -75,8 +75,8 @@ def _repr(self):
# This file was generated from:
# Id: option_parser.py 5
09 2006-04-20 00:58:24
Z gward
# Id: option.py 5
09 2006-04-20 00:58:24
Z gward
# Id: option_parser.py 5
22 2006-06-11 16:22:03
Z gward
# Id: option.py 5
22 2006-06-11 16:22:03
Z gward
# Id: help.py 509 2006-04-20 00:58:24Z gward
# Id: errors.py 509 2006-04-20 00:58:24Z gward
...
...
@@ -256,7 +256,7 @@ class HelpFormatter:
text_width
,
initial_indent
=
indent
,
subsequent_indent
=
indent
)
def
format_description
(
self
,
description
):
if
description
:
return
self
.
_format_text
(
description
)
+
"
\
n
"
...
...
@@ -1214,7 +1214,7 @@ class OptionParser (OptionContainer):
"""
Declare that you are done with this OptionParser. This cleans up
reference cycles so the OptionParser (and all objects referenced by
it) can be garbage-collected promptly. After calling destroy(), the
it) can be garbage-collected promptly. After calling destroy(), the
OptionParser is unusable.
"""
OptionContainer
.
destroy
(
self
)
...
...
@@ -1629,6 +1629,10 @@ class OptionParser (OptionContainer):
result
.
append
(
self
.
format_epilog
(
formatter
))
return
""
.
join
(
result
)
# used by test suite
def
_get_encoding
(
self
,
file
):
return
getattr
(
file
,
"encoding"
,
sys
.
getdefaultencoding
())
def
print_help
(
self
,
file
=
None
):
"""print_help(file : file = stdout)
...
...
@@ -1637,7 +1641,8 @@ class OptionParser (OptionContainer):
"""
if
file
is
None
:
file
=
sys
.
stdout
file
.
write
(
self
.
format_help
())
encoding
=
self
.
_get_encoding
(
file
)
file
.
write
(
self
.
format_help
().
encode
(
encoding
,
"replace"
))
# class OptionParser
...
...
Lib/test/test_optparse.py
View file @
f6a5ed98
...
...
@@ -15,7 +15,7 @@ import copy
import
types
import
unittest
from
c
StringIO
import
StringIO
from
StringIO
import
StringIO
from
pprint
import
pprint
from
test
import
test_support
...
...
@@ -164,15 +164,23 @@ and kwargs %(kwargs)r
expected_error
=
None
):
"""Assert the parser prints the expected output on stdout."""
save_stdout
=
sys
.
stdout
encoding
=
getattr
(
save_stdout
,
'encoding'
,
None
)
try
:
try
:
sys
.
stdout
=
StringIO
()
if
encoding
:
sys
.
stdout
.
encoding
=
encoding
self
.
parser
.
parse_args
(
cmdline_args
)
finally
:
output
=
sys
.
stdout
.
getvalue
()
sys
.
stdout
=
save_stdout
except
InterceptedError
,
err
:
self
.
assert_
(
type
(
output
)
is
types
.
StringType
,
"expected output to be an ordinary string, not %r"
%
type
(
output
))
if
output
!=
expected_output
:
self
.
fail
(
"expected:
\
n
'''
\
n
"
+
expected_output
+
"'''
\
n
but got
\
n
'''
\
n
"
+
output
+
"'''"
)
...
...
@@ -1456,6 +1464,10 @@ class TestHelp(BaseTest):
return
InterceptingOptionParser
(
option_list
=
options
)
def
assertHelpEquals
(
self
,
expected_output
):
if
type
(
expected_output
)
is
types
.
UnicodeType
:
encoding
=
self
.
parser
.
_get_encoding
(
sys
.
stdout
)
expected_output
=
expected_output
.
encode
(
encoding
,
"replace"
)
save_argv
=
sys
.
argv
[:]
try
:
# Make optparse believe bar.py is being executed.
...
...
@@ -1486,6 +1498,27 @@ class TestHelp(BaseTest):
self
.
parser
=
self
.
make_parser
(
60
)
self
.
assertHelpEquals
(
_expected_help_short_lines
)
def
test_help_unicode
(
self
):
self
.
parser
=
InterceptingOptionParser
(
usage
=
SUPPRESS_USAGE
)
self
.
parser
.
add_option
(
"-a"
,
action
=
"store_true"
,
help
=
u"ol
\
u00E9
!"
)
expect
=
u"""
\
Options:
-h, --help show this help message and exit
-a ol
\
u00E9
!
"""
self
.
assertHelpEquals
(
expect
)
def
test_help_unicode_description
(
self
):
self
.
parser
=
InterceptingOptionParser
(
usage
=
SUPPRESS_USAGE
,
description
=
u"ol
\
u00E9
!"
)
expect
=
u"""
\
ol
\
u00E9
!
Options:
-h, --help show this help message and exit
"""
self
.
assertHelpEquals
(
expect
)
def
test_help_description_groups
(
self
):
self
.
parser
.
set_description
(
"This is the program description for %prog. %prog has "
...
...
Misc/NEWS
View file @
f6a5ed98
...
...
@@ -145,6 +145,9 @@ Extension Modules
Library
-------
- Bug #1498146: fix optparse to handle Unicode strings in option help,
description, and epilog.
- Bug #1366250: minor optparse documentation error.
- Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately;
...
...
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