Commit a3c242c1 authored by Georg Brandl's avatar Georg Brandl

Merged revisions...

Merged revisions 72558,72745,72750,72876,73042,73045-73048,73069,73089,73163,73186,73213,73215,73217,73257-73258,73260 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r72558 | benjamin.peterson | 2009-05-11 01:52:09 +0200 (Mo, 11 Mai 2009) | 1 line

  sys.setdefaultencoding() strikes me as a bad example
........
  r72745 | benjamin.peterson | 2009-05-17 16:16:29 +0200 (So, 17 Mai 2009) | 1 line

  ignore .rst files in sphinx its self
........
  r72750 | benjamin.peterson | 2009-05-17 18:59:27 +0200 (So, 17 Mai 2009) | 1 line

  chop off slash
........
  r72876 | benjamin.peterson | 2009-05-23 22:59:09 +0200 (Sa, 23 Mai 2009) | 1 line

  remove mention of old ctypes version
........
  r73042 | benjamin.peterson | 2009-05-30 05:10:52 +0200 (Sa, 30 Mai 2009) | 1 line

  no fdatasync on macos
........
  r73045 | georg.brandl | 2009-05-30 09:26:04 +0200 (Sa, 30 Mai 2009) | 1 line

  #6146: fix markup bug.
........
  r73046 | georg.brandl | 2009-05-30 09:31:25 +0200 (Sa, 30 Mai 2009) | 1 line

  Use preferred form of raising exceptions.
........
  r73047 | georg.brandl | 2009-05-30 12:33:23 +0200 (Sa, 30 Mai 2009) | 1 line

  Fix some more small markup problems.
........
  r73048 | georg.brandl | 2009-05-30 12:34:25 +0200 (Sa, 30 Mai 2009) | 1 line

  Fix markup problem.
........
  r73069 | benjamin.peterson | 2009-05-31 02:42:42 +0200 (So, 31 Mai 2009) | 1 line

  fix signature
........
  r73089 | andrew.kuchling | 2009-06-01 02:14:19 +0200 (Mo, 01 Jun 2009) | 1 line

  The class for regexes isn't called RegexObject any more; correct the text
........
  r73163 | georg.brandl | 2009-06-03 09:25:35 +0200 (Mi, 03 Jun 2009) | 1 line

  Use the preferred form of raise statements in the docs.
........
  r73186 | georg.brandl | 2009-06-03 23:21:09 +0200 (Mi, 03 Jun 2009) | 1 line

  #6174: fix indentation in code example.
........
  r73213 | georg.brandl | 2009-06-04 12:15:57 +0200 (Do, 04 Jun 2009) | 1 line

  #5967: note that the C slicing APIs do not support negative indices.
........
  r73215 | georg.brandl | 2009-06-04 12:22:31 +0200 (Do, 04 Jun 2009) | 1 line

  #6176: fix man page section for flock(2).
........
  r73217 | georg.brandl | 2009-06-04 12:27:21 +0200 (Do, 04 Jun 2009) | 1 line

  #6175: document that inet_aton supports alternate input formats with less than three dots.
........
  r73257 | georg.brandl | 2009-06-06 19:50:05 +0200 (Sa, 06 Jun 2009) | 1 line

  #6211: elaborate a bit on ways to call the function.
........
  r73258 | georg.brandl | 2009-06-06 19:51:31 +0200 (Sa, 06 Jun 2009) | 1 line

  #6204: use a real reference instead of "see later".
........
  r73260 | georg.brandl | 2009-06-06 20:21:58 +0200 (Sa, 06 Jun 2009) | 1 line

  #6224: s/JPython/Jython/, and remove one link to a module nine years old.
