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


Python tcp.Port方法代码示例

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


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

示例1: adoptStreamPort

# 需要导入模块: from twisted.internet import tcp [as 别名]
# 或者: from twisted.internet.tcp import Port [as 别名]
def adoptStreamPort(self, fileDescriptor, addressFamily, factory):
        """
        Create a new L{IListeningPort} from an already-initialized socket.

        This just dispatches to a suitable port implementation (eg from
        L{IReactorTCP}, etc) based on the specified C{addressFamily}.

        @see: L{twisted.internet.interfaces.IReactorSocket.adoptStreamPort}
        """
        if addressFamily not in (socket.AF_INET, socket.AF_INET6):
            raise error.UnsupportedAddressFamily(addressFamily)

        p = tcp.Port._fromListeningDescriptor(
            self, fileDescriptor, addressFamily, factory)
        p.startListening()
        return p 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:posixbase.py

示例2: connectionLost

# 需要导入模块: from twisted.internet import tcp [as 别名]
# 或者: from twisted.internet.tcp import Port [as 别名]
def connectionLost(self, reason=None):
        """Cleans up my socket.
        """
        log.msg('(Port %s Closed)' % repr(self.port))
        base.BasePort.connectionLost(self, reason)
        if hasattr(self, "protocol"):
            # we won't have attribute in ConnectedPort, in cases
            # where there was an error in connection process
            self.protocol.doStop()
        self.connected = 0
        self.socket.close()
        del self.socket
        del self.fileno
        if hasattr(self, "d"):
            self.d.callback(None)
            del self.d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:unix.py

示例3: adoptStreamPort

# 需要导入模块: from twisted.internet import tcp [as 别名]
# 或者: from twisted.internet.tcp import Port [as 别名]
def adoptStreamPort(self, fileDescriptor, addressFamily, factory):
        """
        Create a new L{IListeningPort} from an already-initialized socket.

        This just dispatches to a suitable port implementation (eg from
        L{IReactorTCP}, etc) based on the specified C{addressFamily}.

        @see: L{twisted.internet.interfaces.IReactorSocket.adoptStreamPort}
        """
        if addressFamily not in self._supportedAddressFamilies:
            raise error.UnsupportedAddressFamily(addressFamily)

        if unixEnabled and addressFamily == socket.AF_UNIX:
            p = unix.Port._fromListeningDescriptor(
                self, fileDescriptor, factory)
        else:
            p = tcp.Port._fromListeningDescriptor(
                self, fileDescriptor, addressFamily, factory)
        p.startListening()
        return p 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:22,代码来源:posixbase.py

示例4: _fromListeningDescriptor

# 需要导入模块: from twisted.internet import tcp [as 别名]
# 或者: from twisted.internet.tcp import Port [as 别名]
def _fromListeningDescriptor(cls, reactor, fd, factory):
        """
        Create a new L{Port} based on an existing listening I{SOCK_STREAM}
        socket.

        Arguments are the same as to L{Port.__init__}, except where noted.

        @param fd: An integer file descriptor associated with a listening
            socket.  The socket must be in non-blocking mode.  Any additional
            attributes desired, such as I{FD_CLOEXEC}, must also be set already.

        @return: A new instance of C{cls} wrapping the socket given by C{fd}.
        """
        port = socket.fromfd(fd, cls.addressFamily, cls.socketType)
        self = cls(port.getsockname(), factory, reactor=reactor)
        self._preexistingSocket = port
        return self 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:19,代码来源:unix.py

示例5: upgradeToVersion7

# 需要导入模块: from twisted.internet import tcp [as 别名]
# 或者: from twisted.internet.tcp import Port [as 别名]
def upgradeToVersion7(self):
        self.tcpPorts = []
        self.udpPorts = []
        self.sslPorts = []
        from twisted.internet import tcp, udp
        for port in self.ports:
            if isinstance(port, tcp.Port):
                self.tcpPorts.append(
                    (port.port, port.factory,
                     port.backlog, port.interface))
            elif isinstance(port, udp.Port):
                self.udpPorts.append(
                    port.port, port.factory,
                    port.interface, port.maxPacketSize)
            else:
                log.msg('upgrade of %s not implemented, sorry' % port.__class__)
        del self.ports 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:19,代码来源:app.py

示例6: unlistenWith

# 需要导入模块: from twisted.internet import tcp [as 别名]
# 或者: from twisted.internet.tcp import Port [as 别名]
def unlistenWith(self, portType, *args, **kw):
        """
        Stop a Port listening with the given parameters.
        """
        toRemove = []
        for t in self.extraPorts:
            _portType, _args, _kw = t
            if portType == _portType:
                if args == _args[:len(args)]:
                    for (k, v) in kw.items():
                        if _kw.has_key(k) and _kw[k] != v:
                            break
                    else:
                        toRemove.append(t)
        if toRemove:
            for t in toRemove:
                self.extraPorts.remove(t)
                if self._extraListeners.has_key(t):
                    self._extraListeners[t].stopListening()
                    del self._extraListeners[t]
        else:
            raise error.NotListeningError, (portType, args, kw) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:24,代码来源:app.py

示例7: unlistenTCP

