blob: 02165897359f624fa2c968fc15ea2c973674cbc3 [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001****************************
2 What's New in Python 2.6
3****************************
4
Andrew M. Kuchlingf10878b2007-09-13 22:49:34 +00005.. % XXX mention switch to reST for documentation
6.. % XXX mention switch to Roundup for bug tracking
7
Georg Brandl8ec7f652007-08-15 14:28:01 +00008:Author: A.M. Kuchling
9:Release: |release|
10:Date: |today|
11
12.. % $Id: whatsnew26.tex 55746 2007-06-02 18:33:53Z neal.norwitz $
13.. % Rules for maintenance:
14.. %
15.. % * Anyone can add text to this document. Do not spend very much time
16.. % on the wording of your changes, because your text will probably
17.. % get rewritten to some degree.
18.. %
19.. % * The maintainer will go through Misc/NEWS periodically and add
20.. % changes; it's therefore more important to add your changes to
21.. % Misc/NEWS than to this file.
22.. %
23.. % * This is not a complete list of every single change; completeness
24.. % is the purpose of Misc/NEWS. Some changes I consider too small
25.. % or esoteric to include. If such a change is added to the text,
26.. % I'll just remove it. (This is another reason you shouldn't spend
27.. % too much time on writing your addition.)
28.. %
29.. % * If you want to draw your new text to the attention of the
30.. % maintainer, add 'XXX' to the beginning of the paragraph or
31.. % section.
32.. %
33.. % * It's OK to just add a fragmentary note about a change. For
34.. % example: "XXX Describe the transmogrify() function added to the
35.. % socket module." The maintainer will research the change and
36.. % write the necessary text.
37.. %
38.. % * You can comment out your additions if you like, but it's not
39.. % necessary (especially when a final release is some months away).
40.. %
41.. % * Credit the author of a patch or bugfix. Just the name is
42.. % sufficient; the e-mail address isn't necessary.
43.. %
44.. % * It's helpful to add the bug/patch number as a comment:
45.. %
46.. % % Patch 12345
47.. % XXX Describe the transmogrify() function added to the socket
48.. % module.
49.. % (Contributed by P.Y. Developer.)
50.. %
51.. % This saves the maintainer the effort of going through the SVN log
52.. % when researching a change.
53
54This article explains the new features in Python 2.6. No release date for
55Python 2.6 has been set; it will probably be released in mid 2008.
56
57This article doesn't attempt to provide a complete specification of the new
58features, but instead provides a convenient overview. For full details, you
59should refer to the documentation for Python 2.6. If you want to understand the
60complete implementation and design rationale, refer to the PEP for a particular
61new feature.
62
63.. % Compare with previous release in 2 - 3 sentences here.
64.. % add hyperlink when the documentation becomes available online.
65
66.. % ======================================================================
67.. % Large, PEP-level features and changes should be described here.
68.. % Should there be a new section here for 3k migration?
69.. % Or perhaps a more general section describing module changes/deprecation?
70.. % sets module deprecated
71.. % ======================================================================
72
Andrew M. Kuchlingf10878b2007-09-13 22:49:34 +000073Python 3.0
74================
75
76.. % XXX add general comment about Python 3.0 features in 2.6
77
78.. % XXX mention -3 switch
79
80A new command-line switch, :option:`-3`, enables warnings
81about features that will be removed in Python 3.0. You can run code
82with this switch to see how much work will be necessary to port
83code to 3.0.
84
85.. seealso::
86
87 The 3xxx series of PEPs, which describes the development process for
88 Python 3.0 and various features that have been accepted, rejected,
89 or are still under consideration.
90
91PEP 343: The 'with' statement
92=============================
93
94The previous version, Python 2.5, added the ':keyword:`with`'
95statement an optional feature, to be enabled by a ``from __future__
96import generators`` directive. In 2.6 the statement no longer need to
97be specially enabled; this means that :keyword:`with` is now always a
98keyword. The rest of this section is a copy of the corresponding
99section from "What's New in Python 2.5" document; if you read
100it back when Python 2.5 came out, you can skip the rest of this
101section.
102
103The ':keyword:`with`' statement clarifies code that previously would use
104``try...finally`` blocks to ensure that clean-up code is executed. In this
105section, I'll discuss the statement as it will commonly be used. In the next
106section, I'll examine the implementation details and show how to write objects
107for use with this statement.
108
109The ':keyword:`with`' statement is a new control-flow structure whose basic
110structure is::
111
112 with expression [as variable]:
113 with-block
114
115The expression is evaluated, and it should result in an object that supports the
116context management protocol (that is, has :meth:`__enter__` and :meth:`__exit__`
117methods.
118
119The object's :meth:`__enter__` is called before *with-block* is executed and
120therefore can run set-up code. It also may return a value that is bound to the
121name *variable*, if given. (Note carefully that *variable* is *not* assigned
122the result of *expression*.)
123
124After execution of the *with-block* is finished, the object's :meth:`__exit__`
125method is called, even if the block raised an exception, and can therefore run
126clean-up code.
127
128Some standard Python objects now support the context management protocol and can
129be used with the ':keyword:`with`' statement. File objects are one example::
130
131 with open('/etc/passwd', 'r') as f:
132 for line in f:
133 print line
134 ... more processing code ...
135
136After this statement has executed, the file object in *f* will have been
137automatically closed, even if the :keyword:`for` loop raised an exception part-
138way through the block.
139
140.. note::
141
142 In this case, *f* is the same object created by :func:`open`, because
143 :meth:`file.__enter__` returns *self*.
144
145The :mod:`threading` module's locks and condition variables also support the
146':keyword:`with`' statement::
147
148 lock = threading.Lock()
149 with lock:
150 # Critical section of code
151 ...
152
153The lock is acquired before the block is executed and always released once the
154block is complete.
155
156The new :func:`localcontext` function in the :mod:`decimal` module makes it easy
157to save and restore the current decimal context, which encapsulates the desired
158precision and rounding characteristics for computations::
159
160 from decimal import Decimal, Context, localcontext
161
162 # Displays with default precision of 28 digits
163 v = Decimal('578')
164 print v.sqrt()
165
166 with localcontext(Context(prec=16)):
167 # All code in this block uses a precision of 16 digits.
168 # The original context is restored on exiting the block.
169 print v.sqrt()
170
171
172.. _new-26-context-managers:
173
174Writing Context Managers
175------------------------
176
177Under the hood, the ':keyword:`with`' statement is fairly complicated. Most
178people will only use ':keyword:`with`' in company with existing objects and
179don't need to know these details, so you can skip the rest of this section if
180you like. Authors of new objects will need to understand the details of the
181underlying implementation and should keep reading.
182
183A high-level explanation of the context management protocol is:
184
185* The expression is evaluated and should result in an object called a "context
186 manager". The context manager must have :meth:`__enter__` and :meth:`__exit__`
187 methods.
188
189* The context manager's :meth:`__enter__` method is called. The value returned
190 is assigned to *VAR*. If no ``'as VAR'`` clause is present, the value is simply
191 discarded.
192
193* The code in *BLOCK* is executed.
194
195* If *BLOCK* raises an exception, the :meth:`__exit__(type, value, traceback)`
196 is called with the exception details, the same values returned by
197 :func:`sys.exc_info`. The method's return value controls whether the exception
198 is re-raised: any false value re-raises the exception, and ``True`` will result
199 in suppressing it. You'll only rarely want to suppress the exception, because
200 if you do the author of the code containing the ':keyword:`with`' statement will
201 never realize anything went wrong.
202
203* If *BLOCK* didn't raise an exception, the :meth:`__exit__` method is still
204 called, but *type*, *value*, and *traceback* are all ``None``.
205
206Let's think through an example. I won't present detailed code but will only
207sketch the methods necessary for a database that supports transactions.
208
209(For people unfamiliar with database terminology: a set of changes to the
210database are grouped into a transaction. Transactions can be either committed,
211meaning that all the changes are written into the database, or rolled back,
212meaning that the changes are all discarded and the database is unchanged. See
213any database textbook for more information.)
214
215Let's assume there's an object representing a database connection. Our goal will
216be to let the user write code like this::
217
218 db_connection = DatabaseConnection()
219 with db_connection as cursor:
220 cursor.execute('insert into ...')
221 cursor.execute('delete from ...')
222 # ... more operations ...
223
224The transaction should be committed if the code in the block runs flawlessly or
225rolled back if there's an exception. Here's the basic interface for
226:class:`DatabaseConnection` that I'll assume::
227
228 class DatabaseConnection:
229 # Database interface
230 def cursor (self):
231 "Returns a cursor object and starts a new transaction"
232 def commit (self):
233 "Commits current transaction"
234 def rollback (self):
235 "Rolls back current transaction"
236
237The :meth:`__enter__` method is pretty easy, having only to start a new
238transaction. For this application the resulting cursor object would be a useful
239result, so the method will return it. The user can then add ``as cursor`` to
240their ':keyword:`with`' statement to bind the cursor to a variable name. ::
241
242 class DatabaseConnection:
243 ...
244 def __enter__ (self):
245 # Code to start a new transaction
246 cursor = self.cursor()
247 return cursor
248
249The :meth:`__exit__` method is the most complicated because it's where most of
250the work has to be done. The method has to check if an exception occurred. If
251there was no exception, the transaction is committed. The transaction is rolled
252back if there was an exception.
253
254In the code below, execution will just fall off the end of the function,
255returning the default value of ``None``. ``None`` is false, so the exception
256will be re-raised automatically. If you wished, you could be more explicit and
257add a :keyword:`return` statement at the marked location. ::
258
259 class DatabaseConnection:
260 ...
261 def __exit__ (self, type, value, tb):
262 if tb is None:
263 # No exception, so commit
264 self.commit()
265 else:
266 # Exception occurred, so rollback.
267 self.rollback()
268 # return False
269
270
271.. _module-contextlib:
272
273The contextlib module
274---------------------
275
276The new :mod:`contextlib` module provides some functions and a decorator that
277are useful for writing objects for use with the ':keyword:`with`' statement.
278
279The decorator is called :func:`contextmanager`, and lets you write a single
280generator function instead of defining a new class. The generator should yield
281exactly one value. The code up to the :keyword:`yield` will be executed as the
282:meth:`__enter__` method, and the value yielded will be the method's return
283value that will get bound to the variable in the ':keyword:`with`' statement's
284:keyword:`as` clause, if any. The code after the :keyword:`yield` will be
285executed in the :meth:`__exit__` method. Any exception raised in the block will
286be raised by the :keyword:`yield` statement.
287
288Our database example from the previous section could be written using this
289decorator as::
290
291 from contextlib import contextmanager
292
293 @contextmanager
294 def db_transaction (connection):
295 cursor = connection.cursor()
296 try:
297 yield cursor
298 except:
299 connection.rollback()
300 raise
301 else:
302 connection.commit()
303
304 db = DatabaseConnection()
305 with db_transaction(db) as cursor:
306 ...
307
308The :mod:`contextlib` module also has a :func:`nested(mgr1, mgr2, ...)` function
309that combines a number of context managers so you don't need to write nested
310':keyword:`with`' statements. In this example, the single ':keyword:`with`'
311statement both starts a database transaction and acquires a thread lock::
312
313 lock = threading.Lock()
314 with nested (db_transaction(db), lock) as (cursor, locked):
315 ...
316
317Finally, the :func:`closing(object)` function returns *object* so that it can be
318bound to a variable, and calls ``object.close`` at the end of the block. ::
319
320 import urllib, sys
321 from contextlib import closing
322
323 with closing(urllib.urlopen('http://www.yahoo.com')) as f:
324 for line in f:
325 sys.stdout.write(line)
326
327
328.. seealso::
329
330 :pep:`343` - The "with" statement
331 PEP written by Guido van Rossum and Nick Coghlan; implemented by Mike Bland,
332 Guido van Rossum, and Neal Norwitz. The PEP shows the code generated for a
333 ':keyword:`with`' statement, which can be helpful in learning how the statement
334 works.
335
336 The documentation for the :mod:`contextlib` module.
337
338.. % ======================================================================
339
340.. _pep-3110:
341
342PEP 3110: Exception-Handling Changes
343=====================================================
344
345One error that Python programmers occasionally make
346is the following::
347
348 try:
349 ...
350 except TypeError, ValueError:
351 ...
352
353The author is probably trying to catch both
354:exc:`TypeError` and :exc:`ValueError` exceptions, but this code
355actually does something different: it will catch
356:exc:`TypeError` and bind the resulting exception object
357to the local name ``"ValueError"``. The correct code
358would have specified a tuple::
359
360 try:
361 ...
362 except (TypeError, ValueError):
363 ...
364
365This error is possible because the use of the comma here is ambiguous:
366does it indicate two different nodes in the parse tree, or a single
367node that's a tuple.
368
369Python 3.0 changes the syntax to make this unambiguous by replacing
370the comma with the word "as". To catch an exception and store the
371exception object in the variable ``exc``, you must write::
372
373 try:
374 ...
375 except TypeError as exc:
376 ...
377
378Python 3.0 will only support the use of "as", and therefore interprets
379the first example as catching two different exceptions. Python 2.6
380supports both the comma and "as", so existing code will continue to
381work.
382
383.. seealso::
384
385 :pep:`3110` - Catching Exceptions in Python 3000
386 PEP written and implemented by Collin Winter.
387
388.. % ======================================================================
389
390.. _pep-3119:
391
392PEP 3119: Abstract Base Classes
393=====================================================
394
395XXX
396
397.. seealso::
398
399 :pep:`3119` - Introducing Abstract Base Classes
400 PEP written by Guido van Rossum and Talin.
401 Implemented by XXX.
402 Backported to 2.6 by Benjamin Aranguren (with Alex Martelli).
Georg Brandl8ec7f652007-08-15 14:28:01 +0000403
404Other Language Changes
405======================
406
407Here are all of the changes that Python 2.6 makes to the core Python language.
408
Andrew M. Kuchlingf10878b2007-09-13 22:49:34 +0000409* Changes to the :class:`Exception` interface
410 as dictated by :pep:`352` continue to be made. For 2.6,
411 the :attr:`message` attribute is being deprecated in favor of the
412 :attr:`args` attribute.
413
414* When calling a function using the ``**`` syntax to provide keyword
415 arguments, you are no longer required to use a Python dictionary;
416 any mapping will now work::
417
418 >>> def f(**kw):
419 ... print sorted(kw)
420 ...
421 >>> ud=UserDict.UserDict()
422 >>> ud['a'] = 1
423 >>> ud['b'] = 'string'
424 >>> f(**ud)
425 ['a', 'b']
426
427 .. % Patch 1686487
428
429* The :func:`compile` built-in function now accepts keyword arguments
430 as well as positional parameters. (Contributed by XXX.)
431
432 .. % Patch 1444529
433
Andrew M. Kuchling6c066dd2007-09-01 20:43:36 +0000434* The :func:`complex` constructor now accepts strings containing
435 parenthesized complex numbers, letting ``complex(repr(cmplx))``
436 will now round-trip values. For example, ``complex('(3+4j)')``
437 now returns the value (3+4j).
438
439 .. % Patch 1491866
440
Andrew M. Kuchlingb4c62952007-09-01 21:18:31 +0000441* The string :meth:`translate` method now accepts ``None`` as the
442 translation table parameter, which is treated as the identity
443 transformation. This makes it easier to carry out operations
444 that only delete characters. (Contributed by Bengt Richter.)
445
446 .. % Patch 1193128
447
Andrew M. Kuchlingf10878b2007-09-13 22:49:34 +0000448* The built-in :func:`dir` function now checks for a :meth:`__dir__`
449 method on the objects it receives. This method must return a list
450 of strings containing the names of valid attributes for the object,
451 and lets the object control the value that :func:`dir` produces.
452 Objects that have :meth:`__getattr__` or :meth:`__getattribute__`
453 methods.
454
455 .. % Patch 1591665
456
Georg Brandl8ec7f652007-08-15 14:28:01 +0000457* An obscure change: when you use the the :func:`locals` function inside a
458 :keyword:`class` statement, the resulting dictionary no longer returns free
459 variables. (Free variables, in this case, are variables referred to in the
460 :keyword:`class` statement that aren't attributes of the class.)
461
462.. % ======================================================================
463
464
465Optimizations
466-------------
467
468* Internally, a bit is now set in type objects to indicate some of the standard
469 built-in types. This speeds up checking if an object is a subclass of one of
470 these types. (Contributed by Neal Norwitz.)
471
472The net result of the 2.6 optimizations is that Python 2.6 runs the pystone
473benchmark around XX% faster than Python 2.5.
474
475.. % ======================================================================
476
477
478New, Improved, and Deprecated Modules
479=====================================
480
481As usual, Python's standard library received a number of enhancements and bug
482fixes. Here's a partial list of the most notable changes, sorted alphabetically
483by module name. Consult the :file:`Misc/NEWS` file in the source tree for a more
484complete list of changes, or look through the CVS logs for all the details.
485
486* A new data type in the :mod:`collections` module: :class:`NamedTuple(typename,
487 fieldnames)` is a factory function that creates subclasses of the standard tuple
488 whose fields are accessible by name as well as index. For example::
489
490 var_type = collections.NamedTuple('variable',
491 'id name type size')
492 var = var_type(1, 'frequency', 'int', 4)
493
494 print var[0], var.id # Equivalent
495 print var[2], var.type # Equivalent
496
497 (Contributed by Raymond Hettinger.)
498
499* A new method in the :mod:`curses` module: for a window, :meth:`chgat` changes
500 the display characters for a certain number of characters on a single line. ::
501
502 # Boldface text starting at y=0,x=21
503 # and affecting the rest of the line.
504 stdscr.chgat(0,21, curses.A_BOLD)
505
506 (Contributed by Fabian Kreutz.)
507
Andrew M. Kuchlingb4c62952007-09-01 21:18:31 +0000508* An optional ``timeout`` parameter was added to the
509 :class:`ftplib.FTP` class constructor as well as the :meth:`connect`
510 method, specifying a timeout measured in seconds. (Added by Facundo
511 Batista.)
512
Georg Brandl8ec7f652007-08-15 14:28:01 +0000513* The :func:`glob.glob` function can now return Unicode filenames if
514 a Unicode path was used and Unicode filenames are matched within the directory.
515
516 .. % Patch #1001604
517
518* The :mod:`gopherlib` module has been removed.
519
520* A new function in the :mod:`heapq` module: ``merge(iter1, iter2, ...)``
521 takes any number of iterables that return data *in sorted order*, and returns
522 a new iterator that returns the contents of all the iterators, also in sorted
523 order. For example::
524
525 heapq.merge([1, 3, 5, 9], [2, 8, 16]) ->
526 [1, 2, 3, 5, 8, 9, 16]
527
528 (Contributed by Raymond Hettinger.)
529
Andrew M. Kuchlingf10878b2007-09-13 22:49:34 +0000530* An optional ``timeout`` parameter was added to the
531 :class:`httplib.HTTPConnection` and :class:`HTTPSConnection`
532 class constructors, specifying a timeout measured in seconds.
533 (Added by Facundo Batista.)
534
Georg Brandl8ec7f652007-08-15 14:28:01 +0000535* A new function in the :mod:`itertools` module: ``izip_longest(iter1, iter2,
536 ...[, fillvalue])`` makes tuples from each of the elements; if some of the
537 iterables are shorter than others, the missing values are set to *fillvalue*.
538 For example::
539
540 itertools.izip_longest([1,2,3], [1,2,3,4,5]) ->
541 [(1, 1), (2, 2), (3, 3), (None, 4), (None, 5)]
542
543 (Contributed by Raymond Hettinger.)
544
545* The :mod:`macfs` module has been removed. This in turn required the
546 :func:`macostools.touched` function to be removed because it depended on the
547 :mod:`macfs` module.
548
549 .. % Patch #1490190
550
Andrew M. Kuchlingf10878b2007-09-13 22:49:34 +0000551* The :func:`os.walk` function now has a "followlinks" parameter. If
552 set to True, it will follow symlinks pointing to directories and
553 visit the directory's contents. For backward compatibility, the
554 parameter's default value is false. Note that the function can fall
555 into an infinite recursion if there's a symlink that points to a
556 parent directory.
557
558 .. % Patch 1273829
559
Andrew M. Kuchling6c066dd2007-09-01 20:43:36 +0000560* In the :mod:`os.path` module, the :func:`splitext` function
561 has been changed to not split on leading period characters.
562 This produces better results when operating on Unix's dot-files.
563 For example, ``os.path.splitext('.ipython')``
564 now returns ``('.ipython', '')`` instead of ``('', '.ipython')``.
565
566 .. % Bug #115886
567
Andrew M. Kuchlingb4c62952007-09-01 21:18:31 +0000568 A new function, :func:`relpath(path, start)` returns a relative path
569 from the ``start`` path, if it's supplied, or from the current
570 working directory to the destination ``path``. (Contributed by
571 Richard Barran.)
572
573 .. % Patch 1339796
574
Andrew M. Kuchlingf10878b2007-09-13 22:49:34 +0000575 On Windows, :func:`os.path.expandvars` will now expand environment variables
576 in the form "%var%", and "~user" will be expanded into the
577 user's home directory path. (Contributed by XXX.)
578
579 .. % Patch 957650
580
Georg Brandl8ec7f652007-08-15 14:28:01 +0000581* New functions in the :mod:`posix` module: :func:`chflags` and :func:`lchflags`
582 are wrappers for the corresponding system calls (where they're available).
583 Constants for the flag values are defined in the :mod:`stat` module; some
584 possible values include :const:`UF_IMMUTABLE` to signal the file may not be
585 changed and :const:`UF_APPEND` to indicate that data can only be appended to the
586 file. (Contributed by M. Levinson.)
587
588* The :mod:`rgbimg` module has been removed.
589
Andrew M. Kuchling6c066dd2007-09-01 20:43:36 +0000590* The :mod:`smtplib` module now supports SMTP over SSL thanks to the
591 addition of the :class:`SMTP_SSL` class. This class supports an
Andrew M. Kuchlingb4c62952007-09-01 21:18:31 +0000592 interface identical to the existing :class:`SMTP` class. Both
593 class constructors also have an optional ``timeout`` parameter
594 that specifies a timeout for the initial connection attempt, measured in
595 seconds.
596
597 An implementation of the LMTP protocol (:rfc:`2033`) was also added to
Andrew M. Kuchling6c066dd2007-09-01 20:43:36 +0000598 the module. LMTP is used in place of SMTP when transferring e-mail
599 between agents that don't manage a mail queue.
Andrew M. Kuchlingb4c62952007-09-01 21:18:31 +0000600
601 (SMTP over SSL contributed by Monty Taylor; timeout parameter
602 added by Facundo Batista; LMTP implemented by Leif
Andrew M. Kuchling6c066dd2007-09-01 20:43:36 +0000603 Hedstrom.)
604
605 .. % Patch #957003
Georg Brandl8ec7f652007-08-15 14:28:01 +0000606
Andrew M. Kuchlingf10878b2007-09-13 22:49:34 +0000607* The :mod:`textwrap` module can now preserve existing whitespace
608 at the beginnings and ends of the newly-created lines
609 by specifying ``drop_whitespace=False``
610 as an argument::
611
612 >>> S = """This sentence has a bunch of extra whitespace."""
613 >>> print textwrap.fill(S, width=15)
614 This sentence
615 has a bunch
616 of extra
617 whitespace.
618 >>> print textwrap.fill(S, drop_whitespace=False, width=15)
619 This sentence
620 has a bunch
621 of extra
622 whitespace.
623 >>>
624
625 .. % Patch #1581073
626
Andrew M. Kuchlingb4c62952007-09-01 21:18:31 +0000627* An optional ``timeout`` parameter was added to the
628 :class:`telnetlib.Telnet` class constructor, specifying a timeout
629 measured in seconds. (Added by Facundo Batista.)
630
Andrew M. Kuchlingf10878b2007-09-13 22:49:34 +0000631* The :class:`tempfile.NamedTemporaryFile` class usually deletes
632 the temporary file it created when the file is closed. This
633 behaviour can now be changed by passing ``delete=False`` to the
634 constructor. (Contributed by Damien Miller.)
635
636 .. % Patch #1537850
637
Georg Brandl8ec7f652007-08-15 14:28:01 +0000638* The :mod:`test.test_support` module now contains a :func:`EnvironmentVarGuard`
639 context manager that supports temporarily changing environment variables and
640 automatically restores them to their old values. (Contributed by Brett Cannon.)
641
Andrew M. Kuchling6c066dd2007-09-01 20:43:36 +0000642* The :mod:`timeit` module now accepts callables as well as strings
643 for the statement being timed and for the setup code.
644 Two convenience functions were added for creating
645 :class:`Timer` instances:
646 ``repeat(stmt, setup, time, repeat, number)`` and
647 ``timeit(stmt, setup, time, number)`` create an instance and call
648 the corresponding method. (Contributed by Erik Demaine.)
649
650 .. % Patch #1533909
651
Andrew M. Kuchlingf10878b2007-09-13 22:49:34 +0000652* An optional ``timeout`` parameter was added to the
653 :func:`urllib.urlopen` function and the
654 :class:`urllib.ftpwrapper` class constructor, as well as the
655 :func:`urllib2.urlopen` function. The parameter specifies a timeout
656 measured in seconds. For example::
657
658 >>> u = urllib2.urlopen("http://slow.example.com", timeout=3)
659 Traceback (most recent call last):
660 ...
661 urllib2.URLError: <urlopen error timed out>
662 >>>
663
664 (Added by Facundo Batista.)
665
Georg Brandl8ec7f652007-08-15 14:28:01 +0000666.. % ======================================================================
667.. % whole new modules get described in \subsections here
668
669.. % ======================================================================
670
671
672Build and C API Changes
673=======================
674
675Changes to Python's build process and to the C API include:
676
677* Detailed changes are listed here.
678
679.. % ======================================================================
680
681
682Port-Specific Changes
683---------------------
684
685Platform-specific changes go here.
686
687.. % ======================================================================
688
689
690.. _section-other:
691
692Other Changes and Fixes
693=======================
694
695As usual, there were a bunch of other improvements and bugfixes scattered
696throughout the source tree. A search through the change logs finds there were
697XXX patches applied and YYY bugs fixed between Python 2.5 and 2.6. Both figures
698are likely to be underestimates.
699
700Some of the more notable changes are:
701
702* Details go here.
703
704.. % ======================================================================
705
706
707Porting to Python 2.6
708=====================
709
710This section lists previously described changes that may require changes to your
711code:
712
Gregory P. Smithe9fef692007-09-09 23:36:46 +0000713* The :mod:`socket` module exception :exc:`socket.error` now inherits from
714 :exc:`IOError`.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000715
716.. % ======================================================================
717
718
719.. _acks:
720
721Acknowledgements
722================
723
724The author would like to thank the following people for offering suggestions,
725corrections and assistance with various drafts of this article: .
726