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


Python TSocket.TSocket方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from thrift.transport import TSocket [as 別名]
# 或者: from thrift.transport.TSocket import TSocket [as 別名]
def __init__(self,
               host=None,
               port=9090,
               certfile='cert.pem',
               unix_socket=None):
    """Initialize a TSSLServerSocket

    @param certfile: filename of the server certificate, defaults to cert.pem
    @type certfile: str
    @param host: The hostname or IP to bind the listen socket to,
                 i.e. 'localhost' for only allowing local network connections.
                 Pass None to bind to all interfaces.
    @type host: str
    @param port: The port to listen on for inbound connections.
    @type port: int
    """
    self.setCertfile(certfile)
    TSocket.TServerSocket.__init__(self, host, port) 
開發者ID:XiaoMi,項目名稱:galaxy-sdk-python,代碼行數:20,代碼來源:TSSLSocket.py

示例2: accept

# 需要導入模塊: from thrift.transport import TSocket [as 別名]
# 或者: from thrift.transport.TSocket import TSocket [as 別名]
def accept(self):
        plain_client, addr = self.handle.accept()
        try:
            client = self._wrap_socket(plain_client)
        except (ssl.SSLError, OSError):
            logger.exception('EROR DISINI SOB %s', addr)
            plain_client.close()
            return None
        if self._should_verify:
            client.peercert = client.getpeercert()
            try:
                self._validate_callback(client.peercert, addr[0])
                client.is_valid = True
            except Exception:
                logger.warn('Failed to validate client certificate address: %s',
                            addr[0], exc_info=True)
                client.close()
                plain_client.close()
                return None
        result = TSocket.TSocket()
        result.handle = client
        return result
# BAHAGIALAH KAWAN 
開發者ID:stya535,項目名稱:SOLO,代碼行數:25,代碼來源:TSSLSocket.py

示例3: get_socket

# 需要導入模塊: from thrift.transport import TSocket [as 別名]
# 或者: from thrift.transport.TSocket import TSocket [as 別名]
def get_socket(host, port, use_ssl, ca_cert):
    # based on the Impala shell impl
    log.debug('get_socket: host=%s port=%s use_ssl=%s ca_cert=%s',
              host, port, use_ssl, ca_cert)

    if use_ssl:
        if six.PY2:
            from thrift.transport.TSSLSocket import TSSLSocket
            if ca_cert is None:
                return TSSLSocket(host, port, validate=False)
            else:
                return TSSLSocket(host, port, validate=True, ca_certs=ca_cert)
        else:
            from thriftpy2.transport.sslsocket import TSSLSocket
            if ca_cert is None:
                return TSSLSocket(host, port, validate=False)
            else:
                return TSSLSocket(host, port, validate=True, cafile=ca_cert)
    else:
        return TSocket(host, port) 
開發者ID:cloudera,項目名稱:impyla,代碼行數:22,代碼來源:_thrift_api.py

示例4: __init__

# 需要導入模塊: from thrift.transport import TSocket [as 別名]
# 或者: from thrift.transport.TSocket import TSocket [as 別名]
def __init__(self, node=None, host=None, port=None, ks_name='ks', cf_name='cf',
                 cassandra_interface='11'):
        """
        initializes the connection.
         - node: a ccm node. If supplied, the host and port, and cassandra_interface
           will be pulled from the node.
         - host, port: overwritten if node is supplied
         - ks_name, cf_name: all operations are done on the supplied ks and cf
         - cassandra_interface: '07' and '11' are currently supported. This is the
           thrift interface to cassandra. '11' suffices for now except when creating
           keyspaces against cassandra0.7, in which case 07 must be used.
        """
        if node:
            host, port = node.network_interfaces['thrift']
        self.node = node
        self.host = host
        self.port = port
        self.cassandra_interface = cassandra_interface

        # import the correct version of the cassandra thrift interface
        # and set self.Cassandra as the imported module
        module_name = 'cassandra-thrift.v%s' % cassandra_interface
        imp = __import__(module_name, globals(), locals(), ['Cassandra'])
        self.Cassandra = imp.Cassandra

        socket = TSocket.TSocket(host, port)
        self.transport = TTransport.TFramedTransport(socket)
        protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
        self.client = self.Cassandra.Client(protocol)

        socket.open()
        self.open_socket = True

        self.ks_name = ks_name
        self.cf_name = cf_name 
開發者ID:apache,項目名稱:cassandra-dtest,代碼行數:37,代碼來源:putget_test.py

示例5: get_thrift_client

# 需要導入模塊: from thrift.transport import TSocket [as 別名]
# 或者: from thrift.transport.TSocket import TSocket [as 別名]
def get_thrift_client(host='127.0.0.1', port=9160):
    socket = TSocket.TSocket(host, port)
    transport = TTransport.TFramedTransport(socket)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    client = Cassandra.Client(protocol)
    client.transport = transport
    return client 
