Loading django/test/testcases.py +3 −0 Original line number Diff line number Diff line Loading @@ -61,9 +61,11 @@ real_enter_transaction_management = transaction.enter_transaction_management real_leave_transaction_management = transaction.leave_transaction_management real_abort = transaction.abort def nop(*args, **kwargs): return def disable_transaction_methods(): transaction.commit = nop transaction.rollback = nop Loading @@ -71,6 +73,7 @@ def disable_transaction_methods(): transaction.leave_transaction_management = nop transaction.abort = nop def restore_transaction_methods(): transaction.commit = real_commit transaction.rollback = real_rollback Loading django/utils/_os.py +1 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ def npath(path): return path.encode(fs_encoding) return path def safe_join(base, *paths): """ Joins one or more path components to the base path component intelligently. Loading django/utils/autoreload.py +8 −0 Original line number Diff line number Diff line Loading @@ -119,6 +119,7 @@ def gen_filenames(): if os.path.exists(filename): yield filename def inotify_code_changed(): """ Checks for changed code using inotify. After being called Loading Loading @@ -149,6 +150,7 @@ def inotify_code_changed(): # If we are here the code must have changed. return True def kqueue_code_changed(): """ Checks for changed code using kqueue. After being called Loading Loading @@ -193,6 +195,7 @@ def kqueue_code_changed(): return True def code_changed(): global _mtimes, _win for filename in gen_filenames(): Loading @@ -212,6 +215,7 @@ def code_changed(): return True return False def check_errors(fn): def wrapper(*args, **kwargs): try: Loading @@ -233,6 +237,7 @@ def check_errors(fn): return wrapper def ensure_echo_on(): if termios: fd = sys.stdin Loading @@ -248,6 +253,7 @@ def ensure_echo_on(): if old_handler is not None: signal.signal(signal.SIGTTOU, old_handler) def reloader_thread(): ensure_echo_on() if USE_INOTIFY: Loading @@ -273,6 +279,7 @@ def restart_with_reloader(): if exit_code != 3: return exit_code def python_reloader(main_func, args, kwargs): if os.environ.get("RUN_MAIN") == "true": thread.start_new_thread(main_func, args, kwargs) Loading @@ -290,6 +297,7 @@ def python_reloader(main_func, args, kwargs): except KeyboardInterrupt: pass def jython_reloader(main_func, args, kwargs): from _systemrestart import SystemRestart thread.start_new_thread(main_func, args) Loading django/utils/cache.py +12 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ from django.utils.translation import get_language cc_delim_re = re.compile(r'\s*,\s*') def patch_cache_control(response, **kwargs): """ This function patches the Cache-Control header by adding all Loading Loading @@ -79,6 +80,7 @@ def patch_cache_control(response, **kwargs): cc = ', '.join(dictvalue(el) for el in cc.items()) response['Cache-Control'] = cc def get_max_age(response): """ Returns the max-age from the response Cache-Control header as an integer Loading @@ -94,11 +96,13 @@ def get_max_age(response): except (ValueError, TypeError): pass def _set_response_etag(response): if not response.streaming: response['ETag'] = '"%s"' % hashlib.md5(response.content).hexdigest() return response def patch_response_headers(response, cache_timeout=None): """ Adds some useful headers to the given HttpResponse object: Loading @@ -124,12 +128,14 @@ def patch_response_headers(response, cache_timeout=None): response['Expires'] = http_date(time.time() + cache_timeout) patch_cache_control(response, max_age=cache_timeout) def add_never_cache_headers(response): """ Adds headers to a response to indicate that a page should never be cached. """ patch_response_headers(response, cache_timeout=-1) def patch_vary_headers(response, newheaders): """ Adds (or updates) the "Vary" header in the given HttpResponse object. Loading @@ -149,6 +155,7 @@ def patch_vary_headers(response, newheaders): if newheader.lower() not in existing_headers] response['Vary'] = ', '.join(vary_headers + additional_headers) def has_vary_header(response, header_query): """ Checks to see if the response has a given header name in its Vary header. Loading @@ -159,6 +166,7 @@ def has_vary_header(response, header_query): existing_headers = set(header.lower() for header in vary_headers) return header_query.lower() in existing_headers def _i18n_cache_key_suffix(request, cache_key): """If necessary, adds the current locale or time zone to the cache key.""" if settings.USE_I18N or settings.USE_L10N: Loading @@ -175,6 +183,7 @@ def _i18n_cache_key_suffix(request, cache_key): cache_key += '.%s' % tz_name.encode('ascii', 'ignore').decode('ascii').replace(' ', '_') return cache_key def _generate_cache_key(request, method, headerlist, key_prefix): """Returns a cache key from the headers given in the header list.""" ctx = hashlib.md5() Loading @@ -187,6 +196,7 @@ def _generate_cache_key(request, method, headerlist, key_prefix): key_prefix, method, path.hexdigest(), ctx.hexdigest()) return _i18n_cache_key_suffix(request, cache_key) def _generate_cache_header_key(key_prefix, request): """Returns a cache key for the header cache.""" path = hashlib.md5(force_bytes(iri_to_uri(request.get_full_path()))) Loading @@ -194,6 +204,7 @@ def _generate_cache_header_key(key_prefix, request): key_prefix, path.hexdigest()) return _i18n_cache_key_suffix(request, cache_key) def get_cache_key(request, key_prefix=None, method='GET', cache=None): """ Returns a cache key based on the request path and query. It can be used Loading @@ -215,6 +226,7 @@ def get_cache_key(request, key_prefix=None, method='GET', cache=None): else: return None def learn_cache_key(request, response, cache_timeout=None, key_prefix=None, cache=None): """ Learns what headers to take into account for some request path from the Loading django/utils/datastructures.py +6 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ import warnings from collections import OrderedDict from django.utils import six class MergeDict(object): """ A simple class for creating new "virtual" dictionaries that actually look Loading Loading @@ -117,6 +118,7 @@ class MergeDict(object): dictreprs = ', '.join(repr(d) for d in self.dicts) return '%s(%s)' % (self.__class__.__name__, dictreprs) class SortedDict(dict): """ A dictionary that keeps its keys in the order in which they're inserted. Loading Loading @@ -239,6 +241,7 @@ class SortedDict(dict): super(SortedDict, self).clear() self.keyOrder = [] class OrderedSet(object): """ A set which keeps the ordering of the inserted items. Loading Loading @@ -269,9 +272,11 @@ class OrderedSet(object): def __nonzero__(self): return bool(self.dict) class MultiValueDictKeyError(KeyError): pass class MultiValueDict(dict): """ A subclass of dictionary customized to handle multiple values for the Loading Loading @@ -504,6 +509,7 @@ class ImmutableList(tuple): sort = complain reverse = complain class DictWrapper(dict): """ Wraps accesses to a dictionary so that certain values (those starting with Loading Loading
django/test/testcases.py +3 −0 Original line number Diff line number Diff line Loading @@ -61,9 +61,11 @@ real_enter_transaction_management = transaction.enter_transaction_management real_leave_transaction_management = transaction.leave_transaction_management real_abort = transaction.abort def nop(*args, **kwargs): return def disable_transaction_methods(): transaction.commit = nop transaction.rollback = nop Loading @@ -71,6 +73,7 @@ def disable_transaction_methods(): transaction.leave_transaction_management = nop transaction.abort = nop def restore_transaction_methods(): transaction.commit = real_commit transaction.rollback = real_rollback Loading
django/utils/_os.py +1 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ def npath(path): return path.encode(fs_encoding) return path def safe_join(base, *paths): """ Joins one or more path components to the base path component intelligently. Loading
django/utils/autoreload.py +8 −0 Original line number Diff line number Diff line Loading @@ -119,6 +119,7 @@ def gen_filenames(): if os.path.exists(filename): yield filename def inotify_code_changed(): """ Checks for changed code using inotify. After being called Loading Loading @@ -149,6 +150,7 @@ def inotify_code_changed(): # If we are here the code must have changed. return True def kqueue_code_changed(): """ Checks for changed code using kqueue. After being called Loading Loading @@ -193,6 +195,7 @@ def kqueue_code_changed(): return True def code_changed(): global _mtimes, _win for filename in gen_filenames(): Loading @@ -212,6 +215,7 @@ def code_changed(): return True return False def check_errors(fn): def wrapper(*args, **kwargs): try: Loading @@ -233,6 +237,7 @@ def check_errors(fn): return wrapper def ensure_echo_on(): if termios: fd = sys.stdin Loading @@ -248,6 +253,7 @@ def ensure_echo_on(): if old_handler is not None: signal.signal(signal.SIGTTOU, old_handler) def reloader_thread(): ensure_echo_on() if USE_INOTIFY: Loading @@ -273,6 +279,7 @@ def restart_with_reloader(): if exit_code != 3: return exit_code def python_reloader(main_func, args, kwargs): if os.environ.get("RUN_MAIN") == "true": thread.start_new_thread(main_func, args, kwargs) Loading @@ -290,6 +297,7 @@ def python_reloader(main_func, args, kwargs): except KeyboardInterrupt: pass def jython_reloader(main_func, args, kwargs): from _systemrestart import SystemRestart thread.start_new_thread(main_func, args) Loading
django/utils/cache.py +12 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ from django.utils.translation import get_language cc_delim_re = re.compile(r'\s*,\s*') def patch_cache_control(response, **kwargs): """ This function patches the Cache-Control header by adding all Loading Loading @@ -79,6 +80,7 @@ def patch_cache_control(response, **kwargs): cc = ', '.join(dictvalue(el) for el in cc.items()) response['Cache-Control'] = cc def get_max_age(response): """ Returns the max-age from the response Cache-Control header as an integer Loading @@ -94,11 +96,13 @@ def get_max_age(response): except (ValueError, TypeError): pass def _set_response_etag(response): if not response.streaming: response['ETag'] = '"%s"' % hashlib.md5(response.content).hexdigest() return response def patch_response_headers(response, cache_timeout=None): """ Adds some useful headers to the given HttpResponse object: Loading @@ -124,12 +128,14 @@ def patch_response_headers(response, cache_timeout=None): response['Expires'] = http_date(time.time() + cache_timeout) patch_cache_control(response, max_age=cache_timeout) def add_never_cache_headers(response): """ Adds headers to a response to indicate that a page should never be cached. """ patch_response_headers(response, cache_timeout=-1) def patch_vary_headers(response, newheaders): """ Adds (or updates) the "Vary" header in the given HttpResponse object. Loading @@ -149,6 +155,7 @@ def patch_vary_headers(response, newheaders): if newheader.lower() not in existing_headers] response['Vary'] = ', '.join(vary_headers + additional_headers) def has_vary_header(response, header_query): """ Checks to see if the response has a given header name in its Vary header. Loading @@ -159,6 +166,7 @@ def has_vary_header(response, header_query): existing_headers = set(header.lower() for header in vary_headers) return header_query.lower() in existing_headers def _i18n_cache_key_suffix(request, cache_key): """If necessary, adds the current locale or time zone to the cache key.""" if settings.USE_I18N or settings.USE_L10N: Loading @@ -175,6 +183,7 @@ def _i18n_cache_key_suffix(request, cache_key): cache_key += '.%s' % tz_name.encode('ascii', 'ignore').decode('ascii').replace(' ', '_') return cache_key def _generate_cache_key(request, method, headerlist, key_prefix): """Returns a cache key from the headers given in the header list.""" ctx = hashlib.md5() Loading @@ -187,6 +196,7 @@ def _generate_cache_key(request, method, headerlist, key_prefix): key_prefix, method, path.hexdigest(), ctx.hexdigest()) return _i18n_cache_key_suffix(request, cache_key) def _generate_cache_header_key(key_prefix, request): """Returns a cache key for the header cache.""" path = hashlib.md5(force_bytes(iri_to_uri(request.get_full_path()))) Loading @@ -194,6 +204,7 @@ def _generate_cache_header_key(key_prefix, request): key_prefix, path.hexdigest()) return _i18n_cache_key_suffix(request, cache_key) def get_cache_key(request, key_prefix=None, method='GET', cache=None): """ Returns a cache key based on the request path and query. It can be used Loading @@ -215,6 +226,7 @@ def get_cache_key(request, key_prefix=None, method='GET', cache=None): else: return None def learn_cache_key(request, response, cache_timeout=None, key_prefix=None, cache=None): """ Learns what headers to take into account for some request path from the Loading
django/utils/datastructures.py +6 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ import warnings from collections import OrderedDict from django.utils import six class MergeDict(object): """ A simple class for creating new "virtual" dictionaries that actually look Loading Loading @@ -117,6 +118,7 @@ class MergeDict(object): dictreprs = ', '.join(repr(d) for d in self.dicts) return '%s(%s)' % (self.__class__.__name__, dictreprs) class SortedDict(dict): """ A dictionary that keeps its keys in the order in which they're inserted. Loading Loading @@ -239,6 +241,7 @@ class SortedDict(dict): super(SortedDict, self).clear() self.keyOrder = [] class OrderedSet(object): """ A set which keeps the ordering of the inserted items. Loading Loading @@ -269,9 +272,11 @@ class OrderedSet(object): def __nonzero__(self): return bool(self.dict) class MultiValueDictKeyError(KeyError): pass class MultiValueDict(dict): """ A subclass of dictionary customized to handle multiple values for the Loading Loading @@ -504,6 +509,7 @@ class ImmutableList(tuple): sort = complain reverse = complain class DictWrapper(dict): """ Wraps accesses to a dictionary so that certain values (those starting with Loading