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


Python hashes.Hashes方法代码示例

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


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

示例1: hashes

# 需要导入模块: from pip._internal.utils import hashes [as 别名]
# 或者: from pip._internal.utils.hashes import Hashes [as 别名]
def hashes(self, trust_internet=True):
        """Return a hash-comparer that considers my option- and URL-based
        hashes to be known-good.

        Hashes in URLs--ones embedded in the requirements file, not ones
        downloaded from an index server--are almost peers with ones from
        flags. They satisfy --require-hashes (whether it was implicitly or
        explicitly activated) but do not activate it. md5 and sha224 are not
        allowed in flags, which should nudge people toward good algos. We
        always OR all hashes together, even ones from URLs.

        :param trust_internet: Whether to trust URL-based (#md5=...) hashes
            downloaded from the internet, as by populate_link()

        """
        good_hashes = self.options.get('hashes', {}).copy()
        link = self.link if trust_internet else self.original_link
        if link and link.hash:
            good_hashes.setdefault(link.hash_name, []).append(link.hash)
        return Hashes(good_hashes) 
开发者ID:HaoZhang95,项目名称:Python24,代码行数:22,代码来源:req_install.py

示例2: _check_download_dir

# 需要导入模块: from pip._internal.utils import hashes [as 别名]
# 或者: from pip._internal.utils.hashes import Hashes [as 别名]
def _check_download_dir(link, download_dir, hashes):
    # type: (Link, str, Hashes) -> Optional[str]
    """ Check download_dir for previously downloaded file with correct hash
        If a correct file is found return its path else None
    """
    download_path = os.path.join(download_dir, link.filename)
    if os.path.exists(download_path):
        # If already downloaded, does its hash match?
        logger.info('File was already downloaded %s', download_path)
        if hashes:
            try:
                hashes.check_against_path(download_path)
            except HashMismatch:
                logger.warning(
                    'Previously-downloaded file %s has bad hash. '
                    'Re-downloading.',
                    download_path
                )
                os.unlink(download_path)
                return None
        return download_path
    return None 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:24,代码来源:download.py

示例3: hashes

# 需要导入模块: from pip._internal.utils import hashes [as 别名]
# 或者: from pip._internal.utils.hashes import Hashes [as 别名]
def hashes(self, trust_internet=True):
        # type: (bool) -> Hashes
        """Return a hash-comparer that considers my option- and URL-based
        hashes to be known-good.

        Hashes in URLs--ones embedded in the requirements file, not ones
        downloaded from an index server--are almost peers with ones from
        flags. They satisfy --require-hashes (whether it was implicitly or
        explicitly activated) but do not activate it. md5 and sha224 are not
        allowed in flags, which should nudge people toward good algos. We
        always OR all hashes together, even ones from URLs.

        :param trust_internet: Whether to trust URL-based (#md5=...) hashes
            downloaded from the internet, as by populate_link()

        """
        good_hashes = self.options.get('hashes', {}).copy()
        link = self.link if trust_internet else self.original_link
        if link and link.hash:
            good_hashes.setdefault(link.hash_name, []).append(link.hash)
        return Hashes(good_hashes) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:23,代码来源:req_install.py

示例4: _download_http_url

# 需要导入模块: from pip._internal.utils import hashes [as 别名]
# 或者: from pip._internal.utils.hashes import Hashes [as 别名]
def _download_http_url(
    link,  # type: Link
    downloader,  # type: Downloader
    temp_dir,  # type: str
    hashes,  # type: Optional[Hashes]
):
    # type: (...) -> Tuple[str, str]
    """Download link url into temp_dir using provided session"""
    download = downloader(link)

    file_path = os.path.join(temp_dir, download.filename)
    with open(file_path, 'wb') as content_file:
        for chunk in download.chunks:
            content_file.write(chunk)

    if hashes:
        hashes.check_against_path(file_path)

    return file_path, download.response.headers.get('content-type', '') 
开发者ID:pantsbuild,项目名称:pex,代码行数:21,代码来源:prepare.py

示例5: _check_download_dir

# 需要导入模块: from pip._internal.utils import hashes [as 别名]
# 或者: from pip._internal.utils.hashes import Hashes [as 别名]
def _check_download_dir(link, download_dir, hashes):
    # type: (Link, str, Optional[Hashes]) -> Optional[str]
    """ Check download_dir for previously downloaded file with correct hash
        If a correct file is found return its path else None
    """
    download_path = os.path.join(download_dir, link.filename)

    if not os.path.exists(download_path):
        return None

    # If already downloaded, does its hash match?
    logger.info('File was already downloaded %s', download_path)
    if hashes:
        try:
            hashes.check_against_path(download_path)
        except HashMismatch:
            logger.warning(
                'Previously-downloaded file %s has bad hash. '
                'Re-downloading.',
                download_path
            )
            os.unlink(download_path)
            return None
    return download_path 
开发者ID:pantsbuild,项目名称:pex,代码行数:26,代码来源:prepare.py

示例6: __init__

# 需要导入模块: from pip._internal.utils import hashes [as 别名]
# 或者: from pip._internal.utils.hashes import Hashes [as 别名]
def __init__(
        self,
        project_name,         # type: str
        supported_tags,       # type: List[Pep425Tag]
        specifier,            # type: specifiers.BaseSpecifier
        prefer_binary=False,  # type: bool
        allow_all_prereleases=False,  # type: bool
        hashes=None,                  # type: Optional[Hashes]
    ):
        # type: (...) -> None
        """
        :param supported_tags: The PEP 425 tags supported by the target
            Python in order of preference (most preferred first).
        """
        self._allow_all_prereleases = allow_all_prereleases
        self._hashes = hashes
        self._prefer_binary = prefer_binary
        self._project_name = project_name
        self._specifier = specifier
        self._supported_tags = supported_tags 
开发者ID:pantsbuild,项目名称:pex,代码行数:22,代码来源:package_finder.py

示例7: make_candidate_evaluator

# 需要导入模块: from pip._internal.utils import hashes [as 别名]
# 或者: from pip._internal.utils.hashes import Hashes [as 别名]
def make_candidate_evaluator(
        self,
        project_name,    # type: str
        specifier=None,  # type: Optional[specifiers.BaseSpecifier]
        hashes=None,     # type: Optional[Hashes]
    ):
        # type: (...) -> CandidateEvaluator
        """Create a CandidateEvaluator object to use.
        """
        candidate_prefs = self._candidate_prefs
        return CandidateEvaluator.create(
            project_name=project_name,
            target_python=self._target_python,
            prefer_binary=candidate_prefs.prefer_binary,
            allow_all_prereleases=candidate_prefs.allow_all_prereleases,
            specifier=specifier,
            hashes=hashes,
        ) 
开发者ID:pantsbuild,项目名称:pex,代码行数:20,代码来源:package_finder.py

示例8: find_best_candidate

# 需要导入模块: from pip._internal.utils import hashes [as 别名]
# 或者: from pip._internal.utils.hashes import Hashes [as 别名]
def find_best_candidate(
        self,
        project_name,       # type: str
        specifier=None,     # type: Optional[specifiers.BaseSpecifier]
        hashes=None,        # type: Optional[Hashes]
    ):
        # type: (...) -> BestCandidateResult
        """Find matches for the given project and specifier.

        :param specifier: An optional object implementing `filter`
            (e.g. `packaging.specifiers.SpecifierSet`) to filter applicable
            versions.

        :return: A `BestCandidateResult` instance.
        """
        candidates = self.find_all_candidates(project_name)
        candidate_evaluator = self.make_candidate_evaluator(
            project_name=project_name,
            specifier=specifier,
            hashes=hashes,
        )
        return candidate_evaluator.compute_best_candidate(candidates) 
开发者ID:pantsbuild,项目名称:pex,代码行数:24,代码来源:package_finder.py

示例9: get_http_url

# 需要导入模块: from pip._internal.utils import hashes [as 别名]
# 或者: from pip._internal.utils.hashes import Hashes [as 别名]
def get_http_url(
    link,  # type: Link
    downloader,  # type: Downloader
    download_dir=None,  # type: Optional[str]
    hashes=None,  # type: Optional[Hashes]
):
    # type: (...) -> File
    temp_dir = TempDirectory(kind="unpack", globally_managed=True)
    # If a download dir is specified, is the file already downloaded there?
    already_downloaded_path = None
    if download_dir:
        already_downloaded_path = _check_download_dir(
            link, download_dir, hashes
        )

    if already_downloaded_path:
        from_path = already_downloaded_path
        content_type = mimetypes.guess_type(from_path)[0]
    else:
        # let's download to a tmp dir
        from_path, content_type = _download_http_url(
            link, downloader, temp_dir.path, hashes
        )

    return File(from_path, content_type) 
开发者ID:ali5h,项目名称:rules_pip,代码行数:27,代码来源:prepare.py

示例10: __init__

# 需要导入模块: from pip._internal.utils import hashes [as 别名]
# 或者: from pip._internal.utils.hashes import Hashes [as 别名]
def __init__(
        self,
        project_name,         # type: str
        supported_tags,       # type: List[Tag]
        specifier,            # type: specifiers.BaseSpecifier
        prefer_binary=False,  # type: bool
        allow_all_prereleases=False,  # type: bool
        hashes=None,                  # type: Optional[Hashes]
    ):
        # type: (...) -> None
        """
        :param supported_tags: The PEP 425 tags supported by the target
            Python in order of preference (most preferred first).
        """
        self._allow_all_prereleases = allow_all_prereleases
        self._hashes = hashes
        self._prefer_binary = prefer_binary
        self._project_name = project_name
        self._specifier = specifier
        self._supported_tags = supported_tags 
开发者ID:ali5h,项目名称:rules_pip,代码行数:22,代码来源:package_finder.py


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