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


Python thriftpy.load方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: import thriftpy [as 別名]
# 或者: from thriftpy import load [as 別名]
def __init__(self, service_name, **kwargs):
        self.service_name = service_name
        super(ServiceHandler, self).__init__(**kwargs)

        self.system_exc_handler = self.default_exception_handler
        self.api_exc_handler = self.default_exception_handler
        self.thrift_exc_handler = lambda tp, v, tb: (tp, v, tb)

        # init hook registry
        self.hook_registry = HookRegistry()
        # register api hook
        self.hook_registry.register(api_called)
        # register log config hook
        self.hook_registry.register(config_log)

        module_name, _ = os.path.splitext(os.path.basename(config.thrift_file))
        # module name should ends with '_thrift'
        if not module_name.endswith('_thrift'):
            module_name = ''.join([module_name, '_thrift'])
        self.thrift_module = load(config.thrift_file, module_name=module_name) 
開發者ID:elemepi,項目名稱:takumi,代碼行數:22,代碼來源:service.py

示例2: thrift_client

# 需要導入模塊: import thriftpy [as 別名]
# 或者: from thriftpy import load [as 別名]
def thrift_client(cls):
    def cls_wrapper(*args, **kwargs):
        def __getattribute__(self, item):
            thrift_module = object.__getattribute__(self, 'thrift_module')
            service_name = object.__getattribute__(self, '__class__').__name__
            thrift_services = getattr(thrift_module, service_name)
            thrift_services_list = thrift_services.thrift_services
            if item in thrift_services_list:
                return thrift_service_wrapper(object.__getattribute__(self, item))
            else:
                return object.__getattribute__(self, item)

        service_client_instance = cls(*args, **kwargs)
        thrift_file = service_client_instance.thrift_file
        thrift_module_name = os.path.splitext(os.path.basename(thrift_file))[0] + '_thrift'
        thrift_module = thriftpy.load(thrift_file, module_name=thrift_module_name)
        setattr(cls, 'thrift_module', thrift_module)
        setattr(cls, '__getattribute__', __getattribute__)
        return service_client_instance

    return cls_wrapper 
開發者ID:yuyu1987,項目名稱:pithy-test,代碼行數:23,代碼來源:thrift_client.py

示例3: main

# 需要導入模塊: import thriftpy [as 別名]
# 或者: from thriftpy import load [as 別名]
def main():
    """
    @brief: Main
    """

    CLIENT_TIMEOUT = 50000

    spider = thriftpy.load(constant.THRIFT_FILE, module_name="spider_thrift")
    server = make_server(spider.SpiderService, DispatchSpider(), constant.RPC_HOST, 
                             constant.RPC_PORT, client_timeout=CLIENT_TIMEOUT)
    server.serve() 
開發者ID:linzhi,項目名稱:minerva,代碼行數:13,代碼來源:master.py

示例4: __init__

# 需要導入模塊: import thriftpy [as 別名]
# 或者: from thriftpy import load [as 別名]
def __init__(self):
        spider = thriftpy.load(constant.THRIFT_FILE, module_name="spider_thrift")
        self.master_spider = make_client(spider.SpiderService, constant.RPC_HOST, 
                                         constant.RPC_PORT, timeout=self.TIMEOUT)
        
        self.mongo_db = utils.MongoDBHandler(hosts=constant.SPIDER_MONGO_ADDRESS,
                                             db=constant.SPIDER_MONGO_DATABASE) 
開發者ID:linzhi,項目名稱:minerva,代碼行數:9,代碼來源:spider.py

示例5: test_thrift

# 需要導入模塊: import thriftpy [as 別名]
# 或者: from thriftpy import load [as 別名]
def test_thrift():
    return thriftpy.load('tests/test.thrift', module_name='test_thrift') 
開發者ID:ryanwang520,項目名稱:aiothrift,代碼行數:4,代碼來源:conftest.py

示例6: test_obj_equalcheck

# 需要導入模塊: import thriftpy [as 別名]
# 或者: from thriftpy import load [as 別名]
def test_obj_equalcheck():
    ab = thriftpy.load("addressbook.thrift")
    ab2 = thriftpy.load("addressbook.thrift")

    assert ab.Person(name="hello") == ab2.Person(name="hello") 
開發者ID:adsharma,項目名稱:flattools,代碼行數:7,代碼來源:test_base.py

示例7: test_exc_equalcheck

# 需要導入模塊: import thriftpy [as 別名]
# 或者: from thriftpy import load [as 別名]
def test_exc_equalcheck():
    ab = thriftpy.load("addressbook.thrift")

    assert ab.PersonNotExistsError("exc") != ab.PersonNotExistsError("exc") 
開發者ID:adsharma,項目名稱:flattools,代碼行數:6,代碼來源:test_base.py

示例8: test_cls_equalcheck

