Permalink
Browse files

Fixed the remaining E302 violations int eh django package

  • Loading branch information...
1 parent 393cdbf commit fe995e6cbdcf2766cf0aa951c8ef4549ad27694c @alex alex committed Nov 3, 2013
@@ -104,6 +104,7 @@ def __add__(self, other):
getattr(combined, 'add_' + name)(getattr(other, '_' + name, None))
return combined
+
def media_property(cls):
def _media(self):
# Get the media property of the superclass, if it exists
@@ -131,6 +132,7 @@ def _media(self):
return base
return property(_media)
+
class MediaDefiningClass(type):
"""
Metaclass for classes that can have media definitions.
@@ -162,6 +164,7 @@ def __str__(self):
args.append(self.choices)
return self.parent_widget.render(*args)
+
class Widget(six.with_metaclass(MediaDefiningClass)):
is_hidden = False # Determines whether this corresponds to an <input type="hidden">.
needs_multipart_form = False # Determines does this widget need multipart form
@@ -224,6 +227,7 @@ def id_for_label(self, id_):
"""
return id_
+
class Input(Widget):
"""
Base class for all <input> widgets (except type='checkbox' and
@@ -279,10 +283,12 @@ def render(self, name, value, attrs=None):
value = None
return super(PasswordInput, self).render(name, value, attrs)
+
class HiddenInput(Input):
input_type = 'hidden'
is_hidden = True
+
class MultipleHiddenInput(HiddenInput):
"""
A widget that handles <input type="hidden"> for fields that have a list
@@ -313,6 +319,7 @@ def value_from_datadict(self, data, files, name):
return data.getlist(name)
return data.get(name, None)
+
class FileInput(Input):
input_type = 'file'
needs_multipart_form = True
@@ -327,6 +334,7 @@ def value_from_datadict(self, data, files, name):
FILE_INPUT_CONTRADICTION = object()
+
class ClearableFileInput(FileInput):
initial_text = ugettext_lazy('Currently')
input_text = ugettext_lazy('Change')
@@ -389,6 +397,7 @@ def value_from_datadict(self, data, files, name):
return False
return upload
+
class Textarea(Widget):
def __init__(self, attrs=None):
# The 'rows' and 'cols' attributes are required for HTML correctness.
@@ -515,6 +524,7 @@ def render_options(self, choices, selected_choices):
output.append(self.render_option(selected_choices, option_value, option_label))
return '\n'.join(output)
+
class NullBooleanSelect(Select):
"""
A Select Widget intended to be used with NullBooleanField.
@@ -849,6 +859,7 @@ def decompress(self, value):
return [value.date(), value.time().replace(microsecond=0)]
return [None, None]
+
class SplitHiddenDateTimeWidget(SplitDateTimeWidget):
"""
A Widget that splits datetime input into two <input type="hidden"> inputs.
@@ -269,6 +269,7 @@ def IE_sanitize(self, filename):
"""Cleanup filename from Internet Explorer full paths."""
return filename and filename[filename.rfind("\\")+1:].strip()
+
class LazyStream(six.Iterator):
"""
The LazyStream wrapper allows one to get and "unget" bytes from a stream.
@@ -380,6 +381,7 @@ def _update_unget_history(self, num_bytes):
" if there is none, report this to the Django developers."
)
+
class ChunkIter(six.Iterator):
"""
An iterable that will yield chunks of data. Given a file-like object as the
@@ -403,6 +405,7 @@ def __next__(self):
def __iter__(self):
return self
+
class InterBoundaryIter(six.Iterator):
"""
A Producer that will iterate over boundaries.
@@ -420,6 +423,7 @@ def __next__(self):
except InputStreamExhausted:
raise StopIteration()
+
class BoundaryIter(six.Iterator):
"""
A Producer that is sensitive to boundaries.
@@ -516,6 +520,7 @@ def _find_boundary(self, data, eof = False):
end -= 1
return end, next
+
def exhaust(stream_or_iterable):
"""
Completely exhausts an iterator or stream.
@@ -534,6 +539,7 @@ def exhaust(stream_or_iterable):
for __ in iterator:
pass
+
def parse_boundary_stream(stream, max_header_size):
"""
Parses one and exactly one stream that encapsulates a boundary.
@@ -592,6 +598,7 @@ def _parse_header(line):
return (TYPE, outdict, stream)
+
class Parser(object):
def __init__(self, stream, boundary):
self._stream = stream
@@ -603,6 +610,7 @@ def __iter__(self):
# Iterate over each part
yield parse_boundary_stream(sub_stream, 1024)
+
def parse_header(line):
""" Parse the header into a key-value.
Input (line): bytes, output: unicode for key/name, bytes for value which
@@ -622,6 +630,7 @@ def parse_header(line):
pdict[name] = value
return key, pdict
+
def _parse_header_params(s):
plist = []
while s[:1] == b';':
@@ -95,9 +95,11 @@ def __str__(self):
return self.msg % tuple(force_text(p, errors='replace')
for p in self.params)
+
class InvalidTemplateLibrary(Exception):
pass
+
class Origin(object):
def __init__(self, name):
self.name = name
@@ -108,6 +110,7 @@ def reload(self):
def __str__(self):
return self.name
+
class StringOrigin(Origin):
def __init__(self, source):
super(StringOrigin, self).__init__(UNKNOWN_SOURCE)
@@ -116,6 +119,7 @@ def __init__(self, source):
def reload(self):
return self.source
+
class Template(object):
def __init__(self, template_string, origin=None,
name='<Unknown Template>'):
@@ -146,6 +150,7 @@ def render(self, context):
finally:
context.render_context.pop()
+
def compile_string(template_string, origin):
"Compiles template_string into NodeList ready for rendering"
if settings.TEMPLATE_DEBUG:
@@ -157,6 +162,7 @@ def compile_string(template_string, origin):
parser = parser_class(lexer.tokenize())
return parser.parse()
+
class Token(object):
def __init__(self, token_type, contents):
# token_type must be TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK or
@@ -184,6 +190,7 @@ def split_contents(self):
split.append(bit)
return split
+
class Lexer(object):
def __init__(self, template_string, origin):
self.template_string = template_string
@@ -235,6 +242,7 @@ def create_token(self, token_string, in_tag):
self.lineno += token_string.count('\n')
return token
+
class Parser(object):
def __init__(self, tokens):
self.tokens = tokens
@@ -370,6 +378,7 @@ def find_filter(self, filter_name):
else:
raise TemplateSyntaxError("Invalid filter: '%s'" % filter_name)
+
class TokenParser(object):
"""
Subclass this and implement the top() method to parse a template line.
@@ -523,6 +532,7 @@ def next_space_index(subject, i):
filter_re = re.compile(filter_raw_string, re.UNICODE | re.VERBOSE)
+
class FilterExpression(object):
"""
Parses a variable token and its optional filters (all as a single string),
@@ -644,6 +654,7 @@ def args_check(name, func, provided):
def __str__(self):
return self.token
+
def resolve_variable(path, context):
"""
Returns the resolved variable, which may contain attribute syntax, within
@@ -653,6 +664,7 @@ def resolve_variable(path, context):
"""
return Variable(path).resolve(context)
+
class Variable(object):
"""
A template variable, resolvable against a given context. The variable may
@@ -793,6 +805,7 @@ def _resolve_lookup(self, context):
return current
+
class Node(object):
# Set this to True for nodes that must be first in the template (although
# they can be preceded by text nodes.
@@ -822,6 +835,7 @@ def get_nodes_by_type(self, nodetype):
nodes.extend(nodelist.get_nodes_by_type(nodetype))
return nodes
+
class NodeList(list):
# Set to True the first time a non-TextNode is inserted by
# extend_nodelist().
@@ -847,6 +861,7 @@ def get_nodes_by_type(self, nodetype):
def render_node(self, node, context):
return node.render(context)
+
class TextNode(Node):
def __init__(self, s):
self.s = s
@@ -858,6 +873,7 @@ def __repr__(self):
def render(self, context):
return self.s
+
def render_value_in_context(value, context):
"""
Converts any value to a string to become part of a rendered template. This
@@ -873,6 +889,7 @@ def render_value_in_context(value, context):
else:
return value
+
class VariableNode(Node):
def __init__(self, filter_expression):
self.filter_expression = filter_expression
@@ -893,6 +910,7 @@ def render(self, context):
# Regex for token keyword arguments
kwarg_re = re.compile(r"(?:(\w+)=)?(.+)")
+
def token_kwargs(bits, parser, support_legacy=False):
"""
A utility method for parsing token keyword arguments.
@@ -942,6 +960,7 @@ def token_kwargs(bits, parser, support_legacy=False):
del bits[:1]
return kwargs
+
def parse_bits(parser, bits, params, varargs, varkw, defaults,
takes_context, name):
"""
@@ -1009,6 +1028,7 @@ def parse_bits(parser, bits, params, varargs, varkw, defaults,
(name, ", ".join("'%s'" % p for p in unhandled_params)))
return args, kwargs
+
def generic_tag_compiler(parser, token, params, varargs, varkw, defaults,
name, takes_context, node_class):
"""
@@ -1019,6 +1039,7 @@ def generic_tag_compiler(parser, token, params, varargs, varkw, defaults,
defaults, takes_context, name)
return node_class(takes_context, args, kwargs)
+
class TagHelperNode(Node):
"""
Base class for tag helper nodes such as SimpleNode, InclusionNode and
@@ -1039,6 +1060,7 @@ def get_resolved_arguments(self, context):
for k, v in self.kwargs.items())
return resolved_args, resolved_kwargs
+
class Library(object):
def __init__(self):
self.filters = {}
@@ -1224,6 +1246,7 @@ def render(self, context):
return func
return dec
+
def is_library_missing(name):
"""Check if library that failed to load cannot be found under any
templatetags directory or does exist but fails to import.
@@ -1240,6 +1263,7 @@ def is_library_missing(name):
except ImportError:
return is_library_missing(path)
+
def import_library(taglib_module):
"""
Load a template tag library module.
@@ -1268,6 +1292,7 @@ def import_library(taglib_module):
templatetags_modules = []
+
def get_templatetags_modules():
"""
Return the list of all available template tag modules.
@@ -1290,6 +1315,7 @@ def get_templatetags_modules():
templatetags_modules = _templatetags_modules
return templatetags_modules
+
def get_library(library_name):
"""
Load the template library module with the given name.
@@ -150,6 +150,7 @@ def get(self, key, otherwise=None):
return d[key]
return otherwise
+
# This is a function rather than module-level procedural code because we only
# want it to execute if somebody uses RequestContext.
def get_standard_processors():
@@ -166,6 +167,7 @@ def get_standard_processors():
_standard_context_processors = tuple(processors)
return _standard_context_processors
+
class RequestContext(Context):
"""
This subclass of template.Context automatically populates itself using
Oops, something went wrong.

0 comments on commit fe995e6

Please sign in to comment.