diff options
author | Christian Heimes <christian@cheimes.de> | 2007-12-03 21:02:03 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2007-12-03 21:02:03 (GMT) |
commit | cbf3b5cb76906fba15dbf59a1e83c540a447b907 (patch) | |
tree | 191de62298cf0af90595802cd47cff23d8f39d80 /Doc | |
parent | f9290773fc026c5064fa96e1d06c3924e49fa89b (diff) | |
download | cpython-cbf3b5cb76906fba15dbf59a1e83c540a447b907.zip cpython-cbf3b5cb76906fba15dbf59a1e83c540a447b907.tar.gz cpython-cbf3b5cb76906fba15dbf59a1e83c540a447b907.tar.bz2 |
Merged revisions 59275-59303 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
NOTE: The merge does NOT contain the modified file Python/import.c from
r59288. I can't get it running. Nick, please check in the PEP 366
manually.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
........
r59279 | georg.brandl | 2007-12-02 19:17:50 +0100 (Sun, 02 Dec 2007) | 2 lines
Fix a sentence I missed before. Do not merge to 3k.
........
r59281 | georg.brandl | 2007-12-02 22:58:54 +0100 (Sun, 02 Dec 2007) | 3 lines
Add documentation for PySys_* functions.
Written by Charlie Shepherd for GHOP. Also fixes #1245.
........
r59288 | nick.coghlan | 2007-12-03 13:55:17 +0100 (Mon, 03 Dec 2007) | 1 line
Implement PEP 366
........
r59290 | christian.heimes | 2007-12-03 14:47:29 +0100 (Mon, 03 Dec 2007) | 3 lines
Applied my patch #1455 with some extra fixes for VS 2005
The new msvc9compiler module supports VS 2005 and VS 2008. I've also fixed build_ext to support PCbuild8 and PCbuild9 and backported my fix for xxmodule.c from py3k. The old code msvccompiler is still in place in case somebody likes to build an extension with VS 2003 or earlier.
I've also updated the cygwin compiler module for VS 2005 and VS 2008. It works with VS 2005 but I'm unable to test it with VS 2008. We have to wait for a new version of cygwin.
........
r59291 | christian.heimes | 2007-12-03 14:55:16 +0100 (Mon, 03 Dec 2007) | 1 line
Added comment to Misc/NEWS for r59290
........
r59292 | christian.heimes | 2007-12-03 15:28:04 +0100 (Mon, 03 Dec 2007) | 1 line
I followed MA Lemberg's suggestion and added comments to the late initialization of the type slots.
........
r59293 | facundo.batista | 2007-12-03 17:29:52 +0100 (Mon, 03 Dec 2007) | 3 lines
Speedup and cleaning of __str__. Thanks Mark Dickinson.
........
r59294 | facundo.batista | 2007-12-03 18:55:00 +0100 (Mon, 03 Dec 2007) | 4 lines
Faster _fix function, and some reordering for a more elegant
coding. Thanks Mark Dickinson.
........
r59295 | martin.v.loewis | 2007-12-03 20:20:02 +0100 (Mon, 03 Dec 2007) | 5 lines
Issue #1727780: Support loading pickles of random.Random objects created
on 32-bit systems on 64-bit systems, and vice versa. As a consequence
of the change, Random pickles created by Python 2.6 cannot be loaded
in Python 2.5.
........
r59297 | facundo.batista | 2007-12-03 20:49:54 +0100 (Mon, 03 Dec 2007) | 3 lines
Two small fixes. Issue 1547.
........
r59299 | georg.brandl | 2007-12-03 20:57:02 +0100 (Mon, 03 Dec 2007) | 2 lines
#1548: fix apostroph placement.
........
r59300 | christian.heimes | 2007-12-03 21:01:02 +0100 (Mon, 03 Dec 2007) | 3 lines
Patch #1537 from Chad Austin
Change GeneratorExit's base class from Exception to BaseException
(This time I'm applying the patch to the correct sandbox.)
........
r59302 | georg.brandl | 2007-12-03 21:03:46 +0100 (Mon, 03 Dec 2007) | 3 lines
Add examples to the xmlrpclib docs.
Written for GHOP by Josip Dzolonga.
........
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/ACKS.txt | 1 | ||||
-rw-r--r-- | Doc/c-api/init.rst | 2 | ||||
-rw-r--r-- | Doc/c-api/utilities.rst | 60 | ||||
-rw-r--r-- | Doc/data/refcounts.dat | 22 | ||||
-rw-r--r-- | Doc/glossary.rst | 2 | ||||
-rw-r--r-- | Doc/library/exceptions.rst | 4 | ||||
-rw-r--r-- | Doc/library/random.rst | 2 | ||||
-rw-r--r-- | Doc/library/simplexmlrpcserver.rst | 8 | ||||
-rw-r--r-- | Doc/library/xmlrpclib.rst | 166 | ||||
-rw-r--r-- | Doc/reference/expressions.rst | 3 | ||||
-rw-r--r-- | Doc/using/cmdline.rst | 2 | ||||
-rw-r--r-- | Doc/whatsnew/2.6.rst | 4 |
12 files changed, 259 insertions, 17 deletions
diff --git a/Doc/ACKS.txt b/Doc/ACKS.txt index 56c5c3e..fc3789f 100644 --- a/Doc/ACKS.txt +++ b/Doc/ACKS.txt @@ -161,6 +161,7 @@ docs@python.org), and we'll be glad to correct the problem. * Barry Scott * Joakim Sernbrant * Justin Sheehy +* Charlie Shepherd * Michael Simcich * Ionel Simionescu * Michael Sloan diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index 11cd551..a4f25fa 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -360,8 +360,6 @@ Initialization, Finalization, and Threads .. % XXX impl. doesn't seem consistent in allowing 0/NULL for the params; .. % check w/ Guido. -.. % XXX Other PySys thingies (doesn't really belong in this chapter) - .. _threads: diff --git a/Doc/c-api/utilities.rst b/Doc/c-api/utilities.rst index 0de23d1..0a92230 100644 --- a/Doc/c-api/utilities.rst +++ b/Doc/c-api/utilities.rst @@ -66,6 +66,66 @@ Operating System Utilities not call those functions directly! :ctype:`PyOS_sighandler_t` is a typedef alias for :ctype:`void (\*)(int)`. +.. _systemfunctions: + +System Functions +================ + +These are utility functions that make functionality from the :mod:`sys` module +accessible to C code. They all work with the current interpreter thread's +:mod:`sys` module's dict, which is contained in the internal thread state structure. + +.. cfunction:: PyObject *PySys_GetObject(char *name) + + Return the object *name* from the :mod:`sys` module or *NULL* if it does + not exist, without setting an exception. + +.. cfunction:: FILE *PySys_GetFile(char *name, FILE *def) + + Return the :ctype:`FILE*` associated with the object *name* in the + :mod:`sys` module, or *def* if *name* is not in the module or is not associated + with a :ctype:`FILE*`. + +.. cfunction:: int PySys_SetObject(char *name, PyObject *v) + + Set *name* in the :mod:`sys` module to *v* unless *v* is *NULL*, in which + case *name* is deleted from the sys module. Returns ``0`` on success, ``-1`` + on error. + +.. cfunction:: void PySys_ResetWarnOptions(void) + + Reset :data:`sys.warnoptions` to an empty list. + +.. cfunction:: void PySys_AddWarnOption(char *s) + + Append *s* to :data:`sys.warnoptions`. + +.. cfunction:: void PySys_SetPath(char *path) + + Set :data:`sys.path` to a list object of paths found in *path* which should + be a list of paths separated with the platform's search path delimiter + (``:`` on Unix, ``;`` on Windows). + +.. cfunction:: void PySys_WriteStdout(const char *format, ...) + + Write the output string described by *format* to :data:`sys.stdout`. No + exceptions are raised, even if truncation occurs (see below). + + *format* should limit the total size of the formatted output string to + 1000 bytes or less -- after 1000 bytes, the output string is truncated. + In particular, this means that no unrestricted "%s" formats should occur; + these should be limited using "%.<N>s" where <N> is a decimal number + calculated so that <N> plus the maximum size of other formatted text does not + exceed 1000 bytes. Also watch out for "%f", which can print hundreds of + digits for very large numbers. + + If a problem occurs, or :data:`sys.stdout` is unset, the formatted message + is written to the real (C level) *stdout*. + +.. cfunction:: void PySys_WriteStderr(const char *format, ...) + + As above, but write to :data:`sys.stderr` or *stderr* instead. + .. _processcontrol: diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat index a17a701..e39c53b 100644 --- a/Doc/data/refcounts.dat +++ b/Doc/data/refcounts.dat @@ -1251,10 +1251,32 @@ PyString_AsEncodedString:PyObject*:str:: PyString_AsEncodedString:const char*:encoding:: PyString_AsEncodedString:const char*:errors:: +PySys_AddWarnOption:void::: +PySys_AddWarnOption:char*:s:: + +PySys_GetFile:FILE*::: +PySys_GetFile:char*:name:: +PySys_GetFile:FILE*:def:: + +PySys_GetObject:PyObject*::0: +PySys_GetObject:char*:name:: + PySys_SetArgv:int::: PySys_SetArgv:int:argc:: PySys_SetArgv:char**:argv:: +PySys_SetObject:int::: +PySys_SetObject:char*:name:: +PySys_SetObject:PyObject*:v:+1: + +PySys_ResetWarnOptions:void::: + +PySys_WriteStdout:void::: +PySys_WriteStdout:char*:format:: + +PySys_WriteStderr:void::: +PySys_WriteStderr:char*:format:: + PyThreadState_Clear:void::: PyThreadState_Clear:PyThreadState*:tstate:: diff --git a/Doc/glossary.rst b/Doc/glossary.rst index 3459bda..6465c83 100644 --- a/Doc/glossary.rst +++ b/Doc/glossary.rst @@ -400,7 +400,7 @@ Glossary :term:`immutable` keys rather than integers. slice - An object usually containing a portion of a :term:`sequence`. A slice is + A list containing a portion of an indexed list-like object. A slice is created using the subscript notation, ``[]`` with colons between numbers when several are given, such as in ``variable_name[1:3:5]``. The bracket (subscript) notation uses :class:`slice` objects internally. diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst index d29ce12..786e825 100644 --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -135,7 +135,9 @@ The following exceptions are the exceptions that are actually raised. .. exception:: GeneratorExit - Raise when a :term:`generator`\'s :meth:`close` method is called. + Raise when a :term:`generator`\'s :meth:`close` method is called. It + directly inherits from :exc:`BaseException` instead of :exc:`Exception` since + it is technically not an error. .. exception:: IOError diff --git a/Doc/library/random.rst b/Doc/library/random.rst index 0062ffe..18c063c 100644 --- a/Doc/library/random.rst +++ b/Doc/library/random.rst @@ -69,6 +69,8 @@ Bookkeeping functions: Return an object capturing the current internal state of the generator. This object can be passed to :func:`setstate` to restore the state. + State values produced in Python 2.6 cannot be loaded into earlier versions. + .. function:: setstate(state) diff --git a/Doc/library/simplexmlrpcserver.rst b/Doc/library/simplexmlrpcserver.rst index 8533bf8..ab20ad0 100644 --- a/Doc/library/simplexmlrpcserver.rst +++ b/Doc/library/simplexmlrpcserver.rst @@ -109,7 +109,11 @@ alone XML-RPC servers. considered valid. The default value is ``('/', '/RPC2')``. -Example:: +.. _simplexmlrpcserver-example: + +SimpleXMLRPCServer Example +^^^^^^^^^^^^^^^^^^^^^^^^^^ +Server code:: from SimpleXMLRPCServer import SimpleXMLRPCServer @@ -137,7 +141,7 @@ Example:: # Run the server's main loop server.serve_forever() -The following client code will call the methods made available by the preceding +The following client code will call the methods made available by the preceding server:: import xmlrpclib diff --git a/Doc/library/xmlrpclib.rst b/Doc/library/xmlrpclib.rst index 0fda893..bde0688 100644 --- a/Doc/library/xmlrpclib.rst +++ b/Doc/library/xmlrpclib.rst @@ -192,6 +192,26 @@ unmarshalling code: Write the XML-RPC encoding of this Boolean item to the out stream object. +A working example follows. The server code:: + + import xmlrpclib + from SimpleXMLRPCServer import SimpleXMLRPCServer + + def is_even(n): + return n%2 == 0 + + server = SimpleXMLRPCServer(("localhost", 8000)) + print "Listening on port 8000..." + server.register_function(is_even, "is_even") + server.serve_forever() + +The client code for the preceding server:: + + import xmlrpclib + + proxy = xmlrpclib.ServerProxy("http://localhost:8000/") + print "3 is even: %s" % str(proxy.is_even(3)) + print "100 is even: %s" % str(proxy.is_even(100)) .. _datetime-objects: @@ -217,6 +237,32 @@ mainly for internal use by the marshalling/unmarshalling code: It also supports certain of Python's built-in operators through :meth:`__cmp__` and :meth:`__repr__` methods. +A working example follows. The server code:: + + import datetime + from SimpleXMLRPCServer import SimpleXMLRPCServer + import xmlrpclib + + def today(): + today = datetime.datetime.today() + return xmlrpclib.DateTime(today) + + server = SimpleXMLRPCServer(("localhost", 8000)) + print "Listening on port 8000..." + server.register_function(today, "today") + server.serve_forever() + +The client code for the preceding server:: + + import xmlrpclib + import datetime + + proxy = xmlrpclib.ServerProxy("http://localhost:8000/") + + today = proxy.today() + # convert the ISO8601 string to a datetime object + converted = datetime.datetime.strptime(today.value, "%Y%m%dT%H:%M:%S") + print "Today: %s" % converted.strftime("%d.%m.%Y, %H:%M") .. _binary-objects: @@ -249,6 +295,31 @@ internal use by the marshalling/unmarshalling code: It also supports certain of Python's built-in operators through a :meth:`__cmp__` method. +Example usage of the binary objects. We're going to transfer an image over +XMLRPC:: + + from SimpleXMLRPCServer import SimpleXMLRPCServer + import xmlrpclib + + def python_logo(): + handle = open("python_logo.jpg") + return xmlrpclib.Binary(handle.read()) + handle.close() + + server = SimpleXMLRPCServer(("localhost", 8000)) + print "Listening on port 8000..." + server.register_function(python_logo, 'python_logo') + + server.serve_forever() + +The client gets the image and saves it to a file:: + + import xmlrpclib + + proxy = xmlrpclib.ServerProxy("http://localhost:8000/") + handle = open("fetched_python_logo.jpg", "w") + handle.write(proxy.python_logo().data) + handle.close() .. _fault-objects: @@ -268,6 +339,35 @@ objects have the following members: A string containing a diagnostic message associated with the fault. +In the following example we're going to intentionally cause a :exc:`Fault` by +returning a complex type object. The server code:: + + from SimpleXMLRPCServer import SimpleXMLRPCServer + + # A marshalling error is going to occur because we're returning a + # complex number + def add(x,y): + return x+y+0j + + server = SimpleXMLRPCServer(("localhost", 8000)) + print "Listening on port 8000..." + server.register_function(add, 'add') + + server.serve_forever() + +The client code for the preceding server:: + + import xmlrpclib + + proxy = xmlrpclib.ServerProxy("http://localhost:8000/") + try: + proxy.add(2, 5) + except xmlrpclib.Fault, err: + print "A fault occured" + print "Fault code: %d" % err.faultCode + print "Fault string: %s" % err.faultString + + .. _protocol-error-objects: @@ -299,6 +399,22 @@ does not exist). It has the following members: A dict containing the headers of the HTTP/HTTPS request that triggered the error. +In the following example we're going to intentionally cause a :exc:`ProtocolError` +by providing an invalid URI:: + + import xmlrpclib + + # create a ServerProxy with an invalid URI + proxy = xmlrpclib.ServerProxy("http://invalidaddress/") + + try: + proxy.some_method() + except xmlrpclib.ProtocolError, err: + print "A protocol error occured" + print "URL: %s" % err.url + print "HTTP/HTTPS headers: %s" % err.headers + print "Error code: %d" % err.errcode + print "Error message: %s" % err.errmsg MultiCall Objects ----------------- @@ -317,12 +433,45 @@ encapsulate multiple calls to a remote server into a single request. is a :term:`generator`; iterating over this generator yields the individual results. -A usage example of this class is :: +A usage example of this class follows. The server code :: + + from SimpleXMLRPCServer import SimpleXMLRPCServer + + def add(x,y): + return x+y - multicall = MultiCall(server_proxy) - multicall.add(2,3) - multicall.get_address("Guido") - add_result, address = multicall() + def subtract(x, y): + return x-y + + def multiply(x, y): + return x*y + + def divide(x, y): + return x/y + + # A simple server with simple arithmetic functions + server = SimpleXMLRPCServer(("localhost", 8000)) + print "Listening on port 8000..." + server.register_multicall_functions() + server.register_function(add, 'add') + server.register_function(subtract, 'subtract') + server.register_function(multiply, 'multiply') + server.register_function(divide, 'divide') + server.serve_forever() + +The client code for the preceding server:: + + import xmlrpclib + + proxy = xmlrpclib.ServerProxy("http://localhost:8000/") + multicall = xmlrpclib.MultiCall(proxy) + multicall.add(7,3) + multicall.subtract(7,3) + multicall.multiply(7,3) + multicall.divide(7,3) + result = multicall() + + print "7+3=%d, 7-3=%d, 7*3=%d, 7/3=%d" % tuple(result) Convenience Functions @@ -407,3 +556,10 @@ transport. The following example, written by NoboNobo, shows how: server = xmlrpclib.Server('http://time.xmlrpc.com/RPC2', transport=p) print(server.currentTime.getCurrentTime()) + +Example of Client and Server Usage +---------------------------------- + +See :ref:`simplexmlrpcserver-example`. + + diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index 64f620b..4bb0074 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -413,9 +413,6 @@ generator functions:: ... while True: ... try: ... value = (yield value) - ... except GeneratorExit: - ... # never catch GeneratorExit - ... raise ... except Exception, e: ... value = e ... finally: diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst index 38b9a0f..6254f31 100644 --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -10,7 +10,7 @@ settings. .. note:: - Other implementation's command line schemes may differ. See + Other implementations' command line schemes may differ. See :ref:`implementations` for further resources. diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst index 3415c1b..0c3c694 100644 --- a/Doc/whatsnew/2.6.rst +++ b/Doc/whatsnew/2.6.rst @@ -108,7 +108,7 @@ PEP 343: The 'with' statement The previous version, Python 2.5, added the ':keyword:`with`' statement an optional feature, to be enabled by a ``from __future__ -import generators`` directive. In 2.6 the statement no longer need to +import with_statement`` directive. In 2.6 the statement no longer need to be specially enabled; this means that :keyword:`with` is now always a keyword. The rest of this section is a copy of the corresponding section from "What's New in Python 2.5" document; if you read @@ -481,7 +481,7 @@ Here are all of the changes that Python 2.6 makes to the core Python language. of strings containing the names of valid attributes for the object, and lets the object control the value that :func:`dir` produces. Objects that have :meth:`__getattr__` or :meth:`__getattribute__` - methods. + methods can use this to advertise pseudo-attributes they will honor. .. % Patch 1591665 |