本文整理汇总了Python中thriftpy.load函数的典型用法代码示例。如果您正苦于以下问题:Python load函数的具体用法?Python load怎么用?Python load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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)
示例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))
示例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)
示例5: __init__
def __init__(self):
if thriftpy._compat.CYTHON:
self.NAME += '+cython'
self.module = thriftpy.load(
'specs/test.thrift',
include_dirs=['specs'],
)
示例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"))
示例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)
示例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')
示例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
示例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
示例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
示例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])
示例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())
示例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,
示例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)