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


Python portnumbergenerator.PortNumberGenerator类代码示例

本文整理汇总了Python中seecr.test.portnumbergenerator.PortNumberGenerator的典型用法代码示例。如果您正苦于以下问题:Python PortNumberGenerator类的具体用法?Python PortNumberGenerator怎么用?Python PortNumberGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testHttpGetViaProxy

    def testHttpGetViaProxy(self):
        get_request = []
        port = PortNumberGenerator.next()
        proxyPort = PortNumberGenerator.next()
        self.proxyServer(proxyPort, get_request)
        self.referenceHttpServer(port, get_request)

        responses = []
        def gethandler(*args, **kwargs):
            response = yield httpget('localhost', port, '/path',
                    headers={'Content-Type': 'text/plain', 'Content-Length': 0},
                    proxyServer="http://localhost:%s" % proxyPort
            )
            yield response
            responses.append(response)
        self.handler = gethandler
        clientget('localhost', self.port, '/')

        self._loopReactorUntilDone()

        self.assertTrue("GET RESPONSE" in responses[0], responses[0])
        self.assertEquals('CONNECT', get_request[0]['command'])
        self.assertEquals('localhost:%s' % port, get_request[0]['path'])
        self.assertEquals('GET', get_request[1]['command'])
        self.assertEquals('/path', get_request[1]['path'])
开发者ID:seecr,项目名称:weightless-core,代码行数:25,代码来源:asyncreadertest.py

示例2: __init__

    def __init__(self, stateName, tests=None, fastMode=False):
        IntegrationState.__init__(self, "examples-" + stateName, tests=tests, fastMode=fastMode)

        self.testdataDir = join(dirname(mydir), 'data')
        self.gatewayPort = PortNumberGenerator.next()
        self.indexPort = PortNumberGenerator.next()
        self.apiPort = PortNumberGenerator.next()
        self.lucenePort = PortNumberGenerator.next()
开发者ID:seecr,项目名称:meresco-examples,代码行数:8,代码来源:integrationstate.py

示例3: testConnectFails

    def testConnectFails(self):
        def failingserver(*args, **kwarg):
            response = yield httpget(*target)

        self.handler = failingserver

        clientget('localhost', self.port, '/')
        target = ('localhost', 'port', '/') # non-numeric port
        self._loopReactorUntilDone()

        expectedTraceback = ignoreLineNumbers("""Traceback (most recent call last):
  File "%(__file__)s", line 0, in handle
      yield self.handler(*args, **kwargs)
  File "%(__file__)s", line 85, in failingserver
    response = yield httpget(*target)
  File "%(httprequest.py)s", line 78, in httprequest
    result = s.getResult()
  File "%(suspend.py)s", line 34, in __call__
    self._doNext(self)
  File "%(httprequest.py)s", line 35, in _do
    sok.connect((host, port))
  File "<string>", line 1, in connect
TypeError: an integer is required
       """ % fileDict)
        if PYVERSION == "2.7":
            expectedTraceback = ignoreLineNumbers("""Traceback (most recent call last):
  File "%(__file__)s", line 0, in handle
      yield self.handler(*args, **kwargs)
  File "%(__file__)s", line 85, in failingserver
    response = yield httpget(*target)
  File "%(httprequest.py)s", line 78, in httprequest
    result = s.getResult()
  File "%(suspend.py)s", line 34, in __call__
    self._doNext(self)
  File "%(httprequest.py)s", line 35, in _do
    sok.connect((host, port))
  File "/usr/lib/python2.7/socket.py", line [#], in meth
    return getattr(self._sock,name)(*args)
TypeError: an integer is required
       """ % fileDict)
        self.assertEquals(TypeError, self.error[0])
        self.assertEqualsWS(expectedTraceback, ignoreLineNumbers(''.join(format_exception(*self.error))))

        target = ('localhost', 87, '/') # invalid port
        clientget('localhost', self.port, '/')
        self._loopReactorUntilDone()
        self.assertEquals(IOError, self.error[0])

        target = ('UEYR^$*FD(#>NDJ.khfd9.(*njnd', PortNumberGenerator.next(), '/') # invalid host
        clientget('localhost', self.port, '/')
        self._loopReactorUntilDone()
        self.assertEquals(SocketGaiError, self.error[0])

        target = ('127.0.0.1', PortNumberGenerator.next(), '/')  # No-one listens
        clientget('localhost', self.port, '/')
        self._loopReactorUntilDone()
        self.assertEquals(IOError, self.error[0])
        self.assertEquals('111', str(self.error[1]))
