before send to remote

This commit is contained in:
5408 changed files with 652023 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
# This file is part of the django-environ.
#
# Copyright (c) 2021-2022, Serghei Iakovlev <egrep@protonmail.ch>
# Copyright (c) 2013-2021, Daniele Faraglia <daniele.faraglia@gmail.com>
#
# For the full copyright and license information, please view
# the LICENSE.txt file that was distributed with this source code.
"""The top-level module for django-environ package.
This module tracks the version of the package as well as the base
package info used by various functions within django-environ.
Refer to the `documentation <https://django-environ.readthedocs.io/en/latest/>`_
for details on the use of this package.
""" # noqa: E501
from .environ import *
__copyright__ = 'Copyright (C) 2021 Daniele Faraglia'
"""The copyright notice of the package."""
__version__ = '0.9.0'
"""The version of the package."""
__license__ = 'MIT'
"""The license of the package."""
__author__ = 'Daniele Faraglia'
"""The author of the package."""
__author_email__ = 'daniele.faraglia@gmail.com'
"""The email of the author of the package."""
__maintainer__ = 'Serghei Iakovlev'
"""The maintainer of the package."""
__maintainer_email__ = 'egrep@protonmail.ch'
"""The email of the maintainer of the package."""
__url__ = 'https://django-environ.readthedocs.org'
"""The URL of the package."""
__description__ = 'A package that allows you to utilize 12factor inspired environment variables to configure your Django application.' # noqa: E501
"""The description of the package."""

View File

@@ -0,0 +1,52 @@
# This file is part of the django-environ.
#
# Copyright (c) 2021-2022, Serghei Iakovlev <egrep@protonmail.ch>
# Copyright (c) 2013-2021, Daniele Faraglia <daniele.faraglia@gmail.com>
#
# For the full copyright and license information, please view
# the LICENSE.txt file that was distributed with this source code.
"""This module handles import compatibility issues."""
from pkgutil import find_loader
if find_loader('simplejson'):
import simplejson as json
else:
import json
if find_loader('django'):
from django import VERSION as DJANGO_VERSION
from django.core.exceptions import ImproperlyConfigured
else:
DJANGO_VERSION = None
class ImproperlyConfigured(Exception):
pass
# back compatibility with django postgresql package
if DJANGO_VERSION is not None and DJANGO_VERSION < (2, 0):
DJANGO_POSTGRES = 'django.db.backends.postgresql_psycopg2'
else:
# https://docs.djangoproject.com/en/2.0/releases/2.0/#id1
DJANGO_POSTGRES = 'django.db.backends.postgresql'
# back compatibility with redis_cache package
if find_loader('redis_cache'):
REDIS_DRIVER = 'redis_cache.RedisCache'
else:
REDIS_DRIVER = 'django_redis.cache.RedisCache'
def choose_pymemcache_driver():
"""Backward compatibility for pymemcache."""
old_django = DJANGO_VERSION is not None and DJANGO_VERSION < (3, 2)
if old_django or not find_loader('pymemcache'):
# The original backend choice for the 'pymemcache' scheme is
# unfortunately 'pylibmc'.
return 'django.core.cache.backends.memcached.PyLibMCCache'
return 'django.core.cache.backends.memcached.PyMemcacheCache'
PYMEMCACHE_DRIVER = choose_pymemcache_driver()

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,92 @@
# This file is part of the django-environ.
#
# Copyright (c) 2021-2022, Serghei Iakovlev <egrep@protonmail.ch>
# Copyright (c) 2013-2021, Daniele Faraglia <daniele.faraglia@gmail.com>
#
# For the full copyright and license information, please view
# the LICENSE.txt file that was distributed with this source code.
"""Docker-style file variable support module."""
import os
from collections.abc import MutableMapping
class FileAwareMapping(MutableMapping):
"""
A mapping that wraps os.environ, first checking for the existence of a key
appended with ``_FILE`` whenever reading a value. If a matching file key is
found then the value is instead read from the file system at this location.
By default, values read from the file system are cached so future lookups
do not hit the disk again.
A ``_FILE`` key has higher precedence than a value is set directly in the
environment, and an exception is raised if the file can not be found.
"""
def __init__(self, env=None, cache=True):
"""
Initialize the mapping.
:param env:
where to read environment variables from (defaults to
``os.environ``)
:param cache:
cache environment variables read from the file system (defaults to
``True``)
"""
self.env = env if env is not None else os.environ
self.cache = cache
self.files_cache = {}
def __getitem__(self, key):
if self.cache and key in self.files_cache:
return self.files_cache[key]
key_file = self.env.get(key + "_FILE")
if key_file:
with open(key_file) as f:
value = f.read()
if self.cache:
self.files_cache[key] = value
return value
return self.env[key]
def __iter__(self):
"""
Iterate all keys, also always including the shortened key if ``_FILE``
keys are found.
"""
for key in self.env:
yield key
if key.endswith("_FILE"):
no_file_key = key[:-5]
if no_file_key and no_file_key not in self.env:
yield no_file_key
def __len__(self):
"""
Return the length of the file, also always counting shortened keys for
any ``_FILE`` key found.
"""
return len(tuple(iter(self)))
def __setitem__(self, key, value):
self.env[key] = value
if self.cache and key.endswith("_FILE"):
no_file_key = key[:-5]
if no_file_key and no_file_key in self.files_cache:
del self.files_cache[no_file_key]
def __delitem__(self, key):
file_key = key + "_FILE"
if file_key in self.env:
del self[file_key]
if key in self.env:
del self.env[key]
return
if self.cache and key.endswith("_FILE"):
no_file_key = key[:-5]
if no_file_key and no_file_key in self.files_cache:
del self.files_cache[no_file_key]
del self.env[key]