Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cbf3b5c

Browse files
committed
Merged revisions 59275-59303 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent f929077 commit cbf3b5c

35 files changed

Lines changed: 3139 additions & 237 deletions

Doc/ACKS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ [email protected]), and we'll be glad to correct the problem.
161161
* Barry Scott
162162
* Joakim Sernbrant
163163
* Justin Sheehy
164+
* Charlie Shepherd
164165
* Michael Simcich
165166
* Ionel Simionescu
166167
* Michael Sloan

Doc/c-api/init.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,6 @@ Initialization, Finalization, and Threads
360360
.. % XXX impl. doesn't seem consistent in allowing 0/NULL for the params;
361361
.. % check w/ Guido.
362362
363-
.. % XXX Other PySys thingies (doesn't really belong in this chapter)
364-
365363
366364
.. _threads:
367365

Doc/c-api/utilities.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,66 @@ Operating System Utilities
6666
not call those functions directly! :ctype:`PyOS_sighandler_t` is a typedef
6767
alias for :ctype:`void (\*)(int)`.
6868

69+
.. _systemfunctions:
70+
71+
System Functions
72+
================
73+
74+
These are utility functions that make functionality from the :mod:`sys` module
75+
accessible to C code. They all work with the current interpreter thread's
76+
:mod:`sys` module's dict, which is contained in the internal thread state structure.
77+
78+
.. cfunction:: PyObject *PySys_GetObject(char *name)
79+
80+
Return the object *name* from the :mod:`sys` module or *NULL* if it does
81+
not exist, without setting an exception.
82+
83+
.. cfunction:: FILE *PySys_GetFile(char *name, FILE *def)
84+
85+
Return the :ctype:`FILE*` associated with the object *name* in the
86+
:mod:`sys` module, or *def* if *name* is not in the module or is not associated
87+
with a :ctype:`FILE*`.
88+
89+
.. cfunction:: int PySys_SetObject(char *name, PyObject *v)
90+
91+
Set *name* in the :mod:`sys` module to *v* unless *v* is *NULL*, in which
92+
case *name* is deleted from the sys module. Returns ``0`` on success, ``-1``
93+
on error.
94+
95+
.. cfunction:: void PySys_ResetWarnOptions(void)
96+
97+
Reset :data:`sys.warnoptions` to an empty list.
98+
99+
.. cfunction:: void PySys_AddWarnOption(char *s)
100+
101+
Append *s* to :data:`sys.warnoptions`.
102+
103+
.. cfunction:: void PySys_SetPath(char *path)
104+
105+
Set :data:`sys.path` to a list object of paths found in *path* which should
106+
be a list of paths separated with the platform's search path delimiter
107+
(``:`` on Unix, ``;`` on Windows).
108+
109+
.. cfunction:: void PySys_WriteStdout(const char *format, ...)
110+
111+
Write the output string described by *format* to :data:`sys.stdout`. No
112+
exceptions are raised, even if truncation occurs (see below).
113+
114+
*format* should limit the total size of the formatted output string to
115+
1000 bytes or less -- after 1000 bytes, the output string is truncated.
116+
In particular, this means that no unrestricted "%s" formats should occur;
117+
these should be limited using "%.<N>s" where <N> is a decimal number
118+
calculated so that <N> plus the maximum size of other formatted text does not
119+
exceed 1000 bytes. Also watch out for "%f", which can print hundreds of
120+
digits for very large numbers.
121+
122+
If a problem occurs, or :data:`sys.stdout` is unset, the formatted message
123+
is written to the real (C level) *stdout*.
124+
125+
.. cfunction:: void PySys_WriteStderr(const char *format, ...)
126+
127+
As above, but write to :data:`sys.stderr` or *stderr* instead.
128+
69129

70130
.. _processcontrol:
71131

Doc/data/refcounts.dat

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,10 +1251,32 @@ PyString_AsEncodedString:PyObject*:str::
12511251
PyString_AsEncodedString:const char*:encoding::
12521252
PyString_AsEncodedString:const char*:errors::
12531253

1254+
PySys_AddWarnOption:void:::
1255+
PySys_AddWarnOption:char*:s::
1256+
1257+
PySys_GetFile:FILE*:::
1258+
PySys_GetFile:char*:name::
1259+
PySys_GetFile:FILE*:def::
1260+
1261+
PySys_GetObject:PyObject*::0:
1262+
PySys_GetObject:char*:name::
1263+
12541264
PySys_SetArgv:int:::
12551265
PySys_SetArgv:int:argc::
12561266
PySys_SetArgv:char**:argv::
12571267

1268+
PySys_SetObject:int:::
1269+
PySys_SetObject:char*:name::
1270+
PySys_SetObject:PyObject*:v:+1:
1271+
1272+
PySys_ResetWarnOptions:void:::
1273+
1274+
PySys_WriteStdout:void:::
1275+
PySys_WriteStdout:char*:format::
1276+
1277+
PySys_WriteStderr:void:::
1278+
PySys_WriteStderr:char*:format::
1279+
12581280
PyThreadState_Clear:void:::
12591281
PyThreadState_Clear:PyThreadState*:tstate::
12601282

Doc/glossary.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ Glossary
400400
:term:`immutable` keys rather than integers.
401401

402402
slice
403-
An object usually containing a portion of a :term:`sequence`. A slice is
403+
A list containing a portion of an indexed list-like object. A slice is
404404
created using the subscript notation, ``[]`` with colons between numbers
405405
when several are given, such as in ``variable_name[1:3:5]``. The bracket
406406
(subscript) notation uses :class:`slice` objects internally.

Doc/library/exceptions.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ The following exceptions are the exceptions that are actually raised.
135135

136136
.. exception:: GeneratorExit
137137

138-
Raise when a :term:`generator`\'s :meth:`close` method is called.
138+
Raise when a :term:`generator`\'s :meth:`close` method is called. It
139+
directly inherits from :exc:`BaseException` instead of :exc:`Exception` since
140+
it is technically not an error.
139141

140142

141143
.. exception:: IOError

Doc/library/random.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ Bookkeeping functions:
6969
Return an object capturing the current internal state of the generator. This
7070
object can be passed to :func:`setstate` to restore the state.
7171

72+
State values produced in Python 2.6 cannot be loaded into earlier versions.
73+
7274

7375
.. function:: setstate(state)
7476

Doc/library/simplexmlrpcserver.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ alone XML-RPC servers.
109109
considered valid. The default value is ``('/', '/RPC2')``.
110110

111111

112-
Example::
112+
.. _simplexmlrpcserver-example:
113+
114+
SimpleXMLRPCServer Example
115+
^^^^^^^^^^^^^^^^^^^^^^^^^^
116+
Server code::
113117

114118
from SimpleXMLRPCServer import SimpleXMLRPCServer
115119

@@ -137,7 +141,7 @@ Example::
137141
# Run the server's main loop
138142
server.serve_forever()
139143

140-
The following client code will call the methods made available by the preceding
144+
The following client code will call the methods made available by the preceding
141145
server::
142146

143147
import xmlrpclib

Doc/library/xmlrpclib.rst

Lines changed: 161 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,26 @@ unmarshalling code:
192192

193193
Write the XML-RPC encoding of this Boolean item to the out stream object.
194194

195+
A working example follows. The server code::
196+
197+
import xmlrpclib
198+
from SimpleXMLRPCServer import SimpleXMLRPCServer
199+
200+
def is_even(n):
201+
return n%2 == 0
202+
203+
server = SimpleXMLRPCServer(("localhost", 8000))
204+
print "Listening on port 8000..."
205+
server.register_function(is_even, "is_even")
206+
server.serve_forever()
207+
208+
The client code for the preceding server::
209+
210+
import xmlrpclib
211+
212+
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
213+
print "3 is even: %s" % str(proxy.is_even(3))
214+
print "100 is even: %s" % str(proxy.is_even(100))
195215

196216
.. _datetime-objects:
197217

@@ -217,6 +237,32 @@ mainly for internal use by the marshalling/unmarshalling code:
217237
It also supports certain of Python's built-in operators through :meth:`__cmp__`
218238
and :meth:`__repr__` methods.
219239

240+
A working example follows. The server code::
241+
242+
import datetime
243+
from SimpleXMLRPCServer import SimpleXMLRPCServer
244+
import xmlrpclib
245+
246+
def today():
247+
today = datetime.datetime.today()
248+
return xmlrpclib.DateTime(today)
249+
250+
server = SimpleXMLRPCServer(("localhost", 8000))
251+
print "Listening on port 8000..."
252+
server.register_function(today, "today")
253+
server.serve_forever()
254+
255+
The client code for the preceding server::
256+
257+
import xmlrpclib
258+
import datetime
259+
260+
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
261+
262+
today = proxy.today()
263+
# convert the ISO8601 string to a datetime object
264+
converted = datetime.datetime.strptime(today.value, "%Y%m%dT%H:%M:%S")
265+
print "Today: %s" % converted.strftime("%d.%m.%Y, %H:%M")
220266

221267
.. _binary-objects:
222268

@@ -249,6 +295,31 @@ internal use by the marshalling/unmarshalling code:
249295
It also supports certain of Python's built-in operators through a
250296
:meth:`__cmp__` method.
251297

298+
Example usage of the binary objects. We're going to transfer an image over
299+
XMLRPC::
300+
301+
from SimpleXMLRPCServer import SimpleXMLRPCServer
302+
import xmlrpclib
303+
304+
def python_logo():
305+
handle = open("python_logo.jpg")
306+
return xmlrpclib.Binary(handle.read())
307+
handle.close()
308+
309+
server = SimpleXMLRPCServer(("localhost", 8000))
310+
print "Listening on port 8000..."
311+
server.register_function(python_logo, 'python_logo')
312+
313+
server.serve_forever()
314+
315+
The client gets the image and saves it to a file::
316+
317+
import xmlrpclib
318+
319+
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
320+
handle = open("fetched_python_logo.jpg", "w")
321+
handle.write(proxy.python_logo().data)
322+
handle.close()
252323

253324
.. _fault-objects:
254325

@@ -268,6 +339,35 @@ objects have the following members:
268339

269340
A string containing a diagnostic message associated with the fault.
270341

342+
In the following example we're going to intentionally cause a :exc:`Fault` by
343+
returning a complex type object. The server code::
344+
345+
from SimpleXMLRPCServer import SimpleXMLRPCServer
346+
347+
# A marshalling error is going to occur because we're returning a
348+
# complex number
349+
def add(x,y):
350+
return x+y+0j
351+
352+
server = SimpleXMLRPCServer(("localhost", 8000))
353+
print "Listening on port 8000..."
354+
server.register_function(add, 'add')
355+
356+
server.serve_forever()
357+
358+
The client code for the preceding server::
359+
360+
import xmlrpclib
361+
362+
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
363+
try:
364+
proxy.add(2, 5)
365+
except xmlrpclib.Fault, err:
366+
print "A fault occured"
367+
print "Fault code: %d" % err.faultCode
368+
print "Fault string: %s" % err.faultString
369+
370+
271371

272372
.. _protocol-error-objects:
273373

@@ -299,6 +399,22 @@ does not exist). It has the following members:
299399
A dict containing the headers of the HTTP/HTTPS request that triggered the
300400
error.
301401