# 需要导入模块: from twisted.internet import tcp [as 别名]
# 或者: from twisted.internet.tcp import Port [as 别名]
def unlistenTCP(self, port, interface=''):
        """
        Stop a Port listening on the given port and interface.
        """
        toRemove = []
        for t in self.tcpPorts:
            port_, factory_, backlog_, interface_ = t
            if port == port_ and interface == interface_:
                toRemove.append(t)
        if toRemove:
            for t in toRemove:
                self.tcpPorts.remove(t)
            if self._listenerDict.has_key((port, interface)):
                self._listenerDict[(port, interface)].stopListening()
        else:
            raise error.NotListeningError, (interface, port) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:18,代码来源:app.py

示例8: unlistenUNIX

# 需要导入模块: from twisted.internet import tcp [as 别名]
# 或者: from twisted.internet.tcp import Port [as 别名]
def unlistenUNIX(self, filename):
        """
        Stop a Port listening on the given filename.
        """
        toRemove = []
        for t in self.unixPorts:
            filename_, factory_, backlog_, mode_ = t
            if filename == filename_:
                toRemove.append(t)
        if toRemove:
            for t in toRemove:
                self.unixPorts.remove(t)
            if self._listenerDict.has_key(filename):
                self._listenerDict[filename].stopListening()
        else:
            raise error.NotListeningError, filename 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:18,代码来源:app.py

示例9: test_starting_and_stopping_the_service

# 需要导入模块: from twisted.internet import tcp [as 别名]
# 或者: from twisted.internet.tcp import Port [as 别名]
def test_starting_and_stopping_the_service(self):
        service = RegionService(sentinel.ipcWorker)
        self.assertThat(service.starting, Is(None))
        service.startService()
        self.assertThat(service.starting, IsInstance(Deferred))

        def check_started(_):
            # Ports are saved as private instance vars.
            self.assertThat(service.ports, HasLength(1))
            [port] = service.ports
            self.assertThat(port, IsInstance(tcp.Port))
            self.assertThat(port.factory, IsInstance(Factory))
            self.assertThat(port.factory.protocol, Equals(RegionServer))
            return service.stopService()

        service.starting.addCallback(check_started)

        def check_stopped(ignore, service=service):
            self.assertThat(service.ports, Equals([]))

        service.starting.addCallback(check_stopped)

        return service.starting 
开发者ID:maas,项目名称:maas,代码行数:25,代码来源:test_regionservice.py

示例10: listenUDP

# 需要导入模块: from twisted.internet import tcp [as 别名]
# 或者: from twisted.internet.tcp import Port [as 别名]
def listenUDP(self, port, protocol, interface='', maxPacketSize=8192):
        """Connects a given L{DatagramProtocol} to the given numeric UDP port.

        @returns: object conforming to L{IListeningPort}.
        """
        p = udp.Port(port, protocol, interface, maxPacketSize, self)
        p.startListening()
        return p

    # IReactorMulticast 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:posixbase.py

示例11: listenUNIX

# 需要导入模块: from twisted.internet import tcp [as 别名]
# 或者: from twisted.internet.tcp import Port [as 别名]
def listenUNIX(self, address, factory, backlog=50, mode=0o666, wantPID=0):
        assert unixEnabled, "UNIX support is not present"
        p = unix.Port(address, factory, backlog, mode, self, wantPID)
        p.startListening()
        return p


    # IReactorUNIXDatagram 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:posixbase.py

示例12: adoptDatagramPort

# 需要导入模块: from twisted.internet import tcp [as 别名]
# 或者: from twisted.internet.tcp import Port [as 别名]
def adoptDatagramPort(self, fileDescriptor, addressFamily, protocol,
                          maxPacketSize=8192):
        if addressFamily not in (socket.AF_INET, socket.AF_INET6):
            raise error.UnsupportedAddressFamily(addressFamily)

        p = udp.Port._fromListeningDescriptor(
            self, fileDescriptor, addressFamily, protocol,
            maxPacketSize=maxPacketSize)
        p.startListening()
        return p



    # IReactorTCP 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:posixbase.py

示例13: listenTCP

# 需要导入模块: from twisted.internet import tcp [as 别名]
# 或者: from twisted.internet.tcp import Port [as 别名]
def listenTCP(self, port, factory, backlog=50, interface=''):
        p = tcp.Port(port, factory, backlog, interface, self)
        p.startListening()
        return p 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:6,代码来源:posixbase.py

示例14: __init__

# 需要导入模块: from twisted.internet import tcp [as 别名]
# 或者: from twisted.internet.tcp import Port [as 别名]
def __init__(self, port, factory, ctxFactory, backlog=50, interface='', reactor=None):
        tcp.Port.__init__(self, port, factory, backlog, interface, reactor)
        self.ctxFactory = ctxFactory 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:5,代码来源:ssl.py

示例15: _getLogPrefix

# 需要导入模块: from twisted.internet import tcp [as 别名]
# 或者: from twisted.internet.tcp import Port [as 别名]
def _getLogPrefix(self, factory):
        """
        Override the normal prefix to include an annotation indicating this is a
        port for TLS connections.
        """
        return tcp.Port._getLogPrefix(self, factory) + ' (TLS)' 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:8,代码来源:ssl.py


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