remove gevent monkey-patch from feed-downloader
[mygpo.git] / mygpo / core / proxy.py
blobc0bb53a1595923ec716777b69538f75ad237d37a
1 from abc import ABCMeta
3 from couchdbkit.ext.django.schema import DocumentMeta
7 class DocumentABCMeta(ABCMeta, DocumentMeta):
8 """ Meta class must be subclass of all parents' meta classes """
9 pass
13 def proxy_object(obj, **kwargs):
14 """ Proxies an object to make it arbitrarily modifiable
16 It is not possible to add arbitrary values to an couchdbkit Document,
17 because all values have to fit the schema and have to be JSON serializable
18 """
20 class ProxyObject(object):
21 """ Proxy for obj that can have properties of arbitrary type """
23 # ensure that proxied objects can be proxied again
24 __metaclass__ = DocumentABCMeta
26 def __init__(self, obj, **kwargs):
27 self.obj = obj
29 for key, val in kwargs.items():
30 setattr(self, key, val)
33 def __getattr__(self, attr):
34 return getattr(self.obj, attr)
37 def __eq__(self, other):
38 return self.obj == other.obj
41 cls = obj.__class__
42 cls.register(ProxyObject)
44 return ProxyObject(obj, **kwargs)