開發者ID:apache,項目名稱:cassandra-dtest,代碼行數:9,代碼來源:thrift_test.py

示例6: __init__

# 需要導入模塊: from thrift.transport import TSocket [as 別名]
# 或者: from thrift.transport.TSocket import TSocket [as 別名]
def __init__(self, host, port):
        self.host = host
        self.port = port
        transport = TSocket.TSocket(host, port)
        self.transport = TTransport.TFramedTransport(transport)
        self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
        self.client = Nimbus.Client(self.protocol) 
開發者ID:dispel4py,項目名稱:dispel4py,代碼行數:9,代碼來源:client.py

示例7: __init__

# 需要導入模塊: from thrift.transport import TSocket [as 別名]
# 或者: from thrift.transport.TSocket import TSocket [as 別名]
def __init__(self, host=None, port=9090, *args, **kwargs):
        """Positional arguments: ``host``, ``port``, ``unix_socket``

        Keyword arguments: ``keyfile``, ``certfile``, ``cert_reqs``, ``ssl_version``,
                           ``ca_certs``, ``ciphers`` (Python 2.7.0 or later)
        See ssl.wrap_socket documentation.

        Alternative keyword arguments: (Python 2.7.9 or later)
          ``ssl_context``: ssl.SSLContext to be used for SSLContext.wrap_socket
          ``server_hostname``: Passed to SSLContext.wrap_socket

        Common keyword argument:
          ``validate_callback`` (cert, hostname) -> None:
              Called after SSL handshake. Can raise when hostname does not
              match the cert.
        """
        if args:
            if len(args) > 3:
                raise TypeError('Too many positional argument')
            if not self._unix_socket_arg(host, port, args, kwargs):
                self._deprecated_arg(args, kwargs, 0, 'certfile')
            self._deprecated_arg(args, kwargs, 1, 'unix_socket')
            self._deprecated_arg(args, kwargs, 2, 'ciphers')

        if 'ssl_context' not in kwargs:
            # Preserve existing behaviors for default values
            if 'cert_reqs' not in kwargs:
                kwargs['cert_reqs'] = ssl.CERT_NONE
            if'certfile' not in kwargs:
                kwargs['certfile'] = 'cert.pem'

        unix_socket = kwargs.pop('unix_socket', None)
        self._validate_callback = \
            kwargs.pop('validate_callback', _match_hostname)
        TSSLBase.__init__(self, True, None, kwargs)
        TSocket.TServerSocket.__init__(self, host, port, unix_socket)
        if self._should_verify and not _match_has_ipaddress:
            raise ValueError('Need ipaddress and backports.ssl_match_hostname '
                             'module to verify client certificate') 
開發者ID:Aditmadzs,項目名稱:Protect4,代碼行數:41,代碼來源:TSSLSocket.py

示例8: accept

# 需要導入模塊: from thrift.transport import TSocket [as 別名]
# 或者: from thrift.transport.TSocket import TSocket [as 別名]
def accept(self):
        plain_client, addr = self.handle.accept()
        try:
            client = self._wrap_socket(plain_client)
        except ssl.SSLError:
            logger.exception('Error while accepting from %s', addr)
            # failed handshake/ssl wrap, close socket to client
            plain_client.close()
            # raise
            # We can't raise the exception, because it kills most TServer derived
            # serve() methods.
            # Instead, return None, and let the TServer instance deal with it in
            # other exception handling.  (but TSimpleServer dies anyway)
            return None

        if self._should_verify:
            client.peercert = client.getpeercert()
            try:
                self._validate_callback(client.peercert, addr[0])
                client.is_valid = True
            except Exception:
                logger.warn('Failed to validate client certificate address: %s',
                            addr[0], exc_info=True)
                client.close()
                plain_client.close()
                return None

        result = TSocket.TSocket()
        result.handle = client
        return result 
開發者ID:Aditmadzs,項目名稱:Protect4,代碼行數:32,代碼來源:TSSLSocket.py

示例9: connectHBase

# 需要導入模塊: from thrift.transport import TSocket [as 別名]
# 或者: from thrift.transport.TSocket import TSocket [as 別名]
def connectHBase():
    '''
    連接遠程HBase
    :return: 連接HBase的客戶端實例
    '''
    # thrift默認端口是9090
    socket = TSocket.TSocket('10.0.86.245',9090) # 10.0.86.245是master結點ip
    socket.setTimeout(5000)
    transport = TTransport.TBufferedTransport(socket)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    client = Hbase.Client(protocol)
    socket.open()
    return client 
開發者ID:SparksFly8,項目名稱:Learning_Python,代碼行數:15,代碼來源:python3_thrift_hbase2.py

示例10: get_socket_factory

