wrapping problem with old-style class

manstey manstey at csu.edu.au
Tue Dec 19 04:29:37 EST 2006


I have a problem I would like some advice on.

We have a Python binding to the Intersystems Cache OO database. It
provides an old style class in Python as an in memory instance of a
Cache class, and this is a intersystems.pythonbind.object type (= ipo).

The ipo class has three basic methods, namely, get, set, and
run_obj_method (which takes the Cache class method, as its first
argument, and the list of its arguments as the second argument)

e.g.
>>> CacheClass=ipo()
>>> CacheClass.set('Name','John')
>>> valName = CacheClass.get('Name')
>>> print valName
'John'

I want to add functionality to ipo, so I have wrapped a new style class
(MyWrapper class, very basic) around it.

PythonCacheClass=MyWrapper(CacheClass)

Now, I want to make PythonCacheClass more pythonic, so I have a
dictionary of all the properties and values of each ipo. Eg

dicCacheProperties = {'Name':'John', 'Address':'The Strand'} etc
for key, val in dicCacheProperties.iteritems():
   setattr(PythonCacheClass, key, val)

So now I have:
>>>print PythonCacheClass.Name
'John'

My problem is this: how do I link the set and get methods of the ipo
class with the set and get methods in the wrapper class
PythonCacheClass?

So, I would like the following code:
>>> PythonCacheClass.Name='Alexander'
to execute automatically
CacheClass.set('Name','Alexander')    etc

My thinking is that inside the PythonCacheClass, I can reference the
ipo class by self.get() - is this right? If so, how then do I set the
set attribute of the PythonCacheClass to automatically run

self.get().set('Name','Alexander')

I hope this is sufficiently clear. Am I tackling the problem the right
way?




More information about the Python-list mailing list