Esempio n. 1
0
def test_duplicate_loads():
    # multiple loads with same module_name returns the same module
    ab_1 = thriftpy2.load("addressbook.thrift",
                          module_name="addressbook_thrift")
    ab_2 = thriftpy2.load("./addressbook.thrift",
                          module_name="addressbook_thrift")
    assert ab_1 == ab_2
Esempio n. 2
0
    def _update_thrift(self):
        """Update client thrift configuration from server.

        The servers thrift configuration must contain at least

          service info { string thrift_content() }

        and the server thrift must run in multiplexed mode.
        """
        if self.thrift_content is None:
            i, fn = tempfile.mkstemp(suffix='.thrift', prefix='rpc-client0-')
            f = os.fdopen(i, mode='w')
            f.write('service %s { string thrift_content() }' %
                    (self.thrift_content_service))
            f.close()
            tmp_thrift = thr.load(fn)
            os.remove(fn)
            if not self.multiplexed:
                factory = thr.protocol.TBinaryProtocolFactory()
            else:
                factory = thr.protocol.TMultiplexedProtocolFactory(
                    thr.protocol.TBinaryProtocolFactory(),
                    self.thrift_content_service)
            service = getattr(tmp_thrift, self.thrift_content_service)
            ctx = thr.rpc.client_context(service,
                                         proto_factory=factory,
                                         **self.options)
            with ctx as c:
                self.thrift_content = c.thrift_content()
        i, fn = tempfile.mkstemp(suffix='.thrift', prefix='rpc-client-')
        f = os.fdopen(i, mode='w')
        f.write(self.thrift_content)
        f.close()
        self.thrift = thr.load(fn)
        os.remove(fn)
Esempio n. 3
0
def test_isinstancecheck():
    ab = thriftpy2.load("addressbook.thrift")
    ab2 = thriftpy2.load("addressbook.thrift")

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

    assert isinstance(ab.PersonNotExistsError(), ab2.PersonNotExistsError)
Esempio n. 4
0
def test_load():
    ab_1 = thriftpy2.load("addressbook.thrift")
    ab_2 = thriftpy2.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))
Esempio n. 5
0
def server_start():
    partition_thrift = thriftpy.load('partition.thrift',
                                     module_name='partition_thrift')
    server = make_server(partition_thrift.Partition, Dispacher(), '127.0.0.1',
                         6000)
    print('Thriftpy server is listening...')
    server.serve()
def test_exceptions(server_func, proto_factory):
    test_thrift = thriftpy2.load("apache_json_test.thrift",
                                 module_name="test_thrift")
    TestException = test_thrift.TestException

    class Handler(object):
        def do_error(self, arg):
            raise TestException(message=arg)

    def do_server():
        server = server_func[0](service=test_thrift.TestService,
                                handler=Handler(),
                                host='localhost',
                                port=9090,
                                proto_factory=proto_factory())
        server.serve()

    proc = Process(target=do_server)
    proc.start()
    time.sleep(0.25)
    msg = "exception raised!"
    with pytest.raises(TestException) as e:
        client = server_func[1](test_thrift.TestService,
                                host='localhost',
                                port=9090,
                                proto_factory=proto_factory())
        client.do_error(msg)
    assert e.value.message == msg

    proc.terminate()
    time.sleep(1)
