hash
stringlengths
64
64
content
stringlengths
0
1.51M
aaeaf235395b00ee6f2264916c840dc72149ee302afccff5be6bb26520a0c8cb
from django.db.models import FloatField, Func, IntegerField __all__ = [ 'CumeDist', 'DenseRank', 'FirstValue', 'Lag', 'LastValue', 'Lead', 'NthValue', 'Ntile', 'PercentRank', 'Rank', 'RowNumber', ] class CumeDist(Func): function = 'CUME_DIST' name = 'CumeDist' output_field = FloatField() wind...
ad21a0eb1e9db3cf9ab82aebf339e5442d66a23114b518c5b012aff0dc1b4564
from datetime import datetime from django.conf import settings from django.db.models import ( DateField, DateTimeField, DurationField, Field, Func, IntegerField, TimeField, Transform, fields, ) from django.db.models.lookups import ( YearExact, YearGt, YearGte, YearLt, YearLte, ) from django.utils import ti...
84c06efb9da20008362cf6670f41651566ebb631d779c8709945ef89d3421ac7
""" Create SQL statements for QuerySets. The code in here encapsulates all of the SQL construction so that QuerySets themselves do not have to (and could be backed by things other than SQL databases). The abstraction barrier only works one way: this module has to know all about the internals of models in order to get ...
a0581f1beaec7e02425231ede29801c5c0b3b8e069930d050b6b8fde6bbc6071
import collections import functools import re import warnings from itertools import chain from django.core.exceptions import EmptyResultSet, FieldError from django.db.models.constants import LOOKUP_SEP from django.db.models.expressions import OrderBy, Random, RawSQL, Ref from django.db.models.query_utils import QueryW...
558117aa28f7cdeb8365d04fda9f45a2219bfc0f1daa537e081a731638efe44a
""" Code to manage the creation and SQL rendering of 'where' constraints. """ from django.core.exceptions import EmptyResultSet from django.utils import tree from django.utils.functional import cached_property # Connection types AND = 'AND' OR = 'OR' class WhereNode(tree.Node): """ An SQL WHERE clause. ...
39cc2b0c3e6b780b407bf2f7881eac9bbbaace2d4939aa28ccdfa9f2f79866b7
from django.core.exceptions import EmptyResultSet from django.db.models.sql.query import * # NOQA from django.db.models.sql.subqueries import * # NOQA from django.db.models.sql.where import AND, OR __all__ = ['Query', 'AND', 'OR', 'EmptyResultSet']
2cf45392b67b22cd5de0c328dbd9965d5eece16deef5fd7a50d01c7b7a64ddae
""" Useful auxiliary data structures for query construction. Not useful outside the SQL domain. """ # for backwards-compatibility in Django 1.11 from django.core.exceptions import EmptyResultSet # NOQA: F401 from django.db.models.sql.constants import INNER, LOUTER class MultiJoin(Exception): """ Used by join...
80c8349ff8f47ec7e6a95e57162cb0657812bee3eafd63d5e746521655986821
""" Constants specific to the SQL storage portion of the ORM. """ import re # Size of each "chunk" for get_iterator calls. # Larger values are slightly faster at the expense of more storage space. GET_ITERATOR_CHUNK_SIZE = 100 # Namedtuples for sql.* internal use. # How many results to expect from a cursor.execute ...
52eae23eb8028e5d46d241ff87181e6af415b2390e7cb4be3b04104b378a3d81
""" Query subclasses which provide extra functionality beyond simple data retrieval. """ from django.core.exceptions import FieldError from django.db import connections from django.db.models.query_utils import Q from django.db.models.sql.constants import ( CURSOR, GET_ITERATOR_CHUNK_SIZE, NO_RESULTS, ) from django...
3b5571e658dfc84568f56fa8e0e56cbbf3937d9e55e4ff475f790d32d744ef9a
from django.core import checks from django.db.backends.base.validation import BaseDatabaseValidation class DatabaseValidation(BaseDatabaseValidation): def check_field_type(self, field, field_type): """Oracle doesn't support a database index on some data types.""" errors = [] if field.db_in...
9a28af2c410fb217105a3a46b8958d54f7e12efa390d422c76c851fb602feae9
from django.db.backends.base.features import BaseDatabaseFeatures from django.db.utils import InterfaceError class DatabaseFeatures(BaseDatabaseFeatures): empty_fetchmany_value = () interprets_empty_strings_as_nulls = True uses_savepoints = True has_select_for_update = True has_select_for_update_n...
c28459528180db1c0fbb3da770cc92eb9f051024ec3e6381f27abc79bdc7761f
from collections import namedtuple import cx_Oracle from django.db import models from django.db.backends.base.introspection import ( BaseDatabaseIntrospection, FieldInfo as BaseFieldInfo, TableInfo, ) FieldInfo = namedtuple('FieldInfo', BaseFieldInfo._fields + ('is_autofield',)) class DatabaseIntrospection(Bas...
e4c24a7579ccaf23a039a0d72c4ee0bc3b7dcf155405306376a440b418c65052
""" Oracle database backend for Django. Requires cx_Oracle: http://cx-oracle.sourceforge.net/ """ import datetime import decimal import os import platform from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.db import utils from django.db.backends.base.base import BaseD...
6fb67721d11b80b5018a90d4de23d0fb96dd5ba84cc47e6c5580f52f1bed0451
import datetime import re import uuid from django.conf import settings from django.db.backends.base.operations import BaseDatabaseOperations from django.db.backends.utils import strip_quotes, truncate_name from django.db.utils import DatabaseError from django.utils import timezone from django.utils.encoding import for...
6c2f2a5f7032bdeafe79d7fe5bc6002dc26e083b70ed47f12cba9a6354e6e046
import copy import datetime import re from django.db.backends.base.schema import BaseDatabaseSchemaEditor from django.db.utils import DatabaseError class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): sql_create_column = "ALTER TABLE %(table)s ADD %(column)s %(definition)s" sql_alter_column_type = "MODIFY ...
79fa006151fbeb1fc030caaad61f0935a0a9abf52d964b72b98b972d97f37b81
import subprocess from django.db.backends.base.client import BaseDatabaseClient class DatabaseClient(BaseDatabaseClient): executable_name = 'sqlplus' def runshell(self): conn_string = self.connection._connect_string() args = [self.executable_name, "-L", conn_string] subprocess.check_...
3c730ef5c0291b512164f0f813455de9dccf984fc3ce8b9ff462166c5d57ee47
from django.db.models import DecimalField, DurationField, Func class IntervalToSeconds(Func): function = '' template = """ EXTRACT(day from %(expressions)s) * 86400 + EXTRACT(hour from %(expressions)s) * 3600 + EXTRACT(minute from %(expressions)s) * 60 + EXTRACT(second from %(expressions)s) ...
9984defba47efb1a188b3949776e8efb91ff942b5f1646786955da2e5b2a4b86
import datetime from .base import Database class InsertIdVar: """ A late-binding cursor variable that can be passed to Cursor.execute as a parameter, in order to receive the id of the row created by an insert statement. """ def bind_parameter(self, cursor): param = cursor.cursor.var(...
2cb68f9e1bf52598515ab76a54f28653142ba745dc53de16eb312ee5834719fd
import sys from django.conf import settings from django.db.backends.base.creation import BaseDatabaseCreation from django.db.utils import DatabaseError from django.utils.crypto import get_random_string from django.utils.functional import cached_property TEST_DATABASE_PREFIX = 'test_' class DatabaseCreation(BaseData...
e3320056c78fc844e246d2bb080c3bf32e198823c84acd0fbf5ee6156cb64ebe
class BaseDatabaseValidation: """Encapsulate backend-specific validation.""" def __init__(self, connection): self.connection = connection def check(self, **kwargs): return [] def check_field(self, field, **kwargs): errors = [] # Backends may implement a check_field_type...
f7c7c3a97763d5a93f7a2cc0657f2883fe0e319192edfb7ec11e85f527aeff1f
from django.db.models.aggregates import StdDev from django.db.utils import NotSupportedError, ProgrammingError from django.utils.functional import cached_property class BaseDatabaseFeatures: gis_enabled = False allows_group_by_pk = False allows_group_by_selected_pks = False empty_fetchmany_value = [] ...
50b5e24c03ebd759d38f40eb7ae4b5f90f143b56fc28fe6233b20b6ae0b68eef
from collections import namedtuple # Structure returned by DatabaseIntrospection.get_table_list() TableInfo = namedtuple('TableInfo', ['name', 'type']) # Structure returned by the DB-API cursor.description interface (PEP 249) FieldInfo = namedtuple('FieldInfo', 'name type_code display_size internal_size precision sca...
efc0a6f224306d31189e945c3d7804b6db0a83be7462d32b33318426b9771220
import copy import time import warnings from collections import deque from contextlib import contextmanager import _thread import pytz from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.db import DEFAULT_DB_ALIAS from django.db.backends import utils from django.db.bac...
ceb28ed05c2a4cffed886d839f2f944cc0971be0cd1817324d713db63dfe5913
import datetime import decimal from importlib import import_module from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.db import NotSupportedError, transaction from django.db.backends import utils from django.utils import timezone from django.utils.encoding import force...
754c619c37c2485e2c42bde4e4a94e2c77c6183d20fd6629c883c7c748ee317b
import hashlib import logging from datetime import datetime from django.db.backends.ddl_references import ( Columns, ForeignKeyName, IndexName, Statement, Table, ) from django.db.backends.utils import split_identifier from django.db.models import Index from django.db.transaction import TransactionManagementError, ...
afa75c461639b4fc7d9730d985b7030b5cfd2c3757c517bfbed9206104a6b842
class BaseDatabaseClient: """Encapsulate backend-specific methods for opening a client shell.""" # This should be a string representing the name of the executable # (e.g., "psql"). Subclasses must override this. executable_name = None def __init__(self, connection): # connection is an insta...
381e0c72e049da6a2f4caee5982b36ae7e9451f887b5427ed43bcef49dda31d4
import sys from io import StringIO from django.apps import apps from django.conf import settings from django.core import serializers from django.db import router # The prefix to put on the default database name when creating # the test database. TEST_DATABASE_PREFIX = 'test_' class BaseDatabaseCreation: """ ...
0b430bb6d7f4286114f62d0dd63ad7c29ad1812574b93eea2f812ef72965a514
from django.core import checks from django.db.backends.base.validation import BaseDatabaseValidation from django.utils.version import get_docs_version class DatabaseValidation(BaseDatabaseValidation): def check(self, **kwargs): issues = super().check(**kwargs) issues.extend(self._check_sql_mode(**...
62b674356aa9607aea8cbdfbf5b339a16accd4d51ed1962742666311bd393685
from django.db.backends.base.features import BaseDatabaseFeatures from django.utils.functional import cached_property class DatabaseFeatures(BaseDatabaseFeatures): empty_fetchmany_value = () update_can_self_select = False allows_group_by_pk = True related_fields_match_type = True # MySQL doesn't s...
995bd1e4981b7822b2881056de3acb1339f1d4f553285bb4feaeccdeac7fa3ed
from collections import namedtuple from MySQLdb.constants import FIELD_TYPE from django.db.backends.base.introspection import ( BaseDatabaseIntrospection, FieldInfo, TableInfo, ) from django.db.models.indexes import Index from django.utils.datastructures import OrderedSet FieldInfo = namedtuple('FieldInfo', Fiel...
277d1b5a02ef89a59f524b5e80ded89d79a9e8268467abbc55eba23780d49381
from django.db.models.sql import compiler class SQLCompiler(compiler.SQLCompiler): def as_subquery_condition(self, alias, columns, compiler): qn = compiler.quote_name_unless_alias qn2 = self.connection.ops.quote_name sql, params = self.as_sql() return '(%s) IN (%s)' % (', '.join('%...
a399abdbfc8599c737f4932235f1df62eebe30ccf98677cd1316b70b947739a3
""" MySQL database backend for Django. Requires mysqlclient: https://pypi.org/project/mysqlclient/ """ import re from django.core.exceptions import ImproperlyConfigured from django.db import utils from django.db.backends import utils as backend_utils from django.db.backends.base.base import BaseDatabaseWrapper from d...
7023440ee1f25eb15ba20c58e1f74a6101794ec80d85850f6200666887c6db36
import uuid from django.conf import settings from django.db.backends.base.operations import BaseDatabaseOperations from django.utils import timezone from django.utils.duration import duration_microseconds from django.utils.encoding import force_text class DatabaseOperations(BaseDatabaseOperations): compiler_modu...
d3ece18d8adabd84c1c390b10d084ac8785b4c88c101889e7ce2900c0e6ea783
from django.db.backends.base.schema import BaseDatabaseSchemaEditor from django.db.models import NOT_PROVIDED class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): sql_rename_table = "RENAME TABLE %(old_table)s TO %(new_table)s" sql_alter_column_null = "MODIFY %(column)s %(type)s NULL" sql_alter_column_...
befb75fb07af61e411e099a496b999fe7ad4ad774c6805d0395ee3e365d9c783
import subprocess from django.db.backends.base.client import BaseDatabaseClient class DatabaseClient(BaseDatabaseClient): executable_name = 'mysql' @classmethod def settings_to_cmd_args(cls, settings_dict): args = [cls.executable_name] db = settings_dict['OPTIONS'].get('db', settings_dic...
bc5850db361b1ab0bf4eb21cef005c6e1fe2edaa460feb74646d21def0ff2094
import subprocess import sys from django.db.backends.base.creation import BaseDatabaseCreation from .client import DatabaseClient class DatabaseCreation(BaseDatabaseCreation): def sql_table_creation_suffix(self): suffix = [] test_settings = self.connection.settings_dict['TEST'] if test_...
9bf6474f2762a31df83d76468fd01b6e98d99e2f545b8e1e2afcff54d6cced48
from django.db.backends.base.features import BaseDatabaseFeatures class DummyDatabaseFeatures(BaseDatabaseFeatures): supports_transactions = False
66c07f84a396f6db9a35b66deb87c663ab64d3f16a32217bdaba7c4c4dcdac30
""" Dummy database backend for Django. Django uses this if the database ENGINE setting is empty (None or empty string). Each of these API functions, except connection.close(), raise ImproperlyConfigured. """ from django.core.exceptions import ImproperlyConfigured from django.db.backends.base.base import BaseDatabase...
e7010c7bf663f921b1439005d3a487ee084cb9a983ff2edd76f27d2c1a99c610
from ..postgresql.features import * # NOQA
ba18ca2418a08644f357425e15826c61e7678b8c3923f37d2e92300da3e63ac1
from ..postgresql.introspection import * # NOQA
e6fe22c24f5dfc434f40c7630df431bcf29394e5f17da5ac9da47eaa008f31c3
import warnings from django.utils.deprecation import RemovedInDjango30Warning warnings.warn( "The django.db.backends.postgresql_psycopg2 module is deprecated in " "favor of django.db.backends.postgresql.", RemovedInDjango30Warning, stacklevel=2 )
836680ced7ccb402fddc5f2d1a63b55b66106e6afec39b26fce6e8a62e091d7e
from ..postgresql.base import * # NOQA
c6420e517fab2c8e988d32ad1076042bcf7085ed89d53f8528d551056d896e1e
from ..postgresql.operations import * # NOQA
47edd3d5e3aadbec83eba2f6fbe2029ed3c5d99b0b67e3a4e13578146c721b97
from ..postgresql.schema import * # NOQA
2110a61ad8414d184ed91546772bb158b268c007391f5ffed5acf0cebbc9f808
from ..postgresql.client import * # NOQA
7a778db396b3ebf434ef1d2af7dd46ed900162013e620320f7e5e4df92d3ecf3
from ..postgresql.utils import * # NOQA
2b6997dee2ab60a3eeeac9cf6ab58e52974f13b9e3325edde45ffdad64c4332e
from ..postgresql.creation import * # NOQA
4d282e8a084e050653323d0ff27ee6cc62f471926864d0b205afc43ce1d3ec5c
from django.db.backends.base.features import BaseDatabaseFeatures from django.db.utils import InterfaceError from django.utils.functional import cached_property class DatabaseFeatures(BaseDatabaseFeatures): allows_group_by_selected_pks = True can_return_id_from_insert = True can_return_ids_from_bulk_inser...
54f4ddad97581100c1ca07ff07117907874a62cf49e4d6e5bc332b7158a42cc6
from django.db.backends.base.introspection import ( BaseDatabaseIntrospection, FieldInfo, TableInfo, ) from django.db.models.indexes import Index class DatabaseIntrospection(BaseDatabaseIntrospection): # Maps type codes to Django Field types. data_types_reverse = { 16: 'BooleanField', 17: ...
2ba56df8287e3c26a8b439630d89b6fd9244df064d61bda5a9bc2521a389ece4
""" PostgreSQL database backend for Django. Requires psycopg 2: http://initd.org/projects/psycopg2 """ import threading import warnings from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.db import connections from django.db.backends.base.base import BaseDatabaseWrapp...
8fe7c18d47ee78c99cd33e5a9334c7e6e7f944dd8dd0bc1baffa284ad018261c
from psycopg2.extras import Inet from django.conf import settings from django.db import NotSupportedError from django.db.backends.base.operations import BaseDatabaseOperations class DatabaseOperations(BaseDatabaseOperations): cast_char_field_without_max_length = 'varchar' explain_prefix = 'EXPLAIN' def ...
d741ab1d14254398f5a4687abe37718163fbc82872066a62efad396ac500f227
import psycopg2 from django.db.backends.base.schema import BaseDatabaseSchemaEditor class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): sql_alter_column_type = "ALTER COLUMN %(column)s TYPE %(type)s USING %(column)s::%(type)s" sql_create_sequence = "CREATE SEQUENCE %(sequence)s" sql_delete_sequence =...
d2ecd93d5b23b07dbca747819fa8564b7bb685e5507c1256ce6d2c401e3d8599
import os import signal import subprocess from django.core.files.temp import NamedTemporaryFile from django.db.backends.base.client import BaseDatabaseClient def _escape_pgpass(txt): """ Escape a fragment of a PostgreSQL .pgpass file. """ return txt.replace('\\', '\\\\').replace(':', '\\:') class D...
dc65ee4c4a323cda9f51c5ce0959c2fa0c3bc5d015d7b66f6586f842ee9fecc7
from django.utils.timezone import utc def utc_tzinfo_factory(offset): if offset != 0: raise AssertionError("database connection isn't set to UTC") return utc
80713795632872623f3a7acbd9a90496aa9b120de3b8fded9c1c85ac08e77dc2
import sys from psycopg2 import errorcodes from django.db.backends.base.creation import BaseDatabaseCreation class DatabaseCreation(BaseDatabaseCreation): def _quote_name(self, name): return self.connection.ops.quote_name(name) def _get_database_create_suffix(self, encoding=None, template=None): ...
d6b855dbaec9d8ebaba781009a03230fee644ef539fc506805649fc1cf2f84c8
from django.db import utils from django.db.backends.base.features import BaseDatabaseFeatures from django.utils.functional import cached_property class DatabaseFeatures(BaseDatabaseFeatures): # SQLite cannot handle us only partially reading from a cursor's result set # and then writing the same rows to the da...
ba135ac54e4781daffe93ece3e031e5a72e840a7ad40692fb0283353b2c5ab91
import re from django.db.backends.base.introspection import ( BaseDatabaseIntrospection, FieldInfo, TableInfo, ) from django.db.models.indexes import Index field_size_re = re.compile(r'^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$') def get_field_size(name): """ Extract the size number from a "varchar(11)" type na...
3c445951f81cdf1188600c8543f3e86f66a7fe6feffee50dfffd72240d37807d
""" SQLite3 backend for the sqlite3 module in the standard library. """ import datetime import decimal import math import operator import re import warnings from sqlite3 import dbapi2 as Database import pytz from django.core.exceptions import ImproperlyConfigured from django.db import utils from django.db.backends im...
7598ef076dce5ba430c1b62ffa2f353b4aa3aacbccd19d0701520d67e116f706
import datetime import decimal import uuid from django.conf import settings from django.core.exceptions import FieldError from django.db import utils from django.db.backends.base.operations import BaseDatabaseOperations from django.db.models import aggregates, fields from django.db.models.expressions import Col from d...
7ece12cb4fa675a4afeab58a0e80f946f8b51b6a4cd18aa9ad925ce615fcfc5c
import contextlib import copy from decimal import Decimal from django.apps.registry import Apps from django.db.backends.base.schema import BaseDatabaseSchemaEditor from django.db.backends.ddl_references import Statement from django.db.transaction import atomic from django.db.utils import NotSupportedError class Data...
c224a3dabe2c086fa7dd2c05289576995130f461578b215b1e00ff21cfc38f10
import subprocess from django.db.backends.base.client import BaseDatabaseClient class DatabaseClient(BaseDatabaseClient): executable_name = 'sqlite3' def runshell(self): args = [self.executable_name, self.connection.settings_dict['NAME']] subprocess.check_call(args)
2da796e65da010d7a97fcb622157e4ef01ed301220a8659c137bd688c975c705
import os import shutil import sys from django.db.backends.base.creation import BaseDatabaseCreation class DatabaseCreation(BaseDatabaseCreation): @staticmethod def is_in_memory_db(database_name): return database_name == ':memory:' or 'mode=memory' in database_name def _get_test_db_name(self): ...
670c88de000b29797d138059dc7d0bb69d5945269d07517ce7ee57b4161051a5
""" HTTP server that implements the Python WSGI protocol (PEP 333, rev 1.21). Based on wsgiref.simple_server which is part of the standard library since 2.5. This is a simple server for use in testing or debugging Django apps. It hasn't been reviewed for security issues. DON'T USE IT FOR PRODUCTION USE! """ import l...
8d1d52e63f94b5131b4046291c063ec9f7e9e9008ac6781bcea8ba300d6d3b02
""" The temp module provides a NamedTemporaryFile that can be reopened in the same process on any platform. Most platforms use the standard Python tempfile.NamedTemporaryFile class, but Windows users are given a custom class. This is needed because the Python implementation of NamedTemporaryFile uses the O_TEMPORARY f...
3a36a514bbecfaf3da4c4def3f4798656c8dc0c8fda4b2593601b801c1a7dbf6
from django.core.files.base import File __all__ = ['File']
0ed9541764f45a40c2adfe9f5269ab89f7d7ffc6992f3c09bd1667ec20acbea8
""" Base file upload handler classes, and the built-in concrete subclasses """ from io import BytesIO from django.conf import settings from django.core.files.uploadedfile import ( InMemoryUploadedFile, TemporaryUploadedFile, ) from django.utils.module_loading import import_string __all__ = [ 'UploadFileExcep...
0fddc9f3b9cb5bab0a59b0673fb885633e2503a60b7eed75740bbcca04ca29ed
import os from io import BytesIO, StringIO, UnsupportedOperation from django.core.files.utils import FileProxyMixin from django.utils.functional import cached_property class File(FileProxyMixin): DEFAULT_CHUNK_SIZE = 64 * 2 ** 10 def __init__(self, file, name=None): self.file = file if name ...
d51df14c9288f4f968d314649f3f94bf6fd0411c3fbe6afead411cad3265a0c0
""" Move a file in the safest way possible:: >>> from django.core.files.move import file_move_safe >>> file_move_safe("/tmp/old_file", "/tmp/new_file") """ import errno import os from shutil import copystat from django.core.files import locks __all__ = ['file_move_safe'] def _samefile(src, dst): # Mac...
fe59e1be4c275c9fc38a1ea7348026f54bd3c3139dec248f8b83233d5c4cc9b6
""" Utility functions for handling images. Requires Pillow as you might imagine. """ import struct import zlib from django.core.files import File class ImageFile(File): """ A mixin for use alongside django.core.files.base.File, which provides additional features for dealing with images. """ @pro...
e40772e89bb30986ff540b52c1cf43afe8939a9b8c215b89dd129c935fac6339
class FileProxyMixin: """ A mixin class used to forward file methods to an underlaying file object. The internal file object has to be called "file":: class FileProxy(FileProxyMixin): def __init__(self, file): self.file = file """ encoding = property(lambda sel...
77365c0b539614c2b9d96a7a8f3546228f8c61b9248521ce85147825981aa101
""" Classes representing uploaded files. """ import os from io import BytesIO from django.conf import settings from django.core.files import temp as tempfile from django.core.files.base import File __all__ = ('UploadedFile', 'TemporaryUploadedFile', 'InMemoryUploadedFile', 'SimpleUploadedFile') class Up...
3eb0b7b442399acdecd158bb70a29b3dd3a65016cef33796465e944662d244dc
import os from datetime import datetime from urllib.parse import urljoin from django.conf import settings from django.core.exceptions import SuspiciousFileOperation from django.core.files import File, locks from django.core.files.move import file_move_safe from django.core.signals import setting_changed from django.ut...
9e7d0a246ff25e8213fe91eacde66106442c035b6085a57337ea780c0e55111e
""" Portable file locking utilities. Based partially on an example by Jonathan Feignberg in the Python Cookbook [1] (licensed under the Python Software License) and a ctypes port by Anatoly Techtonik for Roundup [2] (license [3]). [1] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65203 [2] http://sourceforg...
54db87d221945bd88ec0c802499a7db73c7ed47b210e703bcf70b42fd0bd676a
from itertools import chain from django.utils.itercompat import is_iterable class Tags: """ Built-in tags for internal checks. """ admin = 'admin' caches = 'caches' compatibility = 'compatibility' database = 'database' models = 'models' security = 'security' signals = 'signals...
1a27f891f9dd05d05ee2c73635f2d385efffa8a709058e5ea83fb63a1ead6a40
import inspect import types from itertools import chain from django.apps import apps from django.core.checks import Error, Tags, register @register(Tags.models) def check_all_models(app_configs=None, **kwargs): errors = [] if app_configs is None: models = apps.get_models() else: models = ...
8e1c9f5ff9ba4dea5361105afa3dea875a300f55bede399c7aef1bf1d205a959
from django.conf import settings from django.core.cache import DEFAULT_CACHE_ALIAS from . import Error, Tags, register E001 = Error( "You must define a '%s' cache in your CACHES setting." % DEFAULT_CACHE_ALIAS, id='caches.E001', ) @register(Tags.caches) def check_default_cache_is_configured(app_configs, **k...
fc73f6744aef3d88229dcd11d41c1b96ad51fa0ca4376b31718082c8c69a9478
from .messages import ( CRITICAL, DEBUG, ERROR, INFO, WARNING, CheckMessage, Critical, Debug, Error, Info, Warning, ) from .registry import Tags, register, run_checks, tag_exists # Import these to force registration of checks import django.core.checks.caches # NOQA isort:skip import django.core.checks.databas...
65b6ac187ecbfcc788188c1bfe76223bd67f317174f9a5ced6bbb6c450028fa6
# Levels DEBUG = 10 INFO = 20 WARNING = 30 ERROR = 40 CRITICAL = 50 class CheckMessage: def __init__(self, level, msg, hint=None, obj=None, id=None): assert isinstance(level, int), "The first argument should be level." self.level = level self.msg = msg self.hint = hint sel...
940f306f0d960c2f9ee1902bfbda28116b46beb372321d46f8c65ba231aaf56f
from collections import Counter from django.conf import settings from . import Error, Tags, Warning, register @register(Tags.urls) def check_url_config(app_configs, **kwargs): if getattr(settings, 'ROOT_URLCONF', None): from django.urls import get_resolver resolver = get_resolver() retur...
2295f2212f930d31f8a74dfb686da5d2a5a701516da7ca33244b1732f6a822ef
from django.db import connections from . import Tags, register @register(Tags.database) def check_database_backends(*args, **kwargs): issues = [] for conn in connections.all(): issues.extend(conn.validation.check(**kwargs)) return issues
f7fa999ff3165fde22db4f4c56edae4bae8d3d181b296b64fd7c5eb4a733c9f5
import copy from django.conf import settings from . import Error, Tags, register E001 = Error( "You have 'APP_DIRS': True in your TEMPLATES but also specify 'loaders' " "in OPTIONS. Either remove APP_DIRS or remove the 'loaders' option.", id='templates.E001', ) E002 = Error( "'string_if_invalid' in T...
2e357bb48c717bbecf795559db10e0efb80356188374f1c91ddd9ae41359a6c7
import functools import os import pkgutil import sys from collections import OrderedDict, defaultdict from difflib import get_close_matches from importlib import import_module import django from django.apps import apps from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django...
a5851b033620e5bc09062853ebb4a6db414e5147ecba54cf8765c6462d9841cb
""" Base classes for writing management commands (named commands which can be executed through ``django-admin`` or ``manage.py``). """ import os import sys from argparse import ArgumentParser, HelpFormatter from io import TextIOBase import django from django.core import checks from django.core.exceptions import Improp...
b744ede0db3eadaf072da93f314097fd5aee83077413d6ffa9c11ec28239fbf5
import os from subprocess import PIPE, Popen from django.apps import apps as installed_apps from django.utils.crypto import get_random_string from django.utils.encoding import DEFAULT_LOCALE_ENCODING from .base import CommandError def popen_wrapper(args, stdout_encoding='utf-8'): """ Friendly wrapper around...
8c8f4a2d5f3000b6ff41ce19464fa373703136bd42bc4bc6d7914a2994d0d2e9
import cgi import mimetypes import os import posixpath import shutil import stat import tempfile from importlib import import_module from os import path from urllib.request import urlretrieve import django from django.conf import settings from django.core.management.base import BaseCommand, CommandError from django.co...
6e7c4451420949c8fa03aeecd2dc69ab8453f2c8749fe452e59c5c36ac926805
from django.apps import apps from django.db import models def sql_flush(style, connection, only_django=False, reset_sequences=True, allow_cascade=False): """ Return a list of the SQL statements used to flush the database. If only_django is True, only include the table names that have associated Djang...
4c10d42322d791952880afc5bc8cb713b9e97086d7a69acd28218683a25f1108
""" Sets up the terminal color scheme. """ import functools import os import sys from django.utils import termcolors def supports_color(): """ Return True if the running system's terminal supports color, and False otherwise. """ plat = sys.platform supported_platform = plat != 'Pocket PC' an...
1b16cb073153dffeaba96f84dbabb7d3ffc1624aa168287aa7384cd4aca4644f
""" Caching framework. This package defines set of cache backends that all conform to a simple API. In a nutshell, a cache is a set of values -- which can be any object that may be pickled -- identified by string keys. For the complete API, see the abstract BaseCache class in django.core.cache.backends.base. Client ...
7dd49398cbe755333b761c1ffaa6c746784b2405755c825efd4b791fe106281c
import hashlib from urllib.parse import quote TEMPLATE_FRAGMENT_KEY_TEMPLATE = 'template.cache.%s.%s' def make_template_fragment_key(fragment_name, vary_on=None): if vary_on is None: vary_on = () key = ':'.join(quote(str(var)) for var in vary_on) args = hashlib.md5(key.encode()) return TEMPLA...
4c42531061ec5b9bd40095aa433ec57650ff34418d686941378cc901edb5c9ea
""" Interfaces for serializing Django objects. Usage:: from django.core import serializers json = serializers.serialize("json", some_queryset) objects = list(serializers.deserialize("json", json)) To add your own serializers, use the SERIALIZATION_MODULES setting:: SERIALIZATION_MODULES = { ...
b0a7f302b4632b6ccd69153161105b5169a841f0d42b3c8a7482aed6005e2a77
""" Serialize data to/from JSON """ import datetime import decimal import json import uuid from django.core.serializers.base import DeserializationError from django.core.serializers.python import ( Deserializer as PythonDeserializer, Serializer as PythonSerializer, ) from django.utils.duration import duration_iso...
cc39e0f598ce1d467f2c5f33c60215eddb46ec382d3ffdedba3b1b7a8ad12fe7
""" Module for abstract serializer/unserializer base classes. """ from io import StringIO from django.db import models class SerializerDoesNotExist(KeyError): """The requested serializer was not found.""" pass class SerializationError(Exception): """Something bad happened during serialization.""" p...
497c171e3b34ff6f6dc9c3ad5d7b3e956192fbe48105578794d6feae385e09a9
""" YAML serializer. Requires PyYaml (http://pyyaml.org/), but that's checked for in __init__. """ import collections import decimal from io import StringIO import yaml from django.core.serializers.base import DeserializationError from django.core.serializers.python import ( Deserializer as PythonDeserializer, ...
c178a1e1eb8c3c66c6c2500d03b981ad0a15f4b9598e5b41008f22e3e792a04b
""" A Python "serializer". Doesn't do much serializing per se -- just converts to and from basic Python data types (lists, dicts, strings, etc.). Useful as a basis for other serializers. """ from collections import OrderedDict from django.apps import apps from django.core.serializers import base from django.db import ...
cdee5e97a3a949a2a776155d5a62300424e5ec3f7b5f8a143fe896507f4ab8d2
""" XML serializer. """ from xml.dom import pulldom from xml.sax import handler from xml.sax.expatreader import ExpatParser as _ExpatParser from django.apps import apps from django.conf import settings from django.core.serializers import base from django.db import DEFAULT_DB_ALIAS, models from django.utils.xmlutils i...
2895ce9b67cbab86496afa83c248587482916d2fed70fb6c3e62e0b3294d5fa1
import cgi import codecs import re from io import BytesIO from django.conf import settings from django.core import signals from django.core.handlers import base from django.http import HttpRequest, QueryDict, parse_cookie from django.urls import set_script_prefix from django.utils.encoding import repercent_broken_unic...
63c0d4b66ff549e24c8e049ef366a5b23172b02e24584639ea4f4c650bef7f22
import logging import sys from functools import wraps from django.conf import settings from django.core import signals from django.core.exceptions import ( PermissionDenied, RequestDataTooBig, SuspiciousOperation, TooManyFieldsSent, ) from django.http import Http404 from django.http.multipartparser import Mult...
feec70f5fb6773b0e5ae39efb249815bb732ca3ee778589ab672422e12783bcb
import logging import types from django.conf import settings from django.core.exceptions import ImproperlyConfigured, MiddlewareNotUsed from django.db import connections, transaction from django.urls import get_resolver, set_urlconf from django.utils.log import log_response from django.utils.module_loading import impo...
2c10bde2a0c62d42f16ac47ded701bd311acb2bdbdf846cd5130e96ed9d0ea21
""" Tools for sending email. """ from django.conf import settings # Imported for backwards compatibility and for the sake # of a cleaner namespace. These symbols used to be in # django/core/mail.py before the introduction of email # backends and the subsequent reorganization (See #10355) from django.core.mail.message i...
9d4416ab33c065fa9663627b4ac61f5658a160c633ea2fc0f07e43d294a406fa
""" Email message and email sending related helper functions. """ import socket # Cache the hostname, but do it lazily: socket.getfqdn() can take a couple of # seconds, which slows down the restart of the server. class CachedDnsName: def __str__(self): return self.get_fqdn() def get_fqdn(self): ...