Exemplo n.º 1
0
 def __init__(self, *args):
     if (len(args) == 2):
         self.__initArgs__(args[0], args[1],
                           TTransport.TTransportFactoryBase(),
                           TTransport.TTransportFactoryBase(),
                           TBinaryProtocol.TBinaryProtocolFactory(),
                           TBinaryProtocol.TBinaryProtocolFactory())
     elif (len(args) == 4):
         self.__initArgs__(args[0], args[1], args[2], args[2], args[3],
                           args[3])
     elif (len(args) == 6):
         self.__initArgs__(args[0], args[1], args[2], args[3], args[4],
                           args[5])
Exemplo n.º 2
0
    def open_SSL(self, ip, port, timeout, ssl_config=None):
        """open the SSL connection

        :param ip: the server ip
        :param port: the server port
        :param timeout: the timeout for connect and execute
        :ssl_config: configs for SSL
        :return: void
        """
        self._ip = ip
        self._port = port
        self._timeout = timeout
        try:
            if ssl_config is not None:
                s = TSSLSocket.TSSLSocket(
                    self._ip, self._port, ssl_config.unix_socket,
                    ssl_config.ssl_version, ssl_config.cert_reqs,
                    ssl_config.ca_certs, ssl_config.verify_name,
                    ssl_config.keyfile, ssl_config.certfile,
                    ssl_config.allow_weak_ssl_versions)
            else:
                s = TSocket.TSocket(self._ip, self._port)
            if timeout > 0:
                s.setTimeout(timeout)
            transport = TTransport.TBufferedTransport(s)
            protocol = TBinaryProtocol.TBinaryProtocol(transport)
            transport.open()
            self._connection = GraphService.Client(protocol)
            resp = self._connection.verifyClientVersion(
                VerifyClientVersionReq())
            if resp.error_code != ErrorCode.SUCCEEDED:
                self._connection._iprot.trans.close()
                raise ClientServerIncompatibleException(resp.error_msg)
        except Exception:
            raise
Exemplo n.º 3
0
def establish_a_rare_connection(pytestconfig):
    addr = pytestconfig.getoption("address")
    host_addr = addr.split(":") if addr else ["localhost", get_ports()[0]]
    socket = TSocket.TSocket(host_addr[0], host_addr[1])
    transport = TTransport.TBufferedTransport(socket)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    transport.open()
    return GraphService.Client(protocol)
Exemplo n.º 4
0
 def get_connection(ip, port):
     try:
         socket = TSocket.TSocket(ip, port)
         transport = TTransport.TBufferedTransport(socket)
         protocol = TBinaryProtocol.TBinaryProtocol(transport)
         transport.open()
         connection = GraphService.Client(protocol)
     except Exception as ex:
         assert False, 'Create connection to {}:{} failed'.format(
             ip, port)
     return connection
Exemplo n.º 5
0
 def open(self):
     try:
         self.close()
         s = TSocket.TSocket(self._leader[0], self._leader[1])
         if self._timeout > 0:
             s.setTimeout(self._timeout)
         transport = TTransport.TBufferedTransport(s)
         protocol = TBinaryProtocol.TBinaryProtocol(transport)
         transport.open()
         self._connection = MetaService.Client(protocol)
     except Exception:
         raise
Exemplo n.º 6
0
 def open(self):
     try:
         self.close()
         s = TSocket.TSocket(self._address.host, self._address.port)
         if self._timeout > 0:
             s.setTimeout(self._timeout)
         transport = TTransport.TBufferedTransport(s)
         protocol = TBinaryProtocol.TBinaryProtocol(transport)
         transport.open()
         self._connection = GraphStorageService.Client(protocol)
     except Exception:
         raise
Exemplo n.º 7
0
 def open(self, ip, port, timeout):
     self._ip = ip
     self._port = port
     try:
         s = TSocket.TSocket(self._ip, self._port)
         if timeout > 0:
             s.setTimeout(timeout)
         transport = TTransport.TBufferedTransport(s)
         protocol = TBinaryProtocol.TBinaryProtocol(transport)
         transport.open()
         self._connection = GraphService.Client(protocol)
     except Exception:
         raise
Exemplo n.º 8
0
    def _get_client_by_transport(self, config, transport, socket=None):
        # Create the protocol and client
        if config.compact:
            protocol = TCompactProtocol.TCompactProtocol(transport)
        # No explicit option about protocol is specified. Try to infer.
        elif config.framed or config.unframed:
            protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
        elif socket is not None:
            protocol = THeaderProtocol.THeaderProtocol(socket)
            transport = protocol.trans
        else:
            raise ValueError("No protocol specified for HTTP Transport")
        transport.open()
        self._transport = transport

        client = self.client_class(protocol)
        return client
Exemplo n.º 9
0
    def _get_client_by_transport(self, options, transport, socket=None):
        # Create the protocol and client
        if options.json:
            protocol = TJSONProtocol.TJSONProtocol(transport)
        elif options.compact:
            protocol = TCompactProtocol.TCompactProtocol(transport)

        # No explicit option about protocol is specified. Try to infer.
        elif options.framed or options.unframed:
            protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)

        elif socket is not None:
            # If json, compact, framed, and unframed are not specified,
            # THeaderProtocol is the default. Create a protocol using either
            # fuzzy or non-fuzzy transport depending on if options.fuzz is set.
            if options.fuzz is not None:
                transport = TFuzzyHeaderTransport(
                    socket, fuzz_fields=options.fuzz, verbose=True)
            else:
                transport = THeaderTransport(socket)
                if options.headers is not None:
                    try:
                        parsed_headers = eval(options.headers)
                    except Exception:
                        self._exit(
                            error_message='Request headers (--headers) argument'
                                          ' failed eval')
                    if not isinstance(parsed_headers, dict):
                        self._exit(
                            error_message='Request headers (--headers) argument'
                                          ' must evaluate to a dict')
                    for header_name, header_value in parsed_headers.items():
                        transport.set_header(header_name, header_value)
            protocol = THeaderProtocol.THeaderProtocol(transport)
        else:
            self._exit(error_message=('No valid protocol '
                                      'specified for %s' % (type(self))),
                       status=os.EX_USAGE)

        transport.open()
        self._transport = transport

        client = self.service_class.Client(protocol)

        return client
Exemplo n.º 10
0
    def open(self, ip, port, timeout):
        """open the connection

        :param ip: the server ip
        :param port: the server port
        :param timeout: the timeout for connect and execute
        :return: void
        """
        self._ip = ip
        self._port = port
        self._timeout = timeout
        s = TSocket.TSocket(self._ip, self._port)
        if timeout > 0:
            s.setTimeout(timeout)
        transport = TTransport.TBufferedTransport(s)
        protocol = TBinaryProtocol.TBinaryProtocol(transport)
        transport.open()
        self._connection = GraphService.Client(protocol)
        resp = self._connection.verifyClientVersion(VerifyClientVersionReq())
        if resp.error_code != ErrorCode.SUCCEEDED:
            self._connection._iprot.trans.close()
            raise ClientVersionRejectedException(resp.error_msg)