• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python thriftpy.load函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_duplicate_loads

def test_duplicate_loads():
    # multiple loads with same module_name returns the same module
    ab_1 = thriftpy.load("addressbook.thrift",
                         module_name="addressbook_thrift")
    ab_2 = thriftpy.load("./addressbook.thrift",
                         module_name="addressbook_thrift")
    assert ab_1 == ab_2
开发者ID:Dnile,项目名称:thriftpy,代码行数:7,代码来源:test_hook.py


示例2: test_isinstancecheck

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:JinLiYan,项目名称:thriftpy,代码行数:8,代码来源:test_base.py


示例3: test_load

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:Dnile,项目名称:thriftpy,代码行数:15,代码来源:test_hook.py


示例4: setUp

    def setUp(self):
        test_thrift   = thriftpy.load("test.thrift", module_name="test_thrift")
        self._output_dict   = dict()
        self._thrift_struct = test_thrift.meta()
        self._thrift_struct.name = "abc"
        self._thrift_struct.num  = 128
        self._thrift_struct.desc = "for_lyj_test"
        self._thrift_struct.error_type = 1
        self._thrift_struct.simple_list = [1, 2, 3, 4]
        tmp_list = []
        for i in xrange(1,5):
            tmp = test_thrift.list_test()
            tmp.l_name = "l_name%d" % i
            tmp_list.append(tmp)
        self._thrift_struct.in_list = tmp_list
        tmp = test_thrift.in_meta()
        tmp.more = "more"
        self._thrift_struct.add_more = tmp
        
        tmp_map = dict()
        map_value = test_thrift.test_map_value()
        map_value.value = "abc"
        tmp_map["a"] = map_value
        map_value = test_thrift.test_map_value()
        map_value.value = "abc1"
        tmp_map["b"] = map_value
        self._thrift_struct.test_struct_map = tmp_map

        tmp_map = {"a": 1, "b": 2}
        self._thrift_struct.test_simple_map = tmp_map

        thrift_json_convertor(self._thrift_struct, self._output_dict)
开发者ID:xuanyuanking,项目名称:thrift_json_convertor,代码行数:32,代码来源:test_convertor.py


示例5: __init__

    def __init__(self):
        if thriftpy._compat.CYTHON:
            self.NAME += '+cython'

        self.module = thriftpy.load(
            'specs/test.thrift',
            include_dirs=['specs'],
        )
开发者ID:QratorLabs,项目名称:ritfest2016,代码行数:8,代码来源:thriftpy_adapter.py


示例6: test_hashable

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:JinLiYan,项目名称:thriftpy,代码行数:9,代码来源:test_base.py


示例7: main

def main():
    host            = '127.0.0.1' if len(sys.argv) < 2 else sys.argv[1]
    port            = 9090 if len(sys.argv) < 3 else int(sys.argv[2])
    uniqueid_thrift = thriftpy.load('../protocol/uniqueid.thrift', module_name='uniqueid_thrift')
    client          = make_client(uniqueid_thrift.Uniqueid, host, port)
    request         = uniqueid_thrift.UniqueidRequest()
    request.logid   = random.randint(-2147483648, 2147483647)
    request.serial  = random.randint(0, 9)
    request.length  = random.randint(1, 10)
    response        = client.uniqueid(request)
    print(response)
开发者ID:hatlonely,项目名称:crystal,代码行数:11,代码来源:uniqueid_client.py


示例8: load_thrift

def load_thrift(grammar_file=None):

    """
    Loads and compiles an Apache Thrift file into a module.
    :param grammar_file: The file path to the Apache Thrift file.
    :return: The compiled module.
    """

    import os

    return thriftpy.load(grammar_file, module_name=os.path.splitext(os.path.basename(grammar_file))[0] + '_thrift')
开发者ID:zivia,项目名称:grove,代码行数:11,代码来源:grammar.py


示例9: test_parse_spec

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:JinLiYan,项目名称:thriftpy,代码行数:15,代码来源:test_base.py


