0

I'm trying to subclass Python 3.5.2's xmlrpc.client ServerProxy() in order to customize its communication with an XML server. However, I'm stymied by how ServerProxy names its attributes.

The attributes are named quite clearly in 'xmlrpc/client.py':

class ServerProxy:
...
self.__transport = ...
self.__encoding = ...
self.__verbose = ...
...

Yet when I try to examine the object interactively, the object's attributes are pre-pended with '_ServerProxy':

import xmlrpc.client
my_client = xmlrpc.client.ServerProxy('http://01.234.567.890')

my_client.__dict__
Out[3]:
{'_ServerProxy__allow_none': False,
 '_ServerProxy__encoding': 'utf-8',
 '_ServerProxy__handler': '/RPC2',
 '_ServerProxy__host': '01.234.567.890:8000',
 '_ServerProxy__transport': <xmlrpc.client.Transport at 0x1043c4320>,
 '_ServerProxy__verbose': False}

How/where in the code is this dynamica renaming performed? I thought I understood __getattr__() and friends, but I can't for the life of me figure out where this is happening.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
JS.
  • 14,781
  • 13
  • 63
  • 75

1 Answers1

1

In CPython it happens during compilation in Python/compile.c:_Py_Mangle. For other implementations see their source code.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • Ah, crap. You're right. I forgot about mangling. You're right. It's a dupe. Thanks Ignacio. – JS. Sep 20 '16 at 00:07