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


Python _socket.error方法代码示例

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


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

示例1: systemcall

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import error [as 别名]
def systemcall(meth):
    """Decorator to make system call methods safe from EINTR."""
    # have to import this way to avoid a circular import
    from _socket import error as SocketError
    def systemcallmeth(*args, **kwargs):
        while 1:
            try:
                rv = meth(*args, **kwargs)
            except EnvironmentError as why:
                if why.args and why.args[0] == EINTR:
                    continue
                else:
                    raise
            except SocketError as why:
                if why.args and why.args[0] == EINTR:
                    continue
                else:
                    raise
            else:
                break
        return rv
    return systemcallmeth 
开发者ID:kdart,项目名称:pycopia,代码行数:24,代码来源:aid.py

示例2: test_makefile_refcount

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import error [as 别名]
def test_makefile_refcount(self):
        "Ensures that the _socket stays open while there's still a file associated"

        def echoer(port):
            s = socket.socket()
            s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # prevents an "Address already in use" error when the socket is in a TIME_WAIT state
            s.bind(('localhost', port))
            s.listen(5)
            (s2, ignore) = s.accept()
            s2.send(s2.recv(10))

        port = 50008

        _thread.start_new_thread(echoer, (port, ))
        time.sleep(1)
        s = socket.socket()
        s.connect(('localhost', port))
        f1 = s.makefile('r')
        f2 = s.makefile('w')
        s.close()
        test_msg = 'abc\n'
        f2.write(test_msg)
        f2.flush()
        str = f1.readline()
        self.assertEqual(str, test_msg) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:27,代码来源:test__socket.py

示例3: _udp_socket

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import error [as 别名]
def _udp_socket(address, backlog=50, reuse_addr=None, family=_socket.AF_INET):
    # backlog argument for compat with tcp_listener
    # pylint:disable=unused-argument

    # we want gevent.socket.socket here
    sock = socket(family=family, type=_socket.SOCK_DGRAM)
    if reuse_addr is not None:
        sock.setsockopt(_socket.SOL_SOCKET, _socket.SO_REUSEADDR, reuse_addr)
    try:
        sock.bind(address)
    except _socket.error as ex:
        strerror = getattr(ex, 'strerror', None)
        if strerror is not None:
            ex.strerror = strerror + ': ' + repr(address)
        raise
    return sock 
开发者ID:priyankark,项目名称:PhonePi_SampleServer,代码行数:18,代码来源:server.py

示例4: test_getprotobyname

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import error [as 别名]
def test_getprotobyname(self):
        '''Tests _socket.getprotobyname'''
        #IP and CPython
        proto_map = {
                    "icmp": _socket.IPPROTO_ICMP,
                    "ip": _socket.IPPROTO_IP,
                    "tcp": _socket.IPPROTO_TCP,
                    "udp": _socket.IPPROTO_UDP,
        }
        
        #supported only by IP
        if is_cli:
            proto_map.update(
                {"dstopts": _socket.IPPROTO_DSTOPTS,
                "none": _socket.IPPROTO_NONE,
                "raw": _socket.IPPROTO_RAW,
                "ipv4": _socket.IPPROTO_IPV4,
                "ipv6": _socket.IPPROTO_IPV6,
                "esp": _socket.IPPROTO_ESP,
                "fragment": _socket.IPPROTO_FRAGMENT,
                "nd": _socket.IPPROTO_ND,
                "icmpv6": _socket.IPPROTO_ICMPV6,
                "routing": _socket.IPPROTO_ROUTING,
                "pup": _socket.IPPROTO_PUP, #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=21918
                "ggp": _socket.IPPROTO_GGP, #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=21918
                })
        
        for proto_name, good_val in proto_map.iteritems():
            temp_val = _socket.getprotobyname(proto_name)
            self.assertEqual(temp_val, good_val)
            
        #negative cases
        bad_list = ["", "blah", "i"]
        for name in bad_list:
            self.assertRaises(_socket.error, _socket.getprotobyname, name) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:37,代码来源:test__socket.py

示例5: test_inet_ntop

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import error [as 别名]
def test_inet_ntop(self):
        '''Tests _socket.inet_ntop'''
        
        #negative
        self.assertRaises(_socket.error, _socket.inet_ntop, _socket.AF_INET, "garbage dkfjdkfjdkfj") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test__socket.py

示例6: test_inet_pton

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import error [as 别名]
def test_inet_pton(self):
        '''Tests _socket.inet_pton'''
       
        #sanity
        _socket.inet_pton(_socket.AF_INET, "127.0.0.1")
            
        #negative
        self.assertRaises(_socket.error, _socket.inet_pton, _socket.AF_INET, "garbage dkfjdkfjdkfj") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test__socket.py

示例7: do_read

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import error [as 别名]
def do_read(self):
            try:
                client_socket, address = self.socket.accept()
            except _socket.error as err:
                if err.args[0] == EWOULDBLOCK:
                    return
                raise
            sockobj = socket(_sock=client_socket)
            if PYPY:
                client_socket._drop()
            return sockobj, address 
开发者ID:leancloud,项目名称:satori,代码行数:13,代码来源:server.py

