Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/environ/compat.py: 60%
23 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1# This file is part of the django-environ.
2#
3# Copyright (c) 2021-2022, Serghei Iakovlev <egrep@protonmail.ch>
4# Copyright (c) 2013-2021, Daniele Faraglia <daniele.faraglia@gmail.com>
5#
6# For the full copyright and license information, please view
7# the LICENSE.txt file that was distributed with this source code.
9"""This module handles import compatibility issues."""
11from pkgutil import find_loader
14if find_loader('simplejson'): 14 ↛ 15line 14 didn't jump to line 15, because the condition on line 14 was never true
15 import simplejson as json
16else:
17 import json
19if find_loader('django'): 19 ↛ 23line 19 didn't jump to line 23, because the condition on line 19 was never false
20 from django import VERSION as DJANGO_VERSION
21 from django.core.exceptions import ImproperlyConfigured
22else:
23 DJANGO_VERSION = None
25 class ImproperlyConfigured(Exception):
26 pass
28# back compatibility with django postgresql package
29if DJANGO_VERSION is not None and DJANGO_VERSION < (2, 0): 29 ↛ 30line 29 didn't jump to line 30, because the condition on line 29 was never true
30 DJANGO_POSTGRES = 'django.db.backends.postgresql_psycopg2'
31else:
32 # https://docs.djangoproject.com/en/2.0/releases/2.0/#id1
33 DJANGO_POSTGRES = 'django.db.backends.postgresql'
35# back compatibility with redis_cache package
36if find_loader('redis_cache'): 36 ↛ 37line 36 didn't jump to line 37, because the condition on line 36 was never true
37 REDIS_DRIVER = 'redis_cache.RedisCache'
38else:
39 REDIS_DRIVER = 'django_redis.cache.RedisCache'
42def choose_pymemcache_driver():
43 """Backward compatibility for pymemcache."""
44 old_django = DJANGO_VERSION is not None and DJANGO_VERSION < (3, 2)
45 if old_django or not find_loader('pymemcache'): 45 ↛ 49line 45 didn't jump to line 49, because the condition on line 45 was never false
46 # The original backend choice for the 'pymemcache' scheme is
47 # unfortunately 'pylibmc'.
48 return 'django.core.cache.backends.memcached.PyLibMCCache'
49 return 'django.core.cache.backends.memcached.PyMemcacheCache'
52PYMEMCACHE_DRIVER = choose_pymemcache_driver()