當前位置: 首頁>>代碼示例>>Python>>正文


Python urllib2.addinfourl方法代碼示例

本文整理匯總了Python中urllib2.addinfourl方法的典型用法代碼示例。如果您正苦於以下問題:Python urllib2.addinfourl方法的具體用法?Python urllib2.addinfourl怎麽用?Python urllib2.addinfourl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在urllib2的用法示例。


在下文中一共展示了urllib2.addinfourl方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: http_error_default

# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import addinfourl [as 別名]
def http_error_default(self, req, fp, code, msg, hdrs):
        infourl = urllib.addinfourl(fp, hdrs, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
開發者ID:Kolifanes,項目名稱:plugin.video.youtube,代碼行數:7,代碼來源:api.py

示例2: http_error_302

# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import addinfourl [as 別名]
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
開發者ID:Kolifanes,項目名稱:plugin.video.youtube,代碼行數:7,代碼來源:api.py

示例3: http_error_303

# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import addinfourl [as 別名]
def http_error_303(self, req, fp, code, msg, headers):
        infourl = addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
開發者ID:ecmwf,項目名稱:ecmwf-api-client,代碼行數:7,代碼來源:api.py

示例4: http_response

# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import addinfourl [as 別名]
def http_response(self, req, resp):
    """Handle encodings in the order that they are encountered."""
    encodings = []
    headers = resp.headers

    for header in headers:
      if header.lower() == "content-encoding":
        for encoding in headers.get(header, "").split(","):
          encoding = encoding.strip()
          if encoding:
            encodings.append(encoding)
        break

    if not encodings:
      return resp

    del headers[header]

    fp = resp
    while encodings and encodings[-1].lower() == "gzip":
      fp = cStringIO.StringIO(fp.read())
      fp = gzip.GzipFile(fileobj=fp, mode="r")
      encodings.pop()

    if encodings:




      headers[header] = ", ".join(encodings)
      logger.warning("Unrecognized Content-Encoding: %s", encodings[-1])

    msg = resp.msg
    if sys.version_info >= (2, 6):
      resp = urllib2.addinfourl(fp, headers, resp.url, resp.code)
    else:
      response_code = resp.code
      resp = urllib2.addinfourl(fp, headers, resp.url)
      resp.code = response_code
    resp.msg = msg

    return resp 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:44,代碼來源:appengine_rpc.py

示例5: s3_open

# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import addinfourl [as 別名]
def s3_open(self, req):
        # The implementation was inspired mainly by the code behind
        # urllib.request.FileHandler.file_open().
        #
        # recipe copied from:
        # http://code.activestate.com/recipes/578957-urllib-handler-for-amazon-s3-buckets/
        # converted to boto3

        if version_info[0] < 3:
            bucket_name = req.get_host()
            key_name = url2pathname(req.get_selector())[1:]
        else:
            bucket_name = req.host
            key_name = url2pathname(req.selector)[1:]

        if not bucket_name or not key_name:
            raise URLError('url must be in the format s3://<bucket>/<key>')

        s3 = boto3.resource('s3')

        key = s3.Object(bucket_name, key_name)

        client = boto3.client('s3')
        obj = client.get_object(Bucket=bucket_name, Key=key_name)
        filelike = _FileLikeKey(obj['Body'])

        origurl = 's3://{}/{}'.format(bucket_name, key_name)

        if key is None:
            raise URLError('no such resource: {}'.format(origurl))

        headers = [
            ('Content-type', key.content_type),
            ('Content-encoding', key.content_encoding),
            ('Content-language', key.content_language),
            ('Content-length', key.content_length),
            ('Etag', key.e_tag),
            ('Last-modified', key.last_modified),
        ]

        headers = email.message_from_string(
            '\n'.join('{}: {}'.format(key, value) for key, value in headers
                      if value is not None))
        return addinfourl(filelike, headers, origurl) 
開發者ID:lunardog,項目名稱:kelner,代碼行數:46,代碼來源:utils.py

示例6: http_response

# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import addinfourl [as 別名]
def http_response(self, req, resp):
    """Handle encodings in the order that they are encountered."""
    encodings = []
    headers = resp.headers

    encoding_header = None
    for header in headers:
      if header.lower() == "content-encoding":
        encoding_header = header
        for encoding in headers[header].split(","):
          encoding = encoding.strip()
          if encoding:
            encodings.append(encoding)
        break

    if not encodings:
      return resp



    del headers[encoding_header]

    fp = resp
    while encodings and encodings[-1].lower() == "gzip":
      fp = cStringIO.StringIO(fp.read())
      fp = gzip.GzipFile(fileobj=fp, mode="r")
      encodings.pop()

    if encodings:




      headers[encoding_header] = ", ".join(encodings)
      logger.warning("Unrecognized Content-Encoding: %s", encodings[-1])

    msg = resp.msg
    if sys.version_info >= (2, 6):
      resp = urllib2.addinfourl(fp, headers, resp.url, resp.code)
    else:
      response_code = resp.code
      resp = urllib2.addinfourl(fp, headers, resp.url)
      resp.code = response_code
    resp.msg = msg

    return resp 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:48,代碼來源:appengine_rpc.py


注:本文中的urllib2.addinfourl方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。