当前位置: 首页>>代码示例>>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;未经允许,请勿转载。