Esempio n. 7
0
    def __init__(self, args_dict):
        self._POLL_MAX_NUM_MESSAGES = 500
        self._POLL_TIMEOUT = py3utils.ensure_long(10000)

        self._set_args(args_dict)

        self._prefix = self._sandboxid + "-" + self._workflowid + "-"
        self._wf_local = {}

        self._setup_loggers()

        self._state_utils = StateUtils(
            self._function_state_type, self._function_state_name,
            self._function_state_info, self._function_runtime, self._logger,
            self._workflowid, self._sandboxid, self._function_topic,
            self._datalayer, self._storage_userid, self._internal_endpoint)

        # check the runtime
        if self._function_runtime == "java":
            self._api_thrift = thriftpy2.load(
                "/opt/mfn/FunctionWorker/MicroFunctionsAPI.thrift",
                module_name="mfnapi_thrift")

        elif self._function_runtime == "python 3.6":
            # if it is python, load the user code
            sys.path.insert(1, self._function_folder)
            if self._state_utils.isTaskState():
                try:
                    prevdir = os.path.dirname(__file__)
                    #self._logger.debug("dir of functionworker before importing user code: " + prevdir)
                    os.chdir(self._function_folder)
                    # FIXME: need to fix this part for python3 compatibility
                    self.code = imp.load_source(self._function_name,
                                                self._function_path)
                    os.chdir(prevdir)
                    #curdir = os.path.dirname(__file__)
                    #self._logger.debug("dir of functionworker after importing user code: " + curdir)
                except Exception as exc:
                    self._logger.exception("Exception loading user code: %s",
                                           str(exc))
                    sys.stdout.flush()
                    os._exit(1)

        # for retrieving new messages
        self.local_queue_client = LocalQueueClient(connect=self._queue)

        # for storing (key, pid) tuples on the data layer
        # keyspace: hostname + "InstancePidMap"
        # tablename: topic with "_" as separator
        # entries := (key, pid)
        #self._map_name_key_pid = "KeyPidMap_" + self._hostname + "_" + self._function_topic.replace("-", "_").replace(".", "_")
        #self.local_data_layer_client = DataLayerClient(locality=0, sid=self._sandboxid, for_mfn=True, connect=self._datalayer)

        signal(SIGCHLD, SIG_IGN)

        # do this once rather than at every forked process
        if self._state_utils.isTaskState():
            os.chdir(self._function_folder)

        self._is_running = False
Esempio n. 8
0
def todo_thrift():
    return thriftpy2.load(
        os.path.join(
            os.path.dirname(os.path.realpath(__file__)),
            "..",
            "example-thrifts",
            "todo.thrift",
        ))
def __getattr__(name):
    try:
        return _interfaces[name]
    except KeyError:
        interface = thriftpy2.load(
            str(_interfaces_path.joinpath(f"{name}.thrift")))
        _interfaces[name] = interface
        return interface
Esempio n. 10
0
 def __getattr__(name):
     try:
         return _INTERFACES[name]
     except KeyError:
         interface = thriftpy2.load(
             str(_INTERFACES_PATH.joinpath(f"{name}.thrift")))
         _INTERFACES[name] = interface
         return interface
Esempio n. 11
0
    def __init__(self, conf_file):
        parser = ConfigParser(conf_file)
        conf = parser.conf["server"]

        self.microservice_thrift = thriftpy.load(conf["thrift_file"],
                                                 conf["module_name"])
        self.service = getattr(self.microservice_thrift, conf["service_name"])
        self.client = make_client(self.service, conf["host"],
                                  int(conf["port"]))
Esempio n. 12
0
def test_hashable():
    ab = thriftpy2.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"))
Esempio n. 13
0
def main() -> None:
    Utils.configure_logger("log/server.log")
    logger = logging.getLogger(__name__)

    s = schema.Schema({
        "--ipv6": bool,
        "--port": schema.Use(int),
        "--help": bool,
    })

    arguments = s.validate(docopt(__doc__))

    current_script_dir = os.path.dirname(os.path.abspath(__file__))
    thrift_path = os.path.join(current_script_dir,
                               "thrift/logging_service.thrift")
    logger.info(f"Loading the thrift definition from: {thrift_path};")
    logging_service_thrift = thriftpy2.load(
        thrift_path,
        module_name="logging_service_thrift",
    )

    if arguments["--ipv6"]:
        socket_family = socket.AF_INET6
        any_host_interface = "::"
        socket_family_name = "IPv6"
    else:
        socket_family = socket.AF_INET
        any_host_interface = "0.0.0.0"
        socket_family_name = "IPv4"

    server_port = arguments["--port"]

    queue_manager = MemoryQueueManager()
    logging_client = MetaLoggingClient()
    metadata_manager = MetadataManager(queue_manager, logging_client)
    handler = LoggingServiceHandler(metadata_manager, logging_client,
                                    logging_service_thrift)

    proc = TProcessor(logging_service_thrift.LoggingService, handler)
    server = TThreadedServer(
        proc,
        TServerSocket(
            host=any_host_interface,
            socket_family=socket_family,
            port=server_port,
            client_timeout=CLIENT_TIMEOUT_MS,
        ),
        iprot_factory=TBinaryProtocolFactory(),
        itrans_factory=TBufferedTransportFactory(),
    )

    logger.info(
        f"Logging service server listens host={any_host_interface}[{socket_family_name}], port={server_port}."
    )
    server.serve()
    logger.info("done.")
