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


Python errno.EAFNOSUPPORT属性代码示例

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


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

示例1: open

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAFNOSUPPORT [as 别名]
def open(name, dscp=DSCP_DEFAULT):
        """Attempts to connect a stream to a remote peer.  'name' is a
        connection name in the form "TYPE:ARGS", where TYPE is an active stream
        class's name and ARGS are stream class-specific.  Currently the only
        supported TYPEs are "unix" and "tcp".

        Returns (error, stream): on success 'error' is 0 and 'stream' is the
        new Stream, on failure 'error' is a positive errno value and 'stream'
        is None.

        Never returns errno.EAGAIN or errno.EINPROGRESS.  Instead, returns 0
        and a new Stream.  The connect() method can be used to check for
        successful connection completion."""
        cls = Stream._find_method(name)
        if not cls:
            return errno.EAFNOSUPPORT, None

        suffix = name.split(":", 1)[1]
        error, sock = cls._open(suffix, dscp)
        if error:
            return error, None
        else:
            status = ovs.socket_util.check_connection_completion(sock)
            return 0, Stream(sock, name, status) 
开发者ID:OpenState-SDN,项目名称:ryu,代码行数:26,代码来源:stream.py

示例2: is_ipv6_supported

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAFNOSUPPORT [as 别名]
def is_ipv6_supported():
    has_ipv6_support = socket.has_ipv6
    try:
        s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
        s.close()
    except socket.error as e:
        if e.errno == errno.EAFNOSUPPORT:
            has_ipv6_support = False
        else:
            raise

    # check if there is at least one interface with ipv6
    if has_ipv6_support and sys.platform.startswith('linux'):
        try:
            with open('/proc/net/if_inet6') as f:
                if not f.read():
                    has_ipv6_support = False
        except IOError:
            has_ipv6_support = False

    return has_ipv6_support 
开发者ID:openstack,项目名称:masakari,代码行数:23,代码来源:utils.py

示例3: __init__

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAFNOSUPPORT [as 别名]
def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, _create=False):
    if family not in (AF_INET, AF_INET6):
      raise error(errno.EAFNOSUPPORT, os.strerror(errno.EAFNOSUPPORT))

    if type not in (SOCK_STREAM, SOCK_DGRAM):
      raise error(errno.EPROTONOSUPPORT, os.strerror(errno.EPROTONOSUPPORT))

    if proto:
      if ((proto not in (IPPROTO_TCP, IPPROTO_UDP)) or
          (proto == IPPROTO_TCP and type != SOCK_STREAM) or
          (proto == IPPROTO_UDP and type != SOCK_DGRAM)):
        raise error(errno.EPROTONOSUPPORT, os.strerror(errno.EPROTONOSUPPORT))

    self.family = family
    self.type = type
    self.proto = proto
    self._created = False
    self._fileno = None
    self._serialized = False
    self.settimeout(getdefaulttimeout())
    self._Clear()

    if _create:
      self._CreateSocket() 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:26,代码来源:_remote_socket.py

示例4: inet_pton

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAFNOSUPPORT [as 别名]
def inet_pton(family, ip_string):
    try:
        if family == AF_INET:
            if not is_ipv4_address(ip_string):
                raise error("illegal IP address string passed to inet_pton")
        elif family == AF_INET6:
            if not is_ipv6_address(ip_string):
                raise error("illegal IP address string passed to inet_pton")
        else:
            raise error(errno.EAFNOSUPPORT, "Address family not supported by protocol")
        ia = java.net.InetAddress.getByName(ip_string)
        bytes = []
        for byte in ia.getAddress():
            if byte < 0:
                bytes.append(byte+256)
            else:
                bytes.append(byte)
        return "".join([chr(byte) for byte in bytes])
    except java.lang.Exception, jlx:
        raise _map_exception(jlx) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:22,代码来源:socket.py

