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


Python support.transient_internet函数代码示例

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


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

示例1: test_connect_using_sslcontext_verified

    def test_connect_using_sslcontext_verified(self):
        with support.transient_internet(self.testServer):
            can_verify = check_ssl_verifiy(self.testServer, self.remotePort)
            if not can_verify:
                self.skipTest("SSL certificate can't be verified")

        support.get_attribute(smtplib, 'SMTP_SSL')
        context = ssl.create_default_context()
        with support.transient_internet(self.testServer):
            server = smtplib.SMTP_SSL(self.testServer, self.remotePort, context=context)
            server.ehlo()
            server.quit()
开发者ID:10sr,项目名称:cpython,代码行数:12,代码来源:test_smtpnet.py

示例2: test_redirect_url_withfrag

 def test_redirect_url_withfrag(self):
     redirect_url_with_frag = "http://bitly.com/urllibredirecttest"
     with support.transient_internet(redirect_url_with_frag):
         req = urllib.request.Request(redirect_url_with_frag)
         res = urllib.request.urlopen(req)
         self.assertEqual(res.geturl(),
                 "http://docs.python.org/3.4/glossary.html#term-global-interpreter-lock")
开发者ID:GuardianRG,项目名称:static-python,代码行数:7,代码来源:test_urllib2net.py

示例3: test_connect_using_sslcontext

 def test_connect_using_sslcontext(self):
     context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
     support.get_attribute(smtplib, 'SMTP_SSL')
     with support.transient_internet(self.testServer):
         server = smtplib.SMTP_SSL(self.testServer, self.remotePort, context=context)
         server.ehlo()
         server.quit()
开发者ID:10sr,项目名称:cpython,代码行数:7,代码来源:test_smtpnet.py

示例4: testPasswordProtectedSite

 def testPasswordProtectedSite(self):
     support.requires('network')
     with support.transient_internet('mueblesmoraleda.com'):
         url = 'http://mueblesmoraleda.com'
         robots_url = url + "/robots.txt"
         # First check the URL is usable for our purposes, since the
         # test site is a bit flaky.
         try:
             urlopen(robots_url)
         except HTTPError as e:
             if e.code not in {401, 403}:
                 self.skipTest(
                     "%r should return a 401 or 403 HTTP error, not %r"
                     % (robots_url, e.code))
         else:
             self.skipTest(
                 "%r should return a 401 or 403 HTTP error, not succeed"
                 % (robots_url))
         parser = urllib.robotparser.RobotFileParser()
         parser.set_url(url)
         try:
             parser.read()
         except URLError:
             self.skipTest('%s is unavailable' % url)
         self.assertEqual(parser.can_fetch("*", robots_url), False)
开发者ID:AlexHorlenko,项目名称:ironpython3,代码行数:25,代码来源:test_robotparser.py

示例5: _test_urls

    def _test_urls(self, urls, handlers, retry=True):
        import socket
        import time
        import logging
        debug = logging.getLogger("test_urllib2").debug

        urlopen = urllib.request.build_opener(*handlers).open
        if retry:
            urlopen = _wrap_with_retry_thrice(urlopen, urllib.error.URLError)

        for url in urls:
            if isinstance(url, tuple):
                url, req, expected_err = url
            else:
                req = expected_err = None
            debug(url)
            try:
                f = urlopen(url, req)
            except EnvironmentError as err:
                debug(err)
                if expected_err:
                    msg = ("Didn't get expected error(s) %s for %s %s, got %s: %s" %
                           (expected_err, url, req, type(err), err))
                    self.assert_(isinstance(err, expected_err), msg)
            else:
                with support.transient_internet():
                    buf = f.read()
                f.close()
                debug("read %d bytes" % len(buf))
            debug("******** next url coming up...")
            time.sleep(0.1)
开发者ID:LinkedModernismProject,项目名称:web_code,代码行数:31,代码来源:test_urllib2net.py

示例6: test_connect_using_sslcontext_verified

 def test_connect_using_sslcontext_verified(self):
     support.get_attribute(smtplib, 'SMTP_SSL')
     context = ssl.create_default_context()
     with support.transient_internet(self.testServer):
         server = smtplib.SMTP_SSL(self.testServer, self.remotePort, context=context)
         server.ehlo()
         server.quit()