开发者ID:seecr,项目名称:weightless-core,代码行数:58,代码来源:asyncreadertest.py

示例4: testBindPortRangeNumberGiven

    def testBindPortRangeNumberGiven(self):
        port = PortNumberGenerator.next(blockSize=2)
        port2 = port + 1
        PortNumberGenerator.bind(port=port, blockSize=2)
        self.assertNotBound(bindV4(ip='127.0.0.1', port=port, protocol='tcp', reuse=True))
        self.assertNotBound(bindV4(ip='127.0.0.1', port=port2, protocol='tcp', reuse=True))

        PortNumberGenerator.unbind(port=port, blockSize=2)
        self.assertBoundAndUnbind(bindV4(ip='127.0.0.1', port=port, protocol='tcp', reuse=True))
        self.assertBoundAndUnbind(bindV4(ip='127.0.0.1', port=port2, protocol='tcp', reuse=True))
开发者ID:seecr,项目名称:seecr-test,代码行数:10,代码来源:portnumbergeneratortest.py

示例5: testUnbindPortNumberV4

    def testUnbindPortNumberV4(self):
        p = PortNumberGenerator.next(bind=True)
        self.assertNotBound(bindV4(ip='127.0.0.1', port=p, protocol='tcp', reuse=True))

        PortNumberGenerator.unbind(port=p)
        self.assertBoundAndUnbind(bindV4(ip='127.0.0.1', port=p, protocol='tcp', reuse=False))
        self.assertBoundAndUnbind(bindV4(ip='127.0.0.1', port=p, protocol='tcp', reuse=False)) # Same IP-version, protocol, host, port combination: basically testing bindV4's close happened.
        self.assertBoundAndUnbind(bindV4(ip='127.0.0.1', port=p, protocol='udp', reuse=False))
        self.assertBoundAndUnbind(bindV4(ip='0.0.0.0', port=p, protocol='tcp', reuse=False))
        self.assertBoundAndUnbind(bindV4(ip='0.0.0.0', port=p, protocol='udp', reuse=False))
开发者ID:seecr,项目名称:seecr-test,代码行数:10,代码来源:portnumbergeneratortest.py

示例6: testBindPortNumberGiven

    def testBindPortNumberGiven(self):
        port, close = attemptBinding(bindPort=0); close()
        PortNumberGenerator.bind(port=port)
        self.assertNotBound(bindV4(ip='127.0.0.1', port=port, protocol='tcp', reuse=True))
        if has_dual_stack():
            self.assertNotBound(bindV6(ip='::1', port=port, protocol='tcp', reuse=True))

        PortNumberGenerator.unbind(port=port)
        self.assertBoundAndUnbind(bindV4(ip='127.0.0.1', port=port, protocol='tcp', reuse=True))
        if has_dual_stack():
            self.assertBoundAndUnbind(bindV6(ip='::1', port=port, protocol='tcp', reuse=True))
开发者ID:seecr,项目名称:seecr-test,代码行数:11,代码来源:portnumbergeneratortest.py

示例7: __init__

    def __init__(self, stateName, tests=None, fastMode=False):
        IntegrationState.__init__(self, stateName=stateName, tests=tests, fastMode=fastMode)

        self.virtuosoDataDir = join(self.integrationTempdir, 'virtuoso-data')
        self.bulkLoadDir = join(self.integrationTempdir, 'bulk-load-data')
        self.virtuosoPort = PortNumberGenerator.next()
        self.odbcPort = PortNumberGenerator.next()
        self.httpPort = PortNumberGenerator.next()
        self.testdataDir = join(dirname(myDir), 'data')
        if not fastMode:
            system('rm -rf ' + self.integrationTempdir)
            system('mkdir --parents ' + self.virtuosoDataDir)
