Re: How to wrap a class's methods?

2005-02-20 Thread rbt
Jeff Shannon wrote: You could probably also do this as a factory function, rather than as a class (also untested!): def Wrapper(func): def wrapped(self, *args, **kwargs): s, r = func(self, *args, **kwargs) if s != 'OK': raise NotOK((s,r)) return r

Re: How to wrap a class's methods?

2005-02-20 Thread Steven Bethard
rbt wrote: Jeff Shannon wrote: You could probably also do this as a factory function, rather than as a class (also untested!): def Wrapper(func): def wrapped(self, *args, **kwargs): s, r = func(self, *args, **kwargs) if s != 'OK': raise NotOK((s,r)) return

How to wrap a class's methods?

2005-02-17 Thread Grant Edwards
I want to subclass an IMAP connection so that most of the methods raise an exception if the returned status isn't 'OK'. This works, but there's got to be a way to do it that doesn't involve so much duplication: class MyImap4_ssl(imaplib.IMAP4_SSL): def login(*args): s,r =

Re: How to wrap a class's methods?

2005-02-17 Thread John Lenton
On Thu, Feb 17, 2005 at 07:32:55PM +, Grant Edwards wrote: I want to subclass an IMAP connection so that most of the methods raise an exception if the returned status isn't 'OK'. This works, but there's got to be a way to do it that doesn't involve so much duplication: class

Re: How to wrap a class's methods?

2005-02-17 Thread Michael Spencer
Grant Edwards wrote: On 2005-02-17, Steven Bethard [EMAIL PROTECTED] wrote: py class C(object): ... def f(self, *args): ... print f:, args ... def g(self, *args): ... print g:, args ... py class D(C): ... pass ... py class Wrapper(object): ... def __init__(self,

Re: How to wrap a class's methods?

2005-02-17 Thread Michael Spencer
John Lenton wrote: On Thu, Feb 17, 2005 at 07:32:55PM +, Grant Edwards wrote: I'd usually put big fat warnings around this code, and explain exaclty why I need to do things this way... As a low-tech alternative, what about sourcecode generation, since you are targetting a python module?