Commit be910013 authored by Denis Bilenko's avatar Denis Bilenko

gevent.local: Implement __copy__ compatible to __copy__ of threading.local. Patch by Galfy Pundee.

--HG--
extra : transplant_source : %89h%CD%7CY%C9u%06%93%83%0A%A8%9FZ%E7f%E0L%05%82
parent c05b91e1
......@@ -127,6 +127,7 @@ affects what we see:
>>> del mydata
"""
from weakref import WeakKeyDictionary
from copy import copy
from gevent.hub import getcurrent
from gevent.coros import RLock
......@@ -215,3 +216,21 @@ class local(_localbase):
else:
object.__setattr__(self, '__dict__', d)
return object.__delattr__(self, name)
def __copy__(self):
currentId = getcurrent()
d = object.__getattribute__(self, '_local__dicts').get(currentId)
duplicate = copy(d)
cls = type(self)
if cls.__init__ is not object.__init__:
args, kw = object.__getattribute__(self, '_local__args')
instance = cls(*args, **kw)
else:
instance = cls()
object.__setattr__(instance, '_local__dicts', {
currentId: duplicate
})
return instance
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment