@@ -217,13 +217,13 @@ often use the ``codecs.lookup(encoding)`` function, which returns a
217
217
was consumed.
218
218
219
219
* *stream_reader * is a class that supports decoding input from a stream.
220
- *stream_reader(file_obj) * returns an object that supports the :meth: `read `,
221
- :meth: `readline `, and :meth: `readlines ` methods. These methods will all
220
+ *stream_reader(file_obj) * returns an object that supports the :meth: `! read `,
221
+ :meth: `! readline `, and :meth: `! readlines ` methods. These methods will all
222
222
translate from the given encoding and return Unicode strings.
223
223
224
224
* *stream_writer *, similarly, is a class that supports encoding output to a
225
225
stream. *stream_writer(file_obj) * returns an object that supports the
226
- :meth: `write ` and :meth: `writelines ` methods. These methods expect Unicode
226
+ :meth: `! write ` and :meth: `! writelines ` methods. These methods expect Unicode
227
227
strings, translating them to the given encoding on output.
228
228
229
229
For example, the following code writes a Unicode string into a file, encoding
@@ -356,8 +356,8 @@ variable ``a`` by 2, equivalent to the slightly lengthier ``a = a + 2``.
356
356
The full list of supported assignment operators is ``+= ``, ``-= ``, ``*= ``,
357
357
``/= ``, ``%= ``, ``**= ``, ``&= ``, ``|= ``, ``^= ``, ``>>= ``, and ``<<= ``. Python
358
358
classes can override the augmented assignment operators by defining methods
359
- named :meth: `__iadd__ `, :meth: `__isub__ `, etc. For example, the following
360
- :class: `Number ` class stores a number and supports using += to create a new
359
+ named :meth: `! __iadd__ `, :meth: `! __isub__ `, etc. For example, the following
360
+ :class: `! Number ` class stores a number and supports using += to create a new
361
361
instance with an incremented value.
362
362
363
363
.. The empty groups below prevent conversion to guillemets.
@@ -374,7 +374,7 @@ instance with an incremented value.
374
374
n += 3
375
375
print n.value
376
376
377
- The :meth: `__iadd__ ` special method is called with the value of the increment,
377
+ The :meth: `! __iadd__ ` special method is called with the value of the increment,
378
378
and should return a new instance with an appropriately modified value; this
379
379
return value is bound as the new value of the variable on the left-hand side.
380
380
@@ -390,10 +390,10 @@ String Methods
390
390
==============
391
391
392
392
Until now string-manipulation functionality was in the :mod: `string ` module,
393
- which was usually a front-end for the :mod: `strop ` module written in C. The
394
- addition of Unicode posed a difficulty for the :mod: `strop ` module, because the
393
+ which was usually a front-end for the :mod: `! strop ` module written in C. The
394
+ addition of Unicode posed a difficulty for the :mod: `! strop ` module, because the
395
395
functions would all need to be rewritten in order to accept either 8-bit or
396
- Unicode strings. For functions such as :func: `string.replace `, which takes 3
396
+ Unicode strings. For functions such as :func: `! string.replace `, which takes 3
397
397
string arguments, that means eight possible permutations, and correspondingly
398
398
complicated code.
399
399
@@ -416,13 +416,13 @@ The old :mod:`string` module is still around for backwards compatibility, but it
416
416
mostly acts as a front-end to the new string methods.
417
417
418
418
Two methods which have no parallel in pre-2.0 versions, although they did exist
419
- in JPython for quite some time, are :meth: `startswith ` and :meth: `endswith `.
419
+ in JPython for quite some time, are :meth: `! startswith ` and :meth: `! endswith `.
420
420
``s.startswith(t) `` is equivalent to ``s[:len(t)] == t ``, while
421
421
``s.endswith(t) `` is equivalent to ``s[-len(t):] == t ``.
422
422
423
- One other method which deserves special mention is :meth: `join `. The
424
- :meth: `join ` method of a string receives one parameter, a sequence of strings,
425
- and is equivalent to the :func: `string.join ` function from the old :mod: `string `
423
+ One other method which deserves special mention is :meth: `! join `. The
424
+ :meth: `! join ` method of a string receives one parameter, a sequence of strings,
425
+ and is equivalent to the :func: `! string.join ` function from the old :mod: `string `
426
426
module, with the arguments reversed. In other words, ``s.join(seq) `` is
427
427
equivalent to the old ``string.join(seq, s) ``.
428
428
@@ -503,9 +503,9 @@ Minor Language Changes
503
503
504
504
A new syntax makes it more convenient to call a given function with a tuple of
505
505
arguments and/or a dictionary of keyword arguments. In Python 1.5 and earlier,
506
- you'd use the :func: `apply ` built-in function: ``apply(f, args, kw) `` calls the
507
- function :func: `f ` with the argument tuple *args * and the keyword arguments in
508
- the dictionary *kw *. :func: `apply ` is the same in 2.0, but thanks to a patch
506
+ you'd use the :func: `! apply ` built-in function: ``apply(f, args, kw) `` calls the
507
+ function :func: `! f ` with the argument tuple *args * and the keyword arguments in
508
+ the dictionary *kw *. :func: `! apply ` is the same in 2.0, but thanks to a patch
509
509
from Greg Ewing, ``f(*args, **kw) `` is a shorter and clearer way to achieve the
510
510
same effect. This syntax is symmetrical with the syntax for defining
511
511
functions::
@@ -518,7 +518,7 @@ functions::
518
518
The ``print `` statement can now have its output directed to a file-like
519
519
object by following the ``print `` with ``>> file ``, similar to the
520
520
redirection operator in Unix shells. Previously you'd either have to use the
521
- :meth: `write ` method of the file-like object, which lacks the convenience and
521
+ :meth: `! write ` method of the file-like object, which lacks the convenience and
522
522
simplicity of ``print ``, or you could assign a new value to
523
523
``sys.stdout `` and then restore the old value. For sending output to standard
524
524
error, it's much easier to write this::
@@ -540,7 +540,7 @@ Previously there was no way to implement a class that overrode Python's built-in
540
540
true if *obj * is present in the sequence *seq *; Python computes this by simply
541
541
trying every index of the sequence until either *obj * is found or an
542
542
:exc: `IndexError ` is encountered. Moshe Zadka contributed a patch which adds a
543
- :meth: `__contains__ ` magic method for providing a custom implementation for
543
+ :meth: `! __contains__ ` magic method for providing a custom implementation for
544
544
:keyword: `!in `. Additionally, new built-in objects written in C can define what
545
545
:keyword: `!in ` means for them via a new slot in the sequence protocol.
546
546
@@ -562,7 +562,7 @@ the python-dev mailing list for the discussion leading up to this
562
562
implementation, and some useful relevant links. Note that comparisons can now
563
563
also raise exceptions. In earlier versions of Python, a comparison operation
564
564
such as ``cmp(a,b) `` would always produce an answer, even if a user-defined
565
- :meth: `__cmp__ ` method encountered an error, since the resulting exception would
565
+ :meth: `! __cmp__ ` method encountered an error, since the resulting exception would
566
566
simply be silently swallowed.
567
567
568
568
.. Starting URL:
@@ -607,7 +607,7 @@ seq1, seq2)`` is that :func:`map` pads the sequences with ``None`` if the
607
607
sequences aren't all of the same length, while :func: `zip ` truncates the
608
608
returned list to the length of the shortest argument sequence.
609
609
610
- The :func: `int ` and :func: `long ` functions now accept an optional "base"
610
+ The :func: `int ` and :func: `! long ` functions now accept an optional "base"
611
611
parameter when the first argument is a string. ``int('123', 10) `` returns 123,
612
612
while ``int('123', 16) `` returns 291. ``int(123, 16) `` raises a
613
613
:exc: `TypeError ` exception with the message "can't convert non-string with
@@ -620,8 +620,8 @@ would be ``(2, 0, 1, 'beta', 1)``. *level* is a string such as ``"alpha"``,
620
620
``"beta" ``, or ``"final" `` for a final release.
621
621
622
622
Dictionaries have an odd new method, ``setdefault(key, default) ``, which
623
- behaves similarly to the existing :meth: `get ` method. However, if the key is
624
- missing, :meth: `setdefault ` both returns the value of *default * as :meth: `get `
623
+ behaves similarly to the existing :meth: `! get ` method. However, if the key is
624
+ missing, :meth: `! setdefault ` both returns the value of *default * as :meth: `! get `
625
625
would do, and also inserts it into the dictionary as the value for *key *. Thus,
626
626
the following lines of code::
627
627
@@ -656,7 +656,7 @@ break.
656
656
The change which will probably break the most code is tightening up the
657
657
arguments accepted by some methods. Some methods would take multiple arguments
658
658
and treat them as a tuple, particularly various list methods such as
659
- :meth: `append ` and :meth: `insert `. In earlier versions of Python, if ``L `` is
659
+ :meth: `! append ` and :meth: `! insert `. In earlier versions of Python, if ``L `` is
660
660
a list, ``L.append( 1,2 ) `` appends the tuple ``(1,2) `` to the list. In Python
661
661
2.0 this causes a :exc: `TypeError ` exception to be raised, with the message:
662
662
'append requires exactly 1 argument; 2 given'. The fix is to simply add an
@@ -693,15 +693,15 @@ advantage of this fact will break in 2.0.
693
693
694
694
Some work has been done to make integers and long integers a bit more
695
695
interchangeable. In 1.5.2, large-file support was added for Solaris, to allow
696
- reading files larger than 2 GiB; this made the :meth: `tell ` method of file
696
+ reading files larger than 2 GiB; this made the :meth: `! tell ` method of file
697
697
objects return a long integer instead of a regular integer. Some code would
698
698
subtract two file offsets and attempt to use the result to multiply a sequence
699
699
or slice a string, but this raised a :exc: `TypeError `. In 2.0, long integers
700
700
can be used to multiply or slice a sequence, and it'll behave as you'd
701
701
intuitively expect it to; ``3L * 'abc' `` produces 'abcabcabc', and
702
702
``(0,1,2,3)[2L:4L] `` produces (2,3). Long integers can also be used in various
703
703
contexts where previously only integers were accepted, such as in the
704
- :meth: `seek ` method of file objects, and in the formats supported by the ``% ``
704
+ :meth: `! seek ` method of file objects, and in the formats supported by the ``% ``
705
705
operator (``%d ``, ``%i ``, ``%x ``, etc.). For example, ``"%d" % 2L**64 `` will
706
706
produce the string ``18446744073709551616 ``.
707
707
@@ -715,15 +715,15 @@ digit.
715
715
716
716
Taking the :func: `repr ` of a float now uses a different formatting precision
717
717
than :func: `str `. :func: `repr ` uses ``%.17g `` format string for C's
718
- :func: `sprintf `, while :func: `str ` uses ``%.12g `` as before. The effect is that
718
+ :func: `! sprintf `, while :func: `str ` uses ``%.12g `` as before. The effect is that
719
719
:func: `repr ` may occasionally show more decimal places than :func: `str `, for
720
720
certain numbers. For example, the number 8.1 can't be represented exactly in
721
721
binary, so ``repr(8.1) `` is ``'8.0999999999999996' ``, while str(8.1) is
722
722
``'8.1' ``.
723
723
724
724
The ``-X `` command-line option, which turned all standard exceptions into
725
725
strings instead of classes, has been removed; the standard exceptions will now
726
- always be classes. The :mod: `exceptions ` module containing the standard
726
+ always be classes. The :mod: `! exceptions ` module containing the standard
727
727
exceptions was translated from Python to a built-in C module, written by Barry
728
728
Warsaw and Fredrik Lundh.
729
729
@@ -879,11 +879,11 @@ joins the basic set of Python documentation.
879
879
XML Modules
880
880
===========
881
881
882
- Python 1.5.2 included a simple XML parser in the form of the :mod: `xmllib `
882
+ Python 1.5.2 included a simple XML parser in the form of the :mod: `! xmllib `
883
883
module, contributed by Sjoerd Mullender. Since 1.5.2's release, two different
884
884
interfaces for processing XML have become common: SAX2 (version 2 of the Simple
885
885
API for XML) provides an event-driven interface with some similarities to
886
- :mod: `xmllib `, and the DOM (Document Object Model) provides a tree-based
886
+ :mod: `! xmllib `, and the DOM (Document Object Model) provides a tree-based
887
887
interface, transforming an XML document into a tree of nodes that can be
888
888
traversed and modified. Python 2.0 includes a SAX2 interface and a stripped-down
889
889
DOM interface as part of the :mod: `xml ` package. Here we will give a brief
@@ -898,9 +898,9 @@ SAX2 Support
898
898
SAX defines an event-driven interface for parsing XML. To use SAX, you must
899
899
write a SAX handler class. Handler classes inherit from various classes
900
900
provided by SAX, and override various methods that will then be called by the
901
- XML parser. For example, the :meth: `startElement ` and :meth: `endElement `
901
+ XML parser. For example, the :meth: `~xml.sax.handler.ContentHandler. startElement ` and :meth: `~xml.sax.handler.ContentHandler. endElement `
902
902
methods are called for every starting and end tag encountered by the parser, the
903
- :meth: `characters ` method is called for every chunk of character data, and so
903
+ :meth: `~xml.sax.handler.ContentHandler. characters ` method is called for every chunk of character data, and so
904
904
forth.
905
905
906
906
The advantage of the event-driven approach is that the whole document doesn't
@@ -940,8 +940,8 @@ DOM Support
940
940
-----------
941
941
942
942
The Document Object Model is a tree-based representation for an XML document. A
943
- top-level :class: `Document ` instance is the root of the tree, and has a single
944
- child which is the top-level :class: `Element ` instance. This :class: `Element `
943
+ top-level :class: `! Document ` instance is the root of the tree, and has a single
944
+ child which is the top-level :class: `! Element ` instance. This :class: `! Element `
945
945
has children nodes representing character data and any sub-elements, which may
946
946
have further children of their own, and so forth. Using the DOM you can
947
947
traverse the resulting tree any way you like, access element and attribute
@@ -955,18 +955,18 @@ simply writing ``<tag1>``...\ ``</tag1>`` to a file.
955
955
956
956
The DOM implementation included with Python lives in the :mod: `xml.dom.minidom `
957
957
module. It's a lightweight implementation of the Level 1 DOM with support for
958
- XML namespaces. The :func: `parse ` and :func: `parseString ` convenience
958
+ XML namespaces. The :func: `! parse ` and :func: `! parseString ` convenience
959
959
functions are provided for generating a DOM tree::
960
960
961
961
from xml.dom import minidom
962
962
doc = minidom.parse('hamlet.xml')
963
963
964
- ``doc `` is a :class: `Document ` instance. :class: `Document `, like all the other
965
- DOM classes such as :class: `Element ` and :class: `Text `, is a subclass of the
966
- :class: `Node ` base class. All the nodes in a DOM tree therefore support certain
967
- common methods, such as :meth: `toxml ` which returns a string containing the XML
964
+ ``doc `` is a :class: `! Document ` instance. :class: `! Document `, like all the other
965
+ DOM classes such as :class: `! Element ` and :class: `Text `, is a subclass of the
966
+ :class: `! Node ` base class. All the nodes in a DOM tree therefore support certain
967
+ common methods, such as :meth: `! toxml ` which returns a string containing the XML
968
968
representation of the node and its children. Each class also has special
969
- methods of its own; for example, :class: `Element ` and :class: `Document `
969
+ methods of its own; for example, :class: `! Element ` and :class: `! Document `
970
970
instances have a method to find all child elements with a given tag name.
971
971
Continuing from the previous 2-line example::
972
972
@@ -995,7 +995,7 @@ its children can be easily modified by deleting, adding, or removing nodes::
995
995
root.insertBefore( root.childNodes[0], root.childNodes[20] )
996
996
997
997
Again, I will refer you to the Python documentation for a complete listing of
998
- the different :class: `Node ` classes and their various methods.
998
+ the different :class: `! Node ` classes and their various methods.
999
999
1000
1000
1001
1001
Relationship to PyXML
@@ -1020,7 +1020,7 @@ features in PyXML include:
1020
1020
1021
1021
* The xmlproc validating parser, written by Lars Marius Garshol.
1022
1022
1023
- * The :mod: `sgmlop ` parser accelerator module, written by Fredrik Lundh.
1023
+ * The :mod: `! sgmlop ` parser accelerator module, written by Fredrik Lundh.
1024
1024
1025
1025
.. ======================================================================
1026
1026
@@ -1031,7 +1031,7 @@ Module changes
1031
1031
Lots of improvements and bugfixes were made to Python's extensive standard
1032
1032
library; some of the affected modules include :mod: `readline `,
1033
1033
:mod: `ConfigParser <configparser> `, :mod: `cgi `, :mod: `calendar `, :mod: `posix `, :mod: `readline `,
1034
- :mod: `xmllib `, :mod: `aifc `, :mod: `chunk, wave `, :mod: `random `, :mod: `shelve `,
1034
+ :mod: `! xmllib `, :mod: `aifc `, :mod: `chunk `, :mod: ` wave `, :mod: `random `, :mod: `shelve `,
1035
1035
and :mod: `nntplib `. Consult the CVS logs for the exact patch-by-patch details.
1036
1036
1037
1037
Brian Gallew contributed OpenSSL support for the :mod: `socket ` module. OpenSSL
@@ -1044,11 +1044,12 @@ were also changed to support ``https://`` URLs, though no one has implemented
1044
1044
FTP or SMTP over SSL.
1045
1045
1046
1046
The :mod: `httplib <http> ` module has been rewritten by Greg Stein to support HTTP/1.1.
1047
+
1047
1048
Backward compatibility with the 1.5 version of :mod: `!httplib ` is provided,
1048
1049
though using HTTP/1.1 features such as pipelining will require rewriting code to
1049
1050
use a different set of interfaces.
1050
1051
1051
- The :mod: `Tkinter ` module now supports Tcl/Tk version 8.1, 8.2, or 8.3, and
1052
+ The :mod: `! Tkinter ` module now supports Tcl/Tk version 8.1, 8.2, or 8.3, and
1052
1053
support for the older 7.x versions has been dropped. The Tkinter module now
1053
1054
supports displaying Unicode strings in Tk widgets. Also, Fredrik Lundh
1054
1055
contributed an optimization which makes operations like ``create_line `` and
@@ -1083,11 +1084,11 @@ module.
1083
1084
calling :func: `atexit.register ` with the function to be called on exit.
1084
1085
(Contributed by Skip Montanaro.)
1085
1086
1086
- * :mod: `codecs `, :mod: `encodings `, :mod: `unicodedata `: Added as part of the new
1087
+ * :mod: `codecs `, :mod: `! encodings `, :mod: `unicodedata `: Added as part of the new
1087
1088
Unicode support.
1088
1089
1089
- * :mod: `filecmp `: Supersedes the old :mod: `cmp `, :mod: `cmpcache ` and
1090
- :mod: `dircmp ` modules, which have now become deprecated. (Contributed by Gordon
1090
+ * :mod: `filecmp `: Supersedes the old :mod: `! cmp `, :mod: `! cmpcache ` and
1091
+ :mod: `! dircmp ` modules, which have now become deprecated. (Contributed by Gordon
1091
1092
MacMillan and Moshe Zadka.)
1092
1093
1093
1094
* :mod: `gettext `: This module provides internationalization (I18N) and
@@ -1105,7 +1106,7 @@ module.
1105
1106
be passed to functions that expect ordinary strings, such as the :mod: `re `
1106
1107
module. (Contributed by Sam Rushing, with some extensions by A.M. Kuchling.)
1107
1108
1108
- * :mod: `pyexpat `: An interface to the Expat XML parser. (Contributed by Paul
1109
+ * :mod: `! pyexpat `: An interface to the Expat XML parser. (Contributed by Paul
1109
1110
Prescod.)
1110
1111
1111
1112
* :mod: `robotparser <urllib.robotparser> `: Parse a :file: `robots.txt ` file, which is used for writing
@@ -1117,7 +1118,7 @@ module.
1117
1118
* :mod: `tabnanny `: A module/script to check Python source code for ambiguous
1118
1119
indentation. (Contributed by Tim Peters.)
1119
1120
1120
- * :mod: `UserString `: A base class useful for deriving objects that behave like
1121
+ * :mod: `! UserString `: A base class useful for deriving objects that behave like
1121
1122
strings.
1122
1123
1123
1124
* :mod: `webbrowser `: A module that provides a platform independent way to launch
@@ -1184,13 +1185,13 @@ Deleted and Deprecated Modules
1184
1185
==============================
1185
1186
1186
1187
A few modules have been dropped because they're obsolete, or because there are
1187
- now better ways to do the same thing. The :mod: `stdwin ` module is gone; it was
1188
+ now better ways to do the same thing. The :mod: `! stdwin ` module is gone; it was
1188
1189
for a platform-independent windowing toolkit that's no longer developed.
1189
1190
1190
1191
A number of modules have been moved to the :file: `lib-old ` subdirectory:
1191
- :mod: `cmp `, :mod: `cmpcache `, :mod: `dircmp `, :mod: `dump `, :mod: `find `,
1192
- :mod: `grep `, :mod: `packmail `, :mod: `poly `, :mod: `util `, :mod: `whatsound `,
1193
- :mod: `zmod `. If you have code which relies on a module that's been moved to
1192
+ :mod: `! cmp `, :mod: `! cmpcache `, :mod: `! dircmp `, :mod: `! dump `, :mod: `! find `,
1193
+ :mod: `! grep `, :mod: `! packmail `, :mod: `! poly `, :mod: `! util `, :mod: `! whatsound `,
1194
+ :mod: `! zmod `. If you have code which relies on a module that's been moved to
1194
1195
:file: `lib-old `, you can simply add that directory to ``sys.path `` to get them
1195
1196
back, but you're encouraged to update any code that uses these modules.
1196
1197
0 commit comments