Esempio n. 14
0
def pingpong_thrift_service(request, pingpong_service_key):
    import thriftpy2
    thrift_service = thriftpy2.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
Esempio n. 15
0
    def __init__(self, filename):
        if PY2:
            self.thrift = load(filename.encode("utf-8"))
        else:
            self.thrift = load(filename)
        if not hasattr(self.thrift, "__thrift_meta__"):
            sys.exit(0)
        self.meta = self.thrift.__thrift_meta__

        self.pyi = PYI()
        self.pyi.imports = Imports()
        self.pyi.services = Services()
        self.pyi.structs = Structs()
        self.pyi.unions = Unions()
        self.pyi.enums = Enums()
        self.pyi.exceptions = Exceptions()
        self.pyi.consts = Consts()
        self.filename = filename

        self._imports = defaultdict(set)
        self._module2file = {}
Esempio n. 16
0
    def __init__(self, conf_file):
        parser = ConfigParser(conf_file)
        conf = parser.conf["server"]

        self.microservice_thrift = thriftpy.load(conf["thrift_file"],
                                                 conf["module_name"])
        self.service = getattr(self.microservice_thrift, conf["service_name"])

        self.handler = MakeMockData(self.microservice_thrift,
                                    conf["module_name"], self.service)
        self.handler.init_generator()

        self.server = make_server(self.service, self.handler, conf["host"],
                                  int(conf["port"]))
