m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.4 KiB

6 months ago
  1. # SPDX-FileCopyrightText: 2015 Eric Larson
  2. #
  3. # SPDX-License-Identifier: Apache-2.0
  4. from __future__ import annotations
  5. from typing import TYPE_CHECKING, Collection
  6. from pip._vendor.cachecontrol.adapter import CacheControlAdapter
  7. from pip._vendor.cachecontrol.cache import DictCache
  8. if TYPE_CHECKING:
  9. from pip._vendor import requests
  10. from pip._vendor.cachecontrol.cache import BaseCache
  11. from pip._vendor.cachecontrol.controller import CacheController
  12. from pip._vendor.cachecontrol.heuristics import BaseHeuristic
  13. from pip._vendor.cachecontrol.serialize import Serializer
  14. def CacheControl(
  15. sess: requests.Session,
  16. cache: BaseCache | None = None,
  17. cache_etags: bool = True,
  18. serializer: Serializer | None = None,
  19. heuristic: BaseHeuristic | None = None,
  20. controller_class: type[CacheController] | None = None,
  21. adapter_class: type[CacheControlAdapter] | None = None,
  22. cacheable_methods: Collection[str] | None = None,
  23. ) -> requests.Session:
  24. cache = DictCache() if cache is None else cache
  25. adapter_class = adapter_class or CacheControlAdapter
  26. adapter = adapter_class(
  27. cache,
  28. cache_etags=cache_etags,
  29. serializer=serializer,
  30. heuristic=heuristic,
  31. controller_class=controller_class,
  32. cacheable_methods=cacheable_methods,
  33. )
  34. sess.mount("http://", adapter)
  35. sess.mount("https://", adapter)
  36. return sess