示例10: pingpong_thrift_service

def pingpong_thrift_service(request, pingpong_service_key):
    import thriftpy
    thrift_service = thriftpy.load(
        os.path.join(
            os.path.dirname(
                os.path.dirname(
                    os.path.dirname(__file__)
                    )
                ),
            "examples/pingpong_app/pingpong.thrift"),
        "pingpong_thrift")
    service = thrift_service.PingService
    service.AboutToShutDownException = \
        thrift_service.AboutToShutDownException
    return service
开发者ID:air-upc,项目名称:thrift_connector,代码行数:15,代码来源:fixtures.py


示例11: test_import_hook

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:bachp,项目名称:thriftpy,代码行数:15,代码来源:test_hook.py


示例12: _load_thrift

def _load_thrift():
    """Load the Scribe Thrift specification.

    The Thrift files we have are borrowed from the facebook-scribe repository here:
    https://github.com/tomprimozic/scribe-python

    As Scribe is now abandoned (per https://github.com/facebookarchive/scribe),
    it's highly unlikely that the scribe format will ever change.
    """
    # In the event that pkg_resources has to extract the thrift files from e.g.
    # a zip file to some temporary place, this asks it to clean them up
    atexit.register(pkg_resources.cleanup_resources)

    # Call this and discard the return value, just to ensure that this file is
    # available on the filesystem; it's included by scribe.thrift
    pkg_resources.resource_filename('clog', 'fb303.thrift')

    path = pkg_resources.resource_filename('clog', 'scribe.thrift')
    include_dir, fn = os.path.split(path)
    return thriftpy.load(
        fn, module_name='scribe_thrift', include_dirs=[include_dir])
开发者ID:asottile,项目名称:yelp_clog,代码行数:21,代码来源:loggers.py


示例13: DingDispatcher

# -*- coding: utf-8 -*-

import thriftpy
from thriftpy.protocol import TBinaryProtocolFactory
from thriftpy.server import TThreadedServer
from thriftpy.thrift import TProcessor, TMultiplexedProcessor
from thriftpy.transport import TBufferedTransportFactory, TServerSocket


dd_thrift = thriftpy.load("dingdong.thrift", module_name="dd_thrift")
pp_thrift = thriftpy.load("pingpong.thrift", module_name="pp_thrift")

DD_SERVICE_NAME = "dd_thrift"
PP_SERVICE_NAME = "pp_thrift"


class DingDispatcher(object):
    def ding(self):
        print("ding dong!")
        return 'dong'


class PingDispatcher(object):
    def ping(self):
        print("ping pong!")
        return 'pong'


def main():
    dd_proc = TProcessor(dd_thrift.DingService, DingDispatcher())
    pp_proc = TProcessor(pp_thrift.PingService, PingDispatcher())
开发者ID:AllanDaemon,项目名称:thriftpy,代码行数:31,代码来源:multiplexed_server.py


示例14: load