Esempio n. 17
0
def main():
    sample_payload = "CwFAAAAAAi9pCwBkAAAACTEyNy4wLjAuMQoAyAAAAVjbnjdoC3ppAAAAQWlnbHU6Y29tLnNub3dwbG93YW5hbHl0aWNzLnNub3dwbG93L0NvbGxlY3RvclBheWxvYWQvdGhyaWZ0LzEtMC0wCwFKAAABaHN0bT0xNDgxMTUzMzI5MDAwJmU9cHYmdXJsPWh0dHAlM0ElMkYlMkZzbm93Zmxha2UtYW5hbHl0aWNzLmNvbSZ0dj1qcy0yLjYuMCZ0bmE9anMtMy42LjAmYWlkPXNub3dmbGFrZSZwPXdlYiZ0ej1BdXN0cmFsaWElMkZTeWRuZXkmbGFuZz1lbi1BVSZjcz1VVEYtOCZyZXM9MzYweDY0MCZjZD0zMiZjb29raWU9MSZlaWQ9YzI1OWMyNWUtZjk0Yi00ZDJjLWExMWMtMGQyNzhjMmU2ZDFhJmR0bT0xNDc5OTI3ODU3MjAxJnZwPTB4LTU2JmRzPTIwMHgyNjI5NSZ2aWQ9NCZzaWQ9N2ZiOTdmQzYtNmUwZi00MDIyLWFkYmQtMDE3NDMxNTIwZGRiJmR1aWQ9NGQxMGQzZDAtYzJiNC00NzNlLWE0ODMtODEyNzk5ZTgyNGQxJmZwPTEyOTExMjMzMgsBLAAAAG1Nb3ppbGxhLzUuMCAoV2luZG93cyBOVCAxMC4wOyBXT1c2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzU0LjAuMjg0MC43MSBTYWZhcmkvNTM3LjM2CwGQAAAAIWNvbGxlY3Rvci5zbm93Zmxha2UtYW5hbHl0aWNzLmNvbQsA0gAAAAVVVEYtOAsBNgAAAB9odHRwczovL3Nub3dmbGFrZS1hbmFseXRpY3MuY29tCwGaAAAAJDRkMTBkM2QwLWMyYjQtNDczZS1hNDgzLTgxMjc5OWU4MjRkMQsA3AAAABFzc2MtMC43LjAta2luZXNpcw8BXgsAAAALAAAAJ0hvc3Q6IGNvbGxlY3Rvci5zbm93Zmxha2UtYW5hbHl0aWNzLmNvbQAAAB1BY2NlcHQ6IGltYWdlL3dlYnAsICovKjtxPTAuOAAAACRBY2NlcHQtRW5jb2Rpbmc6IGd6aXAsIGRlZmxhdGUsIHNkY2gAAAA3QWNjZXB0LUxhbmd1YWdlOiBlbi1BVSwgZW47cT0wLjgsIGVuLVVTO3E9MC42LCBlbjtxPTAuNAAAABRDb29raWU6IHNwPWFiY2QtMTIzNAAAACdSZWZlcmVyOiBodHRwOi8vc25vd2ZsYWtlLWFuYWx5dGljcy5jb20AAAB6VXNlci1BZ2VudDogIE1vemlsbGEvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdPVzY0KSBBcHBsZVdlYktpdC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWUvNTQuMC4yODQwLjcxIFNhZmFyaS81MzcuMzYAAAAaWC1Gb3J3YXJkZWQtRm9yOiAxMjcuMC4wLjEAAAAVWC1Gb3J3YXJkZWQtUG9ydDogNDQzAAAAGFgtRm9yd2FyZGVkLVByb3RvOiBodHRwcwAAABZDb25uZWN0aW9uOiBrZWVwLWFsaXZlAA=="
    decoded_payload = base64.b64decode(sample_payload)
    # print(decoded_payload)

    collector = thriftpy2.load("collector-payload.thrift")
    collector_payload = collector.CollectorPayload()
    raw_payload = deserialize(collector_payload, decoded_payload,
                              TCyBinaryProtocolFactory())
    print(raw_payload)

    querystring = raw_payload.querystring
    network_userid = raw_payload.networkUserId
    print(network_userid)
    print(querystring)
Esempio n. 18
0
def pingpong_thrift_service(request, pingpong_service_key):
    import thriftpy2
    thrift_service = thriftpy2.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
Esempio n. 19
0
 def __init__(self,
              schema='../resources/proxy.thrift',
              host="localhost",
              port=50096,
              user='******',
              password='******'):
     self.thrift = thriftpy2.load(schema)
     self.login = None
     self.client = None
     self._conn_params = {
         'host': host,
         'port': port,
         'user': user,
         'password': password
     }
Esempio n. 20
0
def test_import_hook():
    ab_1 = thriftpy2.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.")

    thriftpy2.install_import_hook()

    import addressbook_thrift as ab_2
    print("Magic import succeed.")
    assert ab_2.DEFAULT_LIST_SIZE == 10
Esempio n. 21
0
    def __init__(self):
        self.thrift = thriftpy2.load("line.thrift")

        self.transport = THttpClient(Config.HOST)
        self.transport.setCustomHeaders({
            "User-Agent": Config.UA,
            "X-Line-Application": Config.LA,
            "X-Line-Carrier": Config.CARRIER,
            "X-LHM": "POST",
            "X-lal": "ja-JP_JP"
        })
        self.protocol = TCompactProtocol(self.transport)
        self.transport.open()
        self.client = TClient(self.thrift.Service, self.protocol)
        self.certificate = None