示例5: inet_pton

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAFNOSUPPORT [as 别名]
def inet_pton(family, ip_string):
    if family == AF_INET:
        if not is_ipv4_address(ip_string):
            raise error("illegal IP address string passed to inet_pton")
    elif family == AF_INET6:
        if not is_ipv6_address(ip_string):
            raise error("illegal IP address string passed to inet_pton")
    else:
        raise error(errno.EAFNOSUPPORT, "Address family not supported by protocol")
    ia = java.net.InetAddress.getByName(ip_string)
    bytes = []
    for byte in ia.getAddress():
        if byte < 0:
            bytes.append(byte+256)
        else:
            bytes.append(byte)
    return "".join([chr(byte) for byte in bytes]) 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:19,代码来源:_socket.py

示例6: server_bind

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAFNOSUPPORT [as 别名]
def server_bind(self):
        """Override to enable IPV4 mapping for IPV6 sockets when desired.

        The main use case for this is so that when no host is specified,
        TensorBoard can listen on all interfaces for both IPv4 and IPv6
        connections, rather than having to choose v4 or v6 and hope the
        browser didn't choose the other one.
        """
        socket_is_v6 = (
            hasattr(socket, "AF_INET6")
            and self.socket.family == socket.AF_INET6
        )
        has_v6only_option = hasattr(socket, "IPPROTO_IPV6") and hasattr(
            socket, "IPV6_V6ONLY"
        )
        if self._auto_wildcard and socket_is_v6 and has_v6only_option:
            try:
                self.socket.setsockopt(
                    socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0
                )
            except socket.error as e:
                # Log a warning on failure to dual-bind, except for EAFNOSUPPORT
                # since that's expected if IPv4 isn't supported at all (IPv6-only).
                if (
                    hasattr(errno, "EAFNOSUPPORT")
                    and e.errno != errno.EAFNOSUPPORT
                ):
                    logger.warning(
                        "Failed to dual-bind to IPv4 wildcard: %s", str(e)
                    )
        super(WerkzeugServer, self).server_bind() 
开发者ID:tensorflow,项目名称:tensorboard,代码行数:33,代码来源:program.py

示例7: nl_syserr2nlerr

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAFNOSUPPORT [as 别名]
def nl_syserr2nlerr(error_):
    """https://github.com/thom311/libnl/blob/libnl3_2_25/lib/error.c#L84."""
    error_ = abs(error_)
    legend = {
        errno.EBADF: libnl.errno_.NLE_BAD_SOCK,
        errno.EADDRINUSE: libnl.errno_.NLE_EXIST,
        errno.EEXIST: libnl.errno_.NLE_EXIST,
        errno.EADDRNOTAVAIL: libnl.errno_.NLE_NOADDR,
        errno.ESRCH: libnl.errno_.NLE_OBJ_NOTFOUND,
        errno.ENOENT: libnl.errno_.NLE_OBJ_NOTFOUND,
        errno.EINTR: libnl.errno_.NLE_INTR,
        errno.EAGAIN: libnl.errno_.NLE_AGAIN,
        errno.ENOTSOCK: libnl.errno_.NLE_BAD_SOCK,
        errno.ENOPROTOOPT: libnl.errno_.NLE_INVAL,
        errno.EFAULT: libnl.errno_.NLE_INVAL,
        errno.EACCES: libnl.errno_.NLE_NOACCESS,
        errno.EINVAL: libnl.errno_.NLE_INVAL,
        errno.ENOBUFS: libnl.errno_.NLE_NOMEM,
        errno.ENOMEM: libnl.errno_.NLE_NOMEM,
        errno.EAFNOSUPPORT: libnl.errno_.NLE_AF_NOSUPPORT,
        errno.EPROTONOSUPPORT: libnl.errno_.NLE_PROTO_MISMATCH,
        errno.EOPNOTSUPP: libnl.errno_.NLE_OPNOTSUPP,
        errno.EPERM: libnl.errno_.NLE_PERM,
        errno.EBUSY: libnl.errno_.NLE_BUSY,
        errno.ERANGE: libnl.errno_.NLE_RANGE,
        errno.ENODEV: libnl.errno_.NLE_NODEV,
    }
    return int(legend.get(error_, libnl.errno_.NLE_FAILURE)) 
开发者ID:Robpol86,项目名称:libnl,代码行数:30,代码来源:error.py

示例8: java_net_socketexception_handler

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAFNOSUPPORT [as 别名]
def java_net_socketexception_handler(exc):
    if exc.message.startswith("Address family not supported by protocol family"):
        return error(errno.EAFNOSUPPORT, 'Address family not supported by protocol family: See http://wiki.python.org/jython/NewSocketModule#IPV6addresssupport')
    return _unmapped_exception(exc) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:6,代码来源:socket.py

示例9: test_inet_pton_exceptions

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAFNOSUPPORT [as 别名]
def test_inet_pton_exceptions(self):
        if not hasattr(socket, 'inet_pton'):
            return # No inet_pton() on this platform

        try:
            socket.inet_pton(socket.AF_UNSPEC, "doesntmatter")
        except socket.error, se:
            self.failUnlessEqual(se[0], errno.EAFNOSUPPORT) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:10,代码来源:test_socket.py

示例10: java_net_socketexception_handler

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAFNOSUPPORT [as 别名]
def java_net_socketexception_handler(exc):
    if exc.message.startswith("Address family not supported by protocol family"):
        return _add_exception_attrs(
            error(errno.EAFNOSUPPORT,
                  'Address family not supported by protocol family: See http://wiki.python.org/jython/NewSocketModule#IPV6_address_support'))
    if exc.message.startswith('Address already in use'):
        return error(errno.EADDRINUSE, 'Address already in use')
    return _unmapped_exception(exc) 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:10,代码来源:_socket.py

示例11: bind_sockets

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAFNOSUPPORT [as 别名]
def bind_sockets(port, address=None, family=socket.AF_UNSPEC, backlog=128, flags=None):
    """Creates listening sockets bound to the given port and address.

    Returns a list of socket objects (multiple sockets are returned if
    the given address maps to multiple IP addresses, which is most common
    for mixed IPv4 and IPv6 use).

    Address may be either an IP address or hostname.  If it's a hostname,
    the server will listen on all IP addresses associated with the
    name.  Address may be an empty string or None to listen on all
    available interfaces.  Family may be set to either `socket.AF_INET`
    or `socket.AF_INET6` to restrict to IPv4 or IPv6 addresses, otherwise
    both will be used if available.

    The ``backlog`` argument has the same meaning as for
    `socket.listen() <socket.socket.listen>`.

    ``flags`` is a bitmask of AI_* flags to `~socket.getaddrinfo`, like
    ``socket.AI_PASSIVE | socket.AI_NUMERICHOST``.
    """
    sockets = []
    if address == "":
        address = None
    if not socket.has_ipv6 and family == socket.AF_UNSPEC:
        # Python can be compiled with --disable-ipv6, which causes
        # operations on AF_INET6 sockets to fail, but does not
        # automatically exclude those results from getaddrinfo
        # results.
        # http://bugs.python.org/issue16208
        family = socket.AF_INET
    if flags is None:
        flags = socket.AI_PASSIVE
    for res in set(socket.getaddrinfo(address, port, family, socket.SOCK_STREAM,
                                      0, flags)):
        af, socktype, proto, canonname, sockaddr = res
        try:
            sock = socket.socket(af, socktype, proto)
        except socket.error as e:
            if e.args[0] == errno.EAFNOSUPPORT:
                continue
            raise
        set_close_exec(sock.fileno())
        if os.name != 'nt':
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        if af == socket.AF_INET6:
            # On linux, ipv6 sockets accept ipv4 too by default,
            # but this makes it impossible to bind to both
            # 0.0.0.0 in ipv4 and :: in ipv6.  On other systems,
            # separate sockets *must* be used to listen for both ipv4
            # and ipv6.  For consistency, always disable ipv4 on our
            # ipv6 sockets and use a separate ipv4 socket when needed.
            #
            # Python 2.x on windows doesn't have IPPROTO_IPV6.
            if hasattr(socket, "IPPROTO_IPV6"):
                sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
        sock.setblocking(0)
        sock.bind(sockaddr)
        sock.listen(backlog)
        sockets.append(sock)
    return sockets 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:62,代码来源:netutil.py