示例8: _tcp_listener

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import error [as 别名]
def _tcp_listener(address, backlog=50, reuse_addr=None, family=_socket.AF_INET):
    """A shortcut to create a TCP socket, bind it and put it into listening state."""
    sock = socket(family=family)
    if reuse_addr is not None:
        sock.setsockopt(_socket.SOL_SOCKET, _socket.SO_REUSEADDR, reuse_addr)
    try:
        sock.bind(address)
    except _socket.error as ex:
        strerror = getattr(ex, 'strerror', None)
        if strerror is not None:
            ex.strerror = strerror + ': ' + repr(address)
        raise
    sock.listen(backlog)
    sock.setblocking(0)
    return sock 
开发者ID:leancloud,项目名称:satori,代码行数:17,代码来源:server.py

示例9: _udp_socket

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import error [as 别名]
def _udp_socket(address, backlog=50, reuse_addr=None, family=_socket.AF_INET):
    # we want gevent.socket.socket here
    sock = socket(family=family, type=_socket.SOCK_DGRAM)
    if reuse_addr is not None:
        sock.setsockopt(_socket.SOL_SOCKET, _socket.SO_REUSEADDR, reuse_addr)
    try:
        sock.bind(address)
    except _socket.error as ex:
        strerror = getattr(ex, 'strerror', None)
        if strerror is not None:
            ex.strerror = strerror + ': ' + repr(address)
        raise
    return sock 
开发者ID:leancloud,项目名称:satori,代码行数:15,代码来源:server.py

示例10: __init__

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import error [as 别名]
def __init__(self, hub, count):
        self.count = count
        self.values = []
        self.error = None
        self.waiter = Waiter(hub) 
开发者ID:leancloud,项目名称:satori,代码行数:7,代码来源:resolver_ares.py

示例11: __call__

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import error [as 别名]
def __call__(self, source):
        self.count -= 1
        if source.exception is None:
            self.values.append(source.value)
        else:
            self.error = source.exception
        if self.count <= 0:
            self.waiter.switch() 
开发者ID:leancloud,项目名称:satori,代码行数:10,代码来源:resolver_ares.py

示例12: _resolve_special

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import error [as 别名]
def _resolve_special(hostname, family):
    if hostname == '':
        result = getaddrinfo(None, 0, family, SOCK_DGRAM, 0, AI_PASSIVE)
        if len(result) != 1:
            raise error('wildcard resolved to multiple address')
        return result[0][4][0]
    return hostname 
开发者ID:leancloud,项目名称:satori,代码行数:9,代码来源:resolver_ares.py

示例13: _formatinfo

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import error [as 别名]
def _formatinfo(self):
        if hasattr(self, 'socket'):
            try:
                fileno = self.socket.fileno()
            except Exception as ex:
                fileno = str(ex)
            result = 'fileno=%s ' % fileno
        else:
            result = ''
        try:
            if isinstance(self.address, tuple) and len(self.address) == 2:
                result += 'address=%s:%s' % self.address
            else:
                result += 'address=%s' % (self.address, )
        except Exception as ex:
            result += str(ex) or '<error>'

        handle = self.__dict__.get('handle')
        if handle is not None:
            fself = getattr(handle, '__self__', None)
            try:
                if fself is self:
                    # Checks the __self__ of the handle in case it is a bound
                    # method of self to prevent recursivly defined reprs.
                    handle_repr = '<bound method %s.%s of self>' % (
                        self.__class__.__name__,
                        handle.__name__,
                    )
                else:
                    handle_repr = repr(handle)

                result += ' handle=' + handle_repr
            except Exception as ex:
                result += str(ex) or '<error>'

        return result 
开发者ID:leancloud,项目名称:satori,代码行数:38,代码来源:baseserver.py

示例14: is_fatal_error

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import error [as 别名]
def is_fatal_error(self, ex):
        return isinstance(ex, _socket.error) and ex.args[0] in self.fatal_errors 
开发者ID:leancloud,项目名称:satori,代码行数:4,代码来源:baseserver.py

示例15: test_getprotobyname

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import error [as 别名]
def test_getprotobyname(self):
        '''Tests _socket.getprotobyname'''
        #IP and CPython
        proto_map = {
                    "icmp": _socket.IPPROTO_ICMP,
                    "ip": _socket.IPPROTO_IP,
                    "tcp": _socket.IPPROTO_TCP,
                    "udp": _socket.IPPROTO_UDP,
        }

        #supported only by IP
        if is_cli:
            proto_map.update(
                {"dstopts": _socket.IPPROTO_DSTOPTS,
                "none": _socket.IPPROTO_NONE,
                "raw": _socket.IPPROTO_RAW,
                "ipv4": _socket.IPPROTO_IPV4,
                "ipv6": _socket.IPPROTO_IPV6,
                "esp": _socket.IPPROTO_ESP,
                "fragment": _socket.IPPROTO_FRAGMENT,
                "nd": _socket.IPPROTO_ND,
                "icmpv6": _socket.IPPROTO_ICMPV6,
                "routing": _socket.IPPROTO_ROUTING,
                "pup": _socket.IPPROTO_PUP, #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=21918
                "ggp": _socket.IPPROTO_GGP, #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=21918
                })

        for proto_name, good_val in proto_map.items():
            temp_val = _socket.getprotobyname(proto_name)
            self.assertEqual(temp_val, good_val)

        #negative cases
        bad_list = ["", "blah", "i"]
        for name in bad_list:
            self.assertRaises(_socket.error, _socket.getprotobyname, name) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:37,代码来源:test__socket.py


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