classification
Title: xmlrpclib methods submit call on __str__, __repr__
Type: behavior Stage: committed/rejected
Components: Library (Lib) Versions: Python 3.2, Python 3.1, Python 2.7
process
Status: pending Resolution: fixed
Dependencies: Superseder:
Assigned To: collinwinter Nosy List: BreamoreBoy, collinwinter, effbot, ghazel, schmir
Priority: normal Keywords: patch

Created on 2007-03-29 19:14 by ghazel, last changed 2010-09-17 12:51 by BreamoreBoy.

Files
File name Uploaded Description Edit
xmlrpc_repr.diff schmir, 2008-07-03 15:01 implement _Method.__repr__/__str__
Messages (9)
msg31678 - (view) Author: Greg Hazel (ghazel) Date: 2007-03-29 19:14
Notice how trying to print a method causes it to submit the call:


Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from xmlrpclib import ServerProxy
>>> s = ServerProxy("http://google.com")
>>> print s.somecall
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python25\lib\xmlrpclib.py", line 1147, in __call__
    return self.__send(self.__name, args)
  File "c:\python25\lib\xmlrpclib.py", line 1437, in __request
    verbose=self.__verbose
  File "c:\python25\lib\xmlrpclib.py", line 1191, in request
    headers
xmlrpclib.ProtocolError: <ProtocolError for google.com/RPC2: 501 Not Implemented


Similarly:

>>> f = s.somecall
>>> locals()
{'f': Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python25\lib\xmlrpclib.py", line 1147, in __call__
    return self.__send(self.__name, args)
  File "c:\python25\lib\xmlrpclib.py", line 1437, in __request
    verbose=self.__verbose
  File "c:\python25\lib\xmlrpclib.py", line 1191, in request
    headers
xmlrpclib.ProtocolError: <ProtocolError for google.com/RPC2: 501 Not Implemented>

msg31679 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-03-30 02:59
What would you rather seem them print?
msg31680 - (view) Author: Greg Hazel (ghazel) Date: 2007-04-04 06:45
This would be reasonable:

>>> from xmlrpclib import ServerProxy
>>> s = ServerProxy("http://google.com")
>>> print s.somecall
<xmlrpclib._Method object at 0x00C08470>

Similarly:

>>> f = s.somecall
>>> locals()
{'f': <xmlrpclib._Method object at 0x00BA8030>, '__builtins__': <module '__built
in__' (built-in)>, 's': <ServerProxy for google.com/RPC2>, '__name__': '__main__
', 'ServerProxy': <class xmlrpclib.ServerProxy at 0x00C61AE0>, '__doc__': None}

Bonus points for:
<xmlrpclib _Method somecall of <ServerProxy for google.com/RPC2>>
msg31681 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-04-04 15:10
Fredrik, you originally wrote xmlrpclib: any objections to stringifying _Method objects to something like "<xmlrpclib _Method somecall at 0x4636e346>"?
msg55815 - (view) Author: Fredrik Lundh (effbot) * (Python committer) Date: 2007-09-11 06:23
I'm trying to think of a reason for actually providing __repr__ over
RPC, but I cannot find any.  Not quite as sure about __str__, though; I
suggest adding a __repr__ method, but leaving the rest as is.
msg55817 - (view) Author: Greg Hazel (ghazel) Date: 2007-09-11 06:35
How about making ServerProxy a new-style class?
msg69203 - (view) Author: Ralf Schmitt (schmir) Date: 2008-07-03 15:01
I think __str__ should also be implemented.
I'm attaching a patch with unittests against current trunk.
msg69204 - (view) Author: Ralf Schmitt (schmir) Date: 2008-07-03 15:04
this is how it looks:

~/pydev/trunk/ python                                              
ralf@red ok
Python 2.6b1+ (trunk, Jul  3 2008, 12:43:37) 
[GCC 4.3.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from xmlrpclib import Server
>>> Server("http://localhost:8000").doit
<xmlrpclib._Method doit <bound method ServerProxy.__request of
<ServerProxy for localhost:8000/RPC2>>>
msg116659 - (view) Author: Mark Lawrence (BreamoreBoy) Date: 2010-09-17 12:51
This has been fixed in py3k but not 2.7.  Is it worth backporting the change?
History
Date User Action Args
2010-09-17 12:51:54BreamoreBoysetstatus: open -> pending

nosy: + BreamoreBoy
versions: + Python 3.1, Python 2.7, Python 3.2
messages: + msg116659
resolution: fixed

type: behavior
stage: committed/rejected
2008-07-03 15:04:29schmirsetmessages: + msg69204
2008-07-03 15:01:46schmirsetfiles: + xmlrpc_repr.diff
keywords: + patch
messages: + msg69203
2008-07-02 17:31:14schmirsetnosy: + schmir
2007-09-11 06:35:42ghazelsetmessages: + msg55817
2007-09-11 06:23:11effbotsetassignee: effbot -> collinwinter
messages: + msg55815
2007-03-29 19:14:04ghazelcreate