if six.PY3:
    # import thriftpy code
    from thriftpy import load
    from thriftpy.thrift import TClient
    # TODO: reenable cython
    # from thriftpy.protocol import TBinaryProtocol
    from thriftpy.protocol.binary import TBinaryProtocol  # noqa
    from thriftpy.transport import TSocket, TTransportException  # noqa
    # TODO: reenable cython
    # from thriftpy.transport import TBufferedTransport
    from thriftpy.transport.buffered import TBufferedTransport  # noqa
    thrift_dir = os.path.join(os.path.dirname(__file__), 'thrift')

    # dynamically load the HS2 modules
    ExecStats = load(os.path.join(thrift_dir, 'ExecStats.thrift'),
                     include_dirs=[thrift_dir])
    TCLIService = load(os.path.join(thrift_dir, 'TCLIService.thrift'),
                       include_dirs=[thrift_dir])
    ImpalaService = load(os.path.join(thrift_dir, 'ImpalaService.thrift'),
                         include_dirs=[thrift_dir])
    sys.modules[ExecStats.__name__] = ExecStats
    sys.modules[TCLIService.__name__] = TCLIService
    sys.modules[ImpalaService.__name__] = ImpalaService

    # import the HS2 objects
    from TCLIService import (  # noqa
        TOpenSessionReq, TFetchResultsReq, TCloseSessionReq,
        TExecuteStatementReq, TGetInfoReq, TGetInfoType, TTypeId,
        TFetchOrientation, TGetResultSetMetadataReq, TStatusCode,
        TGetColumnsReq, TGetSchemasReq, TGetTablesReq, TGetFunctionsReq,
        TGetOperationStatusReq, TOperationState, TCancelOperationReq,
开发者ID:MrMaynard,项目名称:sqlbench,代码行数:31,代码来源:_thrift_api.py


示例15: __init__

 def __init__(self, address, port=9196):
     thrift = load(resource_filename(__name__, "static/yaoguang.thrift"), module_name="yaoguang_thrift")
     self._client = make_client(thrift.ThriftInterface, address, port)
开发者ID:TaskForceX,项目名称:yaoguang-python-client,代码行数:3,代码来源:entity.py


示例16: ServerError

# coding: utf-8

import os
import thriftpy
import json
import logging

from thriftpy.rpc import make_client

LIMIT = 1000

logger = logging.getLogger(__name__)


articlemeta_thrift = thriftpy.load(
    os.path.join(os.path.dirname(__file__)) + '/articlemeta.thrift')


class ServerError(Exception):
    def __init__(self, message=None):
        self.message = message or 'thirftclient: ServerError'

    def __str__(self):
        return repr(self.message)


class ArticleMeta(object):

    def __init__(self, address, port):
        """
        Cliente thrift para o Articlemeta.
开发者ID:jfunez,项目名称:opac_proc,代码行数:31,代码来源:am_clients.py


示例17: test_init_func

def test_init_func():
    thriftpy.load("addressbook.thrift")
    assert linecache.getline('<generated PhoneNumber.__init__>', 1) != ''
开发者ID:JinLiYan,项目名称:thriftpy,代码行数:3,代码来源:test_base.py


示例18:

from __future__ import absolute_import

import os
import thriftpy

cassandra_thrift = thriftpy.load(os.path.join(os.path.dirname(os.path.realpath(__file__)), "cassandra-v20.thrift"), module_name="cassandra_thrift")
开发者ID:pista329,项目名称:pycassa-thriftpy,代码行数:6,代码来源:client.py


示例19: load

from sys import argv
from uuid import uuid4
from multiprocessing import Process, Value
from thriftpy import load
from thriftpy.rpc import make_client
from thriftpy.transport import TFramedTransportFactory
echo_thrift = load("/app/sh/echo.thrift", module_name="echo_thrift")


def handleClient(num, actual):
    # Open independent client connection
    client = make_client(service=echo_thrift.Echo, host='127.0.0.1',
                         port=9999, trans_factory=TFramedTransportFactory())

    # UUID
    uid = str(uuid4())

    for i in range(num):
        # Make thrift call and increment atomic count
        txt = uid + str(i)
        ret = client.echo(echo_thrift.Message(text=txt))
        if (txt == ret):
            with actual.get_lock():
                actual.value += 1


# Parse command line arguments
# Number of requests each client will make
num = int(argv[1])

# Number of concurrent clients to run
开发者ID:ryyan,项目名称:thrift-benchmark,代码行数:31,代码来源:client.py


示例20:

import thriftpy
pingpong_thrift = thriftpy.load("pingpong.thrift", module_name="pingpong_thrift")

from thriftpy.rpc import make_client

client = make_client(pingpong_thrift.PingPong, '127.0.0.1', 6000)
client.ping()
开发者ID:ahjdzx,项目名称:python_work,代码行数:7,代码来源:client.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python cybin.read_val函数代码示例发布时间:2022-05-27
下一篇:
Python thrift_tests.get_thrift_client函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap