当前位置: 首页>>代码示例>>Python>>正文


Python socket.error方法代码示例

本文整理汇总了Python中gevent.socket.error方法的典型用法代码示例。如果您正苦于以下问题:Python socket.error方法的具体用法?Python socket.error怎么用?Python socket.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gevent.socket的用法示例。


在下文中一共展示了socket.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import error [as 别名]
def read(self, size):
        while len(self.buffer) < size:
            self.ensure_connection()

            try:
                packet = self.socket.recv(self.buffer_size)
            except socket.error as error:
                if error.errno in (EDEADLK, EAGAIN, EWOULDBLOCK):
                    gevent.sleep()
                    continue
                six.raise_from(NSQSocketError(*error.args), error)

            if not packet:
                self.close()

            self.buffer += packet

        data = self.buffer[:size]
        self.buffer = self.buffer[size:]

        return data 
开发者ID:wtolson,项目名称:gnsq,代码行数:23,代码来源:stream.py

示例2: upgrade_to_tls

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import error [as 别名]
def upgrade_to_tls(
        self,
        keyfile=None,
        certfile=None,
        cert_reqs=CERT_NONE,
        ca_certs=None,
        ssl_version=PROTOCOL_TLSv1_2
    ):
        self.ensure_connection()

        try:
            self.socket = SSLSocket(
                self.socket,
                keyfile=keyfile,
                certfile=certfile,
                cert_reqs=cert_reqs,
                ca_certs=ca_certs,
                ssl_version=ssl_version,
            )
        except socket.error as error:
            six.raise_from(NSQSocketError(*error.args), error) 
开发者ID:wtolson,项目名称:gnsq,代码行数:23,代码来源:stream.py

示例3: handle

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import error [as 别名]
def handle(self, sock, addr):

        logger.debug('Incomming connection %s:%s', *addr[:2])

        if self.relay and not addr[0] in self.remoteaddr:
            logger.debug('Not in remoteaddr', *addr[:2])
            return 
        try:
            with Timeout(self.timeout, ConnectionTimeout):
                sc = SMTPChannel(self, sock, addr, self.data_size_limit)
                while not sc.closed:
                    sc.handle_read()

        except ConnectionTimeout:
            logger.warn('%s:%s Timeouted', *addr[:2])
            try:
                sc.smtp_TIMEOUT()
            except Exception as err:
                logger.debug(err)
        except Exception as err:
            logger.error(err)

    # API for "doing something useful with the message" 
开发者ID:34nm,项目名称:gsmtpd,代码行数:25,代码来源:server.py

示例4: smtp_STARTTLS

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import error [as 别名]
def smtp_STARTTLS(self, arg):

        if arg:
            self.push('501 Syntax: STARTTLS')
            return
        self.push('220 Ready to start TLS')
        
        if self.data:
            self.push('500 Too late to changed')
            return

        try:
            self.conn = ssl.wrap_socket(self.conn, **self.server.ssl)
            self.state = self.COMMAND
            self.seen_greeting = 0
            self.rcpttos = []
            self.mailfrom = None
            self.tls = True
        except Exception as err:
            logger.error(err, exc_info=True)
            self.push('503 certificate is FAILED')
            self.close_when_done() 
开发者ID:34nm,项目名称:gsmtpd,代码行数:24,代码来源:channel.py

示例5: connect

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import error [as 别名]
def connect(self, server_addr):
        self._new_socket()

        logger.debug("Attempting connection to %s", str(server_addr))

        try:
            self._connect(server_addr)
        except socket.error:
            return False

        self.server_addr = server_addr
        self.recv_queue.queue.clear()

        self._reader = gevent.spawn(self._reader_loop)
        self._writer = gevent.spawn(self._writer_loop)

        logger.debug("Connected.")
        self.event_connected.set()
        return True 
开发者ID:ValvePython,项目名称:steam,代码行数:21,代码来源:connection.py

示例6: _real_connect

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import error [as 别名]
def _real_connect(self, addr, connect_ex):
        if self.server_side:
            raise ValueError("can't connect in server-side mode")
        # Here we assume that the socket is client-side, and not
        # connected at the time of the call.  We connect it, then wrap it.
        if self._connected:
            raise ValueError("attempt to connect already-connected SSLSocket!")
        self._sslobj = self.context._wrap_socket(self._sock, False, self.server_hostname)
        try:
            if connect_ex:
                rc = socket.connect_ex(self, addr)
            else:
                rc = None
                socket.connect(self, addr)
            if not rc:
                if self.do_handshake_on_connect:
                    self.do_handshake()
                self._connected = True
            return rc
        except socket_error:
            self._sslobj = None
            raise 
开发者ID:leancloud,项目名称:satori,代码行数:24,代码来源:_ssl3.py

示例7: _real_connect

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import error [as 别名]
def _real_connect(self, addr, connect_ex):
        if self.server_side:
            raise ValueError("can't connect in server-side mode")
        # Here we assume that the socket is client-side, and not
        # connected at the time of the call.  We connect it, then wrap it.
        if self._connected:
            raise ValueError("attempt to connect already-connected SSLSocket!")
        self._sslobj = self.context._wrap_socket(self._sock, False, self.server_hostname, ssl_sock=self)
        try:
            if connect_ex:
                rc = socket.connect_ex(self, addr)
            else:
                rc = None
                socket.connect(self, addr)
            if not rc:
                self._connected = True
                if self.do_handshake_on_connect:
                    self.do_handshake()
            return rc
        except socket_error:
            self._sslobj = None
            raise 
开发者ID:leancloud,项目名称:satori,代码行数:24,代码来源:_sslgte279.py

示例8: send_message_to_slave

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import error [as 别名]
def send_message_to_slave(message, address):
    try:
        payload = generate_msgpack_message_payload(message)
    except TypeError:
        logger.exception('Failed encoding message %s as msgpack', message)
        metrics.incr('rpc_message_pass_fail_cnt')
        return False

    pretty_address = '%s:%s' % address
    message_id = message.get('message_id', '?')
    try:
        s = socket.create_connection(address)
        s.send(payload)
        sender_resp = msgpack_unpack_msg_from_socket(s)
        s.close()
    except socket.error:
        logging.exception('Failed connecting to %s to send message (ID %s)',
                          pretty_address, message_id)
        metrics.incr('rpc_message_pass_fail_cnt')
        return False

    if sender_resp == 'OK':
        access_logger.info('Successfully passed message (ID %s) to %s for sending',
                           message_id, pretty_address)
        metrics.incr('rpc_message_pass_success_cnt')
        return True
    else:
        logger.error('Failed sending message (ID %s) through %s: %s',
                     message_id, pretty_address, sender_resp)
        metrics.incr('rpc_message_pass_fail_cnt')
        return False 
开发者ID:linkedin,项目名称:iris,代码行数:33,代码来源:rpc.py

示例9: handle_slave_send

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import error [as 别名]
def handle_slave_send(socket, address, req):
    message = req['data']
    message_id = message.get('message_id', '?')

    message['to_slave'] = True

    try:
        runtime = send_funcs['message_send_enqueue'](message)
        response = 'OK'
        access_logger.info('Message (ID %s) from master %s queued successfully', message_id, address)
    except Exception:
        response = 'FAIL'
        logger.exception('Queueing message (ID %s) from master %s failed.')
        access_logger.error('Failed queueing message (ID %s) from master %s: %s', message_id, address, runtime)
        metrics.incr('slave_message_send_fail_cnt')

    socket.sendall(msgpack.packb(response)) 
开发者ID:linkedin,项目名称:iris,代码行数:19,代码来源:rpc.py

示例10: _real_connect

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import error [as 别名]
def _real_connect(self, addr, connect_ex):
        if self.server_side:
            raise ValueError("can't connect in server-side mode")
        # Here we assume that the socket is client-side, and not
        # connected at the time of the call.  We connect it, then wrap it.
        if self._connected:
            raise ValueError("attempt to connect already-connected SSLSocket!")
        self._sslobj = self._context._wrap_socket(self._sock, False, self.server_hostname)
        if self._session is not None: # 3.6
            self._sslobj = SSLObject(self._sslobj, owner=self, session=self._session)
        try:
            if connect_ex:
                rc = socket.connect_ex(self, addr)
            else:
                rc = None
                socket.connect(self, addr)
            if not rc:
                if self.do_handshake_on_connect:
                    self.do_handshake()
                self._connected = True
            return rc
        except socket_error:
            self._sslobj = None
            raise 
开发者ID:priyankark,项目名称:PhonePi_SampleServer,代码行数:26,代码来源:_ssl3.py

