This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: xmlrpclib methods submit call on __str__, __repr__
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: collinwinter Nosy List: collinwinter, effbot, ghazel, iritkatriel, schmir, techtonik
Priority: normal Keywords: patch

Created on 2007-03-29 19:14 by ghazel, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
xmlrpc_repr.diff schmir, 2008-07-03 15:01 implement _Method.__repr__/__str__
Messages (12)
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?
msg176124 - (view) Author: anatoly techtonik (techtonik) Date: 2012-11-22 20:45
I'd say this one worthy to be backported.
msg377107 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-09-18 11:37
Python 3.10.0a0 (heads/master:6595cb0af4, Sep 18 2020, 12:33:44) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xmlrpc.client
>>> s = xmlrpc.client.ServerProxy("http://google.com")
>>> print(s.somecall)
<xmlrpc.client._Method object at 0x00F5AEC8>
>>>
msg377108 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-09-18 11:37
Since this was fixed in python 3, and the backport to python 2 is no longer relevant, I think this issue can now be closed.
History
Date User Action Args
2022-04-11 14:56:23adminsetgithub: 44785
2020-09-18 11:43:26serhiy.storchakasetstatus: open -> closed
resolution: fixed -> out of date
2020-09-18 11:37:13iritkatrielsetmessages: + msg377108
2020-09-18 11:37:07iritkatrielsetstatus: pending -> open
nosy: + iritkatriel
messages: + msg377107

2016-01-20 09:57:45serhiy.storchakasetstatus: open -> pending
2014-02-03 19:06:31BreamoreBoysetnosy: - BreamoreBoy
2012-11-22 20:45:22techtoniksetstatus: pending -> open
nosy: + techtonik
messages: + msg176124

2010-09-17 12:51:54BreamoreBoysetstatus: open -> pending

type: behavior
versions: + Python 3.1, Python 2.7, Python 3.2
nosy: + BreamoreBoy

messages: + msg116659
resolution: fixed
stage: resolved
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