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


Python socket.AF_UNIX属性代码示例

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


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

示例1: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AF_UNIX [as 别名]
def __init__(self, addr: Union[str, tuple, socket.socket]):
        """
        Args:
            addr: can be /var/run/usbmuxd or (localhost, 27015)
        """
        self._sock = None
        if isinstance(addr, socket.socket):
            self._sock = addr
            return
        if isinstance(addr, str):
            if not os.path.exists(addr):
                raise MuxError("socket unix:{} unable to connect".format(addr))
            family = socket.AF_UNIX
        else:
            family = socket.AF_INET

        self._sock = socket.socket(family, socket.SOCK_STREAM)
        self._sock.connect(addr) 
开发者ID:openatx,项目名称:facebook-wda,代码行数:20,代码来源:usbmux.py

示例2: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AF_UNIX [as 别名]
def __init__(self, global_config, address = '/var/run/rtpproxy.sock', \
      bind_address = None, nworkers = 1, family = socket.AF_UNIX):
        #print('Rtp_proxy_client_stream.__init__', address, bind_address, nworkers, family)
        if family == socket.AF_UNIX:
            self.is_local = True
            self.address = address
        else:
            self.is_local = False
            self.address = self.getdestbyaddr(address, family)
        self.family = family
        self.wi_available = Condition()
        self.wi = []
        self.nworkers = nworkers
        self.workers = []
        for i in range(0, self.nworkers):
            try:
                self.workers.append(_RTPPLWorker(self))
            except:
                break
        self.nworkers_act = i + 1
        self.delay_flt = recfilter(0.95, 0.25) 
开发者ID:sippy,项目名称:rtp_cluster,代码行数:23,代码来源:Rtp_proxy_client_stream.py

示例3: test_unix_socket_creation

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AF_UNIX [as 别名]
def test_unix_socket_creation(caplog):
    from socket import AF_UNIX, socket

    with socket(AF_UNIX) as sock:
        sock.bind(SOCKPATH)
    assert os.path.exists(SOCKPATH)
    ino = os.stat(SOCKPATH).st_ino

    app = Sanic(name=__name__)

    @app.listener("after_server_start")
    def running(app, loop):
        assert os.path.exists(SOCKPATH)
        assert ino != os.stat(SOCKPATH).st_ino
        app.stop()

    with caplog.at_level(logging.INFO):
        app.run(unix=SOCKPATH)

    assert (
        "sanic.root",
        logging.INFO,
        f"Goin' Fast @ {SOCKPATH} http://...",
    ) in caplog.record_tuples
    assert not os.path.exists(SOCKPATH) 
开发者ID:huge-success,项目名称:sanic,代码行数:27,代码来源:test_unix_socket.py

示例4: peer_creds

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AF_UNIX [as 别名]
def peer_creds(self):
        if self._creds is not False:
            return self._creds
        # works only for unix sockets
        if self.request.family != socket.AF_UNIX:
            self._creds = None
            return self._creds
        # pid_t: signed int32, uid_t/gid_t: unsigned int32
        fmt = 'iII'
        creds = self.request.getsockopt(socket.SOL_SOCKET, SO_PEERCRED,
                                        struct.calcsize(fmt))
        pid, uid, gid = struct.unpack(fmt, creds)
        try:
            creds = self.request.getsockopt(socket.SOL_SOCKET, SO_PEERSEC,
                                            SELINUX_CONTEXT_LEN)
            context = creds.rstrip(b'\x00').decode('utf-8')
        except Exception:  # pylint: disable=broad-except
            logger.debug("Couldn't retrieve SELinux Context", exc_info=True)
            context = None

        self._creds = {'pid': pid, 'uid': uid, 'gid': gid, 'context': context}
        return self._creds 
开发者ID:latchset,项目名称:custodia,代码行数:24,代码来源:server.py

示例5: connect

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AF_UNIX [as 别名]
def connect(self):
        """Connect to the UNIX socket
        """
        self._socket = socketlib.socket(
            socketlib.AF_UNIX, socketlib.SOCK_STREAM
        )
        self._socket.settimeout(self._timeout)
        try:
            self._socket.connect(self.path)
        except FileNotFoundError:
            raise GvmError(
                "Socket {path} does not exist".format(path=self.path)
            ) from None
        except ConnectionError:
            raise GvmError(
                "Could not connect to socket {}".format(self.path)
            ) from None 
开发者ID:greenbone,项目名称:python-gvm,代码行数:19,代码来源:connections.py