示例11: update_environ

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import error [as 别名]
def update_environ(self):
        """
        Called before the first request is handled to fill in WSGI environment values.

        This includes getting the correct server name and port.
        """
        address = self.address
        if isinstance(address, tuple):
            if 'SERVER_NAME' not in self.environ:
                try:
                    name = socket.getfqdn(address[0])
                except socket.error:
                    name = str(address[0])
                if PY3 and not isinstance(name, str):
                    name = name.decode('ascii') # python 2 pylint:disable=redefined-variable-type
                self.environ['SERVER_NAME'] = name
            self.environ.setdefault('SERVER_PORT', str(address[1]))
        else:
            self.environ.setdefault('SERVER_NAME', '')
            self.environ.setdefault('SERVER_PORT', '') 
开发者ID:priyankark,项目名称:PhonePi_SampleServer,代码行数:22,代码来源:pywsgi.py

示例12: _real_connect

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import error [as 别名]
def _real_connect(self, addr, connect_ex):
        if self.server_side:
            raise ValueError("can't connect in server-side mode")
        # Here we assume that the socket is client-side, and not
        # connected at the time of the call.  We connect it, then wrap it.
        if self._connected:
            raise ValueError("attempt to connect already-connected SSLSocket!")
        self._sslobj = self._context._wrap_socket(self._sock, False, self.server_hostname, ssl_sock=self)
        try:
            if connect_ex:
                rc = socket.connect_ex(self, addr)
            else:
                rc = None
                socket.connect(self, addr)
            if not rc:
                self._connected = True
                if self.do_handshake_on_connect:
                    self.do_handshake()
            return rc
        except socket_error:
            self._sslobj = None
            raise 
开发者ID:priyankark,项目名称:PhonePi_SampleServer,代码行数:24,代码来源:_sslgte279.py

示例13: update_environ

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import error [as 别名]
def update_environ(self):
        """
        Called before the first request is handled to fill in WSGI environment values.

        This includes getting the correct server name and port.
        """
        address = self.address
        if isinstance(address, tuple):
            if 'SERVER_NAME' not in self.environ:
                try:
                    name = socket.getfqdn(address[0])
                except socket.error:
                    name = str(address[0])
                if PY3 and not isinstance(name, str):
                    name = name.decode('ascii')
                self.environ['SERVER_NAME'] = name
            self.environ.setdefault('SERVER_PORT', str(address[1]))
        else:
            self.environ.setdefault('SERVER_NAME', '')
            self.environ.setdefault('SERVER_PORT', '') 
开发者ID:mchristopher,项目名称:PokemonGo-DesktopMap,代码行数:22,代码来源:pywsgi.py

示例14: get_ip_version

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import error [as 别名]
def get_ip_version(ip):
    # CR: http://stackoverflow.com/questions/11827961/checking-for-ip-addresses

    try:
        socket.inet_aton(ip)
        return 4
    except socket.error:
        pass
    try:
        socket.inet_pton(socket.AF_INET6, ip)
        return 6
    except socket.error:
        pass
    raise ValueError(ip) 
开发者ID:yahoo,项目名称:panoptes,代码行数:16,代码来源:helpers.py

示例15: parse_config_file

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import error [as 别名]
def parse_config_file(config_file, config_spec_file):

    assert validators.PanoptesValidators.valid_nonempty_string(config_file), u'config_file must be a non-empty str'
    assert validators.PanoptesValidators.valid_nonempty_string(config_spec_file), \
        u'config_spec_file must be a non empty str'

    try:
        config = ConfigObj(config_file, configspec=config_spec_file, interpolation=u'template', file_error=True)
    except IOError as e:
        raise PanoptesConfigurationParsingError(u'Error reading file: %s' % str(e))
    except ConfigObjError as e:
        raise PanoptesConfigurationParsingError(u'Error parsing config file "%s": %s' % (config_file, str(e)))

    validator = Validator()
    result = config.validate(validator, preserve_errors=True)

    if result is not True:
        errors = u''
        for (section_list, key, error) in flatten_errors(config, result):
            if key is None:
                errors += u'Section(s) ' + u','.join(section_list) + u' are missing\n'
            else:
                errors += u'The "' + key + u'" key in section "' + u','.join(section_list) + u'" failed validation\n'

        raise PanoptesConfigurationParsingError(u'Error parsing the configuration file: %s' % errors)

    return config 
开发者ID:yahoo,项目名称:panoptes,代码行数:29,代码来源:helpers.py


注:本文中的gevent.socket.error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。