當前位置: 首頁>>代碼示例>>Python>>正文


Python ndbm.open方法代碼示例

本文整理匯總了Python中dbm.ndbm.open方法的典型用法代碼示例。如果您正苦於以下問題:Python ndbm.open方法的具體用法?Python ndbm.open怎麽用?Python ndbm.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dbm.ndbm的用法示例。


在下文中一共展示了ndbm.open方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_annotation

# 需要導入模塊: from dbm import ndbm [as 別名]
# 或者: from dbm.ndbm import open [as 別名]
def test_annotation(server, dbm_db, tracker_ctx):
    with client() as c:
        with SampleTracker.annotate(ann="value"):
            c.ping()

        with SampleTracker.annotate() as ann:
            ann.update({"sig": "c.hello()", "user_id": "125"})
            c.hello('you')

    time.sleep(0.2)

    db = dbm.open(db_file, 'r')
    headers = list(db.keys())

    data = [pickle.loads(db[i]) for i in headers]
    data.sort(key=lambda x: x["seq"])

    assert data[0]["annotation"] == {"ann": "value"} and \
        data[1]["annotation"] == {"sig": "c.hello()", "user_id": "125"} 
開發者ID:Thriftpy,項目名稱:thriftpy2,代碼行數:21,代碼來源:test_tracking.py

示例2: test_counter

# 需要導入模塊: from dbm import ndbm [as 別名]
# 或者: from dbm.ndbm import open [as 別名]
def test_counter(server, dbm_db, tracker_ctx):
    with client() as c:
        c.get_phonenumbers("hello", 1)

        with SampleTracker.counter():
            c.ping()
            c.hello("counter")

        c.sleep(8)

    time.sleep(0.2)

    db = dbm.open(db_file, 'r')
    headers = list(db.keys())

    data = [pickle.loads(db[i]) for i in headers]
    data.sort(key=lambda x: x["api"])
    get, hello, ping, sleep = data

    assert get["api"] == "get_phonenumbers" and get["seq"] == '1'
    assert ping["api"] == "ping" and ping["seq"] == '1'
    assert hello["api"] == "hello" and hello["seq"] == '2'
    assert sleep["api"] == "sleep" and sleep["seq"] == '2' 
開發者ID:Thriftpy,項目名稱:thriftpy2,代碼行數:25,代碼來源:test_tracking.py

示例3: record

# 需要導入模塊: from dbm import ndbm [as 別名]
# 或者: from dbm.ndbm import open [as 別名]
def record(self, header, exception):
        db = dbm.open(db_file, 'w')
        key = "%s:%s" % (header.request_id, header.seq)
        db[key.encode("ascii")] = pickle.dumps(header.__dict__)
        db.close() 
開發者ID:Thriftpy,項目名稱:thriftpy2,代碼行數:7,代碼來源:test_tracking.py

示例4: client

# 需要導入模塊: from dbm import ndbm [as 別名]
# 或者: from dbm.ndbm import open [as 別名]
def client(client_class=TTrackedClient, port=PORT):
    socket = TSocket("localhost", port)

    try:
        trans = TBufferedTransportFactory().get_transport(socket)
        proto = TBinaryProtocolFactory().get_protocol(trans)
        trans.open()
        args = [addressbook.AddressBookService, proto]
        if client_class.__name__ == TTrackedClient.__name__:
            args.insert(0, SampleTracker("test_client", "test_server"))
        yield client_class(*args)
    finally:
        trans.close() 
開發者ID:Thriftpy,項目名稱:thriftpy2,代碼行數:15,代碼來源:test_tracking.py

示例5: dbm_db

# 需要導入模塊: from dbm import ndbm [as 別名]
# 或者: from dbm.ndbm import open [as 別名]
def dbm_db(request):
    db = dbm.open(db_file, 'n')
    db.close()

    def fin():
        try:
            os.remove(db_file)
        except OSError:
            pass

    request.addfinalizer(fin) 
開發者ID:Thriftpy,項目名稱:thriftpy2,代碼行數:13,代碼來源:test_tracking.py

示例6: test_tracker

# 需要導入模塊: from dbm import ndbm [as 別名]
# 或者: from dbm.ndbm import open [as 別名]
def test_tracker(server, dbm_db, tracker_ctx):
    with client() as c:
        c.hello('you')
        assert c.tracker.response_header.meta == {'you': 'you'}

    time.sleep(0.2)

    db = dbm.open(db_file, 'r')
    headers = list(db.keys())
    assert len(headers) == 1

    request_id = headers[0]
    data = pickle.loads(db[request_id])

    assert "start" in data and "end" in data
    data.pop("start")
    data.pop("end")
    assert data == {
        "request_id": request_id.decode("ascii").split(':')[0],
        "seq": '1',
        "client": "test_client",
        "server": "test_server",
        "api": "hello",
        "status": True,
        "annotation": {},
        "meta": {},
    } 