示例6: select_address_family

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AF_UNIX [as 别名]
def select_address_family(host, port):
    """Return ``AF_INET4``, ``AF_INET6``, or ``AF_UNIX`` depending on
    the host and port."""
    # disabled due to problems with current ipv6 implementations
    # and various operating systems.  Probably this code also is
    # not supposed to work, but I can't come up with any other
    # ways to implement this.
    # try:
    #     info = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
    #                               socket.SOCK_STREAM, 0,
    #                               socket.AI_PASSIVE)
    #     if info:
    #         return info[0][0]
    # except socket.gaierror:
    #     pass
    if host.startswith("unix://"):
        return socket.AF_UNIX
    elif ":" in host and hasattr(socket, "AF_INET6"):
        return socket.AF_INET6
    return socket.AF_INET 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:serving.py

示例7: init

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AF_UNIX [as 别名]
def init(self, daemon, connected_socket):
        connected_socket.getpeername()   # check that it is connected
        if config.SSL and not isinstance(connected_socket, ssl.SSLSocket):
            raise socket.error("SSL configured for Pyro but existing socket is not a SSL socket")
        self.daemon = daemon
        self.sock = connected_socket
        log.info("starting server on user-supplied connected socket " + str(connected_socket))
        sn = connected_socket.getsockname()
        if hasattr(socket, "AF_UNIX") and connected_socket.family == socket.AF_UNIX:
            self.locationStr = "./u:" + (sn or "<<not-bound>>")
        else:
            host, port = sn[:2]
            if ":" in host:  # ipv6
                self.locationStr = "[%s]:%d" % (host, port)
            else:
                self.locationStr = "%s:%d" % (host, port)
        self.conn = socketutil.SocketConnection(connected_socket) 
开发者ID:irmen,项目名称:Pyro5,代码行数:19,代码来源:svr_existingconn.py

示例8: testSendUnix

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AF_UNIX [as 别名]
def testSendUnix(self):
        if not hasattr(socket, "AF_UNIX"):
            pytest.skip("no unix domain sockets capability")
        SOCKNAME = "test_unixsocket"
        if os.path.exists(SOCKNAME):
            os.remove(SOCKNAME)
        ss = socketutil.create_socket(bind=SOCKNAME)
        cs = socketutil.create_socket(connect=SOCKNAME)
        socketutil.send_data(cs, b"foobar!" * 10)
        cs.shutdown(socket.SHUT_WR)
        a = ss.accept()
        data = socketutil.receive_data(a[0], 5)
        assert b"fooba" == data
        data = socketutil.receive_data(a[0], 5)
        assert b"r!foo" == data
        a[0].close()
        ss.close()
        cs.close()
        if os.path.exists(SOCKNAME):
            os.remove(SOCKNAME) 
开发者ID:irmen,项目名称:Pyro5,代码行数:22,代码来源:test_socketutil.py

示例9: _make_gevent_unix_socket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AF_UNIX [as 别名]
def _make_gevent_unix_socket(self, socket_file):
        # the socket file must not exist prior to bind()
        if os.path.exists(socket_file):
            # avoid nuking regular files and symbolic links (could be a mistype or security issue)
            if os.path.isfile(socket_file) or os.path.islink(socket_file):
                raise OSError(errno.EEXIST, os.strerror(errno.EEXIST), socket_file)
            os.remove(socket_file)

        unix_sock = WSGIServer.get_listener(socket_file, family=socket.AF_UNIX)
        self.unix_socket_file = socket_file

        # ensure current user and group have r/w permissions, no permissions for other users
        # this way the socket can be shared in a semi-secure manner
        # between the user running calibre-web and the user running the fronting webserver
        os.chmod(socket_file, 0o660)

        return unix_sock 
开发者ID:janeczku,项目名称:calibre-web,代码行数:19,代码来源:server.py

示例10: create_server

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AF_UNIX [as 别名]
def create_server(application,
                  map=None,
                  _start=True,      # test shim
                  _sock=None,       # test shim
                  _dispatcher=None, # test shim
                  **kw              # adjustments
                  ):
    """
    if __name__ == '__main__':
        server = create_server(app)
        server.run()
    """
    adj = Adjustments(**kw)
    if adj.unix_socket and hasattr(socket, 'AF_UNIX'):
        cls = UnixWSGIServer
    else:
        cls = TcpWSGIServer
    return cls(application, map, _start, _sock, _dispatcher, adj) 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:20,代码来源:server.py