Esempio n. 22
0
def test_parse_spec():
    ab = thriftpy2.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
Esempio n. 23
0
File: client.py Progetto: yelban/LLL
    def __init__(self):
        self.line_thrift = thriftpy2.load(os.path.dirname(__file__) +
                                          "/line.thrift",
                                          module_name="line_thrift")

        self.transport = THttpClient("https://gd2.line.naver.jp:443")
        self.transport.setCustomHeaders({
            "User-Agent": "Line/7.14.0 iPad5,1 10.2.0",
            "X-Line-Application": "IOSIPAD\t7.14.0\tiPhone OS\t10.12.0",
            "X-LHM": "POST",
            "X-lal": "ja-JP_JP"
        })
        self.protocol = TCompactProtocol(self.transport)
        self.transport.open()
        self.client = TClient(self.line_thrift.LineService, self.protocol)
        self._session = requests.session()
Esempio n. 24
0
    def setUp(self):
        thrift_mod = thriftpy.load("tests/test_resources/service.thrift")
        uri = os.environ.get('AMQP_URI',
                             'amqp://*****:*****@localhost:5672/%2f')

        self.multi = Multi(uri)

        responder = Responder(thrift_mod)
        self.responder = responder
        self.client = self.multi.new_client(thrift_mod.TestService,
                                            read_timeout=1)
        self.server = self.multi.new_server(thrift_mod.TestService,
                                            responder,
                                            routing_keys=True)

        self.multi.start()
Esempio n. 25
0
    def setUp(self):
        thrift_mod = thriftpy.load("tests/test_resources/service.thrift")
        uri = os.environ.get('AMQP_URI',
                             'amqp://*****:*****@localhost:5672/%2f')

        self.multi = Multi(uri)

        self.listener_queue = Queue()
        responder = Responder(thrift_mod, self.listener_queue)
        self.responder = responder
        self.sender = self.multi.new_sender(thrift_mod.TestBroadcastService)
        self.listener = self.multi.new_listener(
            thrift_mod.TestBroadcastService, responder, routing_keys=True)
        self.multi.start()

        # Give the listener enough time to start up
        sleep(3)
def test_client(server_func):
    test_thrift = thriftpy2.load("apache_json_test.thrift",
                                 module_name="test_thrift")

    class Handler:
        @staticmethod
        def test(t):
            return t

    def run_server():
        server = make_http_server(test_thrift.TestService,
                                  handler=Handler(),
                                  host='localhost',
                                  port=9090,
                                  proto_factory=TApacheJSONProtocolFactory(),
                                  trans_factory=TBufferedTransportFactory())
        server.serve()

    proc = Process(target=run_server, )
    proc.start()
    time.sleep(0.25)

    try:
        test_object = test_thrift.Test(tdouble=12.3456,
                                       tint=567,
                                       tstr='A test \'{["string',
                                       tmap_of_bool2str={
                                           True: "true string",
                                           False: "false string"
                                       },
                                       tmap_of_bool2int={
                                           True: 0,
                                           False: 1
                                       })

        client = make_http_client(test_thrift.TestService,
                                  host='localhost',
                                  port=9090,
                                  proto_factory=TApacheJSONProtocolFactory(),
                                  trans_factory=TBufferedTransportFactory())
        res = client.test(test_object)
        assert recursive_vars(res) == recursive_vars(test_object)
    finally:
        proc.terminate()
    time.sleep(1)
Esempio n. 27
0
 def __init__(self, dispatcher, thrift_file, **options):
     self.multiplexed = options.pop('multiplexed', True)
     self.thrift_content_service = options.pop(
         'thrift_content_service', 'info')
     thrift_content = options.pop('thrift_content', None)
     self.options = options
     module_name = os.path.splitext(
         os.path.abspath(thrift_file))[0]+'_thrift'
     self._dispatcher = dispatcher
     self.thrift_file = thrift_file
     if thrift_content is None:
         thrift_content = utils.resolve_includes(
             open(thrift_file).read(), [os.path.dirname(thrift_file)])
     i, fn = tempfile.mkstemp(suffix='.thrift', prefix='rpc-server-')
     f = os.fdopen(i, mode='w')
     f.write(thrift_content)
     f.close()
     self.thrift = thr.load(fn, module_name=module_name)
     os.remove(fn)
