diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2014-04-27 14:52:25 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2014-04-27 14:52:25 (GMT) |
commit | 2dbc9b554f322ea23b224d923d9a6475e33ad6e9 (patch) | |
tree | 55df42ddf7a0ec8d4ca6ef007218b1056409dc0b /sugar_network/toolkit/coroutine.py | |
parent | 046073b04229021ec53833a353ffd069d0a5b561 (diff) |
Implementation polishing
* http.request does not load posting stream before sending;
* one-sigment packets;
* move node related code to node module;
* Principal capabilities;
* batch posting while pushing client offline updates.
Diffstat (limited to 'sugar_network/toolkit/coroutine.py')
-rw-r--r-- | sugar_network/toolkit/coroutine.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/sugar_network/toolkit/coroutine.py b/sugar_network/toolkit/coroutine.py index 4a54975..e3a6173 100644 --- a/sugar_network/toolkit/coroutine.py +++ b/sugar_network/toolkit/coroutine.py @@ -303,25 +303,45 @@ class Spooler(object): class _Local(object): + PROPERTY_NOT_SET = object() + def __init__(self): self.attrs = set() + self.properties = {} if hasattr(gevent.getcurrent(), 'local'): current = gevent.getcurrent().local for attr in current.attrs: self.attrs.add(attr) setattr(self, attr, getattr(current, attr)) + self.properties = current.properties class _LocalAccess(object): def __getattr__(self, name): - return getattr(gevent.getcurrent().local, name) + local = gevent.getcurrent().local + value = getattr(local, name) + if value is _Local.PROPERTY_NOT_SET: + value = local.properties[name]() + setattr(local, name, value) + return value def __setattr__(self, name, value): local = gevent.getcurrent().local local.attrs.add(name) - return setattr(local, name, value) + if value is None and name in local.properties: + value = _Local.PROPERTY_NOT_SET + setattr(local, name, value) + + def add_property(self, name, getter): + local = gevent.getcurrent().local + local.properties[name] = getter + setattr(local, name, _Local.PROPERTY_NOT_SET) + + def reset_property(self, name): + local = gevent.getcurrent().local + setattr(local, name, _Local.PROPERTY_NOT_SET) class _Child(object): |