# 需要導入模塊: import thriftpy [as 別名]
# 或者: from thriftpy import load [as 別名]
def test_cls_equalcheck():
    ab = thriftpy.load("addressbook.thrift")
    ab2 = thriftpy.load("addressbook.thrift")

    assert ab.Person == ab2.Person 
開發者ID:adsharma,項目名稱:flattools,代碼行數:7,代碼來源:test_base.py

示例9: test_isinstancecheck

# 需要導入模塊: import thriftpy [as 別名]
# 或者: from thriftpy import load [as 別名]
def test_isinstancecheck():
    ab = thriftpy.load("addressbook.thrift")
    ab2 = thriftpy.load("addressbook.thrift")

    assert isinstance(ab.Person(), ab2.Person)
    assert isinstance(ab.Person(name="hello"), ab2.Person)

    assert isinstance(ab.PersonNotExistsError(), ab2.PersonNotExistsError) 
開發者ID:adsharma,項目名稱:flattools,代碼行數:10,代碼來源:test_base.py

示例10: test_hashable

# 需要導入模塊: import thriftpy [as 別名]
# 或者: from thriftpy import load [as 別名]
def test_hashable():
    ab = thriftpy.load("addressbook.thrift")

    # exception is hashable
    hash(ab.PersonNotExistsError("test error"))

    # container struct is not hashable
    with pytest.raises(TypeError):
        hash(ab.Person(name="Tom")) 
開發者ID:adsharma,項目名稱:flattools,代碼行數:11,代碼來源:test_base.py

示例11: test_parse_spec

# 需要導入模塊: import thriftpy [as 別名]
# 或者: from thriftpy import load [as 別名]
def test_parse_spec():
    ab = thriftpy.load("addressbook.thrift")

    cases = [
        ((TType.I32, None), "I32"),
        ((TType.STRUCT, ab.PhoneNumber), "PhoneNumber"),
        ((TType.LIST, TType.I32), "LIST<I32>"),
        ((TType.LIST, (TType.STRUCT, ab.PhoneNumber)), "LIST<PhoneNumber>"),
        ((TType.MAP, (TType.STRING, (
            TType.LIST, (TType.MAP, (TType.STRING, TType.STRING))))),
         "MAP<STRING, LIST<MAP<STRING, STRING>>>")
    ]

    for spec, res in cases:
        assert parse_spec(*spec) == res 
開發者ID:adsharma,項目名稱:flattools,代碼行數:17,代碼來源:test_base.py

示例12: test_init_func

# 需要導入模塊: import thriftpy [as 別名]
# 或者: from thriftpy import load [as 別名]
def test_init_func():
    thriftpy.load("addressbook.thrift")
    assert linecache.getline('<generated PhoneNumber.__init__>', 1) != '' 
開發者ID:adsharma,項目名稱:flattools,代碼行數:5,代碼來源:test_base.py

示例13: test_set

# 需要導入模塊: import thriftpy [as 別名]
# 或者: from thriftpy import load [as 別名]
def test_set():
    s = load("type.thrift")

    assert s.Set.thrift_spec == {1: (TType.SET, "a_set", TType.STRING, True)} 
開發者ID:adsharma,項目名稱:flattools,代碼行數:6,代碼來源:test_type.py

示例14: test_import_hook

# 需要導入模塊: import thriftpy [as 別名]
# 或者: from thriftpy import load [as 別名]
def test_import_hook():
    ab_1 = thriftpy.load("addressbook.thrift")
    print("Load file succeed.")
    assert ab_1.DEFAULT_LIST_SIZE == 10

    try:
        import addressbook_thrift as ab  # noqa
    except ImportError:
        print("Import hook not installed.")

    thriftpy.install_import_hook()

    import addressbook_thrift as ab_2
    print("Magic import succeed.")
    assert ab_2.DEFAULT_LIST_SIZE == 10 
開發者ID:adsharma,項目名稱:flattools,代碼行數:17,代碼來源:test_hook.py

示例15: test_load

# 需要導入模塊: import thriftpy [as 別名]
# 或者: from thriftpy import load [as 別名]
def test_load():
    ab_1 = thriftpy.load("addressbook.thrift")
    ab_2 = thriftpy.load("addressbook.thrift",
                         module_name="addressbook_thrift")

    assert ab_1.__name__ == "addressbook"
    assert ab_2.__name__ == "addressbook_thrift"

    # load without module_name can't do pickle
    with pytest.raises(pickle.PicklingError):
        pickle.dumps(ab_1.Person(name='Bob'))

    # load with module_name set and it can be pickled
    person = ab_2.Person(name='Bob')
    assert person == pickle.loads(pickle.dumps(person)) 
開發者ID:adsharma,項目名稱:flattools,代碼行數:17,代碼來源:test_hook.py


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