Esempio n. 28
0
    def __init__(
        self,
        server_host: str,
        server_port: int,
    ) -> None:
        self.logger: logging.Logger = logging.getLogger(__name__)

        current_script_dir = os.path.dirname(os.path.abspath(__file__))
        thrift_path = os.path.join(
            current_script_dir, "../../server/thrift/logging_service.thrift"
        )
        self.logger.info(f"Loading the thrift definition from: {thrift_path};")
        self.logging_service_thrift: ModuleType = thriftpy2.load(
            thrift_path,
            module_name="logging_service_thrift",
        )

        self.client: Optional[TClient] = None
        self._init_thrift_client(server_host, server_port)
Esempio n. 29
0
def PingServiceThriftpy(make_test_thrift):
    import thriftpy2
    pingpong_thrift = thriftpy2.load("tests/pingpong.thrift")
    return pingpong_thrift.PingService
Esempio n. 30
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import time
import thriftpy2
from thriftpy2.thrift import TProcessor

thrift_service = thriftpy2.load(os.path.join(os.path.dirname(__file__), "pingpong.thrift"), "pingpong_thrift")  # noqa
service = thrift_service.PingService


class PingpongServer(object):
    def ping(self):
        if os.environ.get('about_to_shutdown') == '1':
            raise service.AboutToShutDownException
        return "pong"

    def win(self):
        return "Yes, you win"

    def sleep(self, seconds):
        time.sleep(seconds)
        return 'good morning'


app = TProcessor(service, PingpongServer())
Esempio n. 31
0
from __future__ import print_function
import os
import time
from multiprocessing import Process

import thriftpy2
from thriftpy2.rpc import make_client, make_server

cdir = os.path.dirname(os.path.realpath(__file__))
test_thrift = thriftpy2.load(cdir + "/spec.thrift")
Bar = test_thrift.Bar
Foo = test_thrift.Foo


def test_img():
    with open(cdir + "/test.png", 'rb') as infile:
        data = infile.read()
    obj = Bar(tbinary=data, tlist_of_binary=[b'a binary string'])

    class Handler(object):
        def test(self, t):
            return t

    def do_server():
        server = make_server(service=test_thrift.BarService,
                             handler=Handler(),
                             host='localhost',
                             port=9090)
        server.serve()

    proc = Process(target=do_server)
Esempio n. 32
0
# -*- coding: utf-8 -*-

import thriftpy2
import math
import random
from pynput.keyboard import Key, Listener
from thriftpy2.rpc import client_context
from thriftpy2.protocol import TCyBinaryProtocolFactory
from thriftpy2.transport import TCyBufferedTransportFactory
from datetime import datetime
from datetime import timedelta
from croniter import croniter

from event import Event

sc_thrift = thriftpy2.load("simple_clash.thrift", module_name="sc_thrift")


class Client:
    def __init__(self, context):
        self.running = True
        self.context = context
        self.user_id = self.create_account()
        time_now = datetime.now()
        self.install_time = time_now.replace(
            minute=math.floor(time_now.minute / 5) * 5,
            second=0,
            microsecond=0)
        self.cur_time = self.install_time
        self.session_count = 0
        self.session_limit = 1000
Esempio n. 33
0
    from impala._thrift_gen.RuntimeProfile.ttypes import TRuntimeProfileFormat