開發者ID:Thriftpy,項目名稱:thriftpy2,代碼行數:29,代碼來源:test_tracking.py

示例7: test_exception

# 需要導入模塊: from dbm import ndbm [as 別名]
# 或者: from dbm.ndbm import open [as 別名]
def test_exception(server, dbm_db, tracker_ctx):
    with pytest.raises(addressbook.PersonNotExistsError):
        with client() as c:
            c.get("jane")

    db = dbm.open(db_file, 'r')
    headers = list(db.keys())
    assert len(headers) == 1

    header = pickle.loads(db[headers[0]])
    assert header["status"] is False 
開發者ID:Thriftpy,項目名稱:thriftpy2,代碼行數:13,代碼來源:test_tracking.py

示例8: test_tracked_client_v2_tracked_server_v2

# 需要導入模塊: from dbm import ndbm [as 別名]
# 或者: from dbm.ndbm import open [as 別名]
def test_tracked_client_v2_tracked_server_v2(
        tracked_server_v2, dbm_db, tracker_ctx):
    with client(TTrackedClientV2, PORT + 4) as c:
        assert c._upgraded is True

        c.ping()
        time.sleep(0.2)

        db = dbm.open(db_file, 'r')
        headers = list(db.keys())
        assert len(headers) == 1

        request_id = headers[0]
        data = pickle.loads(db[request_id])

        assert "start" in data and "end" in data
        data.pop("start")
        data.pop("end")
        assert data == {
            "request_id": request_id.decode("ascii").split(':')[0],
            "seq": '1',
            "client": "test_client",
            "server": "test_server",
            "api": "ping",
            "status": True,
            "annotation": {},
            "meta": {},
        } 
開發者ID:Thriftpy,項目名稱:thriftpy2,代碼行數:30,代碼來源:test_tracking.py

示例9: test_tracked_client_v2_tracked_server_v3

# 需要導入模塊: from dbm import ndbm [as 別名]
# 或者: from dbm.ndbm import open [as 別名]
def test_tracked_client_v2_tracked_server_v3(server, dbm_db, tracker_ctx):
    with client(TTrackedClientV2) as c:
        assert c._upgraded is True

        c.ping()
        time.sleep(0.2)

        db = dbm.open(db_file, 'r')
        headers = list(db.keys())
        assert len(headers) == 1

        request_id = headers[0]
        data = pickle.loads(db[request_id])

        assert "start" in data and "end" in data
        data.pop("start")
        data.pop("end")
        assert data == {
            "request_id": request_id.decode("ascii").split(':')[0],
            "seq": '1',
            "client": "test_client",
            "server": "test_server",
            "api": "ping",
            "status": True,
            "annotation": {},
            "meta": {},
        }

        assert not hasattr(ctx, 'response_header') 
開發者ID:Thriftpy,項目名稱:thriftpy2,代碼行數:31,代碼來源:test_tracking.py

示例10: open

# 需要導入模塊: from dbm import ndbm [as 別名]
# 或者: from dbm.ndbm import open [as 別名]
def open(file, flag='r', mode=0o666):
    """Open or create database at path given by *file*.

    Optional argument *flag* can be 'r' (default) for read-only access, 'w'
    for read-write access of an existing database, 'c' for read-write access
    to a new or existing database, and 'n' for read-write access to a new
    database.

    Note: 'r' and 'w' fail if the database doesn't exist; 'c' creates it
    only if it doesn't exist; and 'n' always creates a new database.
    """
    global _defaultmod
    if _defaultmod is None:
        for name in _names:
            try:
                mod = __import__(name, fromlist=['open'])
            except ImportError:
                continue
            if not _defaultmod:
                _defaultmod = mod
            _modules[name] = mod
        if not _defaultmod:
            raise ImportError("no dbm clone found; tried %s" % _names)

    # guess the type of an existing database, if not creating a new one
    result = whichdb(file) if 'n' not in flag else None
    if result is None:
        # db doesn't exist or 'n' flag was specified to create a new db
        if 'c' in flag or 'n' in flag:
            # file doesn't exist and the new flag was used so use default type
            mod = _defaultmod
        else:
            raise error[0]("need 'c' or 'n' flag to open new db")
    elif result == "":
        # db type cannot be determined
        raise error[0]("db type could not be determined")
    elif result not in _modules:
        raise error[0]("db type is {0}, but the module is not "
                       "available".format(result))
    else:
        mod = _modules[result]
    return mod.open(file, flag, mode) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:44,代碼來源:__init__.py


注:本文中的dbm.ndbm.open方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。