示例12: __init__

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAFNOSUPPORT [as 别名]
def __init__(self, wsgi_app, flags):
        self._flags = flags
        host = flags.host
        port = flags.port

        self._auto_wildcard = flags.bind_all
        if self._auto_wildcard:
            # Serve on all interfaces, and attempt to serve both IPv4 and IPv6
            # traffic through one socket.
            host = self._get_wildcard_address(port)
        elif host is None:
            host = "localhost"

        self._host = host
        self._url = None  # Will be set by get_url() below

        self._fix_werkzeug_logging()
        try:
            super(WerkzeugServer, self).__init__(host, port, wsgi_app)
        except socket.error as e:
            if hasattr(errno, "EACCES") and e.errno == errno.EACCES:
                raise TensorBoardServerException(
                    "TensorBoard must be run as superuser to bind to port %d"
                    % port
                )
            elif hasattr(errno, "EADDRINUSE") and e.errno == errno.EADDRINUSE:
                if port == 0:
                    raise TensorBoardServerException(
                        "TensorBoard unable to find any open port"
                    )
                else:
                    raise TensorBoardPortInUseError(
                        "TensorBoard could not bind to port %d, it was already in use"
                        % port
                    )
            elif (
                hasattr(errno, "EADDRNOTAVAIL")
                and e.errno == errno.EADDRNOTAVAIL
            ):
                raise TensorBoardServerException(
                    "TensorBoard could not bind to unavailable address %s"
                    % host
                )
            elif (
                hasattr(errno, "EAFNOSUPPORT") and e.errno == errno.EAFNOSUPPORT
            ):
                raise TensorBoardServerException(
                    "Tensorboard could not bind to unsupported address family %s"
                    % host
                )
            # Raise the raw exception if it wasn't identifiable as a user error.
            raise 
开发者ID:tensorflow,项目名称:tensorboard,代码行数:54,代码来源:program.py

示例13: inet_pton

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAFNOSUPPORT [as 别名]
def inet_pton(af, ip):
  """inet_pton(af, ip) -> packed IP address string

  Convert an IP address from string format to a packed string suitable
  for use with low-level network functions.
  """

  if not isinstance(af, (int, long)):
    raise TypeError('an integer is required')
  if not isinstance(ip, basestring):
    raise TypeError('inet_pton() argument 2 must be string, not %s' %
                    _TypeName(ip))
  if af == AF_INET:
    parts = ip.split('.')
    if len(parts) != 4:
      raise error('illegal IP address string passed to inet_pton')
    ret = 0
    bits = 32
    for part in parts:
      if not re.match(r'^(0|[1-9]\d*)$', part) or int(part) > 0xff:
        raise error('illegal IP address string passed to inet_pton')
      bits -= 8
      ret |= ((int(part) & 0xff) << bits)
    return struct.pack('!L', ret)
  elif af == AF_INET6:
    parts = ip.split(':')

    if '.' in parts[-1]:
      ipv4_shorts = struct.unpack('!2H', inet_pton(AF_INET, parts[-1]))
      parts[-1:] = [hex(n)[2:] for n in ipv4_shorts]

    if '' in parts:
      if len(parts) == 1 or len(parts) >= 8:
        raise error('illegal IP address string passed to inet_pton')

      idx = parts.index('')
      count = parts.count('')
      pad = ['0']*(count+(8-len(parts)))

      if count == len(parts) == 3:
        parts = pad
      elif count == 2 and parts[0:2] == ['', '']:
        parts[0:2] = pad
      elif count == 2 and parts[-2:] == ['', '']:
        parts[-2:] = pad
      elif count == 1:
        parts[idx:idx+1] = pad
      else:
        raise error('illegal IP address string passed to inet_pton')
    if (len(parts) != 8 or
        [x for x in parts if not re.match(r'^[0-9A-Fa-f]{1,4}$', x)]):
      raise error('illegal IP address string passed to inet_pton')
    return struct.pack('!8H', *[int(x, 16) for x in parts])
  else:
    raise error(errno.EAFNOSUPPORT, os.strerror(errno.EAFNOSUPPORT)) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:57,代码来源:_remote_socket_addr.py


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