if six.PY3:
    # import thriftpy2 code
    from thriftpy2 import load
    from thriftpy2.protocol.binary import TBinaryProtocol
    from thrift.transport.THttpClient import THttpClient
    from thrift.Thrift import TApplicationException
    from thrift.transport.TSocket import TSocket
    from thrift.transport.TTransport import (TBufferedTransport,
                                             TTransportException)
    from thriftpy2.thrift import TClient
    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])
    RuntimeProfile = load(os.path.join(thrift_dir, 'RuntimeProfile.thrift'),
                          include_dirs=[thrift_dir])
    sys.modules[ExecStats.__name__] = ExecStats
    sys.modules[TCLIService.__name__] = TCLIService
    sys.modules[ImpalaService.__name__] = ImpalaService
    sys.modules[RuntimeProfile.__name__] = RuntimeProfile

    # import the HS2 objects
    from TCLIService import (  # noqa
        TOpenSessionReq, TFetchResultsReq, TCloseSessionReq,
        TExecuteStatementReq, TGetInfoReq, TGetInfoType, TTypeId,
Esempio n. 34
0
# -*- coding: utf-8 -*-
from __future__ import print_function

import thriftpy2
from thrift_connector import ClientPool, ThriftPyCyClient

service = thriftpy2.load("pingpong_app/pingpong.thrift")
pool = ClientPool(
    service.PingService,
    'localhost',
    8880,
    connection_class=ThriftPyCyClient
    )

print("Sending Ping...")
print("Receive:", pool.ping())
print("Winning the match...")
print("Receive:", pool.win())
Esempio n. 35
0
"""
HappyBase, a developer-friendly Python library to interact with Apache
HBase.
"""

import pkg_resources as _pkg_resources
import thriftpy2 as _thriftpy
_thriftpy.load(
    _pkg_resources.resource_filename('happybase', 'Hbase.thrift'),
    'Hbase_thrift')

from ._version import __version__  # noqa

from .connection import DEFAULT_HOST, DEFAULT_PORT, Connection  # noqa
from .table import Table  # noqa
from .batch import Batch  # noqa
from .pool import ConnectionPool, NoConnectionsAvailable  # noqa
Esempio n. 36
0
if six.PY3:
    # import thriftpy2 code
    from thriftpy2 import load
    from thriftpy2.thrift import TClient, TApplicationException
    # TODO: reenable cython
    # from thriftpy2.protocol import TBinaryProtocol
    from thriftpy2.protocol.binary import TBinaryProtocol  # noqa
    from thriftpy2.transport import TSocket, TTransportException  # noqa
    # TODO: reenable cython
    # from thriftpy2.transport import TBufferedTransport
    from thriftpy2.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])
    RuntimeProfile = load(os.path.join(thrift_dir, 'RuntimeProfile.thrift'),
                          include_dirs=[thrift_dir])
    sys.modules[ExecStats.__name__] = ExecStats
    sys.modules[TCLIService.__name__] = TCLIService
    sys.modules[ImpalaService.__name__] = ImpalaService
    sys.modules[RuntimeProfile.__name__] = RuntimeProfile

    # import the HS2 objects
    from TCLIService import (  # noqa
        TOpenSessionReq, TFetchResultsReq, TCloseSessionReq,
        TExecuteStatementReq, TGetInfoReq, TGetInfoType, TTypeId,
Esempio n. 37
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os

import thriftpy2
from thriftpy2.thrift import TProcessor


pingpong_thrift = thriftpy2.load(
    os.path.join(
        os.path.dirname(__file__),
        "pingpong.thrift"
        )
    )
PingService = pingpong_thrift.PingService


class PingpongServer(object):
    def ping(self):
        if os.environ.get('about_to_shutdown') == '1':
            raise pingpong_thrift.AboutToShutDownException
        return "pong"


app = TProcessor(pingpong_thrift.PingService, PingpongServer())
Esempio n. 38
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# FileName  : thrift_client.py
# Author    : wuqingfeng@

import thriftpy2
from thriftpy2.rpc import make_client


if __name__ == '__main__':
    time_thrift = thriftpy2.load("time_service.thrift", module_name="time_thrift")
    client = make_client(time_thrift.TimeService, '127.0.0.1', 6000)

    print(client.get_time())