402+
In the following example we're going to intentionally cause a :exc:`ProtocolError`
403+
by providing an invalid URI::
404+
405+
import xmlrpclib
406+
407+
# create a ServerProxy with an invalid URI
408+
proxy = xmlrpclib.ServerProxy("http://invalidaddress/")
409+
410+
try:
411+
proxy.some_method()
412+
except xmlrpclib.ProtocolError, err:
413+
print "A protocol error occured"
414+
print "URL: %s" % err.url
415+
print "HTTP/HTTPS headers: %s" % err.headers
416+
print "Error code: %d" % err.errcode
417+
print "Error message: %s" % err.errmsg
302418

303419
MultiCall Objects
304420
-----------------
@@ -317,12 +433,45 @@ encapsulate multiple calls to a remote server into a single request.
317433
is a :term:`generator`; iterating over this generator yields the individual
318434
results.
319435

320-
A usage example of this class is ::
436+
A usage example of this class follows. The server code ::
437+
438+
from SimpleXMLRPCServer import SimpleXMLRPCServer
439+
440+
def add(x,y):
441+
return x+y
321442

322-
multicall = MultiCall(server_proxy)
323-
multicall.add(2,3)
324-
multicall.get_address("Guido")
325-
add_result, address = multicall()
443+
def subtract(x, y):
444+
return x-y
445+
446+
def multiply(x, y):
447+
return x*y
448+
449+
def divide(x, y):
450+
return x/y
451+
452+
# A simple server with simple arithmetic functions
453+
server = SimpleXMLRPCServer(("localhost", 8000))
454+
print "Listening on port 8000..."
455+
server.register_multicall_functions()
456+
server.register_function(add, 'add')
457+
server.register_function(subtract, 'subtract')
458+
server.register_function(multiply, 'multiply')
459+
server.register_function(divide, 'divide')
460+
server.serve_forever()
461+
462+
The client code for the preceding server::
463+
464+
import xmlrpclib
465+
466+
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
467+
multicall = xmlrpclib.MultiCall(proxy)
468+
multicall.add(7,3)
469+
multicall.subtract(7,3)
470+
multicall.multiply(7,3)
471+
multicall.divide(7,3)
472+
result = multicall()
473+
474+
print "7+3=%d, 7-3=%d, 7*3=%d, 7/3=%d" % tuple(result)
326475

327476

328477
Convenience Functions
@@ -407,3 +556,10 @@ transport. The following example, written by NoboNobo, shows how:
407556
server = xmlrpclib.Server('http://time.xmlrpc.com/RPC2', transport=p)
408557
print(server.currentTime.getCurrentTime())
409558

559+
560+
Example of Client and Server Usage
561+
----------------------------------
562+
563+
See :ref:`simplexmlrpcserver-example`.
564+
565+

Doc/reference/expressions.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,6 @@ generator functions::
413413
... while True:
414414
... try:
415415
... value = (yield value)
416-
... except GeneratorExit:
417-
... # never catch GeneratorExit
418-
... raise
419416
... except Exception, e:
420417
... value = e
421418
... finally:

0 commit comments

Comments
 (0)