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


Python _socket.AF_INET属性代码示例

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


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

示例1: _parse_address

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def _parse_address(address):
    if isinstance(address, tuple):
        if ':' in address[0]:
            return _socket.AF_INET6, address
        return _socket.AF_INET, address
    elif isinstance(address, string_types):
        if ':' in address:
            host, port = address.rsplit(':', 1)
            family, host = _extract_family(host)
            if host == '*':
                host = ''
            return family, (host, int(port))
        else:
            return _socket.AF_INET, ('', int(address))
    elif isinstance(address, integer_types):
        return _socket.AF_INET, ('', int(address))
    else:
        raise TypeError('Expected tuple or string, got %s' % type(address)) 
开发者ID:leancloud,项目名称:satori,代码行数:20,代码来源:baseserver.py

示例2: _udp_socket

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [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

示例3: _parse_address

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def _parse_address(address):
    if isinstance(address, tuple):
        if not address[0] or ':' in address[0]:
            return _socket.AF_INET6, address
        return _socket.AF_INET, address

    if ((isinstance(address, string_types) and ':' not in address)
        or isinstance(address, integer_types)): # noqa (pep8 E129)
        # Just a port
        return _socket.AF_INET6, ('', int(address))

    if not isinstance(address, string_types):
        raise TypeError('Expected tuple or string, got %s' % type(address))

    host, port = address.rsplit(':', 1)
    family, host = _extract_family(host)
    if host == '*':
        host = ''
    return family, (host, int(port)) 
开发者ID:priyankark,项目名称:PhonePi_SampleServer,代码行数:21,代码来源:baseserver.py

示例4: test_inet_ntop

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [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

示例5: test_inet_pton

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [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

示例6: _tcp_listener

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [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

示例7: _udp_socket

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [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

示例8: _extract_family

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def _extract_family(host):
    if host.startswith('[') and host.endswith(']'):
        host = host[1:-1]
        return _socket.AF_INET6, host
    return _socket.AF_INET, host 
开发者ID:leancloud,项目名称:satori,代码行数:7,代码来源:baseserver.py

示例9: _prepare_server

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def _prepare_server(self, address):
        import _socket
        # 只有这样,才能保证在主进程里面,不会启动accept
        listener = self.server_class.get_listener(address, backlog=self.backlog, family=_socket.AF_INET)
        listener.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        self.server = self.server_class(listener, handle=self._handle_stream) 
开发者ID:dantezhu,项目名称:haven,代码行数:8,代码来源:gevent_impl.py

示例10: _prepare_server

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def _prepare_server(self, address):
        import _socket
        # 只有这样,才能保证在主进程里面,不会启动accept
        listener = self.server_class.get_listener(address, backlog=self.backlog, family=_socket.AF_INET)
        listener.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        self.server = WebSocketServer(listener, self.wsgi_app) 
开发者ID:dantezhu,项目名称:haven,代码行数:8,代码来源:websocket_gevent_impl.py

示例11: test_inet_ntop

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def test_inet_ntop(self):
        '''Tests _socket.inet_ntop'''

        #negative
        self.assertRaises(ValueError, _socket.inet_ntop, _socket.AF_INET, b"garbage dkfjdkfjdkfj") 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:7,代码来源:test__socket.py

示例12: test_inet_pton

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [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,项目名称:ironpython3,代码行数:10,代码来源:test__socket.py


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