blob: 96b0972ae1304d9e65de8dc2ae6370ba024ff7df [file] [log] [blame]
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +00001\documentclass{howto}
2
3% $Id$
4
5\title{What's New in Python 2.2}
Andrew M. Kuchling8cfa9052001-07-19 01:19:59 +00006\release{0.03}
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +00007\author{A.M. Kuchling}
Andrew M. Kuchling7bf82772001-07-11 18:54:26 +00008\authoraddress{\email{akuchlin@mems-exchange.org}}
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +00009\begin{document}
10\maketitle\tableofcontents
11
12\section{Introduction}
13
14{\large This document is a draft, and is subject to change until the
15final version of Python 2.2 is released. Currently it's not up to
16date at all. Please send any comments, bug reports, or questions, no
Andrew M. Kuchling7bf82772001-07-11 18:54:26 +000017matter how minor, to \email{akuchlin@mems-exchange.org}. }
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +000018
Andrew M. Kuchling7bf82772001-07-11 18:54:26 +000019This article explains the new features in Python 2.2. Python 2.2
20includes some significant changes that go far toward cleaning up the
21language's darkest corners, and some exciting new features.
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +000022
23This article doesn't attempt to provide a complete specification for
24the new features, but instead provides a convenient overview of the
25new features. For full details, you should refer to 2.2 documentation
Fred Drake0d002542001-07-17 13:55:33 +000026such as the
27\citetitle[http://python.sourceforge.net/devel-docs/lib/lib.html]{Python
28Library Reference} and the
29\citetitle[http://python.sourceforge.net/devel-docs/ref/ref.html]{Python
30Reference Manual}, or to the PEP for a particular new feature.
31% These \citetitle marks should get the python.org URLs for the final
32% release, just as soon as the docs are published there.
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +000033
34The final release of Python 2.2 is planned for October 2001.
35
Andrew M. Kuchling8cfa9052001-07-19 01:19:59 +000036
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +000037%======================================================================
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +000038% It looks like this set of changes will likely get into 2.2,
39% so I need to read and digest the relevant PEPs.
Andrew M. Kuchling7bf82772001-07-11 18:54:26 +000040%\section{PEP 252: Type and Class Changes}
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +000041
Andrew M. Kuchling7bf82772001-07-11 18:54:26 +000042%XXX
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +000043
Andrew M. Kuchling8cfa9052001-07-19 01:19:59 +000044% GvR's description at http://www.python.org/2.2/descrintro.html
45
Andrew M. Kuchling7bf82772001-07-11 18:54:26 +000046%\begin{seealso}
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +000047
Andrew M. Kuchling7bf82772001-07-11 18:54:26 +000048%\seepep{252}{Making Types Look More Like Classes}{Written and implemented
49%by GvR.}
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +000050
Andrew M. Kuchling7bf82772001-07-11 18:54:26 +000051%\end{seealso}
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +000052
Andrew M. Kuchling8cfa9052001-07-19 01:19:59 +000053
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +000054%======================================================================
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +000055\section{PEP 234: Iterators}
56
57A significant addition to 2.2 is an iteration interface at both the C
58and Python levels. Objects can define how they can be looped over by
59callers.
60
61In Python versions up to 2.1, the usual way to make \code{for item in
62obj} work is to define a \method{__getitem__()} method that looks
63something like this:
64
65\begin{verbatim}
66 def __getitem__(self, index):
67 return <next item>
68\end{verbatim}
69
70\method{__getitem__()} is more properly used to define an indexing
71operation on an object so that you can write \code{obj[5]} to retrieve
72the fifth element. It's a bit misleading when you're using this only
73to support \keyword{for} loops. Consider some file-like object that
74wants to be looped over; the \var{index} parameter is essentially
75meaningless, as the class probably assumes that a series of
76\method{__getitem__()} calls will be made, with \var{index}
77incrementing by one each time. In other words, the presence of the
78\method{__getitem__()} method doesn't mean that \code{file[5]} will
79work, though it really should.
80
81In Python 2.2, iteration can be implemented separately, and
82\method{__getitem__()} methods can be limited to classes that really
83do support random access. The basic idea of iterators is quite
84simple. A new built-in function, \function{iter(obj)}, returns an
85iterator for the object \var{obj}. (It can also take two arguments:
Fred Drake0d002542001-07-17 13:55:33 +000086\code{iter(\var{C}, \var{sentinel})} will call the callable \var{C},
87until it returns \var{sentinel}, which will signal that the iterator
88is done. This form probably won't be used very often.)
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +000089
90Python classes can define an \method{__iter__()} method, which should
91create and return a new iterator for the object; if the object is its
92own iterator, this method can just return \code{self}. In particular,
93iterators will usually be their own iterators. Extension types
94implemented in C can implement a \code{tp_iter} function in order to
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +000095return an iterator, and extension types that want to behave as
96iterators can define a \code{tp_iternext} function.
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +000097
98So what do iterators do? They have one required method,
99\method{next()}, which takes no arguments and returns the next value.
100When there are no more values to be returned, calling \method{next()}
101should raise the \exception{StopIteration} exception.
102
103\begin{verbatim}
104>>> L = [1,2,3]
105>>> i = iter(L)
106>>> print i
107<iterator object at 0x8116870>
108>>> i.next()
1091
110>>> i.next()
1112
112>>> i.next()
1133
114>>> i.next()
115Traceback (most recent call last):
116 File "<stdin>", line 1, in ?
117StopIteration
118>>>
119\end{verbatim}
120
121In 2.2, Python's \keyword{for} statement no longer expects a sequence;
122it expects something for which \function{iter()} will return something.
123For backward compatibility, and convenience, an iterator is
124automatically constructed for sequences that don't implement
125\method{__iter__()} or a \code{tp_iter} slot, so \code{for i in
126[1,2,3]} will still work. Wherever the Python interpreter loops over
127a sequence, it's been changed to use the iterator protocol. This
128means you can do things like this:
129
130\begin{verbatim}
131>>> i = iter(L)
132>>> a,b,c = i
133>>> a,b,c
134(1, 2, 3)
135>>>
136\end{verbatim}
137
138Iterator support has been added to some of Python's basic types. The
139\keyword{in} operator now works on dictionaries, so \code{\var{key} in
140dict} is now equivalent to \code{dict.has_key(\var{key})}.
Fred Drake0d002542001-07-17 13:55:33 +0000141Calling \function{iter()} on a dictionary will return an iterator
Andrew M. Kuchling6ea9f0b2001-07-17 14:50:31 +0000142which loops over its keys:
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000143
144\begin{verbatim}
145>>> m = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6,
146... 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12}
147>>> for key in m: print key, m[key]
148...
149Mar 3
150Feb 2
151Aug 8
152Sep 9
153May 5
154Jun 6
155Jul 7
156Jan 1
157Apr 4
158Nov 11
159Dec 12
160Oct 10
161>>>
162\end{verbatim}
163
164That's just the default behaviour. If you want to iterate over keys,
165values, or key/value pairs, you can explicitly call the
166\method{iterkeys()}, \method{itervalues()}, or \method{iteritems()}
167methods to get an appropriate iterator.
168
169Files also provide an iterator, which calls its \method{readline()}
170method until there are no more lines in the file. This means you can
171now read each line of a file using code like this:
172
173\begin{verbatim}
174for line in file:
175 # do something for each line
176\end{verbatim}
177
178Note that you can only go forward in an iterator; there's no way to
179get the previous element, reset the iterator, or make a copy of it.
Fred Drake0d002542001-07-17 13:55:33 +0000180An iterator object could provide such additional capabilities, but the
181iterator protocol only requires a \method{next()} method.
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000182
183\begin{seealso}
184
185\seepep{234}{Iterators}{Written by Ka-Ping Yee and GvR; implemented
186by the Python Labs crew, mostly by GvR and Tim Peters.}
187
188\end{seealso}
189
Andrew M. Kuchling8cfa9052001-07-19 01:19:59 +0000190
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000191%======================================================================
192\section{PEP 255: Simple Generators}
193
194Generators are another new feature, one that interacts with the
195introduction of iterators.
196
197You're doubtless familiar with how function calls work in Python or
198C. When you call a function, it gets a private area where its local
199variables are created. When the function reaches a \keyword{return}
200statement, the local variables are destroyed and the resulting value
201is returned to the caller. A later call to the same function will get
202a fresh new set of local variables. But, what if the local variables
203weren't destroyed on exiting a function? What if you could later
204resume the function where it left off? This is what generators
205provide; they can be thought of as resumable functions.
206
207Here's the simplest example of a generator function:
208
209\begin{verbatim}
210def generate_ints(N):
211 for i in range(N):
212 yield i
213\end{verbatim}
214
215A new keyword, \keyword{yield}, was introduced for generators. Any
216function containing a \keyword{yield} statement is a generator
217function; this is detected by Python's bytecode compiler which
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000218compiles the function specially. Because a new keyword was
219introduced, generators must be explicitly enabled in a module by
220including a \code{from __future__ import generators} statement near
221the top of the module's source code. In Python 2.3 this statement
222will become unnecessary.
223
224When you call a generator function, it doesn't return a single value;
225instead it returns a generator object that supports the iterator
226interface. On executing the \keyword{yield} statement, the generator
227outputs the value of \code{i}, similar to a \keyword{return}
228statement. The big difference between \keyword{yield} and a
229\keyword{return} statement is that, on reaching a \keyword{yield} the
230generator's state of execution is suspended and local variables are
231preserved. On the next call to the generator's \code{.next()} method,
232the function will resume executing immediately after the
233\keyword{yield} statement. (For complicated reasons, the
234\keyword{yield} statement isn't allowed inside the \keyword{try} block
235of a \code{try...finally} statement; read PEP 255 for a full
236explanation of the interaction between \keyword{yield} and
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000237exceptions.)
238
239Here's a sample usage of the \function{generate_ints} generator:
240
241\begin{verbatim}
242>>> gen = generate_ints(3)
243>>> gen
244<generator object at 0x8117f90>
245>>> gen.next()
2460
247>>> gen.next()
2481
249>>> gen.next()
2502
251>>> gen.next()
252Traceback (most recent call last):
253 File "<stdin>", line 1, in ?
254 File "<stdin>", line 2, in generate_ints
255StopIteration
256>>>
257\end{verbatim}
258
259You could equally write \code{for i in generate_ints(5)}, or
260\code{a,b,c = generate_ints(3)}.
261
262Inside a generator function, the \keyword{return} statement can only
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000263be used without a value, and signals the end of the procession of
264values; afterwards the generator cannot return any further values.
265\keyword{return} with a value, such as \code{return 5}, is a syntax
266error inside a generator function. The end of the generator's results
267can also be indicated by raising \exception{StopIteration} manually,
268or by just letting the flow of execution fall off the bottom of the
269function.
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000270
271You could achieve the effect of generators manually by writing your
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000272own class and storing all the local variables of the generator as
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000273instance variables. For example, returning a list of integers could
274be done by setting \code{self.count} to 0, and having the
275\method{next()} method increment \code{self.count} and return it.
Andrew M. Kuchlingc32cc7c2001-07-17 18:25:01 +0000276However, for a moderately complicated generator, writing a
277corresponding class would be much messier.
278\file{Lib/test/test_generators.py} contains a number of more
279interesting examples. The simplest one implements an in-order
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000280traversal of a tree using generators recursively.
281
282\begin{verbatim}
283# A recursive generator that generates Tree leaves in in-order.
284def inorder(t):
285 if t:
286 for x in inorder(t.left):
287 yield x
288 yield t.label
289 for x in inorder(t.right):
290 yield x
291\end{verbatim}
292
293Two other examples in \file{Lib/test/test_generators.py} produce
294solutions for the N-Queens problem (placing $N$ queens on an $NxN$
295chess board so that no queen threatens another) and the Knight's Tour
296(a route that takes a knight to every square of an $NxN$ chessboard
297without visiting any square twice).
298
299The idea of generators comes from other programming languages,
300especially Icon (\url{http://www.cs.arizona.edu/icon/}), where the
301idea of generators is central to the language. In Icon, every
302expression and function call behaves like a generator. One example
303from ``An Overview of the Icon Programming Language'' at
304\url{http://www.cs.arizona.edu/icon/docs/ipd266.htm} gives an idea of
305what this looks like:
306
307\begin{verbatim}
308sentence := "Store it in the neighboring harbor"
309if (i := find("or", sentence)) > 5 then write(i)
310\end{verbatim}
311
312The \function{find()} function returns the indexes at which the
313substring ``or'' is found: 3, 23, 33. In the \keyword{if} statement,
314\code{i} is first assigned a value of 3, but 3 is less than 5, so the
315comparison fails, and Icon retries it with the second value of 23. 23
316is greater than 5, so the comparison now succeeds, and the code prints
317the value 23 to the screen.
318
319Python doesn't go nearly as far as Icon in adopting generators as a
320central concept. Generators are considered a new part of the core
321Python language, but learning or using them isn't compulsory; if they
322don't solve any problems that you have, feel free to ignore them.
323This is different from Icon where the idea of generators is a basic
324concept. One novel feature of Python's interface as compared to
325Icon's is that a generator's state is represented as a concrete object
326that can be passed around to other functions or stored in a data
327structure.
328
329\begin{seealso}
330
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000331\seepep{255}{Simple Generators}{Written by Neil Schemenauer, Tim
332Peters, Magnus Lie Hetland. Implemented mostly by Neil Schemenauer
333and Tim Peters, with other fixes from the Python Labs crew.}
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000334
335\end{seealso}
336
Andrew M. Kuchling8cfa9052001-07-19 01:19:59 +0000337
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000338%======================================================================
Andrew M. Kuchlinga43e7032001-06-27 20:32:12 +0000339\section{Unicode Changes}
340
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000341Python's Unicode support has been enhanced a bit in 2.2. Unicode
342strings are usually stored as UCS-2, as 16-bit unsigned integers.
Andrew M. Kuchlingf5fec3c2001-07-19 01:48:08 +0000343Python 2.2 can also be compiled to use UCS-4, 32-bit unsigned
344integers, as its internal encoding by supplying
345\longprogramopt{enable-unicode=ucs4} to the configure script. When
346built to use UCS-4, in theory Python could handle Unicode characters
347from U-00000000 to U-7FFFFFFF. Being able to use UCS-4 internally is
348a necessary step to do that, but it's not the only step, and in Python
3492.2alpha1 the work isn't complete yet. For example, the
350\function{unichr()} function still only accepts values from 0 to
35165535, and there's no \code{\e U} notation for embedding characters
352greater than 65535 in a Unicode string literal. All this is the
353province of the still-unimplemented PEP 261, ``Support for `wide'
354Unicode characters''; consult it for further details, and please offer
355comments and suggestions on the proposal it describes.
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000356
Andrew M. Kuchlingf5fec3c2001-07-19 01:48:08 +0000357Another change is much simpler to explain.
Andrew M. Kuchling8cfa9052001-07-19 01:19:59 +0000358Since their introduction, Unicode strings have supported an
359\method{encode()} method to convert the string to a selected encoding
360such as UTF-8 or Latin-1. A symmetric
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000361\method{decode(\optional{\var{encoding}})} method has been added to
362both 8-bit and Unicode strings in 2.2, which assumes that the string
363is in the specified encoding and decodes it. This means that
364\method{encode()} and \method{decode()} can be called on both types of
365strings, and can be used for tasks not directly related to Unicode.
366For example, codecs have been added for UUencoding, MIME's base-64
367encoding, and compression with the \module{zlib} module.
368
369\begin{verbatim}
370>>> s = """Here is a lengthy piece of redundant, overly verbose,
371... and repetitive text.
372... """
373>>> data = s.encode('zlib')
374>>> data
375'x\x9c\r\xc9\xc1\r\x80 \x10\x04\xc0?Ul...'
376>>> data.decode('zlib')
377'Here is a lengthy piece of redundant, overly verbose,\nand repetitive text.\n'
378>>> print s.encode('uu')
379begin 666 <data>
380M2&5R92!I<R!A(&QE;F=T:'D@<&EE8V4@;V8@<F5D=6YD86YT+"!O=F5R;'D@
381>=F5R8F]S92P*86YD(')E<&5T:71I=F4@=&5X="X*
382
383end
384>>> "sheesh".encode('rot-13')
385'furrfu'
386\end{verbatim}
Andrew M. Kuchlinga43e7032001-06-27 20:32:12 +0000387
Andrew M. Kuchlingf5fec3c2001-07-19 01:48:08 +0000388\method{encode()} and \method{decode()} were implemented by
389Marc-Andr\'e Lemburg. The changes to support using UCS-4 internally
390were implemented by Fredrik Lundh and Martin von L\"owis.
Andrew M. Kuchlinga43e7032001-06-27 20:32:12 +0000391
Andrew M. Kuchlingf5fec3c2001-07-19 01:48:08 +0000392\begin{seealso}
393
394\seepep{261}{Support for `wide' Unicode characters}{PEP written by
395Paul Prescod. Not yet accepted or fully implemented.}
396
397\end{seealso}
Andrew M. Kuchling8cfa9052001-07-19 01:19:59 +0000398
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000399%======================================================================
400\section{PEP 227: Nested Scopes}
401
402In Python 2.1, statically nested scopes were added as an optional
403feature, to be enabled by a \code{from __future__ import
404nested_scopes} directive. In 2.2 nested scopes no longer need to be
405specially enabled, but are always enabled. The rest of this section
406is a copy of the description of nested scopes from my ``What's New in
407Python 2.1'' document; if you read it when 2.1 came out, you can skip
408the rest of this section.
409
410The largest change introduced in Python 2.1, and made complete in 2.2,
411is to Python's scoping rules. In Python 2.0, at any given time there
412are at most three namespaces used to look up variable names: local,
413module-level, and the built-in namespace. This often surprised people
414because it didn't match their intuitive expectations. For example, a
415nested recursive function definition doesn't work:
416
417\begin{verbatim}
418def f():
419 ...
420 def g(value):
421 ...
422 return g(value-1) + 1
423 ...
424\end{verbatim}
425
426The function \function{g()} will always raise a \exception{NameError}
427exception, because the binding of the name \samp{g} isn't in either
428its local namespace or in the module-level namespace. This isn't much
429of a problem in practice (how often do you recursively define interior
430functions like this?), but this also made using the \keyword{lambda}
431statement clumsier, and this was a problem in practice. In code which
432uses \keyword{lambda} you can often find local variables being copied
433by passing them as the default values of arguments.
434
435\begin{verbatim}
436def find(self, name):
437 "Return list of any entries equal to 'name'"
438 L = filter(lambda x, name=name: x == name,
439 self.list_attribute)
440 return L
441\end{verbatim}
442
443The readability of Python code written in a strongly functional style
444suffers greatly as a result.
445
446The most significant change to Python 2.2 is that static scoping has
447been added to the language to fix this problem. As a first effect,
448the \code{name=name} default argument is now unnecessary in the above
449example. Put simply, when a given variable name is not assigned a
450value within a function (by an assignment, or the \keyword{def},
451\keyword{class}, or \keyword{import} statements), references to the
452variable will be looked up in the local namespace of the enclosing
453scope. A more detailed explanation of the rules, and a dissection of
454the implementation, can be found in the PEP.
455
456This change may cause some compatibility problems for code where the
457same variable name is used both at the module level and as a local
458variable within a function that contains further function definitions.
459This seems rather unlikely though, since such code would have been
460pretty confusing to read in the first place.
461
462One side effect of the change is that the \code{from \var{module}
463import *} and \keyword{exec} statements have been made illegal inside
464a function scope under certain conditions. The Python reference
465manual has said all along that \code{from \var{module} import *} is
466only legal at the top level of a module, but the CPython interpreter
467has never enforced this before. As part of the implementation of
468nested scopes, the compiler which turns Python source into bytecodes
469has to generate different code to access variables in a containing
470scope. \code{from \var{module} import *} and \keyword{exec} make it
471impossible for the compiler to figure this out, because they add names
472to the local namespace that are unknowable at compile time.
473Therefore, if a function contains function definitions or
474\keyword{lambda} expressions with free variables, the compiler will
475flag this by raising a \exception{SyntaxError} exception.
476
477To make the preceding explanation a bit clearer, here's an example:
478
479\begin{verbatim}
480x = 1
481def f():
482 # The next line is a syntax error
483 exec 'x=2'
484 def g():
485 return x
486\end{verbatim}
487
488Line 4 containing the \keyword{exec} statement is a syntax error,
489since \keyword{exec} would define a new local variable named \samp{x}
490whose value should be accessed by \function{g()}.
491
492This shouldn't be much of a limitation, since \keyword{exec} is rarely
493used in most Python code (and when it is used, it's often a sign of a
494poor design anyway).
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000495
496\begin{seealso}
497
498\seepep{227}{Statically Nested Scopes}{Written and implemented by
499Jeremy Hylton.}
500
501\end{seealso}
502
Andrew M. Kuchlinga43e7032001-06-27 20:32:12 +0000503
504%======================================================================
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +0000505\section{New and Improved Modules}
506
507\begin{itemize}
508
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000509 \item The \module{xmlrpclib} module was contributed to the standard
510library by Fredrik Lundh. It provides support for writing XML-RPC
511clients; XML-RPC is a simple remote procedure call protocol built on
512top of HTTP and XML. For example, the following snippet retrieves a
513list of RSS channels from the O'Reilly Network, and then retrieves a
514list of the recent headlines for one channel:
515
516\begin{verbatim}
517import xmlrpclib
518s = xmlrpclib.Server(
519 'http://www.oreillynet.com/meerkat/xml-rpc/server.php')
520channels = s.meerkat.getChannels()
521# channels is a list of dictionaries, like this:
522# [{'id': 4, 'title': 'Freshmeat Daily News'}
523# {'id': 190, 'title': '32Bits Online'},
524# {'id': 4549, 'title': '3DGamers'}, ... ]
525
526# Get the items for one channel
527items = s.meerkat.getItems( {'channel': 4} )
528
529# 'items' is another list of dictionaries, like this:
530# [{'link': 'http://freshmeat.net/releases/52719/',
531# 'description': 'A utility which converts HTML to XSL FO.',
532# 'title': 'html2fo 0.3 (Default)'}, ... ]
533\end{verbatim}
534
Fred Drake0d002542001-07-17 13:55:33 +0000535See \url{http://www.xmlrpc.com/} for more information about XML-RPC.
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000536
537 \item The \module{socket} module can be compiled to support IPv6;
Andrew M. Kuchlingddeb1352001-07-16 14:35:52 +0000538 specify the \longprogramopt{enable-ipv6} option to Python's configure
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000539 script. (Contributed by Jun-ichiro ``itojun'' Hagino.)
540
541 \item Two new format characters were added to the \module{struct}
542 module for 64-bit integers on platforms that support the C
543 \ctype{long long} type. \samp{q} is for a signed 64-bit integer,
544 and \samp{Q} is for an unsigned one. The value is returned in
545 Python's long integer type. (Contributed by Tim Peters.)
546
547 \item In the interpreter's interactive mode, there's a new built-in
548 function \function{help()}, that uses the \module{pydoc} module
549 introduced in Python 2.1 to provide interactive.
550 \code{help(\var{object})} displays any available help text about
551 \var{object}. \code{help()} with no argument puts you in an online
552 help utility, where you can enter the names of functions, classes,
553 or modules to read their help text.
554 (Contributed by Guido van Rossum, using Ka-Ping Yee's \module{pydoc} module.)
555
556 \item Various bugfixes and performance improvements have been made
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000557 to the SRE engine underlying the \module{re} module. For example,
558 \function{re.sub()} will now use \function{string.replace()}
559 automatically when the pattern and its replacement are both just
560 literal strings without regex metacharacters. Another contributed
561 patch speeds up certain Unicode character ranges by a factor of
562 two. (SRE is maintained by Fredrik Lundh. The BIGCHARSET patch was
563 contributed by Martin von L\"owis.)
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000564
565 \item The \module{imaplib} module now has support for the IMAP
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000566 NAMESPACE extension defined in \rfc{2342}. (Contributed by Michel
567 Pelletier.)
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000568
Fred Drake0d002542001-07-17 13:55:33 +0000569 \item The \module{rfc822} module's parsing of email addresses is
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000570 now compliant with \rfc{2822}, an update to \rfc{822}. The module's
571 name is \emph{not} going to be changed to \samp{rfc2822}.
572 (Contributed by Barry Warsaw.)
573
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +0000574\end{itemize}
575
576
577%======================================================================
578\section{Other Changes and Fixes}
579
Andrew M. Kuchling8cfa9052001-07-19 01:19:59 +0000580% XXX update the patch and bug figures as we go
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000581As usual there were a bunch of other improvements and bugfixes
582scattered throughout the source tree. A search through the CVS change
Andrew M. Kuchling8cfa9052001-07-19 01:19:59 +0000583logs finds there were 43 patches applied, and 77 bugs fixed; both
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000584figures are likely to be underestimates. Some of the more notable
585changes are:
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +0000586
587\begin{itemize}
588
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000589 \item Keyword arguments passed to builtin functions that don't take them
590 now cause a \exception{TypeError} exception to be raised, with the
591 message "\var{function} takes no keyword arguments".
592
Fred Drake0d002542001-07-17 13:55:33 +0000593 \item The code for the Mac OS port for Python, maintained by Jack
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000594 Jansen, is now kept in the main Python CVS tree.
595
596 \item The new license introduced with Python 1.6 wasn't
597 GPL-compatible. This is fixed by some minor textual changes to the
598 2.2 license, so Python can now be embedded inside a GPLed program
599 again. The license changes were also applied to the Python 2.0.1
600 and 2.1.1 releases.
601
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000602 \item Profiling and tracing functions can now be implemented in C,
603 which can operate at much higher speeds than Python-based functions
604 and should reduce the overhead of enabling profiling and tracing, so
605 it will be of interest to authors of development environments for
606 Python. Two new C functions were added to Python's API,
607 \cfunction{PyEval_SetProfile()} and \cfunction{PyEval_SetTrace()}.
608 The existing \function{sys.setprofile()} and
609 \function{sys.settrace()} functions still exist, and have simply
Fred Drake0d002542001-07-17 13:55:33 +0000610 been changed to use the new C-level interface. (Contributed by Fred
611 L. Drake, Jr.)
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000612
Andrew M. Kuchling8cfa9052001-07-19 01:19:59 +0000613 % XXX is this explanation correct?
614 \item When presented with a Unicode filename on Windows, Python will
615 now correctly convert it to a string using the MBCS encoding.
616 Filenames on Windows are a case where Python's choice of ASCII as
617 the default encoding turns out to be an annoyance.
618
619 This patch also adds \samp{et} as a format sequence to
620 \cfunction{PyArg_ParseTuple}; \samp{et} takes both a parameter and
621 an encoding name, and converts it to the given encoding if the
622 parameter turns out to be a Unicode string, or leaves it alone if
623 it's an 8-bit string, assuming it to already be in the desired
624 encoding. (This differs from the \samp{es} format character, which
625 assumes that 8-bit strings are in Python's default ASCII encoding
626 and converts them to the specified new encoding.)
627
628 (Contributed by Mark Hammond with assistance from Marc-Andr\'e
629 Lemburg.)
630
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000631 \item The \file{Tools/scripts/ftpmirror.py} script
632 now parses a \file{.netrc} file, if you have one.
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000633 (Contributed by Mike Romberg.)
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000634
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000635 \item Some features of the object returned by the
636 \function{xrange()} function are now deprecated, and trigger
637 warnings when they're accessed; they'll disappear in Python 2.3.
638 \class{xrange} objects tried to pretend they were full sequence
639 types by supporting slicing, sequence multiplication, and the
640 \keyword{in} operator, but these features were rarely used and
641 therefore buggy. The \method{tolist()} method and the
642 \member{start}, \member{stop}, and \member{step} attributes are also
643 being deprecated. At the C level, the fourth argument to the
644 \cfunction{PyRange_New()} function, \samp{repeat}, has also been
645 deprecated.
646
Andrew M. Kuchling8cfa9052001-07-19 01:19:59 +0000647 \item There were a bunch of patches to the dictionary
648 implementation, mostly to fix potential core dumps if a dictionary
649 contains objects that sneakily changed their hash value, or mutated
650 the dictionary they were contained in. For a while python-dev fell
651 into a gentle rhythm of Michael Hudson finding a case that dump
652 core, Tim Peters fixing it, Michael finding another case, and round
653 and round it went.
654
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000655 \item On Windows, Python can now be compiled with Borland C thanks
Andrew M. Kuchling8cfa9052001-07-19 01:19:59 +0000656 to a number of patches contributed by Stephen Hansen.
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000657
Andrew M. Kuchling8cfa9052001-07-19 01:19:59 +0000658 \item On platforms where Python uses the C \cfunction{dlopen()} function
659 to load extension modules, it's now possible to set the flags used
660 by \cfunction{dlopen()} using the \function{sys.getdlopenflags()} and
661 \function{sys.setdlopenflags()} functions. (Contributed by Bram Stolk.)
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000662
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +0000663\end{itemize}
664
665
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +0000666%======================================================================
667\section{Acknowledgements}
668
669The author would like to thank the following people for offering
Andrew M. Kuchling6ea9f0b2001-07-17 14:50:31 +0000670suggestions and corrections to various drafts of this article: Fred
Andrew M. Kuchlingc32cc7c2001-07-17 18:25:01 +0000671Bremmer, Fred L. Drake, Jr., Tim Peters, Neil Schemenauer.
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +0000672
673\end{document}