示例11: pickaddr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AF_UNIX [as 别名]
def pickaddr(self, proto):
        if proto == socket.AF_INET:
            return (HOST, 0)
        else:
            # XXX: We need a way to tell AF_UNIX to pick its own name
            # like AF_INET provides port==0.
            dir = None
            if os.name == 'os2':
                dir = '\socket'
            fn = tempfile.mktemp(prefix='unix_socket.', dir=dir)
            if os.name == 'os2':
                # AF_UNIX socket names on OS/2 require a specific prefix
                # which can't include a drive letter and must also use
                # backslashes as directory separators
                if fn[1] == ':':
                    fn = fn[2:]
                if fn[0] in (os.sep, os.altsep):
                    fn = fn[1:]
                if os.sep == '/':
                    fn = fn.replace(os.sep, os.altsep)
                else:
                    fn = fn.replace(os.altsep, os.sep)
            self.test_files.append(fn)
            return fn 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_socketserver.py

示例12: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AF_UNIX [as 别名]
def __init__(self):
        tcp4 = ("tcp", socket.AF_INET, socket.SOCK_STREAM)
        tcp6 = ("tcp6", socket.AF_INET6, socket.SOCK_STREAM)
        udp4 = ("udp", socket.AF_INET, socket.SOCK_DGRAM)
        udp6 = ("udp6", socket.AF_INET6, socket.SOCK_DGRAM)
        unix = ("unix", socket.AF_UNIX, None)
        self.tmap = {
            "all": (tcp4, tcp6, udp4, udp6, unix),
            "tcp": (tcp4, tcp6),
            "tcp4": (tcp4,),
            "tcp6": (tcp6,),
            "udp": (udp4, udp6),
            "udp4": (udp4,),
            "udp6": (udp6,),
            "unix": (unix,),
            "inet": (tcp4, tcp6, udp4, udp6),
            "inet4": (tcp4, udp4),
            "inet6": (tcp6, udp6),
        }
        self._procfs_path = None 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,代码来源:_pslinux.py

示例13: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AF_UNIX [as 别名]
def __init__(self):
        # The string represents the basename of the corresponding
        # /proc/net/{proto_name} file.
        tcp4 = ("tcp", socket.AF_INET, socket.SOCK_STREAM)
        tcp6 = ("tcp6", socket.AF_INET6, socket.SOCK_STREAM)
        udp4 = ("udp", socket.AF_INET, socket.SOCK_DGRAM)
        udp6 = ("udp6", socket.AF_INET6, socket.SOCK_DGRAM)
        unix = ("unix", socket.AF_UNIX, None)
        self.tmap = {
            "all": (tcp4, tcp6, udp4, udp6, unix),
            "tcp": (tcp4, tcp6),
            "tcp4": (tcp4,),
            "tcp6": (tcp6,),
            "udp": (udp4, udp6),
            "udp4": (udp4,),
            "udp6": (udp6,),
            "unix": (unix,),
            "inet": (tcp4, tcp6, udp4, udp6),
            "inet4": (tcp4, udp4),
            "inet6": (tcp6, udp6),
        }
        self._procfs_path = None 
开发者ID:giampaolo,项目名称:psutil,代码行数:24,代码来源:_pslinux.py

示例14: recvfd

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AF_UNIX [as 别名]
def recvfd(socketfd):
    """
    Receive a file descriptor from a L{sendmsg} message on the given C{AF_UNIX}
    socket.

    @param socketfd: An C{AF_UNIX} socket, attached to another process waiting
        to send sockets via the ancillary data mechanism in L{send1msg}.

    @param fd: C{int}

    @return: a 2-tuple of (new file descriptor, description).
    @rtype: 2-tuple of (C{int}, C{bytes})
    """
    ourSocket = socket.fromfd(socketfd, socket.AF_UNIX, socket.SOCK_STREAM)
    data, ancillary, flags = recvmsg(ourSocket)
    [(cmsgLevel, cmsgType, packedFD)] = ancillary
    # cmsgLevel and cmsgType really need to be SOL_SOCKET / SCM_RIGHTS, but
    # since those are the *only* standard values, there's not much point in
    # checking.
    [unpackedFD] = unpack("i", packedFD)
    return (unpackedFD, data) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:pullpipe.py

示例15: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AF_UNIX [as 别名]
def __init__(self, global_config, address = '/var/run/rtpproxy.sock', \
      bind_address = None, nworkers = 1):
        Rtp_proxy_client_stream.__init__(self, global_config = global_config, \
          address = address, bind_address = bind_address, nworkers = nworkers, \
          family = socket.AF_UNIX) 
开发者ID:sippy,项目名称:rtp_cluster,代码行数:7,代码来源:Rtp_proxy_client_local.py


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