# 需要導入模塊: from thrift.transport import TSocket [as 別名]
# 或者: from thrift.transport.TSocket import TSocket [as 別名]
def get_socket_factory(self):
        from thrift.transport import TSocket
        return TSocket.TSocket 
開發者ID:Thriftpy,項目名稱:thrift_connector,代碼行數:5,代碼來源:connection_pool.py

示例11: connect

# 需要導入模塊: from thrift.transport import TSocket [as 別名]
# 或者: from thrift.transport.TSocket import TSocket [as 別名]
def connect(self):
        self.transport = TSocket(self.host, self.port)
        self.transport = TBufferedTransport(self.transport)
        protocol = TBinaryProtocol(self.transport)
        self.client = Client(protocol)
        self.transport.open() 
開發者ID:snower,項目名稱:forsun,代碼行數:8,代碼來源:__init__.py

示例12: _check_open

# 需要導入模塊: from thrift.transport import TSocket [as 別名]
# 或者: from thrift.transport.TSocket import TSocket [as 別名]
def _check_open():
    """
    Test to see if OmniSci running on localhost and socket open
    """
    socket = TSocket.TSocket("localhost", 6274)
    transport = TTransport.TBufferedTransport(socket)

    try:
        transport.open()
        return True
    except TTransportException:
        return False 
開發者ID:omnisci,項目名稱:pymapd,代碼行數:14,代碼來源:conftest.py

示例13: get_client

# 需要導入模塊: from thrift.transport import TSocket [as 別名]
# 或者: from thrift.transport.TSocket import TSocket [as 別名]
def get_client():
    transport = TSocket.TSocket('localhost', 8200)
    transport = TTransport.TBufferedTransport(transport)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    client = PasteFileService.Client(protocol)
    transport.open()
    return client 
開發者ID:dongweiming,項目名稱:web_develop,代碼行數:9,代碼來源:client.py

示例14: __init__

# 需要導入模塊: from thrift.transport import TSocket [as 別名]
# 或者: from thrift.transport.TSocket import TSocket [as 別名]
def __init__(self, host='localhost', port=9500, framed_transport=False, use_ssl=False, **kwargs):
        """
        :arg framed_transport: use `TTransport.TFramedTransport` instead of
            `TTransport.TBufferedTransport`
        """
        if not THRIFT_AVAILABLE:
            raise ImproperlyConfigured("Thrift is not available.")

        super(ThriftConnection, self).__init__(host=host, port=port, **kwargs)
        self._framed_transport = framed_transport
        self._tsocket_class = TSocket.TSocket
        if use_ssl:
            self._tsocket_class = TSSLSocket.TSSLSocket 
        self._tsocket_args = (host, port) 
開發者ID:hvandenb,項目名稱:splunk-elasticsearch,代碼行數:16,代碼來源:thrift.py

示例15: __init__

# 需要導入模塊: from thrift.transport import TSocket [as 別名]
# 或者: from thrift.transport.TSocket import TSocket [as 別名]
def __init__(self, host=None, port=9090, *args, **kwargs):
        """PRANKBOT MODIFED: ``host``, ``port``, ``unix_socket``
        Keyword arguments: ``keyfile``, ``certfile``, ``cert_reqs``, ``ssl_version``,
                           ``ca_certs``, ``ciphers`` (Python 2.7.0 or later)
        See ssl.wrap_socket documentation.
        Alternative keyword arguments: (Python 2.7.9 or later)
          ``ssl_context``: ssl.SSLContext to be used for SSLContext.wrap_socket
          ``server_hostname``: Passed to SSLContext.wrap_socket
        Common keyword argument:
          ``validate_callback`` (cert, hostname) -> None:
              Called after SSL handshake. Can raise when hostname does not
              match the cert.
        """
        if args:
            if len(args) > 3:
                raise TypeError('Too many positional argument')
            if not self._unix_socket_arg(host, port, args, kwargs):
                self._deprecated_arg(args, kwargs, 0, 'certfile')
            self._deprecated_arg(args, kwargs, 1, 'unix_socket')
            self._deprecated_arg(args, kwargs, 2, 'ciphers')
        if 'ssl_context' not in kwargs:
            # Preserve existing behaviors for default values
            if 'cert_reqs' not in kwargs:
                kwargs['cert_reqs'] = ssl.CERT_NONE
            if'certfile' not in kwargs:
                kwargs['certfile'] = 'cert.pem'
        unix_socket = kwargs.pop('unix_socket', None)
        self._validate_callback = \
            kwargs.pop('validate_callback', _match_hostname)
        TSSLBase.__init__(self, True, None, kwargs)
        TSocket.TServerSocket.__init__(self, host, port, unix_socket)
        if self._should_verify and not _match_has_ipaddress:
            raise ValueError('Need ipaddress and backports.ssl_match_hostname '
                             'module to verify client certificate') 
開發者ID:stya535,項目名稱:SOLO,代碼行數:36,代碼來源:TSSLSocket.py


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