Re: [Tutor] Proxies/Interceptors for file-like objects

2009-02-19 Thread Kent Johnson
On Thu, Feb 19, 2009 at 6:03 AM, Lie Ryan wrote: > If you replace sys.stdin with your own file object, you don't need to > define all of the file object interface, just the one that generates an > error if not defined (i.e. the ones that you use). Yes, probably just defining read() and readline(

Re: [Tutor] Proxies/Interceptors for file-like objects

2009-02-19 Thread Lie Ryan
On Thu, 19 Feb 2009 20:12:57 +1100, Oxymoron wrote: > Thanks for the answers everyone. > > Denis, I wish to wrap an already open file handle basically, so simply > extending and overriding doesn't help - my proxy won't be instantiated > like a file, just used like one and if not intercepting I ne

Re: [Tutor] Proxies/Interceptors for file-like objects

2009-02-19 Thread Oxymoron
Thanks for the answers everyone. Denis, I wish to wrap an already open file handle basically, so simply extending and overriding doesn't help - my proxy won't be instantiated like a file, just used like one and if not intercepting I need to delegate down to the proxied "real" handle. If I'm missin

Re: [Tutor] Proxies/Interceptors for file-like objects

2009-02-19 Thread spir
Le Wed, 18 Feb 2009 22:01:34 -0500, Kent Johnson s'exprima ainsi: > Hmm. I guess this is Python 3? In 2.6, open is a function and trying > to subclass it gives an error: > > In [10]: open > Out[10]: > > In [11]: class myopen(open): pass > >: > > TypeError: Error when calling the meta

Re: [Tutor] Proxies/Interceptors for file-like objects

2009-02-18 Thread Kent Johnson
On Wed, Feb 18, 2009 at 7:51 PM, Emile van Sebille wrote: class open(open): > ... def mything(self): > ... print "it's my thing" Hmm. I guess this is Python 3? In 2.6, open is a function and trying to subclass it gives an error: In [10]: open Out[10]: In [11]: class myopen(op

Re: [Tutor] Proxies/Interceptors for file-like objects

2009-02-18 Thread Oxymoron
On Thu, Feb 19, 2009 at 11:51 AM, Emile van Sebille wrote: > Oxymoron wrote: >> >> I'm trying to intercept one or more methods in file-like objects > > Shadowing perhaps? Neat stuff - but not applicable for me I think: 1. I receive the handle. I need this function in a CGI script for example, so

Re: [Tutor] Proxies/Interceptors for file-like objects

2009-02-18 Thread Emile van Sebille
Oxymoron wrote: I'm trying to intercept one or more methods in file-like objects Shadowing perhaps? >>> class open(open): ... def mything(self): ... print "it's my thing" ... >>> a = open(r'c:\testfile','wb') >>> a.mything() it's my thing >>> a.write("this is a test") >>> a.flush()

[Tutor] Proxies/Interceptors for file-like objects

2009-02-18 Thread Oxymoron
Hello, I'm trying to intercept one or more methods in file-like objects (in this particular case just sys.stdin really), essentially I need a decorator/proxy implemented. What's the idiomatic way to do this? Since file objects do not have a base class(?), would I need to implement all methods to