On Sun, Sep 27, 2009 at 08:18:11AM -0700, Chris wrote: > > I see. Thanks for the info about __html__. > > > I didn't know WebOb itself also did it. > It only seems to do it on an HTTP Redirection. In webob.exc, > _make_body(self, environ, escape) it loops over environ, calling > escape on any values. (i'm still not exactly sure why). > > > Or is it just returning something for all .__getattr__ calls > > regardless of value? > > pymongo.database instance always returns a collection object, > regardless of the attr name. The collection object is not callable, > (well actually it defines __call__, but its implementation throws an > exception immediately on purpose). The pymongo database __getattr__ > looks like this > > # in pymongo database > def __getattr__(self, name): > return Collection(self.db, name)
There are all kinds of special names that can trip you up, in various
places. I've found that it's safest to add
if name.startswith('_'):
raise AttributeError(name)
to such magic __getattr__ methods.
If you actually use collection names starting with an underscore, you
could make a stricter check and look for __..., or __...__.
Marius Gedminas
--
There's a special hell 4 people who replace words with numbers.
-- Ben "Yahtzee" Croshaw
signature.asc
Description: Digital signature
