[Web-SIG] Any practical reason type(environ) must be dict (not subclass)?

Cory Benfield cory at lukasa.co.uk
Fri Mar 25 13:23:35 EDT 2016


> On 25 Mar 2016, at 15:04, Jason Madden <jason.madden at nextthought.com> wrote:
> 
> 
>> On Mar 25, 2016, at 05:01, Cory Benfield <cory at lukasa.co.uk> wrote:
>> 
>> Given that gevent is keeping hold of its own reference to the environ, why does gevent not simply wrap the environ dict in a class that implements this functionality directly? In that manner, gevent can expose its own error handling behaviour as desired, and continue to follow PEP-3333.
> 
> I did consider that, but didn't want to do that unless there were actual practical problems passing the same object that gevent references. Making a copy just to pass to the application adds additional time and memory requirements that are always nice to avoid in a server.

For what it’s worth, I’m not advocating a copy. I’m advocating a class like this:


class SecureDictWrapper(collections.MutableMapping):
    def __init__(self, environ):
        self._environ = environ

That class would then implement the MutableMapping API and delegate its calls through to the dictionary itself. There would still only be one dictionary: the only new allocation is for the wrapper class. The overhead is small. =)

Cory

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.python.org/pipermail/web-sig/attachments/20160325/fddf8542/attachment.sig>


More information about the Web-SIG mailing list