开发者ID:seecr,项目名称:meresco-virtuoso,代码行数:12,代码来源:virtuosointegrationstate.py

示例8: __init__

 def __init__(self, stateName, tests=None, fastMode=False):
     SeecrIntegrationState.__init__(self, "meresco-lucene-" + stateName, tests=tests, fastMode=fastMode)
     self.stateName = stateName
     if not fastMode:
         system('rm -rf ' + self.integrationTempdir)
         system('mkdir --parents '+ self.integrationTempdir)
     self.suggestionServerPort = PortNumberGenerator.next()
     self.luceneServerPort = PortNumberGenerator.next()
     self.httpPort = PortNumberGenerator.next()
     self.testdataDir = join(dirname(mydir), "data")
     self.JAVA_BIN = "/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/bin"
     if not isdir(self.JAVA_BIN):
         self.JAVA_BIN = "/usr/lib/jvm/java-1.8.0/bin"
开发者ID:seecr,项目名称:meresco-lucene,代码行数:13,代码来源:integrationstate.py

示例9: testReasonableAmountOfUniquePortNumbers

    def testReasonableAmountOfUniquePortNumbers(self):
        number = PortNumberGenerator.next()

        self.assertEquals(int, type(number))

        numbers = []
        # More than 14000 gets *very* slow or fails
        # When guaranteed uniqe numbers for that many ports are needed,
        # change the approach (say reading: cat /proc/net/tcp | awk '{print $2}' | sed -e '1d')
        for i in xrange(14000):
            numbers.append(PortNumberGenerator.next())

        self.assertEquals(14000, len(numbers))
        self.assertEquals(14000, len(set(numbers)))
        self.assertEquals(True, all((0 <= n < 65536) for n in numbers))
开发者ID:seecr,项目名称:seecr-test,代码行数:15,代码来源:portnumbergeneratortest.py

示例10: testCloseStatesLocalFirst

    def testCloseStatesLocalFirst(self):
        remoteport = PortNumberGenerator.next()
        server = socket()
        server.bind(('localhost', remoteport))
        server.listen(1)
        local = socket()
        local.connect(('localhost', remoteport))
        localport = local.getsockname()[1]

        remote = server.accept()[0]
        self.assertNetStat(remoteport, localport, 'ESTABLISHED')
        self.assertNetStat(localport, remoteport, 'ESTABLISHED')

        local.close()
        self.assertNetStat(localport, remoteport, 'FIN_WAIT')
        self.assertNetStat(remoteport, localport, 'CLOSE_WAIT')

        remote.close()
        self.assertNetStat(localport, remoteport, 'TIME_WAIT')
        self.assertNetStat(remoteport, localport, None)

        server = socket()
        try:
            server.bind(('127.0.0.1', remoteport))
        except:
            self.fail('bind must succeed')
开发者ID:seecr,项目名称:weightless-core,代码行数:26,代码来源:httpprotocolintegrationtest.py

示例11: testSuspendProtocol

    def testSuspendProtocol(self):
        with Reactor() as reactor:
            suspend = Suspend()
            def handler(**httpvars):
                yield 'before suspend'
                yield suspend
                yield "result = %s" % suspend.getResult()
                yield 'after suspend'
            listener = MyMockSocket()
            port = PortNumberGenerator.next()
            httpserver = HttpServer(reactor, port, handler, sok=listener)
            httpserver.listen()
            reactor.removeReader(listener) # avoid new connections
            httpserver._acceptor._accept()
            self.assertEquals(1, len(reactor._fds))
            self.assertEquals([READ_INTENT], [v.intent for v in reactor._fds.values()])
            reactor.step()
            self.assertEquals(1, len(reactor._fds))
            self.assertEquals([WRITE_INTENT], [v.intent for v in reactor._fds.values()])
            reactor.step()
            reactor.step()
            self.assertEquals(reactor, suspend._reactor)
            self.assertEquals(0, len(reactor._fds))
            suspend.resume('RESPONSE')
            self.assertEquals(1, len(reactor._fds))
            self.assertEquals([WRITE_INTENT], [v.intent for v in reactor._fds.values()])
            reactor.step()
            reactor.step()
            reactor.step()
            self.assertEquals(['before suspend', 'result = RESPONSE', 'after suspend'], listener.data)
            self.assertEquals(0, len(reactor._fds))

            # cleanup (most) fd's
            listener.close()
开发者ID:seecr,项目名称:weightless-core,代码行数:34,代码来源:suspendtest.py

示例12: testConnect

    def testConnect(self):
        self.req = False
        serverResponse = 'Hello World'
        def onRequest(**kwargs):
            yield 'HTTP/1.0 200 OK\r\n\r\n' + serverResponse
            self.req = True

        port = PortNumberGenerator.next()
        with Reactor() as reactor:
            try:
                server = HttpsServer(reactor, port, onRequest, keyfile='ssl/server.pkey', certfile='ssl/server.cert')
                server.listen()

                p = Popen('wget -O - --no-check-certificate --quiet https://localhost:%s' % port, shell=True, stdout=PIPE)

                popenStdout = []
                def readPopenStdout():
                    popenStdout.append(p.stdout.read())
                reactor.addReader(p.stdout, readPopenStdout)

                while not self.req:
                   reactor.step()

                reactor.step()
                self.assertEquals(1, len(popenStdout))
                self.assertEquals(serverResponse, popenStdout[0])
            finally:
                server.shutdown()

            # cleanup
            reactor.removeReader(p.stdout)
开发者ID:seecr,项目名称:weightless-core,代码行数:31,代码来源:httpsservertest.py

示例13: testSuspendProtocolWithThrow

 def testSuspendProtocolWithThrow(self):
     with Reactor() as reactor:
         suspend = Suspend()
         def handler(**httpvars):
             yield 'before suspend'
             yield suspend
             try:
                 suspend.getResult()
                 self.fail()
             except ValueError, e:
                 tbstring = format_exc()
                 yield "result = %s" % tbstring
             yield 'after suspend'
         listener = MyMockSocket()
         port = PortNumberGenerator.next()
         httpserver = HttpServer(reactor, port, handler, sok=listener)
         httpserver.listen()
         reactor.removeReader(listener) # avoid new connections
         httpserver._acceptor._accept()
         reactor.step()
         reactor.step()
         reactor.step()
         self.assertEquals(reactor, suspend._reactor)
         self.assertEquals(0, len(reactor._fds))
         def raiser():
             raise ValueError("BAD VALUE")
         try:
             raiser()
         except ValueError, e:
             exc_type, exc_value, exc_traceback = exc_info()
             suspend.throw(exc_type, exc_value, exc_traceback)
开发者ID:seecr,项目名称:weightless-core,代码行数:31,代码来源:suspendtest.py

示例14: setUp

 def setUp(self):
     TestCase.setUp(self)
     self.tempdir = mkdtemp()
     fd, self.tempfile = mkstemp()
     os.close(fd)
     self.reactor = Reactor()
     self.port = PortNumberGenerator.next()
开发者ID:seecr,项目名称:weightless-core,代码行数:7,代码来源:weightlesstestcase.py

示例15: testCloseStatesRemoteFirst

    def testCloseStatesRemoteFirst(self):
        remoteport = PortNumberGenerator.next()
        server = socket()
        server.bind(('127.0.0.1', remoteport))
        server.listen(1)
        local = socket()
        local.connect(('127.0.0.1', remoteport))
        localport = local.getsockname()[1]

        remote = server.accept()[0]
        self.assertNetStat(remoteport, localport, 'ESTABLISHED')
        self.assertNetStat(localport, remoteport, 'ESTABLISHED')

        remote.close()
        self.assertNetStat(remoteport, localport, 'FIN_WAIT')
        self.assertNetStat(localport, remoteport, 'CLOSE_WAIT')

        local.close()
        self.assertNetStat(remoteport, localport, 'TIME_WAIT')
        self.assertNetStat(localport, remoteport, None)

        server.close()
        server = socket()
        try:
            server.bind(('127.0.0.1', remoteport))
            self.fail('re-bind must raise Address Already in Use Exception')
        except AssertionError:
            raise
        except Exception, e:
            pass
开发者ID:seecr,项目名称:weightless-core,代码行数:30,代码来源:httpprotocolintegrationtest.py


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