........
parent c917746a
...@@ -140,7 +140,7 @@ Buffer related functions ...@@ -140,7 +140,7 @@ Buffer related functions
Return 1 if *obj* supports the buffer interface otherwise 0. Return 1 if *obj* supports the buffer interface otherwise 0.
.. cfunction:: int PyObject_GetBuffer(PyObject *obj, PyObject *view, int flags) .. cfunction:: int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)
Export *obj* into a :ctype:`Py_buffer`, *view*. These arguments must Export *obj* into a :ctype:`Py_buffer`, *view*. These arguments must
never be *NULL*. The *flags* argument is a bit field indicating what never be *NULL*. The *flags* argument is a bit field indicating what
......
...@@ -149,9 +149,10 @@ List Objects ...@@ -149,9 +149,10 @@ List Objects
.. cfunction:: PyObject* PyList_GetSlice(PyObject *list, Py_ssize_t low, Py_ssize_t high) .. cfunction:: PyObject* PyList_GetSlice(PyObject *list, Py_ssize_t low, Py_ssize_t high)
Return a list of the objects in *list* containing the objects *between* Return a list of the objects in *list* containing the objects *between* *low*
*low* and *high*. Return *NULL* and set an exception if unsuccessful. and *high*. Return *NULL* and set an exception if unsuccessful. Analogous
Analogous to ``list[low:high]``. to ``list[low:high]``. Negative indices, as when slicing from Python, are not
supported.
.. versionchanged:: 2.5 .. versionchanged:: 2.5
This function used an :ctype:`int` for *low* and *high*. This might This function used an :ctype:`int` for *low* and *high*. This might
...@@ -163,7 +164,8 @@ List Objects ...@@ -163,7 +164,8 @@ List Objects
Set the slice of *list* between *low* and *high* to the contents of Set the slice of *list* between *low* and *high* to the contents of
*itemlist*. Analogous to ``list[low:high] = itemlist``. The *itemlist* may *itemlist*. Analogous to ``list[low:high] = itemlist``. The *itemlist* may
be *NULL*, indicating the assignment of an empty list (slice deletion). be *NULL*, indicating the assignment of an empty list (slice deletion).
Return ``0`` on success, ``-1`` on failure. Return ``0`` on success, ``-1`` on failure. Negative indices, as when
slicing from Python, are not supported.
.. versionchanged:: 2.5 .. versionchanged:: 2.5
This function used an :ctype:`int` for *low* and *high*. This might This function used an :ctype:`int` for *low* and *high*. This might
......
...@@ -62,7 +62,7 @@ Sequence Protocol ...@@ -62,7 +62,7 @@ Sequence Protocol
.. cfunction:: PyObject* PySequence_GetItem(PyObject *o, Py_ssize_t i) .. cfunction:: PyObject* PySequence_GetItem(PyObject *o, Py_ssize_t i)
Return the *i*th element of *o*, or *NULL* on failure. This is the equivalent of Return the *i*\ th element of *o*, or *NULL* on failure. This is the equivalent of
the Python expression ``o[i]``. the Python expression ``o[i]``.
.. versionchanged:: 2.5 .. versionchanged:: 2.5
...@@ -82,7 +82,7 @@ Sequence Protocol ...@@ -82,7 +82,7 @@ Sequence Protocol
.. cfunction:: int PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v) .. cfunction:: int PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v)
Assign object *v* to the *i*th element of *o*. Returns ``-1`` on failure. This Assign object *v* to the *i*\ th element of *o*. Returns ``-1`` on failure. This
is the equivalent of the Python statement ``o[i] = v``. This function *does is the equivalent of the Python statement ``o[i] = v``. This function *does
not* steal a reference to *v*. not* steal a reference to *v*.
...@@ -93,7 +93,7 @@ Sequence Protocol ...@@ -93,7 +93,7 @@ Sequence Protocol
.. cfunction:: int PySequence_DelItem(PyObject *o, Py_ssize_t i) .. cfunction:: int PySequence_DelItem(PyObject *o, Py_ssize_t i)
Delete the *i*th element of object *o*. Returns ``-1`` on failure. This is the Delete the *i*\ th element of object *o*. Returns ``-1`` on failure. This is the
equivalent of the Python statement ``del o[i]``. equivalent of the Python statement ``del o[i]``.
.. versionchanged:: 2.5 .. versionchanged:: 2.5
...@@ -175,7 +175,7 @@ Sequence Protocol ...@@ -175,7 +175,7 @@ Sequence Protocol
.. cfunction:: PyObject* PySequence_Fast_GET_ITEM(PyObject *o, Py_ssize_t i) .. cfunction:: PyObject* PySequence_Fast_GET_ITEM(PyObject *o, Py_ssize_t i)
Return the *i*th element of *o*, assuming that *o* was returned by Return the *i*\ th element of *o*, assuming that *o* was returned by
:cfunc:`PySequence_Fast`, *o* is not *NULL*, and that *i* is within bounds. :cfunc:`PySequence_Fast`, *o* is not *NULL*, and that *i* is within bounds.
.. versionchanged:: 2.5 .. versionchanged:: 2.5
...@@ -197,7 +197,7 @@ Sequence Protocol ...@@ -197,7 +197,7 @@ Sequence Protocol
.. cfunction:: PyObject* PySequence_ITEM(PyObject *o, Py_ssize_t i) .. cfunction:: PyObject* PySequence_ITEM(PyObject *o, Py_ssize_t i)
Return the *i*th element of *o* or *NULL* on failure. Macro form of Return the *i*\ th element of *o* or *NULL* on failure. Macro form of
:cfunc:`PySequence_GetItem` but without checking that :cfunc:`PySequence_GetItem` but without checking that
:cfunc:`PySequence_Check(o)` is true and without adjustment for negative :cfunc:`PySequence_Check(o)` is true and without adjustment for negative
indices. indices.
......
...@@ -46,6 +46,9 @@ unused_docs = [ ...@@ -46,6 +46,9 @@ unused_docs = [
'library/xml.etree', 'library/xml.etree',
] ]
# Ignore .rst in Sphinx its self.
exclude_trees = ['tools/sphinx']
# Relative filename of the reference count data file. # Relative filename of the reference count data file.
refcount_file = 'data/refcounts.dat' refcount_file = 'data/refcounts.dat'
......
...@@ -257,7 +257,7 @@ matches with them. ...@@ -257,7 +257,7 @@ matches with them.
Compiling Regular Expressions Compiling Regular Expressions
----------------------------- -----------------------------
Regular expressions are compiled into :class:`RegexObject` instances, which have Regular expressions are compiled into pattern objects, which have
methods for various operations such as searching for pattern matches or methods for various operations such as searching for pattern matches or
performing string substitutions. :: performing string substitutions. ::
...@@ -336,7 +336,7 @@ Performing Matches ...@@ -336,7 +336,7 @@ Performing Matches
------------------ ------------------
Once you have an object representing a compiled regular expression, what do you Once you have an object representing a compiled regular expression, what do you
do with it? :class:`RegexObject` instances have several methods and attributes. do with it? Pattern objects have several methods and attributes.
Only the most significant ones will be covered here; consult the :mod:`re` docs Only the most significant ones will be covered here; consult the :mod:`re` docs
for a complete listing. for a complete listing.
...@@ -427,8 +427,8 @@ Trying these methods will soon clarify their meaning:: ...@@ -427,8 +427,8 @@ Trying these methods will soon clarify their meaning::
and :meth:`end` return the starting and ending index of the match. :meth:`span` and :meth:`end` return the starting and ending index of the match. :meth:`span`
returns both start and end indexes in a single tuple. Since the :meth:`match` returns both start and end indexes in a single tuple. Since the :meth:`match`
method only checks if the RE matches at the start of a string, :meth:`start` method only checks if the RE matches at the start of a string, :meth:`start`
will always be zero. However, the :meth:`search` method of :class:`RegexObject` will always be zero. However, the :meth:`search` method of patterns
instances scans through the string, so the match may not start at zero in that scans through the string, so the match may not start at zero in that
case. :: case. ::
>>> print p.match('::: message') >>> print p.match('::: message')
...@@ -450,7 +450,7 @@ in a variable, and then check if it was ``None``. This usually looks like:: ...@@ -450,7 +450,7 @@ in a variable, and then check if it was ``None``. This usually looks like::
else: else:
print 'No match' print 'No match'
Two :class:`RegexObject` methods return all of the matches for a pattern. Two pattern methods return all of the matches for a pattern.
:meth:`findall` returns a list of matching strings:: :meth:`findall` returns a list of matching strings::
>>> p = re.compile('\d+') >>> p = re.compile('\d+')
...@@ -475,10 +475,10 @@ instances as an :term:`iterator`. [#]_ :: ...@@ -475,10 +475,10 @@ instances as an :term:`iterator`. [#]_ ::
Module-Level Functions Module-Level Functions
---------------------- ----------------------
You don't have to create a :class:`RegexObject` and call its methods; the You don't have to create a pattern object and call its methods; the
:mod:`re` module also provides top-level functions called :func:`match`, :mod:`re` module also provides top-level functions called :func:`match`,
:func:`search`, :func:`findall`, :func:`sub`, and so forth. These functions :func:`search`, :func:`findall`, :func:`sub`, and so forth. These functions
take the same arguments as the corresponding :class:`RegexObject` method, with take the same arguments as the corresponding pattern method, with
the RE string added as the first argument, and still return either ``None`` or a the RE string added as the first argument, and still return either ``None`` or a
:class:`MatchObject` instance. :: :class:`MatchObject` instance. ::
...@@ -487,12 +487,12 @@ the RE string added as the first argument, and still return either ``None`` or a ...@@ -487,12 +487,12 @@ the RE string added as the first argument, and still return either ``None`` or a
>>> re.match(r'From\s+', 'From amk Thu May 14 19:12:10 1998') >>> re.match(r'From\s+', 'From amk Thu May 14 19:12:10 1998')
<re.MatchObject instance at 80c5978> <re.MatchObject instance at 80c5978>
Under the hood, these functions simply produce a :class:`RegexObject` for you Under the hood, these functions simply create a pattern object for you
and call the appropriate method on it. They also store the compiled object in a and call the appropriate method on it. They also store the compiled object in a
cache, so future calls using the same RE are faster. cache, so future calls using the same RE are faster.
Should you use these module-level functions, or should you get the Should you use these module-level functions, or should you get the
:class:`RegexObject` and call its methods yourself? That choice depends on how pattern and call its methods yourself? That choice depends on how
frequently the RE will be used, and on your personal coding style. If the RE is frequently the RE will be used, and on your personal coding style. If the RE is
being used at only one point in the code, then the module functions are probably being used at only one point in the code, then the module functions are probably
more convenient. If a program contains a lot of regular expressions, or re-uses more convenient. If a program contains a lot of regular expressions, or re-uses
...@@ -1030,7 +1030,7 @@ Modifying Strings ...@@ -1030,7 +1030,7 @@ Modifying Strings
Up to this point, we've simply performed searches against a static string. Up to this point, we've simply performed searches against a static string.
Regular expressions are also commonly used to modify strings in various ways, Regular expressions are also commonly used to modify strings in various ways,
using the following :class:`RegexObject` methods: using the following pattern methods:
+------------------+-----------------------------------------------+ +------------------+-----------------------------------------------+
| Method/Attribute | Purpose | | Method/Attribute | Purpose |
...@@ -1050,7 +1050,7 @@ using the following :class:`RegexObject` methods: ...@@ -1050,7 +1050,7 @@ using the following :class:`RegexObject` methods:
Splitting Strings Splitting Strings
----------------- -----------------
The :meth:`split` method of a :class:`RegexObject` splits a string apart The :meth:`split` method of a pattern splits a string apart
wherever the RE matches, returning a list of the pieces. It's similar to the wherever the RE matches, returning a list of the pieces. It's similar to the
:meth:`split` method of strings but provides much more generality in the :meth:`split` method of strings but provides much more generality in the
delimiters that you can split by; :meth:`split` only supports splitting by delimiters that you can split by; :meth:`split` only supports splitting by
...@@ -1195,10 +1195,10 @@ hexadecimal:: ...@@ -1195,10 +1195,10 @@ hexadecimal::
'Call 0xffd2 for printing, 0xc000 for user code.' 'Call 0xffd2 for printing, 0xc000 for user code.'
When using the module-level :func:`re.sub` function, the pattern is passed as When using the module-level :func:`re.sub` function, the pattern is passed as
the first argument. The pattern may be a string or a :class:`RegexObject`; if the first argument. The pattern may be provided as an object or as a string; if
you need to specify regular expression flags, you must either use a you need to specify regular expression flags, you must either use a
:class:`RegexObject` as the first parameter, or use embedded modifiers in the pattern object as the first parameter, or use embedded modifiers in the
pattern, e.g. ``sub("(?i)b+", "x", "bbbb BBBB")`` returns ``'x x'``. pattern string, e.g. ``sub("(?i)b+", "x", "bbbb BBBB")`` returns ``'x x'``.
Common Problems Common Problems
......
...@@ -204,8 +204,7 @@ length message:: ...@@ -204,8 +204,7 @@ length message::
while totalsent < MSGLEN: while totalsent < MSGLEN:
sent = self.sock.send(msg[totalsent:]) sent = self.sock.send(msg[totalsent:])
if sent == 0: if sent == 0:
raise RuntimeError, \ raise RuntimeError("socket connection broken")
"socket connection broken"
totalsent = totalsent + sent totalsent = totalsent + sent
def myreceive(self): def myreceive(self):
...@@ -213,8 +212,7 @@ length message:: ...@@ -213,8 +212,7 @@ length message::
while len(msg) < MSGLEN: while len(msg) < MSGLEN:
chunk = self.sock.recv(MSGLEN-len(msg)) chunk = self.sock.recv(MSGLEN-len(msg))
if chunk == '': if chunk == '':
raise RuntimeError, \ raise RuntimeError("socket connection broken")
"socket connection broken"
msg = msg + chunk msg = msg + chunk
return msg return msg
......
...@@ -37,7 +37,7 @@ Usage: %prog [options] msgfile ...@@ -37,7 +37,7 @@ Usage: %prog [options] msgfile
os.mkdir(opts.directory) os.mkdir(opts.directory)
except OSError, e: except OSError, e:
# Ignore directory exists error # Ignore directory exists error
if e.errno <> errno.EEXIST: if e.errno != errno.EEXIST:
raise raise
fp = open(msgfile) fp = open(msgfile)
......
...@@ -149,21 +149,21 @@ def test(): ...@@ -149,21 +149,21 @@ def test():
except ZeroDivisionError: except ZeroDivisionError:
print '\tGot ZeroDivisionError as expected from pool.apply()' print '\tGot ZeroDivisionError as expected from pool.apply()'
else: else:
raise AssertionError, 'expected ZeroDivisionError' raise AssertionError('expected ZeroDivisionError')
try: try:
print pool.map(f, range(10)) print pool.map(f, range(10))
except ZeroDivisionError: except ZeroDivisionError:
print '\tGot ZeroDivisionError as expected from pool.map()' print '\tGot ZeroDivisionError as expected from pool.map()'
else: else:
raise AssertionError, 'expected ZeroDivisionError' raise AssertionError('expected ZeroDivisionError')
try: try:
print list(pool.imap(f, range(10))) print list(pool.imap(f, range(10)))
except ZeroDivisionError: except ZeroDivisionError:
print '\tGot ZeroDivisionError as expected from list(pool.imap())' print '\tGot ZeroDivisionError as expected from list(pool.imap())'
else: else:
raise AssertionError, 'expected ZeroDivisionError' raise AssertionError('expected ZeroDivisionError')
it = pool.imap(f, range(10)) it = pool.imap(f, range(10))
for i in range(10): for i in range(10):
...@@ -176,7 +176,7 @@ def test(): ...@@ -176,7 +176,7 @@ def test():
break break
else: else:
if i == 5: if i == 5:
raise AssertionError, 'expected ZeroDivisionError' raise AssertionError('expected ZeroDivisionError')
assert i == 9 assert i == 9
print '\tGot ZeroDivisionError as expected from IMapIterator.next()' print '\tGot ZeroDivisionError as expected from IMapIterator.next()'
......
...@@ -249,7 +249,7 @@ def test(namespace=multiprocessing): ...@@ -249,7 +249,7 @@ def test(namespace=multiprocessing):
info = multiprocessing._debug_info() info = multiprocessing._debug_info()
if info: if info:
print info print info
raise ValueError, 'there should be no positive refcounts left' raise ValueError('there should be no positive refcounts left')
if __name__ == '__main__': if __name__ == '__main__':
...@@ -271,6 +271,6 @@ if __name__ == '__main__': ...@@ -271,6 +271,6 @@ if __name__ == '__main__':
import multiprocessing.dummy as namespace import multiprocessing.dummy as namespace
else: else:
print 'Usage:\n\t%s [processes | manager | threads]' % sys.argv[0] print 'Usage:\n\t%s [processes | manager | threads]' % sys.argv[0]
raise SystemExit, 2 raise SystemExit(2)
test(namespace) test(namespace)
...@@ -52,7 +52,8 @@ A simple example illustrating typical use:: ...@@ -52,7 +52,8 @@ A simple example illustrating typical use::
cryptedpasswd = pwd.getpwnam(username)[1] cryptedpasswd = pwd.getpwnam(username)[1]
if cryptedpasswd: if cryptedpasswd:
if cryptedpasswd == 'x' or cryptedpasswd == '*': if cryptedpasswd == 'x' or cryptedpasswd == '*':
raise "Sorry, currently no support for shadow passwords" raise NotImplementedError(
"Sorry, currently no support for shadow passwords")
cleartext = getpass.getpass() cleartext = getpass.getpass()
return crypt.crypt(cleartext, cryptedpasswd) == cryptedpasswd return crypt.crypt(cleartext, cryptedpasswd) == cryptedpasswd
else: else:
......
...@@ -1210,8 +1210,7 @@ constructs a new Python object each time! ...@@ -1210,8 +1210,7 @@ constructs a new Python object each time!
Variable-sized data types Variable-sized data types
^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^
``ctypes`` provides some support for variable-sized arrays and structures (this ``ctypes`` provides some support for variable-sized arrays and structures.
was added in version 0.9.9.7).
The ``resize`` function can be used to resize the memory buffer of an existing The ``resize`` function can be used to resize the memory buffer of an existing
ctypes object. The function takes the object as first argument, and the ctypes object. The function takes the object as first argument, and the
......
...@@ -100,7 +100,7 @@ The :mod:`EasyDialogs` module defines the following functions: ...@@ -100,7 +100,7 @@ The :mod:`EasyDialogs` module defines the following functions:
+----------------------+------------------------------------------+ +----------------------+------------------------------------------+
*commandlist* is a list of items of the form *cmdstr* or ``(cmdstr, descr)``, *commandlist* is a list of items of the form *cmdstr* or ``(cmdstr, descr)``,
where *descr* is as above. The *cmdstr*s will appear in a popup menu. When where *descr* is as above. The *cmdstr*\ s will appear in a popup menu. When
chosen, the text of *cmdstr* will be appended to the command line as is, except chosen, the text of *cmdstr* will be appended to the command line as is, except
that a trailing ``':'`` or ``'='`` (if present) will be trimmed off. that a trailing ``':'`` or ``'='`` (if present) will be trimmed off.
......
...@@ -84,9 +84,9 @@ The following exceptions are only used as base classes for other exceptions. ...@@ -84,9 +84,9 @@ The following exceptions are only used as base classes for other exceptions.
.. exception:: LookupError .. exception:: LookupError
The base class for the exceptions that are raised when a key or index used on a The base class for the exceptions that are raised when a key or index used on
mapping or sequence is invalid: :exc:`IndexError`, :exc:`KeyError`. This can be a mapping or sequence is invalid: :exc:`IndexError`, :exc:`KeyError`. This
raised directly by :func:`sys.setdefaultencoding`. can be raised directly by :func:`codecs.lookup`.
.. exception:: EnvironmentError .. exception:: EnvironmentError
......
...@@ -96,7 +96,7 @@ The module defines the following functions: ...@@ -96,7 +96,7 @@ The module defines the following functions:
Perform the lock operation *op* on file descriptor *fd* (file objects providing Perform the lock operation *op* on file descriptor *fd* (file objects providing
a :meth:`fileno` method are accepted as well). See the Unix manual a :meth:`fileno` method are accepted as well). See the Unix manual
:manpage:`flock(3)` for details. (On some systems, this function is emulated :manpage:`flock(2)` for details. (On some systems, this function is emulated
using :cfunc:`fcntl`.) using :cfunc:`fcntl`.)
......
...@@ -160,7 +160,7 @@ This code is intended to be read, not executed. However, it does work ...@@ -160,7 +160,7 @@ This code is intended to be read, not executed. However, it does work
parent = None parent = None
q = import_module(head, qname, parent) q = import_module(head, qname, parent)
if q: return q, tail if q: return q, tail
raise ImportError, "No module named " + qname raise ImportError("No module named " + qname)
def load_tail(q, tail): def load_tail(q, tail):
m = q m = q
...@@ -171,7 +171,7 @@ This code is intended to be read, not executed. However, it does work ...@@ -171,7 +171,7 @@ This code is intended to be read, not executed. However, it does work
mname = "%s.%s" % (m.__name__, head) mname = "%s.%s" % (m.__name__, head)
m = import_module(head, mname, m) m = import_module(head, mname, m)
if not m: if not m:
raise ImportError, "No module named " + mname raise ImportError("No module named " + mname)
return m return m
def ensure_fromlist(m, fromlist, recursive=0): def ensure_fromlist(m, fromlist, recursive=0):
...@@ -189,7 +189,7 @@ This code is intended to be read, not executed. However, it does work ...@@ -189,7 +189,7 @@ This code is intended to be read, not executed. However, it does work
subname = "%s.%s" % (m.__name__, sub) subname = "%s.%s" % (m.__name__, sub)
submod = import_module(sub, subname, m) submod = import_module(sub, subname, m)
if not submod: if not submod:
raise ImportError, "No module named " + subname raise ImportError("No module named " + subname)
def import_module(partname, fqname, parent): def import_module(partname, fqname, parent):
try: try:
......
...@@ -528,6 +528,9 @@ by file descriptors. ...@@ -528,6 +528,9 @@ by file descriptors.
Force write of file with filedescriptor *fd* to disk. Does not force update of Force write of file with filedescriptor *fd* to disk. Does not force update of
metadata. Availability: Unix. metadata. Availability: Unix.
.. note::
This function is not available on MacOS.
.. function:: fpathconf(fd, name) .. function:: fpathconf(fd, name)
......
...@@ -169,7 +169,7 @@ Java Platform ...@@ -169,7 +169,7 @@ Java Platform
.. function:: java_ver(release='', vendor='', vminfo=('','',''), osinfo=('','','')) .. function:: java_ver(release='', vendor='', vminfo=('','',''), osinfo=('','',''))
Version interface for JPython. Version interface for Jython.
Returns a tuple ``(release, vendor, vminfo, osinfo)`` with *vminfo* being a Returns a tuple ``(release, vendor, vminfo, osinfo)`` with *vminfo* being a
tuple ``(vm_name, vm_release, vm_vendor)`` and *osinfo* being a tuple tuple ``(vm_name, vm_release, vm_vendor)`` and *osinfo* being a tuple
......
...@@ -272,11 +272,11 @@ Let us say that we want a slightly more relaxed policy than the standard ...@@ -272,11 +272,11 @@ Let us say that we want a slightly more relaxed policy than the standard
elif mode in ('w', 'wb', 'a', 'ab'): elif mode in ('w', 'wb', 'a', 'ab'):
# check filename : must begin with /tmp/ # check filename : must begin with /tmp/
if file[:5]!='/tmp/': if file[:5]!='/tmp/':
raise IOError, "can't write outside /tmp" raise IOError("can't write outside /tmp")
elif (string.find(file, '/../') >= 0 or elif (string.find(file, '/../') >= 0 or
file[:3] == '../' or file[-3:] == '/..'): file[:3] == '../' or file[-3:] == '/..'):
raise IOError, "'..' in filename forbidden" raise IOError("'..' in filename forbidden")
else: raise IOError, "Illegal open() mode" else: raise IOError("Illegal open() mode")
return open(file, mode, buf) return open(file, mode, buf)
Notice that the above code will occasionally forbid a perfectly valid filename; Notice that the above code will occasionally forbid a perfectly valid filename;
......
...@@ -52,7 +52,7 @@ Completer objects have the following method: ...@@ -52,7 +52,7 @@ Completer objects have the following method:
.. method:: Completer.complete(text, state) .. method:: Completer.complete(text, state)
Return the *state*th completion for *text*. Return the *state*\ th completion for *text*.
If called for *text* that doesn't include a period character (``'.'``), it will If called for *text* that doesn't include a period character (``'.'``), it will
complete from names currently defined in :mod:`__main__`, :mod:`__builtin__` and complete from names currently defined in :mod:`__main__`, :mod:`__builtin__` and
......
...@@ -216,7 +216,7 @@ provided by this module. :: ...@@ -216,7 +216,7 @@ provided by this module. ::
except OSError, why: except OSError, why:
errors.extend((src, dst, str(why))) errors.extend((src, dst, str(why)))
if errors: if errors:
raise Error, errors raise Error(errors)
Another example that uses the :func:`ignore_patterns` helper:: Another example that uses the :func:`ignore_patterns` helper::
......
...@@ -232,7 +232,7 @@ be sent, and the handler raises an exception. :: ...@@ -232,7 +232,7 @@ be sent, and the handler raises an exception. ::
def handler(signum, frame): def handler(signum, frame):
print 'Signal handler called with signal', signum print 'Signal handler called with signal', signum
raise IOError, "Couldn't open device!" raise IOError("Couldn't open device!")
# Set the signal handler and a 5-second alarm # Set the signal handler and a 5-second alarm
signal.signal(signal.SIGALRM, handler) signal.signal(signal.SIGALRM, handler)
......
...@@ -401,6 +401,9 @@ The module :mod:`socket` exports the following constants and functions: ...@@ -401,6 +401,9 @@ The module :mod:`socket` exports the following constants and functions:
library and needs objects of type :ctype:`struct in_addr`, which is the C type library and needs objects of type :ctype:`struct in_addr`, which is the C type
for the 32-bit packed binary this function returns. for the 32-bit packed binary this function returns.
:func:`inet_aton` also accepts strings with less than three dots; see the
Unix manual page :manpage:`inet(3)` for details.
If the IPv4 address string passed to this function is invalid, If the IPv4 address string passed to this function is invalid,
:exc:`socket.error` will be raised. Note that exactly what is valid depends on :exc:`socket.error` will be raised. Note that exactly what is valid depends on
the underlying C implementation of :cfunc:`inet_aton`. the underlying C implementation of :cfunc:`inet_aton`.
......
...@@ -29,9 +29,6 @@ is maintained at ActiveState.) ...@@ -29,9 +29,6 @@ is maintained at ActiveState.)
`Tkinter reference: a GUI for Python <http://infohost.nmt.edu/tcc/help/pubs/lang.html>`_ `Tkinter reference: a GUI for Python <http://infohost.nmt.edu/tcc/help/pubs/lang.html>`_
On-line reference material. On-line reference material.
`Tkinter for JPython <http://jtkinter.sourceforge.net>`_
The Jython interface to Tkinter.
`Python and Tkinter Programming <http://www.amazon.com/exec/obidos/ASIN/1884777813>`_ `Python and Tkinter Programming <http://www.amazon.com/exec/obidos/ASIN/1884777813>`_
The book by John Grayson (ISBN 1-884777-81-3). The book by John Grayson (ISBN 1-884777-81-3).
......
...@@ -288,7 +288,7 @@ The simple form, ``assert expression``, is equivalent to :: ...@@ -288,7 +288,7 @@ The simple form, ``assert expression``, is equivalent to ::
The extended form, ``assert expression1, expression2``, is equivalent to :: The extended form, ``assert expression1, expression2``, is equivalent to ::
if __debug__: if __debug__:
if not expression1: raise AssertionError, expression2 if not expression1: raise AssertionError(expression2)
.. index:: .. index::
single: __debug__ single: __debug__
......
...@@ -40,9 +40,9 @@ romanNumeralMap = (('M', 1000), ...@@ -40,9 +40,9 @@ romanNumeralMap = (('M', 1000),
def toRoman(n): def toRoman(n):
"""convert integer to Roman numeral""" """convert integer to Roman numeral"""
if not (0 < n < 5000): if not (0 < n < 5000):
raise OutOfRangeError, "number out of range (must be 1..4999)" raise OutOfRangeError("number out of range (must be 1..4999)")
if int(n) <> n: if int(n) != n:
raise NotIntegerError, "decimals can not be converted" raise NotIntegerError("decimals can not be converted")
result = "" result = ""
for numeral, integer in romanNumeralMap: for numeral, integer in romanNumeralMap:
...@@ -67,9 +67,9 @@ romanNumeralPattern = re.compile(""" ...@@ -67,9 +67,9 @@ romanNumeralPattern = re.compile("""
def fromRoman(s): def fromRoman(s):
"""convert Roman numeral to integer""" """convert Roman numeral to integer"""
if not s: if not s:
raise InvalidRomanNumeralError, 'Input can not be blank' raise InvalidRomanNumeralError('Input can not be blank')
if not romanNumeralPattern.search(s): if not romanNumeralPattern.search(s):
raise InvalidRomanNumeralError, 'Invalid Roman numeral: %s' % s raise InvalidRomanNumeralError('Invalid Roman numeral: %s' % s)
result = 0 result = 0
index = 0 index = 0
......
...@@ -164,7 +164,7 @@ class CheckSuspiciousMarkupBuilder(Builder): ...@@ -164,7 +164,7 @@ class CheckSuspiciousMarkupBuilder(Builder):
except IOError: return except IOError: return
for i, row in enumerate(csv.reader(f)): for i, row in enumerate(csv.reader(f)):
if len(row) != 4: if len(row) != 4:
raise ValueError, "wrong format in %s, line %d: %s" % (filename, i+1, row) raise ValueError("wrong format in %s, line %d: %s" % (filename, i+1, row))
docname, lineno, issue, text = row docname, lineno, issue, text = row
docname = docname.decode('utf-8') docname = docname.decode('utf-8')
if lineno: lineno = int(lineno) if lineno: lineno = int(lineno)
......
...@@ -285,7 +285,7 @@ This example, as usual, demonstrates some new Python features: ...@@ -285,7 +285,7 @@ This example, as usual, demonstrates some new Python features:
and ``methodname`` is the name of a method that is defined by the object's type. and ``methodname`` is the name of a method that is defined by the object's type.
Different types define different methods. Methods of different types may have Different types define different methods. Methods of different types may have
the same name without causing ambiguity. (It is possible to define your own the same name without causing ambiguity. (It is possible to define your own
object types and methods, using *classes*, as discussed later in this tutorial.) object types and methods, using *classes*, see :ref:`tut-classes`)
The method :meth:`append` shown in the example is defined for list objects; it The method :meth:`append` shown in the example is defined for list objects; it
adds a new element at the end of the list. In this example it is equivalent to adds a new element at the end of the list. In this example it is equivalent to
``result = result + [b]``, but more efficient. ``result = result + [b]``, but more efficient.
...@@ -312,14 +312,23 @@ defined to allow. For example:: ...@@ -312,14 +312,23 @@ defined to allow. For example::
def ask_ok(prompt, retries=4, complaint='Yes or no, please!'): def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
while True: while True:
ok = raw_input(prompt) ok = raw_input(prompt)
if ok in ('y', 'ye', 'yes'): return True if ok in ('y', 'ye', 'yes'):
if ok in ('n', 'no', 'nop', 'nope'): return False return True
if ok in ('n', 'no', 'nop', 'nope'):
return False
retries = retries - 1 retries = retries - 1
if retries < 0: raise IOError, 'refusenik user' if retries < 0:
raise IOError('refusenik user')
print complaint print complaint
This function can be called either like this: ``ask_ok('Do you really want to This function can be called in several ways:
quit?')`` or like this: ``ask_ok('OK to overwrite the file?', 2)``.
* giving only the mandatory argument:
``ask_ok('Do you really want to quit?')``
* giving one of the optional arguments:
``ask_ok('OK to overwrite the file?', 2)``
* or even giving all arguments:
``ask_ok('OK to overwrite the file?', 2, 'Come on, only yes or no!')``
This example also introduces the :keyword:`in` keyword. This tests whether or This example also introduces the :keyword:`in` keyword. This tests whether or
not a sequence contains a certain value. not a sequence contains a certain value.
......
...@@ -14,7 +14,7 @@ warnpy3k("the imputil module has been removed in Python 3.0", stacklevel=2) ...@@ -14,7 +14,7 @@ warnpy3k("the imputil module has been removed in Python 3.0", stacklevel=2)
del warnpy3k del warnpy3k
# note: avoid importing non-builtin modules # note: avoid importing non-builtin modules
import imp ### not available in JPython? import imp ### not available in Jython?
import sys import sys
import __builtin__ import __builtin__
...@@ -25,7 +25,7 @@ import marshal ...@@ -25,7 +25,7 @@ import marshal
__all__ = ["ImportManager","Importer","BuiltinImporter"] __all__ = ["ImportManager","Importer","BuiltinImporter"]
_StringType = type('') _StringType = type('')
_ModuleType = type(sys) ### doesn't work in JPython... _ModuleType = type(sys) ### doesn't work in Jython...
class ImportManager: class ImportManager:
"Manage the import process." "Manage the import process."
...@@ -639,8 +639,8 @@ def _test_revamp(): ...@@ -639,8 +639,8 @@ def _test_revamp():
# TODO # TODO
# #
# from Finn Bock: # from Finn Bock:
# type(sys) is not a module in JPython. what to use instead? # type(sys) is not a module in Jython. what to use instead?
# imp.C_EXTENSION is not in JPython. same for get_suffixes and new_module # imp.C_EXTENSION is not in Jython. same for get_suffixes and new_module
# #
# given foo.py of: # given foo.py of:
# import sys # import sys
......
...@@ -6194,7 +6194,7 @@ unicode_center(PyUnicodeObject *self, PyObject *args) ...@@ -6194,7 +6194,7 @@ unicode_center(PyUnicodeObject *self, PyObject *args)
/* This code should go into some future Unicode collation support /* This code should go into some future Unicode collation support
module. The basic comparison should compare ordinals on a naive module. The basic comparison should compare ordinals on a naive
basis (this is what Java does and thus JPython too). */ basis (this is what Java does and thus Jython too). */
/* speedy UTF-16 code point order comparison */ /* speedy UTF-16 code point order comparison */
/* gleaned from: */ /* gleaned from: */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment