Kaydet (Commit) 14eba5fa authored tarafından Éric Araujo's avatar Éric Araujo

Brench merge

...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
=============================================================================== ===============================================================================
.. module:: argparse .. module:: argparse
:synopsis: Command-line option and argument-parsing library. :synopsis: Command-line option and argument parsing library.
.. moduleauthor:: Steven Bethard <steven.bethard@gmail.com> .. moduleauthor:: Steven Bethard <steven.bethard@gmail.com>
.. sectionauthor:: Steven Bethard <steven.bethard@gmail.com> .. sectionauthor:: Steven Bethard <steven.bethard@gmail.com>
...@@ -107,7 +107,7 @@ or the :func:`max` function if it was not. ...@@ -107,7 +107,7 @@ or the :func:`max` function if it was not.
Parsing arguments Parsing arguments
^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
:class:`ArgumentParser` parses args through the :class:`ArgumentParser` parses arguments through the
:meth:`~ArgumentParser.parse_args` method. This will inspect the command line, :meth:`~ArgumentParser.parse_args` method. This will inspect the command line,
convert each arg to the appropriate type and then invoke the appropriate action. convert each arg to the appropriate type and then invoke the appropriate action.
In most cases, this means a simple :class:`Namespace` object will be built up from In most cases, this means a simple :class:`Namespace` object will be built up from
...@@ -118,7 +118,7 @@ attributes parsed out of the command line:: ...@@ -118,7 +118,7 @@ attributes parsed out of the command line::
In a script, :meth:`~ArgumentParser.parse_args` will typically be called with no In a script, :meth:`~ArgumentParser.parse_args` will typically be called with no
arguments, and the :class:`ArgumentParser` will automatically determine the arguments, and the :class:`ArgumentParser` will automatically determine the
command-line args from :data:`sys.argv`. command-line arguments from :data:`sys.argv`.
ArgumentParser objects ArgumentParser objects
...@@ -669,11 +669,11 @@ be positional:: ...@@ -669,11 +669,11 @@ be positional::
action action
^^^^^^ ^^^^^^
:class:`ArgumentParser` objects associate command-line args with actions. These :class:`ArgumentParser` objects associate command-line arguments with actions. These
actions can do just about anything with the command-line args associated with actions can do just about anything with the command-line arguments associated with
them, though most actions simply add an attribute to the object returned by them, though most actions simply add an attribute to the object returned by
:meth:`~ArgumentParser.parse_args`. The ``action`` keyword argument specifies :meth:`~ArgumentParser.parse_args`. The ``action`` keyword argument specifies
how the command-line args should be handled. The supported actions are: how the command-line arguments should be handled. The supported actions are:
* ``'store'`` - This just stores the argument's value. This is the default * ``'store'`` - This just stores the argument's value. This is the default
action. For example:: action. For example::
...@@ -745,8 +745,8 @@ the Action API. The easiest way to do this is to extend ...@@ -745,8 +745,8 @@ the Action API. The easiest way to do this is to extend
:meth:`~ArgumentParser.parse_args`. Most actions add an attribute to this :meth:`~ArgumentParser.parse_args`. Most actions add an attribute to this
object. object.
* ``values`` - The associated command-line args, with any type-conversions * ``values`` - The associated command-line arguments, with any type conversions
applied. (Type-conversions are specified with the type_ keyword argument to applied. (Type conversions are specified with the type_ keyword argument to
:meth:`~ArgumentParser.add_argument`. :meth:`~ArgumentParser.add_argument`.
* ``option_string`` - The option string that was used to invoke this action. * ``option_string`` - The option string that was used to invoke this action.
...@@ -778,7 +778,7 @@ single action to be taken. The ``nargs`` keyword argument associates a ...@@ -778,7 +778,7 @@ single action to be taken. The ``nargs`` keyword argument associates a
different number of command-line arguments with a single action. The supported different number of command-line arguments with a single action. The supported
values are: values are:
* N (an integer). N args from the command line will be gathered together into a * N (an integer). N arguments from the command line will be gathered together into a
list. For example:: list. For example::
>>> parser = argparse.ArgumentParser() >>> parser = argparse.ArgumentParser()
...@@ -822,7 +822,7 @@ values are: ...@@ -822,7 +822,7 @@ values are:
Namespace(infile=<_io.TextIOWrapper name='<stdin>' encoding='UTF-8'>, Namespace(infile=<_io.TextIOWrapper name='<stdin>' encoding='UTF-8'>,
outfile=<_io.TextIOWrapper name='<stdout>' encoding='UTF-8'>) outfile=<_io.TextIOWrapper name='<stdout>' encoding='UTF-8'>)
* ``'*'``. All command-line args present are gathered into a list. Note that * ``'*'``. All command-line arguments present are gathered into a list. Note that
it generally doesn't make much sense to have more than one positional argument it generally doesn't make much sense to have more than one positional argument
with ``nargs='*'``, but multiple optional arguments with ``nargs='*'`` is with ``nargs='*'``, but multiple optional arguments with ``nargs='*'`` is
possible. For example:: possible. For example::
...@@ -846,7 +846,7 @@ values are: ...@@ -846,7 +846,7 @@ values are:
usage: PROG [-h] foo [foo ...] usage: PROG [-h] foo [foo ...]
PROG: error: too few arguments PROG: error: too few arguments
If the ``nargs`` keyword argument is not provided, the number of args consumed If the ``nargs`` keyword argument is not provided, the number of arguments consumed
is determined by the action_. Generally this means a single command-line arg is determined by the action_. Generally this means a single command-line arg
will be consumed and a single item (not a list) will be produced. will be consumed and a single item (not a list) will be produced.
...@@ -864,7 +864,7 @@ the various :class:`ArgumentParser` actions. The two most common uses of it are ...@@ -864,7 +864,7 @@ the various :class:`ArgumentParser` actions. The two most common uses of it are
* When :meth:`~ArgumentParser.add_argument` is called with option strings * When :meth:`~ArgumentParser.add_argument` is called with option strings
(like ``-f`` or ``--foo``) and ``nargs='?'``. This creates an optional (like ``-f`` or ``--foo``) and ``nargs='?'``. This creates an optional
argument that can be followed by zero or one command-line args. argument that can be followed by zero or one command-line arguments.
When parsing the command line, if the option string is encountered with no When parsing the command line, if the option string is encountered with no
command-line arg following it, the value of ``const`` will be assumed instead. command-line arg following it, the value of ``const`` will be assumed instead.
See the nargs_ description for examples. See the nargs_ description for examples.
...@@ -914,11 +914,11 @@ command-line argument was not present.:: ...@@ -914,11 +914,11 @@ command-line argument was not present.::
type type
^^^^ ^^^^
By default, :class:`ArgumentParser` objects read command-line args in as simple By default, :class:`ArgumentParser` objects read command-line arguments in as simple
strings. However, quite often the command-line string should instead be strings. However, quite often the command-line string should instead be
interpreted as another type, like a :class:`float` or :class:`int`. The interpreted as another type, like a :class:`float` or :class:`int`. The
``type`` keyword argument of :meth:`~ArgumentParser.add_argument` allows any ``type`` keyword argument of :meth:`~ArgumentParser.add_argument` allows any
necessary type-checking and type-conversions to be performed. Common built-in necessary type-checking and type conversions to be performed. Common built-in
types and functions can be used directly as the value of the ``type`` argument:: types and functions can be used directly as the value of the ``type`` argument::
>>> parser = argparse.ArgumentParser() >>> parser = argparse.ArgumentParser()
...@@ -938,7 +938,7 @@ writable file:: ...@@ -938,7 +938,7 @@ writable file::
Namespace(bar=<_io.TextIOWrapper name='out.txt' encoding='UTF-8'>) Namespace(bar=<_io.TextIOWrapper name='out.txt' encoding='UTF-8'>)
``type=`` can take any callable that takes a single string argument and returns ``type=`` can take any callable that takes a single string argument and returns
the type-converted value:: the converted value::
>>> def perfect_square(string): >>> def perfect_square(string):
... value = int(string) ... value = int(string)
...@@ -973,7 +973,7 @@ See the choices_ section for more details. ...@@ -973,7 +973,7 @@ See the choices_ section for more details.
choices choices
^^^^^^^ ^^^^^^^
Some command-line args should be selected from a restricted set of values. Some command-line arguments should be selected from a restricted set of values.
These can be handled by passing a container object as the ``choices`` keyword These can be handled by passing a container object as the ``choices`` keyword
argument to :meth:`~ArgumentParser.add_argument`. When the command line is argument to :meth:`~ArgumentParser.add_argument`. When the command line is
parsed, arg values will be checked, and an error message will be displayed if parsed, arg values will be checked, and an error message will be displayed if
...@@ -1331,7 +1331,7 @@ An error is produced for arguments that could produce more than one options. ...@@ -1331,7 +1331,7 @@ An error is produced for arguments that could produce more than one options.
Beyond ``sys.argv`` Beyond ``sys.argv``
^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^
Sometimes it may be useful to have an ArgumentParser parse args other than those Sometimes it may be useful to have an ArgumentParser parse arguments other than those
of :data:`sys.argv`. This can be accomplished by passing a list of strings to of :data:`sys.argv`. This can be accomplished by passing a list of strings to
:meth:`~ArgumentParser.parse_args`. This is useful for testing at the :meth:`~ArgumentParser.parse_args`. This is useful for testing at the
interactive prompt:: interactive prompt::
...@@ -1559,7 +1559,7 @@ FileType objects ...@@ -1559,7 +1559,7 @@ FileType objects
The :class:`FileType` factory creates objects that can be passed to the type The :class:`FileType` factory creates objects that can be passed to the type
argument of :meth:`ArgumentParser.add_argument`. Arguments that have argument of :meth:`ArgumentParser.add_argument`. Arguments that have
:class:`FileType` objects as their type will open command-line args as files :class:`FileType` objects as their type will open command-line arguments as files
with the requested modes and buffer sizes: with the requested modes and buffer sizes:
>>> parser = argparse.ArgumentParser() >>> parser = argparse.ArgumentParser()
...@@ -1673,7 +1673,7 @@ Parser defaults ...@@ -1673,7 +1673,7 @@ Parser defaults
.. method:: ArgumentParser.set_defaults(**kwargs) .. method:: ArgumentParser.set_defaults(**kwargs)
Most of the time, the attributes of the object returned by :meth:`parse_args` Most of the time, the attributes of the object returned by :meth:`parse_args`
will be fully determined by inspecting the command-line args and the argument will be fully determined by inspecting the command-line arguments and the argument
actions. :meth:`set_defaults` allows some additional actions. :meth:`set_defaults` allows some additional
attributes that are determined without any inspection of the command line to attributes that are determined without any inspection of the command line to
be added:: be added::
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
.. module:: email.policy .. module:: email.policy
:synopsis: Controlling the parsing and generating of messages :synopsis: Controlling the parsing and generating of messages
.. versionadded: 3.3 .. versionadded:: 3.3
The :mod:`email` package's prime focus is the handling of email messages as The :mod:`email` package's prime focus is the handling of email messages as
......
...@@ -10,7 +10,7 @@ from distutils.core import Distribution ...@@ -10,7 +10,7 @@ from distutils.core import Distribution
from distutils.errors import DistutilsFileError from distutils.errors import DistutilsFileError
from distutils.tests import support from distutils.tests import support
from test.support import run_unittest, create_empty_file from test.support import run_unittest
class BuildPyTestCase(support.TempdirManager, class BuildPyTestCase(support.TempdirManager,
...@@ -71,11 +71,11 @@ class BuildPyTestCase(support.TempdirManager, ...@@ -71,11 +71,11 @@ class BuildPyTestCase(support.TempdirManager,
# create the distribution files. # create the distribution files.
sources = self.mkdtemp() sources = self.mkdtemp()
create_empty_file(os.path.join(sources, "__init__.py")) open(os.path.join(sources, "__init__.py"), "w").close()
testdir = os.path.join(sources, "doc") testdir = os.path.join(sources, "doc")
os.mkdir(testdir) os.mkdir(testdir)
create_empty_file(os.path.join(testdir, "testfile")) open(os.path.join(testdir, "testfile"), "w").close()
os.chdir(sources) os.chdir(sources)
old_stdout = sys.stdout old_stdout = sys.stdout
......
...@@ -3,18 +3,14 @@ ...@@ -3,18 +3,14 @@
from packaging.pypi.xmlrpc import Client, InvalidSearchField, ProjectNotFound from packaging.pypi.xmlrpc import Client, InvalidSearchField, ProjectNotFound
from packaging.tests import unittest from packaging.tests import unittest
from packaging.tests.support import fake_dec
try: try:
import threading import threading
from packaging.tests.pypi_server import use_xmlrpc_server from packaging.tests.pypi_server import use_xmlrpc_server
except ImportError: except ImportError:
threading = None threading = None
def use_xmlrpc_server(): use_xmlrpc_server = fake_dec
def _use(func):
def __use(*args, **kw):
return func(*args, **kw)
return __use
return _use
@unittest.skipIf(threading is None, "Needs threading") @unittest.skipIf(threading is None, "Needs threading")
......
...@@ -276,7 +276,7 @@ def split(s, comments=False, posix=True): ...@@ -276,7 +276,7 @@ def split(s, comments=False, posix=True):
return list(lex) return list(lex)
_find_unsafe = re.compile(r'[^\w\d@%_\-\+=:,\./]').search _find_unsafe = re.compile(r'[^\w@%\-\+=:,\./]', re.ASCII).search
def quote(s): def quote(s):
"""Return a shell-escaped version of the string *s*.""" """Return a shell-escaped version of the string *s*."""
......
...@@ -267,7 +267,7 @@ def rmtree(path, ignore_errors=False, onerror=None): ...@@ -267,7 +267,7 @@ def rmtree(path, ignore_errors=False, onerror=None):
names = [] names = []
try: try:
names = os.listdir(path) names = os.listdir(path)
except os.error as err: except os.error:
onerror(os.listdir, path, sys.exc_info()) onerror(os.listdir, path, sys.exc_info())
for name in names: for name in names:
fullname = os.path.join(path, name) fullname = os.path.join(path, name)
...@@ -280,7 +280,7 @@ def rmtree(path, ignore_errors=False, onerror=None): ...@@ -280,7 +280,7 @@ def rmtree(path, ignore_errors=False, onerror=None):
else: else:
try: try:
os.remove(fullname) os.remove(fullname)
except os.error as err: except os.error:
onerror(os.remove, fullname, sys.exc_info()) onerror(os.remove, fullname, sys.exc_info())
try: try:
os.rmdir(path) os.rmdir(path)
...@@ -323,7 +323,7 @@ def move(src, dst): ...@@ -323,7 +323,7 @@ def move(src, dst):
raise Error("Destination path '%s' already exists" % real_dst) raise Error("Destination path '%s' already exists" % real_dst)
try: try:
os.rename(src, real_dst) os.rename(src, real_dst)
except OSError as exc: except OSError:
if os.path.isdir(src): if os.path.isdir(src):
if _destinsrc(src, dst): if _destinsrc(src, dst):
raise Error("Cannot move a directory '%s' into itself '%s'." % (src, dst)) raise Error("Cannot move a directory '%s' into itself '%s'." % (src, dst))
......
...@@ -176,7 +176,8 @@ class ShlexTest(unittest.TestCase): ...@@ -176,7 +176,8 @@ class ShlexTest(unittest.TestCase):
def testQuote(self): def testQuote(self):
safeunquoted = string.ascii_letters + string.digits + '@%_-+=:,./' safeunquoted = string.ascii_letters + string.digits + '@%_-+=:,./'
unsafe = '"`$\\!' unicode_sample = '\xe9\xe0\xdf' # e + acute accent, a + grave, sharp s
unsafe = '"`$\\!' + unicode_sample
self.assertEqual(shlex.quote(''), "''") self.assertEqual(shlex.quote(''), "''")
self.assertEqual(shlex.quote(safeunquoted), safeunquoted) self.assertEqual(shlex.quote(safeunquoted), safeunquoted)
......
...@@ -1330,8 +1330,8 @@ smelly: all ...@@ -1330,8 +1330,8 @@ smelly: all
# Find files with funny names # Find files with funny names
funny: funny:
find $(DISTDIRS) \ find $(SUBDIRS) $(SUBDIRSTOO) \
-o -type d \ -type d \
-o -name '*.[chs]' \ -o -name '*.[chs]' \
-o -name '*.py' \ -o -name '*.py' \
-o -name '*.pyw' \ -o -name '*.pyw' \
...@@ -1359,7 +1359,7 @@ funny: ...@@ -1359,7 +1359,7 @@ funny:
-o -name .hgignore \ -o -name .hgignore \
-o -name .bzrignore \ -o -name .bzrignore \
-o -name MANIFEST \ -o -name MANIFEST \
-o -print -print
# Perform some verification checks on any modified files. # Perform some verification checks on any modified files.
patchcheck: patchcheck:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment