def test_it(self): from zope.proxy import ProxyBase from zope.proxy import non_overridable class Proxy(ProxyBase): def who(self): raise AssertionError("Not called") @non_overridable def what(self): return 'PROXY' class Foo(object): def who(self): return 'FOO' def what(self): return 'FOO' p0 = ProxyBase(Foo()) self.assertEqual(p0.who(), 'FOO') self.assertEqual(p0.what(), 'FOO') proxy = Proxy(Foo()) self.assertEqual(proxy.who(), 'FOO') self.assertEqual(proxy.what(), 'PROXY')
def __setattr__(self, name, value): if name in self.__slots__ + getattr(ProxyBase, '__slots__', ()): #('_wrapped', '__parent__', '__name__'): try: return object.__setattr__(self, name, value) except TypeError: #pragma NO COVER C Optimization return ProxyBase.__setattr__(self, name, value) return ProxyBase.__setattr__(self, name, value)
def test_w_nested_proxies(self): from zope.proxy import ProxyBase class C(object): pass c = C() proxy = ProxyBase(c) proxy2 = ProxyBase(proxy) proxy3 = ProxyBase(proxy2) proxy4 = ProxyBase(proxy3) self.assertEqual(list(self._callFUT(proxy4)), [proxy4, proxy3, proxy2, proxy, c])
def __init__(self, opts, *args, **kwargs): """ Initialize the connection pool. """ self.opts = opts try: adbapi.ConnectionPool.__init__(self, *args, **kwargs) except dbapi2.DatabaseError as e: raise DatabaseAccessError( 'Error initializing u1db connection pool: %s' % str(e)) # all u1db connections, hashed by thread-id self._u1dbconnections = {} # The replica uid, primed by the connections on init. self.replica_uid = ProxyBase(None) try: conn = self.connectionFactory( self, init_u1db=True) replica_uid = conn._u1db._real_replica_uid setProxiedObject(self.replica_uid, replica_uid) except DatabaseAccessError as e: self.threadpool.stop() raise DatabaseAccessError( "Error initializing connection factory: %s" % str(e))
def test_has_usable_external_object_proxied(self): obj = WithToExternalObject() proxied = ProxyBase(obj) self.assertTrue(_obj_has_usable_externalObject(proxied)) self.assertEqual({'a': 42}, to_external_object(proxied))
def test_w_simple_proxy(self): from zope.proxy import ProxyBase class C(object): pass c = C() proxy = ProxyBase(c) self.assertEqual(list(self._callFUT(proxy)), [proxy, c])
def test_it(self): from zope.proxy import ProxyBase from zope.proxy import non_overridable class Proxy(ProxyBase): def who(self): return 'PROXY' @non_overridable def what(self): return 'PROXY' class Foo(object): def who(self): return 'FOO' def what(self): return 'FOO' p0 = ProxyBase(Foo()) self.assertEqual(p0.who(), 'FOO') self.assertEqual(p0.what(), 'FOO') proxy = Proxy(Foo()) self.assertEqual(proxy.who(), 'FOO') self.assertEqual(proxy.what(), 'PROXY')
def test_serialize_on_adaptable(self): from jsonpublish.encoder import JSONEncoder encoder = JSONEncoder() from zope.proxy import ProxyBase from datetime import date o = date(1987, 5, 8) p = ProxyBase(o) def adapt_date(d): return d.strftime("%Y-%m-%d") encoder.adapters.register_adapter(date, adapt_date) self.assertEqual(encoder.encode(p), '"1987-05-08"')
def __init__(self, *args, **kwargs): """ Initialize the connection pool. """ adbapi.ConnectionPool.__init__(self, *args, **kwargs) # all u1db connections, hashed by thread-id self._u1dbconnections = {} # The replica uid, primed by the connections on init. self.replica_uid = ProxyBase(None) conn = self.connectionFactory(self, init_u1db=True) replica_uid = conn._u1db._real_replica_uid setProxiedObject(self.replica_uid, replica_uid)
def test___get___w_inst_w_proxy(self): from zope.interface import Interface from zope.interface import implementer from zope.interface import provider from zope.proxy import ProxyBase class IContextFactory(Interface): pass class IContext(Interface): pass @provider(IContextFactory) @implementer(IContext) class Context(object): pass context = Context() proxy = ProxyBase(context) dsd = self._makeOne() self.assertEqual(list(dsd.__get__(proxy, None)), [IContext])
def __init__(self, *args, **kwargs): """ Initialize the connection pool. """ # extract soledad-specific objects from keyword arguments self.opts = kwargs.pop("opts") self._sync_enc_pool = kwargs.pop("sync_enc_pool") try: adbapi.ConnectionPool.__init__(self, *args, **kwargs) except DatabaseError: raise DatabaseAccessError('Could not open sqlcipher database') # all u1db connections, hashed by thread-id self._u1dbconnections = {} # The replica uid, primed by the connections on init. self.replica_uid = ProxyBase(None) conn = self.connectionFactory(self, self._sync_enc_pool, init_u1db=True) replica_uid = conn._u1db._real_replica_uid setProxiedObject(self.replica_uid, replica_uid)
def __new__(self, ob, target): checker = getCheckerForInstancesOf(type(removeAllProxies(ob))) ob = ProxyBase.__new__(self, ob) ob.__Security_checker__ = checker return ob
def test_serialize_proxy(self): from jsonpublish.encoder import JSONEncoder encoder = JSONEncoder() from zope.proxy import ProxyBase p = ProxyBase(1) self.assertEqual(encoder.encode(p), '1')
def __init__(self, ob, target): ProxyBase.__init__(self, ob) self.__target__ = target
def __new__(self, ob, title=None, description=None): checker = getCheckerForInstancesOf(type(removeAllProxies(ob))) ob = ProxyBase.__new__(self, ob) ob.__Security_checker__ = checker return ob
def __init__(self, ob, title=None, description=None): ProxyBase.__init__(self, ob) self.title = title self.description = description
def __init__(self, file, streamsize=1 << 16): ProxyBase.__init__(self, file) self.streamsize = streamsize
def __init__(self, ob, short_name=None): ProxyBase.__init__(self, ob) self.short_name = short_name
def __new__(self, ob, container=None, name=None): checker = getCheckerForInstancesOf(type(removeAllProxies(ob))) ob = ProxyBase.__new__(self, ob) ob.__Security_checker__ = checker return ob
def __new__(self, ob, short_name=None): checker = getCheckerForInstancesOf(type(ob)) ob = ProxyBase.__new__(self, ob) ob.__Security_checker__ = checker return ob
def __getattribute__(self, name): if name in LocationProxy.__dict__: return object.__getattribute__(self, name) return ProxyBase.__getattribute__(self, name)
def __init__(self, base, site_manager): ProxyBase.__init__(self, base) self.__site_manager = site_manager
def __new__(cls, item, *args, **kwargs): return ProxyBase.__new__(cls, item)
def __init__(self, ob, container=None, name=None): ProxyBase.__init__(self, ob) self.__parent__ = container self.__name__ = name
def __new__(self, file, streamsize=1 << 16): return ProxyBase.__new__(self, file)
def __new__(cls, base, site_manager): return ProxyBase.__new__(cls, base)
def _makeProxy(self, obj): from zope.proxy import ProxyBase return ProxyBase(obj)
def __new__(self, ob, container=None, name=None): return ProxyBase.__new__(self, ob)
def __init__(self, context): self.context = context ProxyBase.__init__(self, globalhelp)
def __new__(cls, tree, exclude=None, _view_root_location=None): return ProxyBase.__new__(cls, tree)