Merged revisions 82805-82806,83523-83527,83536,83538,83542,83546-83548,83550-83555,83558,83560 via svnmerge from
svn+ssh://svn.python.org/python/branches/py3k ........ r82805 | georg.brandl | 2010-07-11 11:42:10 +0200 (So, 11 Jul 2010) | 1 line #7935: cross-reference to ast.literal_eval() from eval() docs. ........ r82806 | georg.brandl | 2010-07-11 12:22:44 +0200 (So, 11 Jul 2010) | 1 line #9223: link to Command class reference, and move Command interface docs nearer to class docs. ........ r83523 | georg.brandl | 2010-08-02 14:06:18 +0200 (Mo, 02 Aug 2010) | 1 line #9209 and #7781: fix two crashes in pstats interactive browser. ........ r83524 | georg.brandl | 2010-08-02 14:20:23 +0200 (Mo, 02 Aug 2010) | 1 line #9428: fix running scripts from profile/cProfile with their own name and the right namespace. Same fix as for trace.py in #1690103. ........ r83525 | georg.brandl | 2010-08-02 14:36:24 +0200 (Mo, 02 Aug 2010) | 1 line Get rid of spurious "threading" entries in trace output. ........ r83526 | georg.brandl | 2010-08-02 14:40:22 +0200 (Mo, 02 Aug 2010) | 1 line Fix softspace relic. ........ r83527 | georg.brandl | 2010-08-02 14:48:46 +0200 (Mo, 02 Aug 2010) | 1 line #3821: beginnings of a trace.py unittest. ........ r83536 | georg.brandl | 2010-08-02 19:49:25 +0200 (Mo, 02 Aug 2010) | 1 line #8578: mention danger of not incref'ing weak referenced object. ........ r83538 | georg.brandl | 2010-08-02 20:10:13 +0200 (Mo, 02 Aug 2010) | 1 line #6928: fix class docs w.r.t. new metaclasses. ........ r83542 | georg.brandl | 2010-08-02 20:56:54 +0200 (Mo, 02 Aug 2010) | 1 line Move test_SimpleHTTPServer into test_httpservers. ........ r83546 | georg.brandl | 2010-08-02 21:16:34 +0200 (Mo, 02 Aug 2010) | 1 line #7973: Fix distutils options spelling. ........ r83547 | georg.brandl | 2010-08-02 21:19:26 +0200 (Mo, 02 Aug 2010) | 1 line #7386: add example that shows that trailing path separators are stripped. ........ r83548 | georg.brandl | 2010-08-02 21:23:34 +0200 (Mo, 02 Aug 2010) | 1 line #8172: how does one use a property? ........ r83550 | georg.brandl | 2010-08-02 21:32:43 +0200 (Mo, 02 Aug 2010) | 1 line #9451: strengthen warning about __*__ special name usage. ........ r83551 | georg.brandl | 2010-08-02 21:35:06 +0200 (Mo, 02 Aug 2010) | 1 line Remove XXX comment that was displayed. ........ r83552 | georg.brandl | 2010-08-02 21:36:36 +0200 (Mo, 02 Aug 2010) | 1 line #9438: clarify that constant names also cannot be assigned as attributes. ........ r83553 | georg.brandl | 2010-08-02 21:39:17 +0200 (Mo, 02 Aug 2010) | 1 line Remove redundant information. ........ r83554 | georg.brandl | 2010-08-02 21:43:05 +0200 (Mo, 02 Aug 2010) | 1 line #7280: note about nasmw.exe. ........ r83555 | georg.brandl | 2010-08-02 21:44:48 +0200 (Mo, 02 Aug 2010) | 1 line #8861: remove unused variable. ........ r83558 | georg.brandl | 2010-08-02 22:05:19 +0200 (Mo, 02 Aug 2010) | 1 line #8648: document UTF-7 codec functions. ........ r83560 | georg.brandl | 2010-08-02 22:16:18 +0200 (Mo, 02 Aug 2010) | 1 line #9087: update json docstrings -- unicode and long do not exist anymore. ........
This commit is contained in:
parent
914a218fbe
commit
4009c9edfc
|
@ -641,6 +641,38 @@ These are the UTF-16 codec APIs:
|
|||
Return *NULL* if an exception was raised by the codec.
|
||||
|
||||
|
||||
UTF-7 Codecs
|
||||
""""""""""""
|
||||
|
||||
These are the UTF-7 codec APIs:
|
||||
|
||||
|
||||
.. cfunction:: PyObject* PyUnicode_DecodeUTF7(const char *s, Py_ssize_t size, const char *errors)
|
||||
|
||||
Create a Unicode object by decoding *size* bytes of the UTF-7 encoded string
|
||||
*s*. Return *NULL* if an exception was raised by the codec.
|
||||
|
||||
|
||||
.. cfunction:: PyObject* PyUnicode_DecodeUTF8Stateful(const char *s, Py_ssize_t size, const char *errors, Py_ssize_t *consumed)
|
||||
|
||||
If *consumed* is *NULL*, behave like :cfunc:`PyUnicode_DecodeUTF7`. If
|
||||
*consumed* is not *NULL*, trailing incomplete UTF-7 base-64 sections will not
|
||||
be treated as an error. Those bytes will not be decoded and the number of
|
||||
bytes that have been decoded will be stored in *consumed*.
|
||||
|
||||
|
||||
.. cfunction:: PyObject* PyUnicode_EncodeUTF7(const Py_UNICODE *s, Py_ssize_t size, int base64SetO, int base64WhiteSpace, const char *errors)
|
||||
|
||||
Encode the :ctype:`Py_UNICODE` buffer of the given size using UTF-7 and
|
||||
return a Python bytes object. Return *NULL* if an exception was raised by
|
||||
the codec.
|
||||
|
||||
If *base64SetO* is nonzero, "Set O" (punctuation that has no otherwise
|
||||
special meaning) will be encoded in base-64. If *base64WhiteSpace* is
|
||||
nonzero, whitespace will be encoded in base-64. Both are set to zero for the
|
||||
Python "utf-7" codec.
|
||||
|
||||
|
||||
Unicode-Escape Codecs
|
||||
"""""""""""""""""""""
|
||||
|
||||
|
|
|
@ -53,7 +53,14 @@ as much as it can.
|
|||
.. cfunction:: PyObject* PyWeakref_GetObject(PyObject *ref)
|
||||
|
||||
Return the referenced object from a weak reference, *ref*. If the referent is
|
||||
no longer live, returns ``None``.
|
||||
no longer live, returns :const:`Py_None`.
|
||||
|
||||
.. warning::
|
||||
|
||||
This function returns a **borrowed reference** to the referenced object.
|
||||
This means that you should always call :cfunc:`Py_INCREF` on the object
|
||||
except if you know that it cannot be destroyed while you are still
|
||||
using it.
|
||||
|
||||
|
||||
.. cfunction:: PyObject* PyWeakref_GET_OBJECT(PyObject *ref)
|
||||
|
|
|
@ -147,11 +147,11 @@ setup script). Indirectly provides the :class:`distutils.dist.Distribution` and
|
|||
In addition, the :mod:`distutils.core` module exposed a number of classes that
|
||||
live elsewhere.
|
||||
|
||||
* :class:`Extension` from :mod:`distutils.extension`
|
||||
* :class:`~distutils.extension.Extension` from :mod:`distutils.extension`
|
||||
|
||||
* :class:`Command` from :mod:`distutils.cmd`
|
||||
* :class:`~distutils.cmd.Command` from :mod:`distutils.cmd`
|
||||
|
||||
* :class:`Distribution` from :mod:`distutils.dist`
|
||||
* :class:`~distutils.dist.Distribution` from :mod:`distutils.dist`
|
||||
|
||||
A short description of each of these follows, but see the relevant module for
|
||||
the full reference.
|
||||
|
@ -1679,8 +1679,8 @@ lines, and joining lines with backslashes.
|
|||
===================================================================
|
||||
|
||||
.. module:: distutils.cmd
|
||||
:synopsis: This module provides the abstract base class Command. This class is subclassed
|
||||
by the modules in the distutils.command subpackage.
|
||||
:synopsis: This module provides the abstract base class Command. This class
|
||||
is subclassed by the modules in the distutils.command subpackage.
|
||||
|
||||
|
||||
This module supplies the abstract base class :class:`Command`.
|
||||
|
@ -1690,20 +1690,84 @@ This module supplies the abstract base class :class:`Command`.
|
|||
|
||||
Abstract base class for defining command classes, the "worker bees" of the
|
||||
Distutils. A useful analogy for command classes is to think of them as
|
||||
subroutines with local variables called *options*. The options are declared in
|
||||
:meth:`initialize_options` and defined (given their final values) in
|
||||
:meth:`finalize_options`, both of which must be defined by every command class.
|
||||
The distinction between the two is necessary because option values might come
|
||||
from the outside world (command line, config file, ...), and any options
|
||||
dependent on other options must be computed after these outside influences have
|
||||
been processed --- hence :meth:`finalize_options`. The body of the subroutine,
|
||||
where it does all its work based on the values of its options, is the
|
||||
:meth:`run` method, which must also be implemented by every command class.
|
||||
subroutines with local variables called *options*. The options are declared
|
||||
in :meth:`initialize_options` and defined (given their final values) in
|
||||
:meth:`finalize_options`, both of which must be defined by every command
|
||||
class. The distinction between the two is necessary because option values
|
||||
might come from the outside world (command line, config file, ...), and any
|
||||
options dependent on other options must be computed after these outside
|
||||
influences have been processed --- hence :meth:`finalize_options`. The body
|
||||
of the subroutine, where it does all its work based on the values of its
|
||||
options, is the :meth:`run` method, which must also be implemented by every
|
||||
command class.
|
||||
|
||||
The class constructor takes a single argument *dist*, a :class:`Distribution`
|
||||
instance.
|
||||
|
||||
|
||||
Creating a new Distutils command
|
||||
================================
|
||||
|
||||
This section outlines the steps to create a new Distutils command.
|
||||
|
||||
A new command lives in a module in the :mod:`distutils.command` package. There
|
||||
is a sample template in that directory called :file:`command_template`. Copy
|
||||
this file to a new module with the same name as the new command you're
|
||||
implementing. This module should implement a class with the same name as the
|
||||
module (and the command). So, for instance, to create the command
|
||||
``peel_banana`` (so that users can run ``setup.py peel_banana``), you'd copy
|
||||
:file:`command_template` to :file:`distutils/command/peel_banana.py`, then edit
|
||||
it so that it's implementing the class :class:`peel_banana`, a subclass of
|
||||
:class:`distutils.cmd.Command`.
|
||||
|
||||
Subclasses of :class:`Command` must define the following methods.
|
||||
|
||||
.. method:: Command.initialize_options()
|
||||
|
||||
Set default values for all the options that this command supports. Note that
|
||||
these defaults may be overridden by other commands, by the setup script, by
|
||||
config files, or by the command-line. Thus, this is not the place to code
|
||||
dependencies between options; generally, :meth:`initialize_options`
|
||||
implementations are just a bunch of ``self.foo = None`` assignments.
|
||||
|
||||
|
||||
.. method:: Command.finalize_options()
|
||||
|
||||
Set final values for all the options that this command supports. This is
|
||||
always called as late as possible, ie. after any option assignments from the
|
||||
command-line or from other commands have been done. Thus, this is the place
|
||||
to to code option dependencies: if *foo* depends on *bar*, then it is safe to
|
||||
set *foo* from *bar* as long as *foo* still has the same value it was
|
||||
assigned in :meth:`initialize_options`.
|
||||
|
||||
|
||||
.. method:: Command.run()
|
||||
|
||||
A command's raison d'etre: carry out the action it exists to perform, controlled
|
||||
by the options initialized in :meth:`initialize_options`, customized by other
|
||||
commands, the setup script, the command-line, and config files, and finalized in
|
||||
:meth:`finalize_options`. All terminal output and filesystem interaction should
|
||||
be done by :meth:`run`.
|
||||
|
||||
|
||||
.. attribute:: Command.sub_commands
|
||||
|
||||
*sub_commands* formalizes the notion of a "family" of commands,
|
||||
e.g. ``install`` as the parent with sub-commands ``install_lib``,
|
||||
``install_headers``, etc. The parent of a family of commands defines
|
||||
*sub_commands* as a class attribute; it's a list of 2-tuples ``(command_name,
|
||||
predicate)``, with *command_name* a string and *predicate* a function, a
|
||||
string or ``None``. *predicate* is a method of the parent command that
|
||||
determines whether the corresponding command is applicable in the current
|
||||
situation. (E.g. we ``install_headers`` is only applicable if we have any C
|
||||
header files to install.) If *predicate* is ``None``, that command is always
|
||||
applicable.
|
||||
|
||||
*sub_commands* is usually defined at the *end* of a class, because
|
||||
predicates can be methods of the class, so they must already have been
|
||||
defined. The canonical example is the :command:`install` command.
|
||||
|
||||
|
||||
:mod:`distutils.command` --- Individual Distutils commands
|
||||
==========================================================
|
||||
|
||||
|
@ -1942,76 +2006,3 @@ The ``register`` command registers the package with the Python Package Index.
|
|||
This is described in more detail in :pep:`301`.
|
||||
|
||||
.. % todo
|
||||
|
||||
:mod:`distutils.command.check` --- Check the meta-data of a package
|
||||
===================================================================
|
||||
|
||||
.. module:: distutils.command.check
|
||||
:synopsis: Check the metadata of a package
|
||||
|
||||
|
||||
The ``check`` command performs some tests on the meta-data of a package.
|
||||
For example, it verifies that all required meta-data are provided as
|
||||
the arguments passed to the :func:`setup` function.
|
||||
|
||||
.. % todo
|
||||
|
||||
|
||||
Creating a new Distutils command
|
||||
================================
|
||||
|
||||
This section outlines the steps to create a new Distutils command.
|
||||
|
||||
A new command lives in a module in the :mod:`distutils.command` package. There
|
||||
is a sample template in that directory called :file:`command_template`. Copy
|
||||
this file to a new module with the same name as the new command you're
|
||||
implementing. This module should implement a class with the same name as the
|
||||
module (and the command). So, for instance, to create the command
|
||||
``peel_banana`` (so that users can run ``setup.py peel_banana``), you'd copy
|
||||
:file:`command_template` to :file:`distutils/command/peel_banana.py`, then edit
|
||||
it so that it's implementing the class :class:`peel_banana`, a subclass of
|
||||
:class:`distutils.cmd.Command`.
|
||||
|
||||
Subclasses of :class:`Command` must define the following methods.
|
||||
|
||||
|
||||
.. method:: Command.initialize_options()
|
||||
|
||||
Set default values for all the options that this command supports. Note that
|
||||
these defaults may be overridden by other commands, by the setup script, by
|
||||
config files, or by the command-line. Thus, this is not the place to code
|
||||
dependencies between options; generally, :meth:`initialize_options`
|
||||
implementations are just a bunch of ``self.foo = None`` assignments.
|
||||
|
||||
|
||||
.. method:: Command.finalize_options()
|
||||
|
||||
Set final values for all the options that this command supports. This is
|
||||
always called as late as possible, ie. after any option assignments from the
|
||||
command-line or from other commands have been done. Thus, this is the place
|
||||
to to code option dependencies: if *foo* depends on *bar*, then it is safe to
|
||||
set *foo* from *bar* as long as *foo* still has the same value it was
|
||||
assigned in :meth:`initialize_options`.
|
||||
|
||||
|
||||
.. method:: Command.run()
|
||||
|
||||
A command's raison d'etre: carry out the action it exists to perform, controlled
|
||||
by the options initialized in :meth:`initialize_options`, customized by other
|
||||
commands, the setup script, the command-line, and config files, and finalized in
|
||||
:meth:`finalize_options`. All terminal output and filesystem interaction should
|
||||
be done by :meth:`run`.
|
||||
|
||||
*sub_commands* formalizes the notion of a "family" of commands, eg. ``install``
|
||||
as the parent with sub-commands ``install_lib``, ``install_headers``, etc. The
|
||||
parent of a family of commands defines *sub_commands* as a class attribute; it's
|
||||
a list of 2-tuples ``(command_name, predicate)``, with *command_name* a string
|
||||
and *predicate* a function, a string or None. *predicate* is a method of
|
||||
the parent command that determines whether the corresponding command is
|
||||
applicable in the current situation. (Eg. we ``install_headers`` is only
|
||||
applicable if we have any C header files to install.) If *predicate* is None,
|
||||
that command is always applicable.
|
||||
|
||||
*sub_commands* is usually defined at the \*end\* of a class, because predicates
|
||||
can be methods of the class, so they must already have been defined. The
|
||||
canonical example is the :command:`install` command.
|
||||
|
|
|
@ -176,7 +176,7 @@ easily specify multiple formats in one run. If you need to do both, you can
|
|||
explicitly specify multiple :command:`bdist_\*` commands and their options::
|
||||
|
||||
python setup.py bdist_rpm --packager="John Doe <jdoe@example.org>" \
|
||||
bdist_wininst --target_version="2.0"
|
||||
bdist_wininst --target-version="2.0"
|
||||
|
||||
Creating RPM packages is driven by a :file:`.spec` file, much as using the
|
||||
Distutils is driven by the setup script. To make your life easier, the
|
||||
|
|
|
@ -15,8 +15,8 @@ want to modify existing commands; many simply add a few file extensions that
|
|||
should be copied into packages in addition to :file:`.py` files as a
|
||||
convenience.
|
||||
|
||||
Most distutils command implementations are subclasses of the :class:`Command`
|
||||
class from :mod:`distutils.cmd`. New commands may directly inherit from
|
||||
Most distutils command implementations are subclasses of the
|
||||
:class:`distutils.cmd.Command` class. New commands may directly inherit from
|
||||
:class:`Command`, while replacements often derive from :class:`Command`
|
||||
indirectly, directly subclassing the command they are replacing. Commands are
|
||||
required to derive from :class:`Command`.
|
||||
|
|
|
@ -3,15 +3,6 @@ Built-in Constants
|
|||
|
||||
A small number of constants live in the built-in namespace. They are:
|
||||
|
||||
|
||||
.. note::
|
||||
|
||||
:data:`None`, :data:`False`, :data:`True` and :data:`__debug__` cannot be
|
||||
reassigned (assignments to them raise :exc:`SyntaxError`), so they can be
|
||||
considered "true" constants.
|
||||
|
||||
.. XXX False, True, None are keywords too
|
||||
|
||||
.. data:: False
|
||||
|
||||
The false value of the :class:`bool` type. Assignments to ``False``
|
||||
|
@ -41,18 +32,22 @@ A small number of constants live in the built-in namespace. They are:
|
|||
.. data:: Ellipsis
|
||||
|
||||
The same as ``...``. Special value used mostly in conjunction with extended
|
||||
slicing syntax for user-defined container data types, as in ::
|
||||
|
||||
.. XXX Someone who understands extended slicing should fill in here.
|
||||
slicing syntax for user-defined container data types.
|
||||
|
||||
|
||||
.. data:: __debug__
|
||||
|
||||
This constant is true if Python was not started with an :option:`-O` option.
|
||||
Assignments to :const:`__debug__` are illegal and raise a :exc:`SyntaxError`.
|
||||
See also the :keyword:`assert` statement.
|
||||
|
||||
|
||||
.. note::
|
||||
|
||||
The names :data:`None`, :data:`False`, :data:`True` and :data:`__debug__`
|
||||
cannot be reassigned (assignments to them, even as an attribute name, raise
|
||||
:exc:`SyntaxError`), so they can be considered "true" constants.
|
||||
|
||||
|
||||
Constants added by the :mod:`site` module
|
||||
-----------------------------------------
|
||||
|
||||
|
|
|
@ -331,6 +331,9 @@ are always available. They are listed here in alphabetical order.
|
|||
returns the current global and local dictionary, respectively, which may be
|
||||
useful to pass around for use by :func:`eval` or :func:`exec`.
|
||||
|
||||
See :func:`ast.literal_eval` for a function that can safely evaluate strings
|
||||
with expressions containing only literals.
|
||||
|
||||
|
||||
.. function:: exec(object[, globals[, locals]])
|
||||
|
||||
|
@ -855,7 +858,7 @@ are always available. They are listed here in alphabetical order.
|
|||
|
||||
*fget* is a function for getting an attribute value, likewise *fset* is a
|
||||
function for setting, and *fdel* a function for del'ing, an attribute. Typical
|
||||
use is to define a managed attribute x::
|
||||
use is to define a managed attribute ``x``::
|
||||
|
||||
class C(object):
|
||||
def __init__(self):
|
||||
|
@ -869,6 +872,9 @@ are always available. They are listed here in alphabetical order.
|
|||
del self._x
|
||||
x = property(getx, setx, delx, "I'm the 'x' property.")
|
||||
|
||||
If then *c* is an instance of *C*, ``c.x`` will invoke the getter,
|
||||
``c.x = value`` will invoke the setter and ``del c.x`` the deleter.
|
||||
|
||||
If given, *doc* will be the docstring of the property attribute. Otherwise, the
|
||||
property will copy *fget*'s docstring (if it exists). This makes it possible to
|
||||
create read-only properties easily using :func:`property` as a :term:`decorator`::
|
||||
|
|
|
@ -206,7 +206,9 @@ applications should use string objects to access all files.
|
|||
.. function:: normpath(path)
|
||||
|
||||
Normalize a pathname. This collapses redundant separators and up-level
|
||||
references so that ``A//B``, ``A/./B`` and ``A/foo/../B`` all become ``A/B``.
|
||||
references so that ``A//B``, ``A/B/``, ``A/./B`` and ``A/foo/../B`` all become
|
||||
``A/B``.
|
||||
|
||||
It does not normalize the case (use :func:`normcase` for that). On Windows, it
|
||||
converts forward slashes to backward slashes. It should be understood that this
|
||||
may change the meaning of the path if it contains symbolic links!
|
||||
|
|
|
@ -550,24 +550,27 @@ Class definitions
|
|||
|
||||
A class definition defines a class object (see section :ref:`types`):
|
||||
|
||||
.. XXX need to document PEP 3115 changes here (new metaclasses)
|
||||
|
||||
.. productionlist::
|
||||
classdef: [`decorators`] "class" `classname` [`inheritance`] ":" `suite`
|
||||
inheritance: "(" [`expression_list`] ")"
|
||||
inheritance: "(" [`argument_list` [","] ] ")"
|
||||
classname: `identifier`
|
||||
|
||||
|
||||
A class definition is an executable statement. It first evaluates the
|
||||
inheritance list, if present. Each item in the inheritance list should evaluate
|
||||
to a class object or class type which allows subclassing. The class's suite is
|
||||
then executed in a new execution frame (see section :ref:`naming`), using a
|
||||
newly created local namespace and the original global namespace. (Usually, the
|
||||
suite contains only function definitions.) When the class's suite finishes
|
||||
execution, its execution frame is discarded but its local namespace is
|
||||
saved. [#]_ A class object is then created using the inheritance list for the
|
||||
base classes and the saved local namespace for the attribute dictionary. The
|
||||
class name is bound to this class object in the original local namespace.
|
||||
A class definition is an executable statement. The inheritance list usually
|
||||
gives a list of base classes (see :ref:`metaclasses` for more advanced uses), so
|
||||
each item in the list should evaluate to a class object which allows
|
||||
subclassing.
|
||||
|
||||
The class's suite is then executed in a new execution frame (see :ref:`naming`),
|
||||
using a newly created local namespace and the original global namespace.
|
||||
(Usually, the suite contains mostly function definitions.) When the class's
|
||||
suite finishes execution, its execution frame is discarded but its local
|
||||
namespace is saved. [#]_ A class object is then created using the inheritance
|
||||
list for the base classes and the saved local namespace for the attribute
|
||||
dictionary. The class name is bound to this class object in the original local
|
||||
namespace.
|
||||
|
||||
Class creation can be customized heavily using :ref:`metaclasses <metaclasses>`.
|
||||
|
||||
Classes can also be decorated; as with functions, ::
|
||||
|
||||
|
@ -581,25 +584,20 @@ is equivalent to ::
|
|||
Foo = f1(arg)(f2(Foo))
|
||||
|
||||
**Programmer's note:** Variables defined in the class definition are class
|
||||
variables; they are shared by instances. Instance variables can be set in a
|
||||
method with ``self.name = value``. Both class and instance variables are
|
||||
accessible through the notation "``self.name``", and an instance variable hides
|
||||
a class variable with the same name when accessed in this way. Class variables
|
||||
can be used as defaults for instance variables, but using mutable values there
|
||||
can lead to unexpected results. Descriptors can be used to create instance
|
||||
variables with different implementation details.
|
||||
attributes; they are shared by instances. Instance attributes can be set in a
|
||||
method with ``self.name = value``. Both class and instance attributes are
|
||||
accessible through the notation "``self.name``", and an instance attribute hides
|
||||
a class attribute with the same name when accessed in this way. Class
|
||||
attributes can be used as defaults for instance attributes, but using mutable
|
||||
values there can lead to unexpected results. :ref:`Descriptors <descriptors>`
|
||||
can be used to create instance variables with different implementation details.
|
||||
|
||||
.. XXX add link to descriptor docs above
|
||||
|
||||
.. seealso::
|
||||
|
||||
:pep:`3116` - Metaclasses in Python 3
|
||||
:pep:`3129` - Class Decorators
|
||||
|
||||
Class definitions, like function definitions, may be wrapped by one or more
|
||||
:term:`decorator` expressions. The evaluation rules for the decorator
|
||||
expressions are the same as for functions. The result must be a class object,
|
||||
which is then bound to the class name.
|
||||
|
||||
|
||||
.. rubric:: Footnotes
|
||||
|
||||
|
|
|
@ -363,10 +363,11 @@ characters:
|
|||
|
||||
``__*__``
|
||||
System-defined names. These names are defined by the interpreter and its
|
||||
implementation (including the standard library); applications should not expect
|
||||
to define additional names using this convention. The set of names of this
|
||||
class defined by Python may be extended in future versions. See section
|
||||
:ref:`specialnames`.
|
||||
implementation (including the standard library). Current system names are
|
||||
discussed in the :ref:`specialnames` section and elsewhere. More will likely
|
||||
be defined in future versions of Python. *Any* use of ``__*__`` names, in
|
||||
any context, that does not follow explicitly documented use, is subject to
|
||||
breakage without warning.
|
||||
|
||||
``__*``
|
||||
Class-private names. Names in this category, when used within the context of a
|
||||
|
|
|
@ -36,7 +36,7 @@ def run(statement, filename=None, sort=-1):
|
|||
result = prof.print_stats(sort)
|
||||
return result
|
||||
|
||||
def runctx(statement, globals, locals, filename=None):
|
||||
def runctx(statement, globals, locals, filename=None, sort=-1):
|
||||
"""Run statement under profiler, supplying your own globals and locals,
|
||||
optionally saving results in filename.
|
||||
|
||||
|
@ -53,7 +53,7 @@ def runctx(statement, globals, locals, filename=None):
|
|||
if filename is not None:
|
||||
prof.dump_stats(filename)
|
||||
else:
|
||||
result = prof.print_stats()
|
||||
result = prof.print_stats(sort)
|
||||
return result
|
||||
|
||||
# Backwards compatibility.
|
||||
|
@ -169,7 +169,8 @@ def main():
|
|||
parser.add_option('-o', '--outfile', dest="outfile",
|
||||
help="Save stats to <outfile>", default=None)
|
||||
parser.add_option('-s', '--sort', dest="sort",
|
||||
help="Sort order when printing to stdout, based on pstats.Stats class", default=-1)
|
||||
help="Sort order when printing to stdout, based on pstats.Stats class",
|
||||
default=-1)
|
||||
|
||||
if not sys.argv[1:]:
|
||||
parser.print_usage()
|
||||
|
@ -178,14 +179,18 @@ def main():
|
|||
(options, args) = parser.parse_args()
|
||||
sys.argv[:] = args
|
||||
|
||||
if (len(sys.argv) > 0):
|
||||
sys.path.insert(0, os.path.dirname(sys.argv[0]))
|
||||
fp = open(sys.argv[0])
|
||||
try:
|
||||
script = fp.read()
|
||||
finally:
|
||||
fp.close()
|
||||
run('exec(%r)' % script, options.outfile, options.sort)
|
||||
if len(args) > 0:
|
||||
progname = args[0]
|
||||
sys.path.insert(0, os.path.dirname(progname))
|
||||
with open(progname, 'rb') as fp:
|
||||
code = compile(fp.read(), progname, 'exec')
|
||||
globs = {
|
||||
'__file__': progname,
|
||||
'__name__': '__main__',
|
||||
'__package__': None,
|
||||
'__cached__': None,
|
||||
}
|
||||
runctx(code, globs, None, options.outfile, options.sort)
|
||||
else:
|
||||
parser.print_usage()
|
||||
return parser
|
||||
|
|
|
@ -17,10 +17,9 @@ def wrapper(func, *args, **kwds):
|
|||
wrapper().
|
||||
"""
|
||||
|
||||
res = None
|
||||
try:
|
||||
# Initialize curses
|
||||
stdscr=curses.initscr()
|
||||
stdscr = curses.initscr()
|
||||
|
||||
# Turn off echoing of keys, and enter cbreak mode,
|
||||
# where no buffering is performed on keyboard input
|
||||
|
|
|
@ -148,7 +148,7 @@ class bdist_msi(Command):
|
|||
if not self.skip_build and self.distribution.has_ext_modules()\
|
||||
and self.target_version != short_version:
|
||||
raise DistutilsOptionError(
|
||||
"target version can only be %s, or the '--skip_build'"
|
||||
"target version can only be %s, or the '--skip-build'"
|
||||
" option must be specified" % (short_version,))
|
||||
else:
|
||||
self.versions = list(self.all_versions)
|
||||
|
|
|
@ -89,7 +89,7 @@ class bdist_wininst(Command):
|
|||
short_version = get_python_version()
|
||||
if self.target_version and self.target_version != short_version:
|
||||
raise DistutilsOptionError(
|
||||
"target version can only be %s, or the '--skip_build'" \
|
||||
"target version can only be %s, or the '--skip-build'" \
|
||||
" option must be specified" % (short_version,))
|
||||
self.target_version = short_version
|
||||
|
||||
|
|
|
@ -125,14 +125,12 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
|
|||
``.write()``-supporting file-like object).
|
||||
|
||||
If ``skipkeys`` is true then ``dict`` keys that are not basic types
|
||||
(``str``, ``unicode``, ``int``, ``float``, ``bool``, ``None``) will be
|
||||
skipped instead of raising a ``TypeError``.
|
||||
(``str``, ``int``, ``float``, ``bool``, ``None``) will be skipped
|
||||
instead of raising a ``TypeError``.
|
||||
|
||||
If ``ensure_ascii`` is false, then the some chunks written to ``fp``
|
||||
may be ``unicode`` instances, subject to normal Python ``str`` to
|
||||
``unicode`` coercion rules. Unless ``fp.write()`` explicitly
|
||||
understands ``unicode`` (as in ``codecs.getwriter()``) this is likely
|
||||
to cause an error.
|
||||
If ``ensure_ascii`` is false, then the strings written to ``fp`` can
|
||||
contain non-ASCII characters if they appear in strings contained in
|
||||
``obj``. Otherwise, all such characters are escaped in JSON strings.
|
||||
|
||||
If ``check_circular`` is false, then the circular reference check
|
||||
for container types will be skipped and a circular reference will
|
||||
|
@ -185,12 +183,12 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
|
|||
"""Serialize ``obj`` to a JSON formatted ``str``.
|
||||
|
||||
If ``skipkeys`` is false then ``dict`` keys that are not basic types
|
||||
(``str``, ``unicode``, ``int``, ``float``, ``bool``, ``None``) will be
|
||||
skipped instead of raising a ``TypeError``.
|
||||
(``str``, ``int``, ``float``, ``bool``, ``None``) will be skipped
|
||||
instead of raising a ``TypeError``.
|
||||
|
||||
If ``ensure_ascii`` is false, then the return value will be a
|
||||
``unicode`` instance subject to normal Python ``str`` to ``unicode``
|
||||
coercion rules instead of being escaped to an ASCII ``str``.
|
||||
If ``ensure_ascii`` is false, then the return value can contain non-ASCII
|
||||
characters if they appear in strings contained in ``obj``. Otherwise, all
|
||||
such characters are escaped in JSON strings.
|
||||
|
||||
If ``check_circular`` is false, then the circular reference check
|
||||
for container types will be skipped and a circular reference will
|
||||
|
|
|
@ -263,9 +263,9 @@ class JSONDecoder(object):
|
|||
+---------------+-------------------+
|
||||
| array | list |
|
||||
+---------------+-------------------+
|
||||
| string | unicode |
|
||||
| string | str |
|
||||
+---------------+-------------------+
|
||||
| number (int) | int, long |
|
||||
| number (int) | int |
|
||||
+---------------+-------------------+
|
||||
| number (real) | float |
|
||||
+---------------+-------------------+
|
||||
|
@ -318,8 +318,8 @@ class JSONDecoder(object):
|
|||
|
||||
|
||||
def decode(self, s, _w=WHITESPACE.match):
|
||||
"""Return the Python representation of ``s`` (a ``str`` or ``unicode``
|
||||
instance containing a JSON document)
|
||||
"""Return the Python representation of ``s`` (a ``str`` instance
|
||||
containing a JSON document).
|
||||
|
||||
"""
|
||||
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
|
||||
|
@ -329,8 +329,8 @@ class JSONDecoder(object):
|
|||
return obj
|
||||
|
||||
def raw_decode(self, s, idx=0):
|
||||
"""Decode a JSON document from ``s`` (a ``str`` or ``unicode``
|
||||
beginning with a JSON document) and return a 2-tuple of the Python
|
||||
"""Decode a JSON document from ``s`` (a ``str`` beginning with
|
||||
a JSON document) and return a 2-tuple of the Python
|
||||
representation and the index in ``s`` where the document ended.
|
||||
|
||||
This can be used to decode a JSON document from a string that may
|
||||
|
|
|
@ -77,9 +77,9 @@ class JSONEncoder(object):
|
|||
+-------------------+---------------+
|
||||
| list, tuple | array |
|
||||
+-------------------+---------------+
|
||||
| str, unicode | string |
|
||||
| str | string |
|
||||
+-------------------+---------------+
|
||||
| int, long, float | number |
|
||||
| int, float | number |
|
||||
+-------------------+---------------+
|
||||
| True | true |
|
||||
+-------------------+---------------+
|
||||
|
@ -102,12 +102,12 @@ class JSONEncoder(object):
|
|||
"""Constructor for JSONEncoder, with sensible defaults.
|
||||
|
||||
If skipkeys is false, then it is a TypeError to attempt
|
||||
encoding of keys that are not str, int, long, float or None. If
|
||||
encoding of keys that are not str, int, float or None. If
|
||||
skipkeys is True, such items are simply skipped.
|
||||
|
||||
If ensure_ascii is true, the output is guaranteed to be str
|
||||
objects with all incoming unicode characters escaped. If
|
||||
ensure_ascii is false, the output will be unicode object.
|
||||
objects with all incoming non-ASCII characters escaped. If
|
||||
ensure_ascii is false, the output can contain non-ASCII characters.
|
||||
|
||||
If check_circular is true, then lists, dicts, and custom encoded
|
||||
objects will be checked for circular references during encoding to
|
||||
|
|
|
@ -75,7 +75,7 @@ def run(statement, filename=None, sort=-1):
|
|||
else:
|
||||
return prof.print_stats(sort)
|
||||
|
||||
def runctx(statement, globals, locals, filename=None):
|
||||
def runctx(statement, globals, locals, filename=None, sort=-1):
|
||||
"""Run statement under profiler, supplying your own globals and locals,
|
||||
optionally saving results in filename.
|
||||
|
||||
|
@ -90,7 +90,7 @@ def runctx(statement, globals, locals, filename=None):
|
|||
if filename is not None:
|
||||
prof.dump_stats(filename)
|
||||
else:
|
||||
return prof.print_stats()
|
||||
return prof.print_stats(sort)
|
||||
|
||||
# Backwards compatibility.
|
||||
def help():
|
||||
|
@ -598,20 +598,28 @@ def main():
|
|||
parser.add_option('-o', '--outfile', dest="outfile",
|
||||
help="Save stats to <outfile>", default=None)
|
||||
parser.add_option('-s', '--sort', dest="sort",
|
||||
help="Sort order when printing to stdout, based on pstats.Stats class", default=-1)
|
||||
help="Sort order when printing to stdout, based on pstats.Stats class",
|
||||
default=-1)
|
||||
|
||||
if not sys.argv[1:]:
|
||||
parser.print_usage()
|
||||
sys.exit(2)
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
if (len(args) > 0):
|
||||
sys.argv[:] = args
|
||||
sys.path.insert(0, os.path.dirname(sys.argv[0]))
|
||||
with open(sys.argv[0], 'rb') as fp:
|
||||
script = fp.read()
|
||||
run('exec(%r)' % script, options.outfile, options.sort)
|
||||
|
||||
if len(args) > 0:
|
||||
progname = args[0]
|
||||
sys.path.insert(0, os.path.dirname(progname))
|
||||
with open(progname, 'rb') as fp:
|
||||
code = compile(fp.read(), progname, 'exec')
|
||||
globs = {
|
||||
'__file__': progname,
|
||||
'__name__': '__main__',
|
||||
'__package__': None,
|
||||
'__cached__': None,
|
||||
}
|
||||
runctx(code, globs, None, options.outfile, options.sort)
|
||||
else:
|
||||
parser.print_usage()
|
||||
return parser
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
# Based on prior profile module by Sjoerd Mullender...
|
||||
# which was hacked somewhat by: Guido van Rossum
|
||||
#
|
||||
# see profile.doc and profile.py for more info.
|
||||
# see profile.py for more info.
|
||||
|
||||
# Copyright 1994, by InfoSeek Corporation, all rights reserved.
|
||||
# Written by James Roskind
|
||||
|
@ -149,7 +149,7 @@ class Stats:
|
|||
if not arg_list: return self
|
||||
if len(arg_list) > 1: self.add(*arg_list[1:])
|
||||
other = arg_list[0]
|
||||
if type(self) != type(other) or self.__class__ != other.__class__:
|
||||
if type(self) != type(other):
|
||||
other = Stats(other)
|
||||
self.files += other.files
|
||||
self.total_calls += other.total_calls
|
||||
|
@ -217,12 +217,12 @@ class Stats:
|
|||
if not field:
|
||||
self.fcn_list = 0
|
||||
return self
|
||||
if len(field) == 1 and type(field[0]) == type(1):
|
||||
if len(field) == 1 and isinstance(field[0], int):
|
||||
# Be compatible with old profiler
|
||||
field = [ {-1: "stdname",
|
||||
0:"calls",
|
||||
1:"time",
|
||||
2: "cumulative" } [ field[0] ] ]
|
||||
0: "calls",
|
||||
1: "time",
|
||||
2: "cumulative"}[field[0]] ]
|
||||
|
||||
sort_arg_defs = self.get_sort_arg_defs()
|
||||
sort_tuple = ()
|
||||
|
@ -299,21 +299,26 @@ class Stats:
|
|||
|
||||
def eval_print_amount(self, sel, list, msg):
|
||||
new_list = list
|
||||
if type(sel) == type(""):
|
||||
if isinstance(sel, str):
|
||||
try:
|
||||
rex = re.compile(sel)
|
||||
except re.error:
|
||||
msg += " <Invalid regular expression %r>\n" % sel
|
||||
return new_list, msg
|
||||
new_list = []
|
||||
for func in list:
|
||||
if re.search(sel, func_std_string(func)):
|
||||
if rex.search(func_std_string(func)):
|
||||
new_list.append(func)
|
||||
else:
|
||||
count = len(list)
|
||||
if type(sel) == type(1.0) and 0.0 <= sel < 1.0:
|
||||
if isinstance(sel, float) and 0.0 <= sel < 1.0:
|
||||
count = int(count * sel + .5)
|
||||
new_list = list[:count]
|
||||
elif type(sel) == type(1) and 0 <= sel < count:
|
||||
elif isinstance(sel, int) and 0 <= sel < count:
|
||||
count = sel
|
||||
new_list = list[:count]
|
||||
if len(list) != len(new_list):
|
||||
msg = msg + " List reduced from %r to %r due to restriction <%r>\n" % (
|
||||
msg += " List reduced from %r to %r due to restriction <%r>\n" % (
|
||||
len(list), len(new_list), sel)
|
||||
|
||||
return new_list, msg
|
||||
|
@ -321,26 +326,26 @@ class Stats:
|
|||
def get_print_list(self, sel_list):
|
||||
width = self.max_name_len
|
||||
if self.fcn_list:
|
||||
list = self.fcn_list[:]
|
||||
stat_list = self.fcn_list[:]
|
||||
msg = " Ordered by: " + self.sort_type + '\n'
|
||||
else:
|
||||
list = self.stats.keys()
|
||||
stat_list = list(self.stats.keys())
|
||||
msg = " Random listing order was used\n"
|
||||
|
||||
for selection in sel_list:
|
||||
list, msg = self.eval_print_amount(selection, list, msg)
|
||||
stat_list, msg = self.eval_print_amount(selection, stat_list, msg)
|
||||
|
||||
count = len(list)
|
||||
count = len(stat_list)
|
||||
|
||||
if not list:
|
||||
return 0, list
|
||||
if not stat_list:
|
||||
return 0, stat_list
|
||||
print(msg, file=self.stream)
|
||||
if count < len(self.stats):
|
||||
width = 0
|
||||
for func in list:
|
||||
for func in stat_list:
|
||||
if len(func_std_string(func)) > width:
|
||||
width = len(func_std_string(func))
|
||||
return width+2, list
|
||||
return width+2, stat_list
|
||||
|
||||
def print_stats(self, *amount):
|
||||
for filename in self.files:
|
||||
|
@ -561,12 +566,10 @@ if __name__ == '__main__':
|
|||
def __init__(self, profile=None):
|
||||
cmd.Cmd.__init__(self)
|
||||
self.prompt = "% "
|
||||
if profile is not None:
|
||||
self.stats = Stats(profile)
|
||||
self.stream = self.stats.stream
|
||||
else:
|
||||
self.stats = None
|
||||
self.stream = sys.stdout
|
||||
if profile is not None:
|
||||
self.do_read(profile)
|
||||
|
||||
def generic(self, fn, line):
|
||||
args = line.split()
|
||||
|
|
|
@ -487,8 +487,8 @@ class Trace:
|
|||
import __main__
|
||||
dict = __main__.__dict__
|
||||
if not self.donothing:
|
||||
sys.settrace(self.globaltrace)
|
||||
threading.settrace(self.globaltrace)
|
||||
sys.settrace(self.globaltrace)
|
||||
try:
|
||||
exec(cmd, dict, dict)
|
||||
finally:
|
||||
|
@ -500,8 +500,8 @@ class Trace:
|
|||
if globals is None: globals = {}
|
||||
if locals is None: locals = {}
|
||||
if not self.donothing:
|
||||
sys.settrace(self.globaltrace)
|
||||
threading.settrace(self.globaltrace)
|
||||
sys.settrace(self.globaltrace)
|
||||
try:
|
||||
exec(cmd, globals, locals)
|
||||
finally:
|
||||
|
@ -616,7 +616,7 @@ class Trace:
|
|||
print('%.2f' % (time.time() - self.start_time), end=' ')
|
||||
bname = os.path.basename(filename)
|
||||
print("%s(%d): %s" % (bname, lineno,
|
||||
linecache.getline(filename, lineno)), end=' ')
|
||||
linecache.getline(filename, lineno)), end='')
|
||||
return self.localtrace
|
||||
|
||||
def localtrace_trace(self, frame, why, arg):
|
||||
|
@ -629,7 +629,7 @@ class Trace:
|
|||
print('%.2f' % (time.time() - self.start_time), end=' ')
|
||||
bname = os.path.basename(filename)
|
||||
print("%s(%d): %s" % (bname, lineno,
|
||||
linecache.getline(filename, lineno)), end=' ')
|
||||
linecache.getline(filename, lineno)), end='')
|
||||
return self.localtrace
|
||||
|
||||
def localtrace_count(self, frame, why, arg):
|
||||
|
|
|
@ -484,7 +484,7 @@ bail:
|
|||
}
|
||||
|
||||
PyDoc_STRVAR(pydoc_scanstring,
|
||||
"scanstring(basestring, end, strict=True) -> (bytes, end)\n"
|
||||
"scanstring(string, end, strict=True) -> (string, end)\n"
|
||||
"\n"
|
||||
"Scan the string s for a JSON string. End is the index of the\n"
|
||||
"character in s after the quote that started the JSON string.\n"
|
||||
|
@ -512,7 +512,7 @@ py_scanstring(PyObject* self UNUSED, PyObject *args)
|
|||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"first argument must be a string or bytes, not %.80s",
|
||||
"first argument must be a string, not %.80s",
|
||||
Py_TYPE(pystr)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -520,7 +520,7 @@ py_scanstring(PyObject* self UNUSED, PyObject *args)
|
|||
}
|
||||
|
||||
PyDoc_STRVAR(pydoc_encode_basestring_ascii,
|
||||
"encode_basestring_ascii(basestring) -> bytes\n"
|
||||
"encode_basestring_ascii(string) -> string\n"
|
||||
"\n"
|
||||
"Return an ASCII-only JSON representation of a Python string"
|
||||
);
|
||||
|
|
|
@ -152,6 +152,8 @@ _ssl
|
|||
You must install the NASM assembler from
|
||||
http://nasm.sf.net
|
||||
for x86 builds. Put nasmw.exe anywhere in your PATH.
|
||||
Note: recent releases of nasm only have nasm.exe. Just rename it to
|
||||
nasmw.exe.
|
||||
|
||||
You can also install ActivePerl from
|
||||
http://www.activestate.com/Products/ActivePerl/
|
||||
|
|
Loading…
Reference in New Issue