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


Python urllib2.OpenerDirector方法代码示例

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


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

示例1: openerHeaders

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import OpenerDirector [as 别名]
def openerHeaders(op):
    headers = {}
    try:
        assert isinstance(op, urllib2.OpenerDirector)
        _ = op.addheaders
        for pair in _:
            # pair_copy = [part for part in pair]
            headers.update({pair[0]: pair[1]})
    except:
        errMsg = 'unable to fetch headers from given opener'
        logger.log(CUSTOM_LOGGING.ERROR, errMsg)
    return headers 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:14,代码来源:parseopener.py

示例2: _GetOpener

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import OpenerDirector [as 别名]
def _GetOpener(self):
    """Returns an OpenerDirector for making HTTP requests.

    Returns:
      A urllib2.OpenerDirector object.
    """
    raise NotImplementedError 
开发者ID:elsigh,项目名称:browserscope,代码行数:9,代码来源:appengine_rpc.py

示例3: _GetOpener

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import OpenerDirector [as 别名]
def _GetOpener(self):
    """Returns an OpenerDirector for making HTTP requests.

    Returns:
      A urllib2.OpenerDirector object.
    """
    raise NotImplementedError() 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:9,代码来源:upload.py

示例4: test_base_fs_creation

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import OpenerDirector [as 别名]
def test_base_fs_creation(self):
        fs = familysearch.FamilySearch(self.agent, self.devkey)
        self.assertTrue(fs.base == 'https://sandbox.familysearch.org')
        print("Base is correct.")
        self.assertTrue(fs.key == self.devkey)
        print("Key is correct.")
        self.assertTrue(isinstance(fs.opener, request.OpenerDirector))
        print("HTTP opener works.")
        self.assertTrue(fs.access_token == None)
        print("Access token works.") 
开发者ID:AmEv7Fam,项目名称:familysearch-python-sdk-opensource,代码行数:12,代码来源:test_basefs.py

示例5: _GetOpener

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import OpenerDirector [as 别名]
def _GetOpener(self):
    """Returns an OpenerDirector that supports cookies and ignores redirects.

    Returns:
      A urllib2.OpenerDirector object.
    """
    opener = appengine_rpc.HttpRpcServer._GetOpener(self)
    opener.add_handler(ThrottleHandler(self.throttle))

    return opener 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:12,代码来源:throttle.py

示例6: testAuth

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import OpenerDirector [as 别名]
def testAuth(self):
        # CNY-981
        try:
            contentServer = rephelp.HTTPServerController(authRequester())
            baseUrl = contentServer.url()

            # test with user:pass
            contentURL = 'http://user:pass@%s' % httplib.urlsplit(baseUrl)[1]
            name = 'foo.tar.gz'
            url = contentURL + '/' + name
            cached = lookaside.fetchURL(self.cfg, url, name)
            f = open(cached, 'r')
            self.assertEqual(f.read(), 'Hello, world!\n')

            # test with no password given
            contentURL = 'http://user@%s' % httplib.urlsplit(baseUrl)[1]
            name = 'foo2.tar.gz'
            url = contentURL + '/' + name
            cached = lookaside.fetchURL(self.cfg, url, name)
            f = open(cached, 'r')
            self.assertEqual(f.read(), 'Hello, world 2!\n')

            # test with no password at all
            name = 'foo3.tar.gz'
            url = baseUrl + '/' + name
            cached = self.logCheck(lookaside.fetchURL, (self.cfg, url, name),
                                   ['error: error downloading http://localhost:[0-9]*//foo3.tar.gz: HTTP Error 401: Unauthorized'],
                                   regExp=True)
            self.assertEqual(cached, None)

            # test ftp with user:pass
            def fakeOpen(od, req, *args, **kw):
                self.req = req
                import StringIO
                s = 'baz file contents'
                r = StringIO.StringIO(s)
                r.headers = {'contentLength': len(s)}
                return r

            import urllib2
            self.mock(urllib2.OpenerDirector, 'open', fakeOpen)
            url = 'ftp://user:pass@foo.com/bar/baz.tgz'
            name = 'baz.tgz'
            cached = lookaside.fetchURL(self.cfg, url, name)
            self.assertEqual(url, self.req.get_full_url())
            self.assertEqual(open(cached).read(), 'baz file contents')

        finally:
            contentServer.kill() 
开发者ID:sassoftware,项目名称:conary,代码行数:51,代码来源:lookasidetest.py


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