Customizing class attribute access in classic classes
Geoff Bache
geoff.bache at gmail.com
Sun Oct 30 05:05:09 EDT 2011
On Oct 30, 4:16 am, Ben Finney <ben+pyt... at benfinney.id.au> wrote:
> Geoff Bache <geoff.ba... at gmail.com> writes:
> > I'm wondering if there is any way to customize class attribute access
> > on classic classes?
>
> Why do that? What is it you're hoping to achieve, and why limit it to
> classic classes only?
>
I'm building a mocking tool, CaptureMock, which works by intercepting
and capturing particular calls, recording and replaying them.
A user can just say "intercept httplib for me" and it will record all
the interactions with httplib and allow a test that can be run without
doing anything via http or writing any handcrafted "mock-code".
So I need to be able to intercept also static attribute access, say
httplib.HTTPConnection.request.
httplib.HTTPConnection is a classic class. I can make my intercepting
version of it into a new-style class but the risk is that that will
change its behaviour in subtle ways, negating the point of the tool.
As for limiting it to classic classes only, I obviously need to do it
on new-style classes also. But I know how to do that...
Regards,
Geoff Bache
More information about the Python-list
mailing list