wrapping problem with old-style class

M

manstey

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.'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:'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: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?
 
G

Gerard Flanagan

manstey said:
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.
'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:
'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:
to execute automatically
CacheClass.set('Name','Alexander') etc

Maybe try:

class WrapperClass(BaseClass, object):

get = object.__getattribute__
set = object.__setattr_

Gerard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top