• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python support.transient_internet函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_sites_no_connection_close

    def test_sites_no_connection_close(self):
        # Some sites do not send Connection: close header.
        # Verify that those work properly. (#issue12576)

        URL = 'http://www.imdb.com' # No Connection:close
        with support.transient_internet(URL):
            req = urllib.request.urlopen(URL)
            res = req.read()
            self.assertTrue(res)
开发者ID:isaiah,项目名称:jython3,代码行数:9,代码来源:test_urllib2net.py


示例17: test_ftp_no_timeout

 def test_ftp_no_timeout(self):
     self.assertTrue(socket.getdefaulttimeout() is None)
     with support.transient_internet(self.FTP_HOST):
         socket.setdefaulttimeout(60)
         try:
             u = _urlopen_with_retry(self.FTP_HOST, timeout=None)
         finally:
             socket.setdefaulttimeout(None)
         self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None)
开发者ID:469306621,项目名称:Languages,代码行数:9,代码来源:test_urllib2net.py


示例18: test_ftp_timeout

 def test_ftp_timeout(self):
     with support.transient_internet(self.FTP_HOST):
         u = _urlopen_with_retry(self.FTP_HOST, timeout=60)
         self.addCleanup(u.close)
         if utils.PY2:
             sock = u.fp.fp._sock
         else:
             sock = u.fp.fp.raw._sock
         self.assertEqual(sock.gettimeout(), 60)
开发者ID:syphar,项目名称:python-future,代码行数:9,代码来源:test_urllib2net.py


示例19: test_networked

 def test_networked(self):
     # Default settings: requires a valid cert from a trusted CA
     import ssl
     support.requires('network')
     with support.transient_internet('self-signed.pythontest.net'):
         h = client.HTTPSConnection('self-signed.pythontest.net', 443)
         with self.assertRaises(ssl.SSLError) as exc_info:
             h.request('GET', '/')
         self.assertEqual(exc_info.exception.reason, 'CERTIFICATE_VERIFY_FAILED')
开发者ID:chidea,项目名称:GoPythonDLLWrapper,代码行数:9,代码来源:test_httplib.py


示例20: test_networked_trusted_by_default_cert

 def test_networked_trusted_by_default_cert(self):
     # Default settings: requires a valid cert from a trusted CA
     support.requires('network')
     with support.transient_internet('www.python.org'):
         h = client.HTTPSConnection('www.python.org', 443)
         h.request('GET', '/')
         resp = h.getresponse()
         content_type = resp.getheader('content-type')
         self.assertIn('text/html', content_type)
开发者ID:Bachmann1234,项目名称:python-emoji,代码行数:9,代码来源:test_httplib.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python support.unlink函数代码示例发布时间:2022-05-27
下一篇:
Python support.threading_setup函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap