mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Branch merge
This commit is contained in:
commit
7fb624fe51
17 changed files with 73 additions and 46 deletions
|
@ -511,13 +511,12 @@ interpreter can only be used after the interpreter has been initialized.
|
||||||
module: builtins
|
module: builtins
|
||||||
module: __main__
|
module: __main__
|
||||||
module: sys
|
module: sys
|
||||||
module: exceptions
|
|
||||||
triple: module; search; path
|
triple: module; search; path
|
||||||
single: path (in module sys)
|
single: path (in module sys)
|
||||||
|
|
||||||
The basic initialization function is :c:func:`Py_Initialize`. This initializes
|
The basic initialization function is :c:func:`Py_Initialize`. This initializes
|
||||||
the table of loaded modules, and creates the fundamental modules
|
the table of loaded modules, and creates the fundamental modules
|
||||||
:mod:`builtins`, :mod:`__main__`, :mod:`sys`, and :mod:`exceptions`. It also
|
:mod:`builtins`, :mod:`__main__`, and :mod:`sys`. It also
|
||||||
initializes the module search path (``sys.path``).
|
initializes the module search path (``sys.path``).
|
||||||
|
|
||||||
.. index:: single: PySys_SetArgvEx()
|
.. index:: single: PySys_SetArgvEx()
|
||||||
|
|
|
@ -279,7 +279,7 @@ For example, if the :file:`setup.py` script is changed like this::
|
||||||
Where the long description is broken, ``check`` will be able to detect it
|
Where the long description is broken, ``check`` will be able to detect it
|
||||||
by using the :mod:`docutils` parser::
|
by using the :mod:`docutils` parser::
|
||||||
|
|
||||||
$ pythontrunk setup.py check --restructuredtext
|
$ python setup.py check --restructuredtext
|
||||||
running check
|
running check
|
||||||
warning: check: Title underline too short. (line 2)
|
warning: check: Title underline too short. (line 2)
|
||||||
warning: check: Could not finish the parsing.
|
warning: check: Could not finish the parsing.
|
||||||
|
|
|
@ -152,7 +152,7 @@ The directives are:
|
||||||
|
|
||||||
Describes global data in a module, including both variables and values used
|
Describes global data in a module, including both variables and values used
|
||||||
as "defined constants." Class and object attributes are not documented
|
as "defined constants." Class and object attributes are not documented
|
||||||
using this environment.
|
using this directive.
|
||||||
|
|
||||||
.. describe:: exception
|
.. describe:: exception
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ The directives are:
|
||||||
parameters, enclosing optional parameters in brackets. Default values can be
|
parameters, enclosing optional parameters in brackets. Default values can be
|
||||||
given if it enhances clarity. For example::
|
given if it enhances clarity. For example::
|
||||||
|
|
||||||
.. function:: Timer.repeat([repeat=3[, number=1000000]])
|
.. function:: repeat([repeat=3[, number=1000000]])
|
||||||
|
|
||||||
Object methods are not documented using this directive. Bound object methods
|
Object methods are not documented using this directive. Bound object methods
|
||||||
placed in the module namespace as part of the public interface of the module
|
placed in the module namespace as part of the public interface of the module
|
||||||
|
@ -217,13 +217,30 @@ The directives are:
|
||||||
|
|
||||||
Describes an object data attribute. The description should include
|
Describes an object data attribute. The description should include
|
||||||
information about the type of the data to be expected and whether it may be
|
information about the type of the data to be expected and whether it may be
|
||||||
changed directly.
|
changed directly. This directive should be nested in a class directive,
|
||||||
|
like in this example::
|
||||||
|
|
||||||
|
.. class:: Spam
|
||||||
|
|
||||||
|
Description of the class.
|
||||||
|
|
||||||
|
.. data:: ham
|
||||||
|
|
||||||
|
Description of the attribute.
|
||||||
|
|
||||||
|
If is also possible to document an attribute outside of a class directive,
|
||||||
|
for example if the documentation for different attributes and methods is
|
||||||
|
split in multiple sections. The class name should then be included
|
||||||
|
explicitly::
|
||||||
|
|
||||||
|
.. data:: Spam.eggs
|
||||||
|
|
||||||
.. describe:: method
|
.. describe:: method
|
||||||
|
|
||||||
Describes an object method. The parameters should not include the ``self``
|
Describes an object method. The parameters should not include the ``self``
|
||||||
parameter. The description should include similar information to that
|
parameter. The description should include similar information to that
|
||||||
described for ``function``.
|
described for ``function``. This method should be nested in a class
|
||||||
|
method, like in the example above.
|
||||||
|
|
||||||
.. describe:: decoratormethod
|
.. describe:: decoratormethod
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ The class can be used to simulate nested scopes and is useful in templating.
|
||||||
* The `MultiContext class
|
* The `MultiContext class
|
||||||
<http://svn.enthought.com/svn/enthought/CodeTools/trunk/enthought/contexts/multi_context.py>`_
|
<http://svn.enthought.com/svn/enthought/CodeTools/trunk/enthought/contexts/multi_context.py>`_
|
||||||
in the Enthought `CodeTools package
|
in the Enthought `CodeTools package
|
||||||
<https://github.com/enthought/codetools>`_\ has options to support
|
<https://github.com/enthought/codetools>`_ has options to support
|
||||||
writing to any mapping in the chain.
|
writing to any mapping in the chain.
|
||||||
|
|
||||||
* Django's `Context class
|
* Django's `Context class
|
||||||
|
@ -150,7 +150,7 @@ The class can be used to simulate nested scopes and is useful in templating.
|
||||||
any mapping in the chain.
|
any mapping in the chain.
|
||||||
|
|
||||||
* A `greatly simplified read-only version of Chainmap
|
* A `greatly simplified read-only version of Chainmap
|
||||||
<http://code.activestate.com/recipes/305268/>`_\.
|
<http://code.activestate.com/recipes/305268/>`_.
|
||||||
|
|
||||||
:class:`Counter` objects
|
:class:`Counter` objects
|
||||||
------------------------
|
------------------------
|
||||||
|
@ -320,14 +320,14 @@ counts, but the output will exclude results with counts of zero or less.
|
||||||
* `Bag class <http://www.gnu.org/software/smalltalk/manual-base/html_node/Bag.html>`_
|
* `Bag class <http://www.gnu.org/software/smalltalk/manual-base/html_node/Bag.html>`_
|
||||||
in Smalltalk.
|
in Smalltalk.
|
||||||
|
|
||||||
* Wikipedia entry for `Multisets <http://en.wikipedia.org/wiki/Multiset>`_\.
|
* Wikipedia entry for `Multisets <http://en.wikipedia.org/wiki/Multiset>`_.
|
||||||
|
|
||||||
* `C++ multisets <http://www.demo2s.com/Tutorial/Cpp/0380__set-multiset/Catalog0380__set-multiset.htm>`_
|
* `C++ multisets <http://www.demo2s.com/Tutorial/Cpp/0380__set-multiset/Catalog0380__set-multiset.htm>`_
|
||||||
tutorial with examples.
|
tutorial with examples.
|
||||||
|
|
||||||
* For mathematical operations on multisets and their use cases, see
|
* For mathematical operations on multisets and their use cases, see
|
||||||
*Knuth, Donald. The Art of Computer Programming Volume II,
|
*Knuth, Donald. The Art of Computer Programming Volume II,
|
||||||
Section 4.6.3, Exercise 19*\.
|
Section 4.6.3, Exercise 19*.
|
||||||
|
|
||||||
* To enumerate all distinct multisets of a given size over a given set of
|
* To enumerate all distinct multisets of a given size over a given set of
|
||||||
elements, see :func:`itertools.combinations_with_replacement`.
|
elements, see :func:`itertools.combinations_with_replacement`.
|
||||||
|
|
|
@ -30,9 +30,9 @@ the Oracle Berkeley DB.
|
||||||
name, such as ``'dbm.ndbm'`` or ``'dbm.gnu'``.
|
name, such as ``'dbm.ndbm'`` or ``'dbm.gnu'``.
|
||||||
|
|
||||||
|
|
||||||
.. function:: open(filename, flag='r', mode=0o666)
|
.. function:: open(file, flag='r', mode=0o666)
|
||||||
|
|
||||||
Open the database file *filename* and return a corresponding object.
|
Open the database file *file* and return a corresponding object.
|
||||||
|
|
||||||
If the database file already exists, the :func:`whichdb` function is used to
|
If the database file already exists, the :func:`whichdb` function is used to
|
||||||
determine its type and the appropriate module is used; if it does not exist,
|
determine its type and the appropriate module is used; if it does not exist,
|
||||||
|
|
|
@ -34,7 +34,7 @@ Encoding basic Python object hierarchies::
|
||||||
Compact encoding::
|
Compact encoding::
|
||||||
|
|
||||||
>>> import json
|
>>> import json
|
||||||
>>> json.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',',':'))
|
>>> json.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',', ':'))
|
||||||
'[1,2,3,{"4":5,"6":7}]'
|
'[1,2,3,{"4":5,"6":7}]'
|
||||||
|
|
||||||
Pretty printing::
|
Pretty printing::
|
||||||
|
|
|
@ -49,7 +49,7 @@ The :mod:`runpy` module provides two functions:
|
||||||
loader does not make filename information available, this variable is set
|
loader does not make filename information available, this variable is set
|
||||||
to :const:`None`.
|
to :const:`None`.
|
||||||
|
|
||||||
``__cached__`` will be set to ``None``.
|
``__cached__`` will be set to ``None``.
|
||||||
|
|
||||||
``__loader__`` is set to the :pep:`302` module loader used to retrieve the
|
``__loader__`` is set to the :pep:`302` module loader used to retrieve the
|
||||||
code for the module (This loader may be a wrapper around the standard
|
code for the module (This loader may be a wrapper around the standard
|
||||||
|
|
|
@ -19,6 +19,10 @@ imported with no automatic modifications to the module search path. To
|
||||||
explicitly trigger the usual site-specific additions, call the
|
explicitly trigger the usual site-specific additions, call the
|
||||||
:func:`site.main` function.
|
:func:`site.main` function.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.3
|
||||||
|
Importing the module used to trigger paths manipulation even when using
|
||||||
|
:option:`-S`.
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
pair: site-python; directory
|
pair: site-python; directory
|
||||||
pair: site-packages; directory
|
pair: site-packages; directory
|
||||||
|
|
|
@ -246,6 +246,9 @@ always available.
|
||||||
.. versionchanged:: 3.2
|
.. versionchanged:: 3.2
|
||||||
Added ``quiet`` attribute for the new :option:`-q` flag.
|
Added ``quiet`` attribute for the new :option:`-q` flag.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.3
|
||||||
|
Removed obsolete ``division_warning`` attribute.
|
||||||
|
|
||||||
|
|
||||||
.. data:: float_info
|
.. data:: float_info
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,8 @@ def literal_eval(node_or_string):
|
||||||
"""
|
"""
|
||||||
Safely evaluate an expression node or a string containing a Python
|
Safely evaluate an expression node or a string containing a Python
|
||||||
expression. The string or node provided may only consist of the following
|
expression. The string or node provided may only consist of the following
|
||||||
Python literal structures: strings, numbers, tuples, lists, dicts, booleans,
|
Python literal structures: strings, bytes, numbers, tuples, lists, dicts,
|
||||||
and None.
|
sets, booleans, and None.
|
||||||
"""
|
"""
|
||||||
_safe_names = {'None': None, 'True': True, 'False': False}
|
_safe_names = {'None': None, 'True': True, 'False': False}
|
||||||
if isinstance(node_or_string, str):
|
if isinstance(node_or_string, str):
|
||||||
|
|
|
@ -23,16 +23,8 @@ It has the following interface (key and data are strings):
|
||||||
list = d.keys() # return a list of all existing keys (slow!)
|
list = d.keys() # return a list of all existing keys (slow!)
|
||||||
|
|
||||||
Future versions may change the order in which implementations are
|
Future versions may change the order in which implementations are
|
||||||
tested for existence, add interfaces to other dbm-like
|
tested for existence, and add interfaces to other dbm-like
|
||||||
implementations.
|
implementations.
|
||||||
|
|
||||||
The open function has an optional second argument. This can be 'r',
|
|
||||||
for read-only access, 'w', for read-write access of an existing
|
|
||||||
database, 'c' for read-write access to a new or existing database, and
|
|
||||||
'n' for read-write access to a new database. The default is 'r'.
|
|
||||||
|
|
||||||
Note: 'r' and 'w' fail if the database doesn't exist; 'c' creates it
|
|
||||||
only if it doesn't exist; and 'n' always creates a new database.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__all__ = ['open', 'whichdb', 'error']
|
__all__ = ['open', 'whichdb', 'error']
|
||||||
|
@ -53,7 +45,17 @@ _modules = {}
|
||||||
error = (error, IOError)
|
error = (error, IOError)
|
||||||
|
|
||||||
|
|
||||||
def open(file, flag = 'r', mode = 0o666):
|
def open(file, flag='r', mode=0o666):
|
||||||
|
"""Open or create database at path given by *file*.
|
||||||
|
|
||||||
|
Optional argument *flag* can be 'r' (default) for read-only access, 'w'
|
||||||
|
for read-write access of an existing database, 'c' for read-write access
|
||||||
|
to a new or existing database, and 'n' for read-write access to a new
|
||||||
|
database.
|
||||||
|
|
||||||
|
Note: 'r' and 'w' fail if the database doesn't exist; 'c' creates it
|
||||||
|
only if it doesn't exist; and 'n' always creates a new database.
|
||||||
|
"""
|
||||||
global _defaultmod
|
global _defaultmod
|
||||||
if _defaultmod is None:
|
if _defaultmod is None:
|
||||||
for name in _names:
|
for name in _names:
|
||||||
|
|
|
@ -294,17 +294,20 @@ class sdist(Command):
|
||||||
join_lines=1, lstrip_ws=1, rstrip_ws=1,
|
join_lines=1, lstrip_ws=1, rstrip_ws=1,
|
||||||
collapse_join=1)
|
collapse_join=1)
|
||||||
|
|
||||||
while True:
|
try:
|
||||||
line = template.readline()
|
while True:
|
||||||
if line is None: # end of file
|
line = template.readline()
|
||||||
break
|
if line is None: # end of file
|
||||||
|
break
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.filelist.process_template_line(line)
|
self.filelist.process_template_line(line)
|
||||||
except DistutilsTemplateError as msg:
|
except DistutilsTemplateError as msg:
|
||||||
self.warn("%s, line %d: %s" % (template.filename,
|
self.warn("%s, line %d: %s" % (template.filename,
|
||||||
template.current_line,
|
template.current_line,
|
||||||
msg))
|
msg))
|
||||||
|
finally:
|
||||||
|
template.close()
|
||||||
|
|
||||||
def prune_file_list(self):
|
def prune_file_list(self):
|
||||||
"""Prune off branches that might slip into the file list as created
|
"""Prune off branches that might slip into the file list as created
|
||||||
|
|
|
@ -137,7 +137,7 @@ class RegisterTestCase(PyPIRCCommandTestCase):
|
||||||
|
|
||||||
# let's see what the server received : we should
|
# let's see what the server received : we should
|
||||||
# have 2 similar requests
|
# have 2 similar requests
|
||||||
self.assertTrue(self.conn.reqs, 2)
|
self.assertEqual(len(self.conn.reqs), 2)
|
||||||
req1 = dict(self.conn.reqs[0].headers)
|
req1 = dict(self.conn.reqs[0].headers)
|
||||||
req2 = dict(self.conn.reqs[1].headers)
|
req2 = dict(self.conn.reqs[1].headers)
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ class RegisterTestCase(PyPIRCCommandTestCase):
|
||||||
del register_module.input
|
del register_module.input
|
||||||
|
|
||||||
# we should have send a request
|
# we should have send a request
|
||||||
self.assertTrue(self.conn.reqs, 1)
|
self.assertEqual(len(self.conn.reqs), 1)
|
||||||
req = self.conn.reqs[0]
|
req = self.conn.reqs[0]
|
||||||
headers = dict(req.headers)
|
headers = dict(req.headers)
|
||||||
self.assertEqual(headers['Content-length'], '608')
|
self.assertEqual(headers['Content-length'], '608')
|
||||||
|
@ -187,7 +187,7 @@ class RegisterTestCase(PyPIRCCommandTestCase):
|
||||||
del register_module.input
|
del register_module.input
|
||||||
|
|
||||||
# we should have send a request
|
# we should have send a request
|
||||||
self.assertTrue(self.conn.reqs, 1)
|
self.assertEqual(len(self.conn.reqs), 1)
|
||||||
req = self.conn.reqs[0]
|
req = self.conn.reqs[0]
|
||||||
headers = dict(req.headers)
|
headers = dict(req.headers)
|
||||||
self.assertEqual(headers['Content-length'], '290')
|
self.assertEqual(headers['Content-length'], '290')
|
||||||
|
|
|
@ -170,7 +170,7 @@ def heappushpop(heap, item):
|
||||||
return item
|
return item
|
||||||
|
|
||||||
def heapify(x):
|
def heapify(x):
|
||||||
"""Transform list into a heap, in-place, in O(len(heap)) time."""
|
"""Transform list into a heap, in-place, in O(len(x)) time."""
|
||||||
n = len(x)
|
n = len(x)
|
||||||
# Transform bottom-up. The largest index there's any point to looking at
|
# Transform bottom-up. The largest index there's any point to looking at
|
||||||
# is the largest with a child index in-range, so must have 2*i + 1 < n,
|
# is the largest with a child index in-range, so must have 2*i + 1 < n,
|
||||||
|
@ -360,7 +360,7 @@ def nsmallest(n, iterable, key=None):
|
||||||
return [min(chain(head, it))]
|
return [min(chain(head, it))]
|
||||||
return [min(chain(head, it), key=key)]
|
return [min(chain(head, it), key=key)]
|
||||||
|
|
||||||
# When n>=size, it's faster to use sort()
|
# When n>=size, it's faster to use sorted()
|
||||||
try:
|
try:
|
||||||
size = len(iterable)
|
size = len(iterable)
|
||||||
except (TypeError, AttributeError):
|
except (TypeError, AttributeError):
|
||||||
|
@ -398,7 +398,7 @@ def nlargest(n, iterable, key=None):
|
||||||
return [max(chain(head, it))]
|
return [max(chain(head, it))]
|
||||||
return [max(chain(head, it), key=key)]
|
return [max(chain(head, it), key=key)]
|
||||||
|
|
||||||
# When n>=size, it's faster to use sort()
|
# When n>=size, it's faster to use sorted()
|
||||||
try:
|
try:
|
||||||
size = len(iterable)
|
size = len(iterable)
|
||||||
except (TypeError, AttributeError):
|
except (TypeError, AttributeError):
|
||||||
|
|
|
@ -31,7 +31,7 @@ Encoding basic Python object hierarchies::
|
||||||
Compact encoding::
|
Compact encoding::
|
||||||
|
|
||||||
>>> import json
|
>>> import json
|
||||||
>>> json.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',',':'))
|
>>> json.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',', ':'))
|
||||||
'[1,2,3,{"4":5,"6":7}]'
|
'[1,2,3,{"4":5,"6":7}]'
|
||||||
|
|
||||||
Pretty printing::
|
Pretty printing::
|
||||||
|
|
|
@ -694,7 +694,6 @@ def get_platform():
|
||||||
m = re.search(
|
m = re.search(
|
||||||
r'<key>ProductUserVisibleVersion</key>\s*' +
|
r'<key>ProductUserVisibleVersion</key>\s*' +
|
||||||
r'<string>(.*?)</string>', f.read())
|
r'<string>(.*?)</string>', f.read())
|
||||||
f.close()
|
|
||||||
if m is not None:
|
if m is not None:
|
||||||
macrelease = '.'.join(m.group(1).split('.')[:2])
|
macrelease = '.'.join(m.group(1).split('.')[:2])
|
||||||
# else: fall back to the default behaviour
|
# else: fall back to the default behaviour
|
||||||
|
|
|
@ -688,7 +688,7 @@ def main(argv=None):
|
||||||
|
|
||||||
for opt, val in opts:
|
for opt, val in opts:
|
||||||
if opt == "--help":
|
if opt == "--help":
|
||||||
usage(sys.stdout)
|
_usage(sys.stdout)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if opt == "--version":
|
if opt == "--version":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue