当前位置: 首页>>代码示例>>Python>>正文


Python ClientStorage.ClientStorage类代码示例

本文整理汇总了Python中ZEO.ClientStorage.ClientStorage的典型用法代码示例。如果您正苦于以下问题:Python ClientStorage类的具体用法?Python ClientStorage怎么用?Python ClientStorage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ClientStorage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _main

def _main(host, port, unix=None, days=1, username=None, password=None,
         realm=None, blob_dir=None, storage='1', shared_blob_dir=True):
    if unix is not None:
        addr = unix
    else:
        if host is None:
            host = socket.gethostname()
        addr = host, int(port)

    if blob_dir:
        blob_dir = os.path.abspath(blob_dir)

    # We do not want to wait until a zeoserver is up and running; it
    # should already be running.
    wait = False
    cs = None
    try:
        cs = ClientStorage(
            addr, storage=storage, wait=wait, read_only=True,
            username=username, password=password, realm=realm,
            blob_dir=blob_dir, shared_blob_dir=shared_blob_dir,
        )
        try:
            cs.pack(wait=wait, days=int(days))
        except ClientDisconnected:
            logger = logging.getLogger(__name__)
            logger.error("Could not connect to zeoserver. Please make sure it "
                         "is running.")
            sys.exit(1)
    finally:
        if cs is not None:
            cs.close()
开发者ID:RohitKumar13,项目名称:plone.recipe.zeoserver,代码行数:32,代码来源:pack.py

示例2: __init__

 def __init__(self, name, blob_dir, shared=False, extrafsoptions=""):
     if shared:
         server_blob_dir = blob_dir
     else:
         server_blob_dir = "server-" + blob_dir
     self.globs = {}
     port = forker.get_port2(self)
     addr, admin, pid, config = forker.start_zeo_server(
         """
         <blobstorage>
             blob-dir %s
             <filestorage>
                path %s
                %s
             </filestorage>
         </blobstorage>
         """
         % (server_blob_dir, name + ".fs", extrafsoptions),
         port=port,
     )
     os.remove(config)
     zope.testing.setupstack.register(self, os.waitpid, pid, 0)
     zope.testing.setupstack.register(self, forker.shutdown_zeo_server, admin)
     if shared:
         ClientStorage.__init__(self, addr, blob_dir=blob_dir, shared_blob_dir=True)
     else:
         ClientStorage.__init__(self, addr, blob_dir=blob_dir)
开发者ID:grodniewicz,项目名称:oship,代码行数:27,代码来源:testZEO.py

示例3: _makeBaseStorage

 def _makeBaseStorage(self):
     logger.info("setUp() %s", self.id())
     port = get_port()
     zconf = forker.ZEOConfig(('', port))
     zport, adminaddr, pid, path = forker.start_zeo_server(self.getConfig(),
                                                           zconf, port)
     self._pids = [pid]
     self._servers = [adminaddr]
     self._conf_path = path
     _base = ClientStorage(zport, '1', cache_size=20000000,
                                   min_disconnect_poll=0.5, wait=1,
                                   wait_timeout=60)
     _base.registerDB(DummyDB(), None)
     return _base
开发者ID:wpjunior,项目名称:proled,代码行数:14,代码来源:testZEO.py

示例4: _new_storage

    def _new_storage(self):
        port = get_port(self)
        zconf = forker.ZEOConfig(("", port))
        zport, adminaddr, pid, path = forker.start_zeo_server(self.getConfig(), zconf, port)
        self._pids.append(pid)
        self._servers.append(adminaddr)

        blob_cache_dir = tempfile.mkdtemp(dir=".")

        storage = ClientStorage(
            zport, "1", cache_size=20000000, min_disconnect_poll=0.5, wait=1, wait_timeout=60, blob_dir=blob_cache_dir
        )
        storage.registerDB(DummyDB())
        return storage
开发者ID:grodniewicz,项目名称:oship,代码行数:14,代码来源:testZEO.py

示例5: remoteZODB

class remoteZODB(object):

    def __init__(self, server, port):
        server_and_port = (server, port)
        self.storage = ClientStorage(server_and_port, storage='data',
                                     read_only=True, wait=False, )
        self.db = DB(self.storage)
        self.connection = self.db.open()
        self.dbroot = self.connection.root()

    def close(self):
        self.connection.close()
        self.db.close()
        self.storage.close()
开发者ID:maerteijn,项目名称:maerteijn,代码行数:14,代码来源:check_zodb_written.py

示例6: __init__

 def __init__(self, server, port):
     server_and_port = (server, port)
     self.storage = ClientStorage(server_and_port, storage='data',
                                  read_only=True, wait=False, )
     self.db = DB(self.storage)
     self.connection = self.db.open()
     self.dbroot = self.connection.root()
开发者ID:maerteijn,项目名称:maerteijn,代码行数:7,代码来源:check_zodb_written.py

示例7: DB

    class DB(BaseDB):
        def __init__(self, server=SERVER, port=PORT):
            self.storage = ClientStorage((server, port,))
            self.db = ZDB(self.storage)
            self.connection = self.db.open()
            self.dbroot = self.connection.root()


        # KISS policy
        # let the lookup raise its own exception on a key lookup problem, etc
        def get(self, key):
            return self.dbroot[key]


        def put(self, key, data):
            self.dbroot[key] = data

        def update(self, key, data):
            if isinstance(data, Persistent):
                data._p_changed = True
            else:
                self.dbroot[key] = data

        def delete(self, key):
            if key in self.dbroot:
                del self.dbroot[key]
            

        def commit(self):
            transaction.commit()


        def abort(self):
            transaction.abort()

        def contains(self, key):
            return key in self.dbroot



        def close(self):
            self.connection.close()
            self.db.close()
            self.storage.close()
开发者ID:HVF,项目名称:Python-OAuth-2.0-Provider,代码行数:44,代码来源:DB.py

示例8: pack

def pack(addr, storage, days, wait):
    cs = ClientStorage(addr, storage=storage, wait_for_server_on_startup=wait)
    if wait:
        # _startup() is an artifact of the way ZEO 1.0 works.  The
        # ClientStorage doesn't get fully initialized until registerDB()
        # is called.  The only thing we care about, though, is that
        # registerDB() calls _startup().
        cs._startup()
    else:
        connect(cs)
    cs.invalidator = None
    cs.pack(wait=1, days=days)
    cs.close()
开发者ID:OS2World,项目名称:APP-SERVER-Zope,代码行数:13,代码来源:zeopack.py

示例9: checkZEOInvalidation

 def checkZEOInvalidation(self):
     addr = self._storage._addr
     storage2 = ClientStorage(addr, wait=1, min_disconnect_poll=0.1)
     try:
         oid = self._storage.new_oid()
         ob = MinPO('first')
         revid1 = self._dostore(oid, data=ob)
         data, serial = storage2.load(oid, '')
         self.assertEqual(zodb_unpickle(data), MinPO('first'))
         self.assertEqual(serial, revid1)
         revid2 = self._dostore(oid, data=MinPO('second'), revid=revid1)
         for n in range(3):
             # Let the server and client talk for a moment.
             # Is there a better way to do this?
             asyncore.poll(0.1)
         data, serial = storage2.load(oid, '')
         self.assertEqual(zodb_unpickle(data), MinPO('second'),
                          'Invalidation message was not sent!')
         self.assertEqual(serial, revid2)
     finally:
         storage2.close()
开发者ID:wpjunior,项目名称:proled,代码行数:21,代码来源:testZEO.py

示例10: __init__

    def __init__( self, hostname=None, port=None ):
        import Configuration # Please leave this import here, db.py is imported during installation process
        cfg = Configuration.Config.getInstance()

        if not hostname:
            hostname = cfg.getDBConnectionParams()[0]
        if not port:
            port = cfg.getDBConnectionParams()[1]

        self._storage=ClientStorage((hostname, port), username=cfg.getDBUserName(), password=cfg.getDBPassword(), realm=cfg.getDBRealm())
        self._db=MaKaCDB(self._storage)
        self._conn={}
开发者ID:davidmorrison,项目名称:indico,代码行数:12,代码来源:db.py

示例11: checkConnectionInvalidationOnReconnect

    def checkConnectionInvalidationOnReconnect(self):

        storage = ClientStorage(self.addr, wait=1, min_disconnect_poll=0.1)
        self._storage = storage

        # and we'll wait for the storage to be reconnected:
        for i in range(100):
            if storage.is_connected():
                break
            time.sleep(0.1)
        else:
            raise AssertionError("Couldn't connect to server")

        class DummyDB:
            _invalidatedCache = 0

            def invalidateCache(self):
                self._invalidatedCache += 1

            def invalidate(*a, **k):
                pass

        db = DummyDB()
        storage.registerDB(db)

        base = db._invalidatedCache

        # Now we'll force a disconnection and reconnection
        storage._connection.close()

        # and we'll wait for the storage to be reconnected:
        for i in range(100):
            if storage.is_connected():
                break
            time.sleep(0.1)
        else:
            raise AssertionError("Couldn't connect to server")

        # Now, the root object in the connection should have been invalidated:
        self.assertEqual(db._invalidatedCache, base + 1)
开发者ID:grodniewicz,项目名称:oship,代码行数:40,代码来源:testZEO.py

示例12: main

