Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/coreapi/compat.py: 47%

39 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1# coding: utf-8 

2 

3import base64 

4 

5 

6__all__ = [ 

7 'urlparse', 'string_types', 

8 'COMPACT_SEPARATORS', 'VERBOSE_SEPARATORS' 

9] 

10 

11 

12try: 

13 # Python 2 

14 import urlparse 

15 import cookielib as cookiejar 

16 

17 string_types = (basestring,) 

18 text_type = unicode 

19 COMPACT_SEPARATORS = (b',', b':') 

20 VERBOSE_SEPARATORS = (b',', b': ') 

21 

22 def b64encode(input_string): 

23 # Provide a consistently-as-unicode interface across 2.x and 3.x 

24 return base64.b64encode(input_string) 

25 

26except ImportError: 

27 # Python 3 

28 import urllib.parse as urlparse 

29 from io import IOBase 

30 from http import cookiejar 

31 

32 string_types = (str,) 

33 text_type = str 

34 COMPACT_SEPARATORS = (',', ':') 

35 VERBOSE_SEPARATORS = (',', ': ') 

36 

37 def b64encode(input_string): 

38 # Provide a consistently-as-unicode interface across 2.x and 3.x 

39 return base64.b64encode(input_string.encode('ascii')).decode('ascii') 

40 

41 

42def force_bytes(string): 

43 if isinstance(string, string_types): 

44 return string.encode('utf-8') 

45 return string 

46 

47 

48def force_text(string): 

49 if not isinstance(string, string_types): 

50 return string.decode('utf-8') 

51 return string 

52 

53 

54try: 

55 import click 

56 console_style = click.style 

57except ImportError: 

58 def console_style(text, **kwargs): 

59 return text 

60 

61 

62try: 

63 from tempfile import _TemporaryFileWrapper 

64except ImportError: 

65 _TemporaryFileWrapper = None