Permalink
Browse files

Merge pull request #1854 from rayashmanjr/master

Correct flake8 E302 violations
  • Loading branch information...
2 parents 3bc0d46 + e459893 commit 393cdbfaa2d47c85f6764e80600de48f26f43327 @alex alex committed Nov 3, 2013
@@ -61,16 +61,19 @@ def to_list(value):
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
transaction.enter_transaction_management = nop
transaction.leave_transaction_management = nop
transaction.abort = nop
+
def restore_transaction_methods():
transaction.commit = real_commit
transaction.rollback = real_rollback
View
@@ -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.
@@ -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
@@ -149,6 +150,7 @@ def update_watch(sender=None, **kwargs):
# If we are here the code must have changed.
return True
+
def kqueue_code_changed():
"""
Checks for changed code using kqueue. After being called
@@ -193,6 +195,7 @@ def kqueue_code_changed():
return True
+
def code_changed():
global _mtimes, _win
for filename in gen_filenames():
@@ -212,6 +215,7 @@ def code_changed():
return True
return False
+
def check_errors(fn):
def wrapper(*args, **kwargs):
try:
@@ -233,6 +237,7 @@ def wrapper(*args, **kwargs):
return wrapper
+
def ensure_echo_on():
if termios:
fd = sys.stdin
@@ -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:
@@ -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)
@@ -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)
View
@@ -31,6 +31,7 @@
cc_delim_re = re.compile(r'\s*,\s*')
+
def patch_cache_control(response, **kwargs):
"""
This function patches the Cache-Control header by adding all
@@ -79,6 +80,7 @@ def dictvalue(t):
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
@@ -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:
@@ -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.
@@ -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.
@@ -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:
@@ -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()
@@ -187,13 +196,15 @@ 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())))
cache_key = 'views.decorators.cache.cache_header.%s.%s' % (
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
@@ -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
@@ -3,6 +3,7 @@
from collections import OrderedDict
from django.utils import six
+
class MergeDict(object):
"""
A simple class for creating new "virtual" dictionaries that actually look
@@ -117,6 +118,7 @@ def __repr__(self):
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.
@@ -239,6 +241,7 @@ def clear(self):
super(SortedDict, self).clear()
self.keyOrder = []
+
class OrderedSet(object):
"""
A set which keeps the ordering of the inserted items.
@@ -269,9 +272,11 @@ def __contains__(self, item):
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
@@ -504,6 +509,7 @@ def complain(self, *wargs, **kwargs):
sort = complain
reverse = complain
+
class DictWrapper(dict):
"""
Wraps accesses to a dictionary so that certain values (those starting with
@@ -26,6 +26,7 @@
re_formatchars = re.compile(r'(?<!\\)([aAbBcdDeEfFgGhHiIjlLmMnNoOPrsStTUuwWyYzZ])')
re_escaped = re.compile(r'\\(.)')
+
class Formatter(object):
def format(self, formatstr):
pieces = []
@@ -36,6 +37,7 @@ def format(self, formatstr):
pieces.append(re_escaped.sub(r'\1', piece))
return ''.join(pieces)
+
class TimeFormat(Formatter):
def __init__(self, obj):
@@ -39,6 +39,7 @@ def parse_date(value):
kw = dict((k, int(v)) for k, v in six.iteritems(match.groupdict()))
return datetime.date(**kw)
+
def parse_time(value):
"""Parses a string and return a datetime.time.
@@ -56,6 +57,7 @@ def parse_time(value):
kw = dict((k, int(v)) for k, v in six.iteritems(kw) if v is not None)
return datetime.time(**kw)
+
def parse_datetime(value):
"""Parses a string and return a datetime.datetime.
@@ -30,10 +30,12 @@ def combine(cls, date, time):
def date(self):
return date(self.year, self.month, self.day)
+
def new_date(d):
"Generate a safe date from a datetime.date object."
return date(d.year, d.month, d.day)
+
def new_datetime(d):
"""
Generate a safe datetime from a datetime.date or datetime.datetime object.
@@ -47,6 +49,7 @@ def new_datetime(d):
# Allowed if there's an even number of "%"s because they are escaped.
_illegal_formatting = re.compile(r"((^|[^%])(%%)*%[sy])")
+
def _findall(text, substr):
# Also finds overlaps
sites = []
@@ -59,6 +62,7 @@ def _findall(text, substr):
i = j + 1
return sites
+
def strftime(dt, fmt):
if dt.year >= 1900:
return super(type(dt), dt).strftime(fmt)
@@ -32,6 +32,7 @@
IDENTIFIER = re.compile('^[a-z_][a-z0-9_]*$', re.I)
+
def valid_ident(s):
m = IDENTIFIER.match(s)
if not m:
@@ -65,6 +66,7 @@ def _checkLevel(level):
# Each wrapper should have a configurator attribute holding the actual
# configurator to use for conversion.
+
class ConvertingDict(dict):
"""A converting dictionary wrapper."""
@@ -102,6 +104,7 @@ def pop(self, key, default=None):
result.key = key
return result
+
class ConvertingList(list):
"""A converting list wrapper."""
def __getitem__(self, key):
@@ -125,6 +128,7 @@ def pop(self, idx=-1):
result.parent = self
return result
+
class ConvertingTuple(tuple):
"""A converting tuple wrapper."""
def __getitem__(self, key):
@@ -137,6 +141,7 @@ def __getitem__(self, key):
result.key = key
return result
+
class BaseConfigurator(object):
"""
The configurator base class which defines some useful defaults.
@@ -270,6 +275,7 @@ def as_tuple(self, value):
value = tuple(value)
return value
+
class DictConfigurator(BaseConfigurator):
"""
Configure logging using a dictionary-like object to describe the
@@ -555,6 +561,7 @@ def configure_root(self, config, incremental=False):
dictConfigClass = DictConfigurator
+
def dictConfig(config):
"""Configure logging using a dictionary."""
dictConfigClass(config).configure()
Oops, something went wrong.

0 comments on commit 393cdbf

Please sign in to comment.