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


Python models.Response方法代碼示例

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


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

示例1: _get_http_response_filename

# 需要導入模塊: from pip._vendor.requests import models [as 別名]
# 或者: from pip._vendor.requests.models import Response [as 別名]
def _get_http_response_filename(resp, link):
    # type: (Response, Link) -> str
    """Get an ideal filename from the given HTTP response, falling back to
    the link filename if not provided.
    """
    filename = link.filename  # fallback
    # Have a look at the Content-Disposition header for a better guess
    content_disposition = resp.headers.get('content-disposition')
    if content_disposition:
        filename = parse_content_disposition(content_disposition, filename)
    ext = splitext(filename)[1]  # type: Optional[str]
    if not ext:
        ext = mimetypes.guess_extension(
            resp.headers.get('content-type', '')
        )
        if ext:
            filename += ext
    if not ext and link.url != resp.url:
        ext = os.path.splitext(resp.url)[1]
        if ext:
            filename += ext
    return filename 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:24,代碼來源:download.py

示例2: send

# 需要導入模塊: from pip._vendor.requests import models [as 別名]
# 或者: from pip._vendor.requests.models import Response [as 別名]
def send(self, request, stream=None, timeout=None, verify=None, cert=None,
             proxies=None):
        pathname = url_to_path(request.url)

        resp = Response()
        resp.status_code = 200
        resp.url = request.url

        try:
            stats = os.stat(pathname)
        except OSError as exc:
            resp.status_code = 404
            resp.raw = exc
        else:
            modified = email.utils.formatdate(stats.st_mtime, usegmt=True)
            content_type = mimetypes.guess_type(pathname)[0] or "text/plain"
            resp.headers = CaseInsensitiveDict({
                "Content-Type": content_type,
                "Content-Length": stats.st_size,
                "Last-Modified": modified,
            })

            resp.raw = open(pathname, "rb")
            resp.close = resp.raw.close

        return resp 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:28,代碼來源:download.py

示例3: send

# 需要導入模塊: from pip._vendor.requests import models [as 別名]
# 或者: from pip._vendor.requests.models import Response [as 別名]
def send(self, request, stream=None, timeout=None, verify=None, cert=None,
             proxies=None):
        parsed_url = urlparse.urlparse(request.url)

        # We only work for requests with a host of localhost
        if parsed_url.netloc.lower() != "localhost":
            raise InvalidURL("Invalid URL %r: Only localhost is allowed" %
                request.url)

        real_url = urlparse.urlunparse(parsed_url[:1] + ("",) + parsed_url[2:])
        pathname = url_to_path(real_url)

        resp = Response()
        resp.status_code = 200
        resp.url = real_url

        stats = os.stat(pathname)
        modified = email.utils.formatdate(stats.st_mtime, usegmt=True)
        resp.headers = CaseInsensitiveDict({
            "Content-Type": mimetypes.guess_type(pathname)[0] or "text/plain",
            "Content-Length": stats.st_size,
            "Last-Modified": modified,
        })

        resp.raw = LocalFSResponse(open(pathname, "rb"))
        resp.close = resp.raw.close

        return resp 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:30,代碼來源:download.py

示例4: _get_http_response_size

# 需要導入模塊: from pip._vendor.requests import models [as 別名]
# 或者: from pip._vendor.requests.models import Response [as 別名]
def _get_http_response_size(resp):
    # type: (Response) -> Optional[int]
    try:
        return int(resp.headers['content-length'])
    except (ValueError, KeyError, TypeError):
        return None 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:8,代碼來源:download.py

示例5: _http_get_download

# 需要導入模塊: from pip._vendor.requests import models [as 別名]
# 或者: from pip._vendor.requests.models import Response [as 別名]
def _http_get_download(session, link):
    # type: (PipSession, Link) -> Response
    target_url = link.url.split('#', 1)[0]
    resp = session.get(
        target_url,
        # We use Accept-Encoding: identity here because requests
        # defaults to accepting compressed responses. This breaks in
        # a variety of ways depending on how the server is configured.
        # - Some servers will notice that the file isn't a compressible
        #   file and will leave the file alone and with an empty
        #   Content-Encoding
        # - Some servers will notice that the file is already
        #   compressed and will leave the file alone and will add a
        #   Content-Encoding: gzip header
        # - Some servers won't notice anything at all and will take
        #   a file that's already been compressed and compress it again
        #   and set the Content-Encoding: gzip header
        # By setting this to request only the identity encoding We're
        # hoping to eliminate the third case. Hopefully there does not
        # exist a server which when given a file will notice it is
        # already compressed and that you're not asking for a
        # compressed file and will then decompress it before sending
        # because if that's the case I don't think it'll ever be
        # possible to make this work.
        headers={"Accept-Encoding": "identity"},
        stream=True,
    )
    resp.raise_for_status()
    return resp 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:31,代碼來源:download.py

示例6: __init__

# 需要導入模塊: from pip._vendor.requests import models [as 別名]
# 或者: from pip._vendor.requests.models import Response [as 別名]
def __init__(
        self,
        response,  # type: Response
        filename,  # type: str
        chunks,  # type: Iterable[bytes]
    ):
        # type: (...) -> None
        self.response = response
        self.filename = filename
        self.chunks = chunks 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:12,代碼來源:download.py

示例7: is_from_cache

# 需要導入模塊: from pip._vendor.requests import models [as 別名]
# 或者: from pip._vendor.requests.models import Response [as 別名]
def is_from_cache(response):
    # type: (Response) -> bool
    return getattr(response, "from_cache", False) 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:5,代碼來源:cache.py


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