开发者ID:LesyaMazurevich,项目名称:python-1,代码行数:7,代码来源:test_smtpnet.py

示例7: test_redirect_url_withfrag

 def test_redirect_url_withfrag(self):
     redirect_url_with_frag = "http://bit.ly/1iSHToT"
     with support.transient_internet(redirect_url_with_frag):
         req = request.Request(redirect_url_with_frag)
         res = yield from request.urlopen(req)
         self.assertEqual(res.geturl(),
                 "https://docs.python.org/3.4/glossary.html#term-global-interpreter-lock")
开发者ID:rdbhost,项目名称:yieldfromUrllib2,代码行数:7,代码来源:test_urllib2net.py

示例8: test_http_basic

 def test_http_basic(self):
     self.assertIsNone(socket.getdefaulttimeout())
     url = support.TEST_HTTP_URL
     with support.transient_internet(url, timeout=None):
         u = _urlopen_with_retry(url)
         self.addCleanup(u.close)
         self.assertIsNone(u.fp.raw._sock.gettimeout())
开发者ID:Eyepea,项目名称:cpython,代码行数:7,代码来源:test_urllib2net.py

示例9: test_urlwithfrag

 def test_urlwithfrag(self):
     urlwith_frag = "http://www.pythontest.net/index.html#frag"
     with support.transient_internet(urlwith_frag):
         req = urllib.request.Request(urlwith_frag)
         res = urllib.request.urlopen(req)
         self.assertEqual(res.geturl(),
                 "http://www.pythontest.net/index.html#frag")
开发者ID:10sr,项目名称:cpython,代码行数:7,代码来源:test_urllib2net.py

示例10: test_networked

 def test_networked(self):
     # Default settings: no cert verification is done
     support.requires("network")
     with support.transient_internet("svn.python.org"):
         h = client.HTTPSConnection("svn.python.org", 443)
         h.request("GET", "/")
         resp = h.getresponse()
         self._check_svn_python_org(resp)
开发者ID:pogigroo,项目名称:py3k-__format__,代码行数:8,代码来源:test_httplib.py

示例11: resolve_address

def resolve_address(host, port):
    """Resolve an (host, port) to an address.

    We must perform name resolution before timeout tests, otherwise it will be
    performed by connect().
    """
    with support.transient_internet(host):
        return socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM)[0][4]
开发者ID:pierreorz,项目名称:web_ctp,代码行数:8,代码来源:test_timeout.py

示例12: testPythonOrg

 def testPythonOrg(self):
     support.requires('network')
     with support.transient_internet('www.python.org'):
         parser = urllib.robotparser.RobotFileParser(
             "http://www.python.org/robots.txt")
         parser.read()
         self.assertTrue(
             parser.can_fetch("*", "http://www.python.org/robots.txt"))
开发者ID:AlexHorlenko,项目名称:ironpython3,代码行数:8,代码来源:test_robotparser.py

示例13: test_logincapa

 def test_logincapa(self):
     with transient_internet(self.host):
         for cap in self.server.capabilities:
             self.assertIsInstance(cap, str)
         self.assertTrue('LOGINDISABLED' in self.server.capabilities)
         self.assertTrue('AUTH=ANONYMOUS' in self.server.capabilities)
         rs = self.server.login(self.username, self.password)
         self.assertEqual(rs[0], 'OK')
开发者ID:Naddiseo,项目名称:cpython,代码行数:8,代码来源:test_imaplib.py

示例14: urlopen

 def urlopen(self, *args, **kwargs):
     resource = args[0]
     with support.transient_internet(resource):
         r = urllib.request.urlopen(*args, **kwargs)
         try:
             yield r
         finally:
             r.close()
开发者ID:3lnc,项目名称:cpython,代码行数:8,代码来源:test_urllibnet.py

示例15: urlretrieve

 def urlretrieve(self, *args, **kwargs):
     resource = args[0]
     with support.transient_internet(resource):
         file_location, info = urllib.request.urlretrieve(*args, **kwargs)
         try:
             yield file_location, info
         finally:
             support.unlink(file_location)
开发者ID:3lnc,项目名称:cpython,代码行数:8,代码来源:test_urllibnet.py


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