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
6a1454f3
Commit
6a1454f3
authored
Mar 20, 2011
by
Éric Araujo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use proper gettext plural forms in optparse (closes #4391).
Original patch by Dwayne Bailey.
parent
2592f62a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
12 deletions
+18
-12
Lib/optparse.py
Lib/optparse.py
+15
-11
Lib/test/test_optparse.py
Lib/test/test_optparse.py
+1
-1
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/optparse.py
View file @
6a1454f3
...
@@ -86,10 +86,16 @@ def _repr(self):
...
@@ -86,10 +86,16 @@ def _repr(self):
# Id: errors.py 509 2006-04-20 00:58:24Z gward
# Id: errors.py 509 2006-04-20 00:58:24Z gward
try
:
try
:
from
gettext
import
gettext
from
gettext
import
gettext
,
ngettext
except
ImportError
:
except
ImportError
:
def
gettext
(
message
):
def
gettext
(
message
):
return
message
return
message
def
ngettext
(
singular
,
plural
,
n
):
if
n
==
1
:
return
singular
return
plural
_
=
gettext
_
=
gettext
...
@@ -1478,11 +1484,10 @@ class OptionParser (OptionContainer):
...
@@ -1478,11 +1484,10 @@ class OptionParser (OptionContainer):
if
option
.
takes_value
():
if
option
.
takes_value
():
nargs
=
option
.
nargs
nargs
=
option
.
nargs
if
len
(
rargs
)
<
nargs
:
if
len
(
rargs
)
<
nargs
:
if
nargs
==
1
:
self
.
error
(
ngettext
(
self
.
error
(
_
(
"%s option requires an argument"
)
%
opt
)
"%(option)s option requires %(number)d argument"
,
else
:
"%(option)s option requires %(number)d arguments"
,
self
.
error
(
_
(
"%s option requires %d arguments"
)
nargs
)
%
{
"option"
:
opt
,
"number"
:
nargs
})
%
(
opt
,
nargs
))
elif
nargs
==
1
:
elif
nargs
==
1
:
value
=
rargs
.
pop
(
0
)
value
=
rargs
.
pop
(
0
)
else
:
else
:
...
@@ -1517,11 +1522,10 @@ class OptionParser (OptionContainer):
...
@@ -1517,11 +1522,10 @@ class OptionParser (OptionContainer):
nargs
=
option
.
nargs
nargs
=
option
.
nargs
if
len
(
rargs
)
<
nargs
:
if
len
(
rargs
)
<
nargs
:
if
nargs
==
1
:
self
.
error
(
ngettext
(
self
.
error
(
_
(
"%s option requires an argument"
)
%
opt
)
"%(option)s option requires %(number)d argument"
,
else
:
"%(option)s option requires %(number)d arguments"
,
self
.
error
(
_
(
"%s option requires %d arguments"
)
nargs
)
%
{
"option"
:
opt
,
"number"
:
nargs
})
%
(
opt
,
nargs
))
elif
nargs
==
1
:
elif
nargs
==
1
:
value
=
rargs
.
pop
(
0
)
value
=
rargs
.
pop
(
0
)
else
:
else
:
...
...
Lib/test/test_optparse.py
View file @
6a1454f3
...
@@ -631,7 +631,7 @@ class TestStandard(BaseTest):
...
@@ -631,7 +631,7 @@ class TestStandard(BaseTest):
option_list
=
options
)
option_list
=
options
)
def
test_required_value
(
self
):
def
test_required_value
(
self
):
self
.
assertParseFail
([
"-a"
],
"-a option requires
an
argument"
)
self
.
assertParseFail
([
"-a"
],
"-a option requires
1
argument"
)
def
test_invalid_integer
(
self
):
def
test_invalid_integer
(
self
):
self
.
assertParseFail
([
"-b"
,
"5x"
],
self
.
assertParseFail
([
"-b"
,
"5x"
],
...
...
Misc/NEWS
View file @
6a1454f3
...
@@ -75,6 +75,8 @@ Core and Builtins
...
@@ -75,6 +75,8 @@ Core and Builtins
Library
Library
-------
-------
-
Issue
#
4391
:
Use
proper
gettext
plural
forms
in
optparse
.
-
Issue
#
11563
:
Connection
:
close
header
is
sent
by
requests
using
URLOpener
-
Issue
#
11563
:
Connection
:
close
header
is
sent
by
requests
using
URLOpener
class
which
helps
in
closing
of
sockets
after
connection
is
over
.
Patch
class
which
helps
in
closing
of
sockets
after
connection
is
over
.
Patch
contributions
by
Jeff
McNeil
and
Nadeem
Vawda
.
contributions
by
Jeff
McNeil
and
Nadeem
Vawda
.
...
...
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