當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。