当前位置: 首页>>代码示例>>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;未经允许,请勿转载。