Add lots of items.
The only thing missing now is the new date/time stuff.
This commit is contained in:
parent
0146f419b4
commit
974ab9d865
|
@ -12,13 +12,11 @@
|
|||
|
||||
% MacOS framework-related changes (section of its own, probably)
|
||||
|
||||
% the new set-next-statement functionality of pdb (SF #643835)
|
||||
|
||||
%\section{Introduction \label{intro}}
|
||||
|
||||
{\large This article is a draft, and is currently up to date for some
|
||||
random version of the CVS tree from early November 2002. Please send any
|
||||
additions, comments or errata to the author.}
|
||||
{\large This article is a draft, and is currently up to date for
|
||||
Python 2.3alpha1. Please send any additions, comments or errata to
|
||||
the author.}
|
||||
|
||||
This article explains the new features in Python 2.3. The tentative
|
||||
release date of Python 2.3 is currently scheduled for some undefined
|
||||
|
@ -646,6 +644,128 @@ Walter D\"orwald.}
|
|||
\end{seealso}
|
||||
|
||||
|
||||
%======================================================================
|
||||
\section{PEP 273: Importing Modules from Zip Archives}
|
||||
|
||||
The new \module{zipimport} module adds support for importing
|
||||
modules from a ZIP-format archive. You shouldn't need to import the
|
||||
module explicitly; it will be automatically imported if a ZIP
|
||||
archive's filename is added to \code{sys.path}. For example:
|
||||
|
||||
\begin{verbatim}
|
||||
amk@nyman:~/src/python$ unzip -l /tmp/example.zip
|
||||
Archive: /tmp/example.zip
|
||||
Length Date Time Name
|
||||
-------- ---- ---- ----
|
||||
8467 11-26-02 22:30 jwzthreading.py
|
||||
-------- -------
|
||||
8467 1 file
|
||||
amk@nyman:~/src/python$ ./python
|
||||
Python 2.3a0 (#1, Dec 30 2002, 19:54:32)
|
||||
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-113)] on linux2
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>> import sys
|
||||
>>> sys.path.insert(0, '/tmp/example.zip') # Add .zip file to front of path
|
||||
>>> import jwzthreading
|
||||
>>> jwzthreading.__file__
|
||||
'/tmp/example.zip/jwzthreading.py'
|
||||
>>>
|
||||
\end{verbatim}
|
||||
|
||||
An entry in \code{sys.path} can now be the filename of a ZIP archive.
|
||||
The ZIP archive can contain any kind of files, but only files named
|
||||
\code{*.py}, \code{*.pyc}, or \code{*.pyo} can be imported. If an
|
||||
archive only contains \code{*.py} files, Python will not attempt to
|
||||
modify the archive by adding the corresponding {*.pyc} file.
|
||||
Therefore, if a ZIP archive doesn't contain {*.pyc} files, importing
|
||||
may be rather slow.
|
||||
|
||||
A path within the archive can also be specified to only import from a
|
||||
subdirectory; for example, the path \file{/tmp/example.zip/lib/}
|
||||
would only import from the \file{lib/} subdirectory within the
|
||||
archive.
|
||||
|
||||
This new feature is implemented using the new import hooks from
|
||||
\pep{302}; see section~\ref{section-pep302} for a description.
|
||||
|
||||
\begin{seealso}
|
||||
|
||||
\seepep{273}{Import Modules from Zip Archives}{Written by James C. Ahlstrom,
|
||||
who also provided an implementation.
|
||||
Python 2.3 follows the specification in \pep{273},
|
||||
but uses an implementation written by Just van Rossum
|
||||
that uses the import hooks described in \pep{302}.}
|
||||
|
||||
\end{seealso}
|
||||
|
||||
%======================================================================
|
||||
\section{PEP 302: New Import Hooks \label{section-pep302}}
|
||||
|
||||
While it's been possible to write custom import hooks ever since the
|
||||
\module{ihooks} module was introduced in Python 1.3, no one has ever
|
||||
been really happy with it, because writing new import hooks is
|
||||
difficult and messy. There have been various alternative interfaces
|
||||
proposed, such as the \module{imputil} and \module{iu} modules, but
|
||||
none has ever gained much acceptance, and none was easily usable from
|
||||
\C{} code.
|
||||
|
||||
\pep{302} borrows ideas from its predecessors, especially from
|
||||
Gordon McMillan's \module{iu} module. Three new items
|
||||
are added to the \module{sys} module:
|
||||
|
||||
\begin{itemize}
|
||||
\item[\code{sys.path_hooks}] is a list of functions. Each function
|
||||
takes a string containing a path and returns either \code{None} or an
|
||||
importer object that will handle imports from this path.
|
||||
|
||||
\item[\code{sys.path_importer_cache}] caches importer objects for
|
||||
each path, so \code{sys.path_hooks} will only need to be traversed
|
||||
once for each path.
|
||||
|
||||
\item[\code{sys.meta_path}] is a list of importer objects
|
||||
that will be traversed before \code{sys.path} is checked at all.
|
||||
This list is initially empty, but can be extended. Additional built-in
|
||||
and frozen modules can be imported by an object added to this list.
|
||||
|
||||
\end{itemize}
|
||||
|
||||
Importer objects must have a single method,
|
||||
\method{find_module(\var{fullname}, \var{path}=None)}. \var{fullname}
|
||||
will be a module or package name, e.g. \samp{string} or
|
||||
\samp{spam.ham}. \method{find_module()} must return a loader object
|
||||
that has a single method, \method{load_module(\var{fullname})}, that
|
||||
creates and returns the corresponding module object.
|
||||
|
||||
Pseudo-code for Python's new import logic, therefore, looks something
|
||||
like this (simplified a bit; see \pep{302} for the full details):
|
||||
|
||||
\begin{verbatim}
|
||||
for mp in sys.meta_path:
|
||||
loader = mp(fullname)
|
||||
if loader is not None:
|
||||
<module> = loader(fullname)
|
||||
|
||||
for path in sys.path:
|
||||
for hook in sys.path_hooks:
|
||||
importer = hook(path)
|
||||
if importer is not None:
|
||||
loader = importer.find_module(fullname)
|
||||
return loader.load_module(fullname)
|
||||
|
||||
# Not found!
|
||||
raise ImportError
|
||||
\end{verbatim}
|
||||
|
||||
\begin{seealso}
|
||||
|
||||
\seepep{302}{New Import Hooks}{Written by Just van~Rossum and Paul Moore.
|
||||
Implemented by Just van Rossum.
|
||||
% XXX is that credit right?
|
||||
}
|
||||
|
||||
\end{seealso}
|
||||
|
||||
|
||||
%======================================================================
|
||||
\section{Extended Slices\label{section-slices}}
|
||||
|
||||
|
@ -797,7 +917,8 @@ section~\ref{section-bool} of this document.
|
|||
integer instead of raising an \exception{OverflowError} when a string
|
||||
or floating-point number is too large to fit into an integer. This
|
||||
can lead to the paradoxical result that
|
||||
\code{isinstance(int(\var{expression}), int)} is false, but that seems unlikely to cause problems in practice.
|
||||
\code{isinstance(int(\var{expression}), int)} is false, but that seems
|
||||
unlikely to cause problems in practice.
|
||||
|
||||
\item Built-in types now support the extended slicing syntax,
|
||||
as described in section~\ref{section-slices} of this document.
|
||||
|
@ -835,7 +956,7 @@ creates a dictionary with keys taken from the supplied iterator
|
|||
|
||||
(Patches contributed by Raymond Hettinger.)
|
||||
|
||||
The \function{dict()} constructor now also accepts keyword arguments to
|
||||
Also, the \function{dict()} constructor now accepts keyword arguments to
|
||||
simplify creating small dictionaries:
|
||||
|
||||
\begin{verbatim}
|
||||
|
@ -1012,6 +1133,9 @@ Oren Tirosh.)
|
|||
|
||||
\begin{itemize}
|
||||
|
||||
\item The creation of new-style class instances has been made much
|
||||
faster; they're now faster than classic classes!
|
||||
|
||||
\item The \method{sort()} method of list objects has been extensively
|
||||
rewritten by Tim Peters, and the implementation is significantly
|
||||
faster.
|
||||
|
@ -1056,7 +1180,7 @@ support using the \code{+=} assignment operator to add another array's
|
|||
contents, and the \code{*=} assignment operator to repeat an array.
|
||||
(Contributed by Jason Orendorff.)
|
||||
|
||||
\item The \module{bsddb} module has been updated to version 3.4.0
|
||||
\item The \module{bsddb} module has been updated to version 4.1.1
|
||||
of the \ulink{PyBSDDB}{http://pybsddb.sourceforge.net} package,
|
||||
providing a more complete interface to the transactional features of
|
||||
the BerkeleyDB library.
|
||||
|
@ -1118,6 +1242,8 @@ now return enhanced tuples:
|
|||
('amk', 500)
|
||||
\end{verbatim}
|
||||
|
||||
\item The \module{gzip} module can now handle files exceeding 2~Gb.
|
||||
|
||||
\item The new \module{heapq} module contains an implementation of a
|
||||
heap queue algorithm. A heap is an array-like data structure that
|
||||
keeps items in a partially sorted order such that,
|
||||
|
@ -1218,13 +1344,21 @@ ValueError: sample larger than population
|
|||
>>> random.sample(xrange(1,10000,2), 10) # Choose ten odds under 10000
|
||||
[3407, 3805, 1505, 7023, 2401, 2267, 9733, 3151, 8083, 9195]
|
||||
\end{verbatim}
|
||||
|
||||
(Contributed by Raymond Hettinger.)
|
||||
|
||||
The \module{random} module now uses a new algorithm, the Mersenne
|
||||
Twister, implemented in C. It's faster and more extensively studied
|
||||
than the previous algorithm.
|
||||
|
||||
(All changes contributed by Raymond Hettinger.)
|
||||
|
||||
\item The \module{readline} module also gained a number of new
|
||||
functions: \function{get_history_item()},
|
||||
\function{get_current_history_length()}, and \function{redisplay()}.
|
||||
|
||||
\item The \module{shutil} module gained a \function{move(\var{src},
|
||||
\var{dest})} that recursively moves a file or directory to a new
|
||||
location.
|
||||
|
||||
\item Support for more advanced POSIX signal handling was added
|
||||
to the \module{signal} module by adding the \function{sigpending},
|
||||
\function{sigprocmask} and \function{sigsuspend} functions, where supported
|
||||
|
@ -1284,6 +1418,28 @@ documentation for details.
|
|||
%XXX add a link to the module docs?
|
||||
(Contributed by Greg Ward.)
|
||||
|
||||
\item The \module{thread} and \module{threading} modules now have
|
||||
companion, \module{dummy_thread} and \module{dummy_threading}, that
|
||||
provide a do-nothing implementation of the \module{thread} module's
|
||||
interface, even if threads are not supported. The intention is to
|
||||
simplify thread-aware modules (that \emph{don't} rely on threads to
|
||||
run) by putting the following code at the top:
|
||||
|
||||
% XXX why as _threading?
|
||||
\begin{verbatim}
|
||||
try:
|
||||
import threading as _threading
|
||||
except ImportError:
|
||||
import dummy_threading as _threading
|
||||
\end{verbatim}
|
||||
|
||||
Code can then call functions and use classes in \module{_threading}
|
||||
whether or not threads are supported, avoiding an \keyword{if}
|
||||
statement and making the code slightly clearer. This module will not
|
||||
magically make multithreaded code run without threads; code that waits
|
||||
for another thread to return or to do something will simply hang
|
||||
forever.
|
||||
|
||||
\item The \module{time} module's \function{strptime()} function has
|
||||
long been an annoyance because it uses the platform C library's
|
||||
\function{strptime()} implementation, and different platforms
|
||||
|
@ -1610,6 +1766,8 @@ allocate objects, and \cfunction{PyObject_GC_Del} to deallocate them.
|
|||
|
||||
\end{itemize}
|
||||
|
||||
It's also no longer possible to build Python without the garbage collector.
|
||||
|
||||
\item Python can now optionally be built as a shared library
|
||||
(\file{libpython2.3.so}) by supplying \longprogramopt{enable-shared}
|
||||
when running Python's \program{configure} script. (Contributed by Ondrej
|
||||
|
@ -1672,6 +1830,22 @@ Expat.
|
|||
\end{itemize}
|
||||
|
||||
|
||||
\begin{comment}
|
||||
%======================================================================
|
||||
\subsection{Date/Time Type}
|
||||
|
||||
Date and time types suitable for expressing timestamps were added as
|
||||
the \module{datetime} module. The types don't support different
|
||||
calendars or many fancy features, and just stick to the basics.
|
||||
|
||||
The three primary types are: \class{date}, representing a day, month,
|
||||
and year; \class{time}, consisting of hour, minute, and second value;
|
||||
and \class{datetime}, which contains both a date and a time.
|
||||
|
||||
XXX finish this section
|
||||
\end{comment}
|
||||
|
||||
|
||||
%======================================================================
|
||||
\subsection{Port-Specific Changes}
|
||||
|
||||
|
@ -1695,7 +1869,8 @@ The RPM spec files, found in the \file{Misc/RPM/} directory in the
|
|||
Python source distribution, were updated for 2.3. (Contributed by
|
||||
Sean Reifschneider.)
|
||||
|
||||
Python now supports AtheOS (\url{http://www.atheos.cx}) and GNU/Hurd.
|
||||
Python now supports AtheOS (\url{http://www.atheos.cx}), GNU/Hurd,
|
||||
OpenVMS, and OS/2 with EMX.
|
||||
|
||||
|
||||
%======================================================================
|
||||
|
@ -1738,6 +1913,12 @@ should instead call \code{PyCode_Addr2Line(f->f_code, f->f_lasti)}.
|
|||
This will have the added effect of making the code work as desired
|
||||
under ``python -O'' in earlier versions of Python.
|
||||
|
||||
A nifty new feature is that trace functions can now the
|
||||
\member{f_lineno} attribute of frame objects can now be assigned to,
|
||||
changing the line that will be executed next. A \samp{jump} command
|
||||
has been added to the \module{pdb} debugger taking advantage of this
|
||||
new feature. (Implemented by Richie Hindle.)
|
||||
|
||||
\end{itemize}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue