Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pip/_vendor/cachecontrol/wrapper.py: 35%

17 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-02-26 06:33 +0000

1# SPDX-FileCopyrightText: 2015 Eric Larson 

2# 

3# SPDX-License-Identifier: Apache-2.0 

4from __future__ import annotations 

5 

6from typing import TYPE_CHECKING, Collection 

7 

8from pip._vendor.cachecontrol.adapter import CacheControlAdapter 

9from pip._vendor.cachecontrol.cache import DictCache 

10 

11if TYPE_CHECKING: 

12 from pip._vendor import requests 

13 

14 from pip._vendor.cachecontrol.cache import BaseCache 

15 from pip._vendor.cachecontrol.controller import CacheController 

16 from pip._vendor.cachecontrol.heuristics import BaseHeuristic 

17 from pip._vendor.cachecontrol.serialize import Serializer 

18 

19 

20def CacheControl( 

21 sess: requests.Session, 

22 cache: BaseCache | None = None, 

23 cache_etags: bool = True, 

24 serializer: Serializer | None = None, 

25 heuristic: BaseHeuristic | None = None, 

26 controller_class: type[CacheController] | None = None, 

27 adapter_class: type[CacheControlAdapter] | None = None, 

28 cacheable_methods: Collection[str] | None = None, 

29) -> requests.Session: 

30 cache = DictCache() if cache is None else cache 

31 adapter_class = adapter_class or CacheControlAdapter 

32 adapter = adapter_class( 

33 cache, 

34 cache_etags=cache_etags, 

35 serializer=serializer, 

36 heuristic=heuristic, 

37 controller_class=controller_class, 

38 cacheable_methods=cacheable_methods, 

39 ) 

40 sess.mount("http://", adapter) 

41 sess.mount("https://", adapter) 

42 

43 return sess