def main(host, port, unix=None, days=1, username=None, password=None,
         realm=None, blob_dir=None, storage='1'):
    if unix is not None:
        addr = unix
    else:
        if host is None:
            host = socket.gethostname()
        addr = host, int(port)

    wait = True
    cs = None
    try:
        if HAS_BLOB:
            cs = ClientStorage(
                addr, storage=storage, wait=wait, read_only=True,
                username=username, password=password, realm=realm,
                blob_dir=blob_dir
            )
        else:
            cs = ClientStorage(
                addr, storage=storage, wait=wait, read_only=True,
                username=username, password=password, realm=realm
            )
        cs.pack(wait=wait, days=int(days))
    finally:
        if cs is not None:
            cs.close()
开发者ID:ale-rt,项目名称:plone.recipe.zope2zeoserver,代码行数:27,代码来源:pack.py

示例13: __init__

    def __init__(self, addr, storage='1', cache_size=20 * MB,
                 name='', client=None, debug=0, var=None,
                 min_disconnect_poll=5, max_disconnect_poll=300,
                 wait_for_server_on_startup=None, # deprecated alias for wait
                 wait=None, wait_timeout=None,
                 read_only=0, read_only_fallback=0,
                 username='', password='', realm=None):


        # swap out the ClientCache with QonClientCache if desired.
        self.ClientCacheClass = ClientCache
        if qon.local.CACHE_INSTRUMENTATION:
            self.ClientCacheClass = QonClientCache
            
        ClientStorage.__init__(self, addr, storage, cache_size, \
                               name, client, debug, var, \
                               min_disconnect_poll, max_disconnect_poll, \
                               wait_for_server_on_startup, \
                               wait, wait_timeout, \
                               read_only, read_only_fallback, \
                               username, password, realm)

        # fix the cache_size bug that we manually patched previously.
        # once ZEO's code is fixed, we can remove everything after
        #  this line of code in this routine.
        if self._cache:
            self._cache.close()
            del self._cache

        # Decide whether to use non-temporary files
        if client is not None:
            dir = var or os.getcwd()
            cache_path = os.path.join(dir, "%s-%s.zec" % (client, storage))
        else:
            cache_path = None

        # create the cache            
        self._cache = self.ClientCacheClass(cache_path, size=cache_size) # this here is that actual cache_size fix
        self._cache.open()
开发者ID:mrmaple,项目名称:open_qon,代码行数:39,代码来源:cache_logging.py

示例14: create_storage

 def create_storage(self):
     from ZEO.ClientStorage import ClientStorage
     if self.port:
         addr = self.host, self.port
     else:
         addr = self.host
     if options["globals", "verbose"]:
         print("Connecting to ZEO server", addr, \
               self.username, self.password, file=sys.stderr)
     # Use persistent caches, with the cache in the temp directory.
     # If the temp directory is cleared out, we lose the cache, but
     # that doesn't really matter, and we should always be able to
     # write to it.
     try:
         self.storage = ClientStorage(addr, name=self.db_name,
                                      read_only=self.mode=='r',
                                      username=self.username,
                                      client=self.db_name,
                                      wait=self.wait,
                                      wait_timeout=self.wait_timeout,
                                      storage=self.storage_name,
                                      var=tempfile.gettempdir(),
                                      password=self.password)
     except ValueError:
         # Probably bad cache; remove it and try without the cache.
         try:
             os.remove(os.path.join(tempfile.gettempdir(),
                                    self.db_name + \
                                    self.storage_name + ".zec"))
         except OSError:
             pass
         self.storage = ClientStorage(addr, name=self.db_name,
                                      read_only=self.mode=='r',
                                      username=self.username,
                                      wait=self.wait,
                                      wait_timeout=self.wait_timeout,
                                      storage=self.storage_name,
                                      password=self.password)
开发者ID:dbrandt,项目名称:spambayes-lite,代码行数:38,代码来源:storage.py

示例15: create_storage

    def create_storage(self):
        from ZEO.ClientStorage import ClientStorage

        if self.port:
            addr = self.host, self.port
        else:
            addr = self.host
        if options["globals", "verbose"]:
            print("Connecting to ZEO server", addr, self.username, self.password, file=sys.stderr)
        try:
            self.storage = ClientStorage(
                addr,
                name=self.db_name,
                read_only=self.mode == "r",
                username=self.username,
                client=self.db_name,
                wait=self.wait,
                wait_timeout=self.wait_timeout,
                storage=self.storage_name,
                var=tempfile.gettempdir(),
                password=self.password,
            )
        except ValueError:
            try:
                os.remove(os.path.join(tempfile.gettempdir(), self.db_name + self.storage_name + ".zec"))
            except OSError:
                pass
            self.storage = ClientStorage(
                addr,
                name=self.db_name,
                read_only=self.mode == "r",
                username=self.username,
                wait=self.wait,
                wait_timeout=self.wait_timeout,
                storage=self.storage_name,
                password=self.password,
            )
开发者ID:,项目名称:,代码行数:37,代码来源:


注:本文中的ZEO.ClientStorage.ClientStorage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。