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(
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
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
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
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
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
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()
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