Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed the remaining E302 violations int eh django package

  • Loading branch information...
commit fe995e6cbdcf2766cf0aa951c8ef4549ad27694c 1 parent 393cdbf
Alex Gaynor authored November 02, 2013
11  django/forms/widgets.py
@@ -104,6 +104,7 @@ def __add__(self, other):
104 104
             getattr(combined, 'add_' + name)(getattr(other, '_' + name, None))
105 105
         return combined
106 106
 
  107
+
107 108
 def media_property(cls):
108 109
     def _media(self):
109 110
         # Get the media property of the superclass, if it exists
@@ -131,6 +132,7 @@ def _media(self):
131 132
             return base
132 133
     return property(_media)
133 134
 
  135
+
134 136
 class MediaDefiningClass(type):
135 137
     """
136 138
     Metaclass for classes that can have media definitions.
@@ -162,6 +164,7 @@ def __str__(self):
162 164
             args.append(self.choices)
163 165
         return self.parent_widget.render(*args)
164 166
 
  167
+
165 168
 class Widget(six.with_metaclass(MediaDefiningClass)):
166 169
     is_hidden = False             # Determines whether this corresponds to an <input type="hidden">.
167 170
     needs_multipart_form = False  # Determines does this widget need multipart form
@@ -224,6 +227,7 @@ def id_for_label(self, id_):
224 227
         """
225 228
         return id_
226 229
 
  230
+
227 231
 class Input(Widget):
228 232
     """
229 233
     Base class for all <input> widgets (except type='checkbox' and
@@ -279,10 +283,12 @@ def render(self, name, value, attrs=None):
279 283
             value = None
280 284
         return super(PasswordInput, self).render(name, value, attrs)
281 285
 
  286
+
282 287
 class HiddenInput(Input):
283 288
     input_type = 'hidden'
284 289
     is_hidden = True
285 290
 
  291
+
286 292
 class MultipleHiddenInput(HiddenInput):
287 293
     """
288 294
     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):
313 319
             return data.getlist(name)
314 320
         return data.get(name, None)
315 321
 
  322
+
316 323
 class FileInput(Input):
317 324
     input_type = 'file'
318 325
     needs_multipart_form = True
@@ -327,6 +334,7 @@ def value_from_datadict(self, data, files, name):
327 334
 
328 335
 FILE_INPUT_CONTRADICTION = object()
329 336
 
  337
+
330 338
 class ClearableFileInput(FileInput):
331 339
     initial_text = ugettext_lazy('Currently')
332 340
     input_text = ugettext_lazy('Change')
@@ -389,6 +397,7 @@ def value_from_datadict(self, data, files, name):
389 397
             return False
390 398
         return upload
391 399
 
  400
+
392 401
 class Textarea(Widget):
393 402
     def __init__(self, attrs=None):
394 403
         # The 'rows' and 'cols' attributes are required for HTML correctness.
@@ -515,6 +524,7 @@ def render_options(self, choices, selected_choices):
515 524
                 output.append(self.render_option(selected_choices, option_value, option_label))
516 525
         return '\n'.join(output)
517 526
 
  527
+
518 528
 class NullBooleanSelect(Select):
519 529
     """
520 530
     A Select Widget intended to be used with NullBooleanField.
@@ -849,6 +859,7 @@ def decompress(self, value):
849 859
             return [value.date(), value.time().replace(microsecond=0)]
850 860
         return [None, None]
851 861
 
  862
+
852 863
 class SplitHiddenDateTimeWidget(SplitDateTimeWidget):
853 864
     """
854 865
     A Widget that splits datetime input into two <input type="hidden"> inputs.
9  django/http/multipartparser.py
@@ -269,6 +269,7 @@ def IE_sanitize(self, filename):
269 269
         """Cleanup filename from Internet Explorer full paths."""
270 270
         return filename and filename[filename.rfind("\\")+1:].strip()
271 271
 
  272
+
272 273
 class LazyStream(six.Iterator):
273 274
     """
274 275
     The LazyStream wrapper allows one to get and "unget" bytes from a stream.
@@ -380,6 +381,7 @@ def _update_unget_history(self, num_bytes):
380 381
                 " if there is none, report this to the Django developers."
381 382
             )
382 383
 
  384
+
383 385
 class ChunkIter(six.Iterator):
384 386
     """
385 387
     An iterable that will yield chunks of data. Given a file-like object as the
@@ -403,6 +405,7 @@ def __next__(self):
403 405
     def __iter__(self):
404 406
         return self
405 407
 
  408
+
406 409
 class InterBoundaryIter(six.Iterator):
407 410
     """
408 411
     A Producer that will iterate over boundaries.
@@ -420,6 +423,7 @@ def __next__(self):
420 423
         except InputStreamExhausted:
421 424
             raise StopIteration()
422 425
 
  426
+
423 427
 class BoundaryIter(six.Iterator):
424 428
     """
425 429
     A Producer that is sensitive to boundaries.
@@ -516,6 +520,7 @@ def _find_boundary(self, data, eof = False):
516 520
                 end -= 1
517 521
             return end, next
518 522
 
  523
+
519 524
 def exhaust(stream_or_iterable):
520 525
     """
521 526
     Completely exhausts an iterator or stream.
@@ -534,6 +539,7 @@ def exhaust(stream_or_iterable):
534 539
     for __ in iterator:
535 540
         pass
536 541
 
  542
+
537 543
 def parse_boundary_stream(stream, max_header_size):
538 544
     """
539 545
     Parses one and exactly one stream that encapsulates a boundary.
@@ -592,6 +598,7 @@ def _parse_header(line):
592 598
 
593 599
     return (TYPE, outdict, stream)
594 600
 
  601
+
595 602
 class Parser(object):
596 603
     def __init__(self, stream, boundary):
597 604
         self._stream = stream
@@ -603,6 +610,7 @@ def __iter__(self):
603 610
             # Iterate over each part
604 611
             yield parse_boundary_stream(sub_stream, 1024)
605 612
 
  613
+
606 614
 def parse_header(line):
607 615
     """ Parse the header into a key-value.
608 616
         Input (line): bytes, output: unicode for key/name, bytes for value which
@@ -622,6 +630,7 @@ def parse_header(line):
622 630
             pdict[name] = value
623 631
     return key, pdict
624 632
 
  633
+
625 634
 def _parse_header_params(s):
626 635
     plist = []
627 636
     while s[:1] == b';':
26  django/template/base.py
@@ -95,9 +95,11 @@ def __str__(self):
95 95
         return self.msg % tuple(force_text(p, errors='replace')
96 96
                                  for p in self.params)
97 97
 
  98
+
98 99
 class InvalidTemplateLibrary(Exception):
99 100
     pass
100 101
 
  102
+
101 103
 class Origin(object):
102 104
     def __init__(self, name):
103 105
         self.name = name
@@ -108,6 +110,7 @@ def reload(self):
108 110
     def __str__(self):
109 111
         return self.name
110 112
 
  113
+
111 114
 class StringOrigin(Origin):
112 115
     def __init__(self, source):
113 116
         super(StringOrigin, self).__init__(UNKNOWN_SOURCE)
@@ -116,6 +119,7 @@ def __init__(self, source):
116 119
     def reload(self):
117 120
         return self.source
118 121
 
  122
+
119 123
 class Template(object):
120 124
     def __init__(self, template_string, origin=None,
121 125
                  name='<Unknown Template>'):
@@ -146,6 +150,7 @@ def render(self, context):
146 150
         finally:
147 151
             context.render_context.pop()
148 152
 
  153
+
149 154
 def compile_string(template_string, origin):
150 155
     "Compiles template_string into NodeList ready for rendering"
151 156
     if settings.TEMPLATE_DEBUG:
@@ -157,6 +162,7 @@ def compile_string(template_string, origin):
157 162
     parser = parser_class(lexer.tokenize())
158 163
     return parser.parse()
159 164
 
  165
+
160 166
 class Token(object):
161 167
     def __init__(self, token_type, contents):
162 168
         # token_type must be TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK or
@@ -184,6 +190,7 @@ def split_contents(self):
184 190
             split.append(bit)
185 191
         return split
186 192
 
  193
+
187 194
 class Lexer(object):
188 195
     def __init__(self, template_string, origin):
189 196
         self.template_string = template_string
@@ -235,6 +242,7 @@ def create_token(self, token_string, in_tag):
235 242
         self.lineno += token_string.count('\n')
236 243
         return token
237 244
 
  245
+
238 246
 class Parser(object):
239 247
     def __init__(self, tokens):
240 248
         self.tokens = tokens
@@ -370,6 +378,7 @@ def find_filter(self, filter_name):
370 378
         else:
371 379
             raise TemplateSyntaxError("Invalid filter: '%s'" % filter_name)
372 380
 
  381
+
373 382
 class TokenParser(object):
374 383
     """
375 384
     Subclass this and implement the top() method to parse a template line.
@@ -523,6 +532,7 @@ def next_space_index(subject, i):
523 532
 
524 533
 filter_re = re.compile(filter_raw_string, re.UNICODE | re.VERBOSE)
525 534
 
  535
+
526 536
 class FilterExpression(object):
527 537
     """
528 538
     Parses a variable token and its optional filters (all as a single string),
@@ -644,6 +654,7 @@ def args_check(name, func, provided):
644 654
     def __str__(self):
645 655
         return self.token
646 656
 
  657
+
647 658
 def resolve_variable(path, context):
648 659
     """
649 660
     Returns the resolved variable, which may contain attribute syntax, within
@@ -653,6 +664,7 @@ def resolve_variable(path, context):
653 664
     """
654 665
     return Variable(path).resolve(context)
655 666
 
  667
+
656 668
 class Variable(object):
657 669
     """
658 670
     A template variable, resolvable against a given context. The variable may
@@ -793,6 +805,7 @@ def _resolve_lookup(self, context):
793 805
 
794 806
         return current
795 807
 
  808
+
796 809
 class Node(object):
797 810
     # Set this to True for nodes that must be first in the template (although
798 811
     # they can be preceded by text nodes.
@@ -822,6 +835,7 @@ def get_nodes_by_type(self, nodetype):
822 835
                 nodes.extend(nodelist.get_nodes_by_type(nodetype))
823 836
         return nodes
824 837
 
  838
+
825 839
 class NodeList(list):
826 840
     # Set to True the first time a non-TextNode is inserted by
827 841
     # extend_nodelist().
@@ -847,6 +861,7 @@ def get_nodes_by_type(self, nodetype):
847 861
     def render_node(self, node, context):
848 862
         return node.render(context)
849 863
 
  864
+
850 865
 class TextNode(Node):
851 866
     def __init__(self, s):
852 867
         self.s = s
@@ -858,6 +873,7 @@ def __repr__(self):
858 873
     def render(self, context):
859 874
         return self.s
860 875
 
  876
+
861 877
 def render_value_in_context(value, context):
862 878
     """
863 879
     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):
873 889
     else:
874 890
         return value
875 891
 
  892
+
876 893
 class VariableNode(Node):
877 894
     def __init__(self, filter_expression):
878 895
         self.filter_expression = filter_expression
@@ -893,6 +910,7 @@ def render(self, context):
893 910
 # Regex for token keyword arguments
894 911
 kwarg_re = re.compile(r"(?:(\w+)=)?(.+)")
895 912
 
  913
+
896 914
 def token_kwargs(bits, parser, support_legacy=False):
897 915
     """
898 916
     A utility method for parsing token keyword arguments.
@@ -942,6 +960,7 @@ def token_kwargs(bits, parser, support_legacy=False):
942 960
             del bits[:1]
943 961
     return kwargs
944 962
 
  963
+
945 964
 def parse_bits(parser, bits, params, varargs, varkw, defaults,
946 965
                takes_context, name):
947 966
     """
@@ -1009,6 +1028,7 @@ def parse_bits(parser, bits, params, varargs, varkw, defaults,
1009 1028
             (name, ", ".join("'%s'" % p for p in unhandled_params)))
1010 1029
     return args, kwargs
1011 1030
 
  1031
+
1012 1032
 def generic_tag_compiler(parser, token, params, varargs, varkw, defaults,
1013 1033
                          name, takes_context, node_class):
1014 1034
     """
@@ -1019,6 +1039,7 @@ def generic_tag_compiler(parser, token, params, varargs, varkw, defaults,
1019 1039
                               defaults, takes_context, name)
1020 1040
     return node_class(takes_context, args, kwargs)
1021 1041
 
  1042
+
1022 1043
 class TagHelperNode(Node):
1023 1044
     """
1024 1045
     Base class for tag helper nodes such as SimpleNode, InclusionNode and
@@ -1039,6 +1060,7 @@ def get_resolved_arguments(self, context):
1039 1060
                                 for k, v in self.kwargs.items())
1040 1061
         return resolved_args, resolved_kwargs
1041 1062
 
  1063
+
1042 1064
 class Library(object):
1043 1065
     def __init__(self):
1044 1066
         self.filters = {}
@@ -1224,6 +1246,7 @@ def render(self, context):
1224 1246
             return func
1225 1247
         return dec
1226 1248
 
  1249
+
1227 1250
 def is_library_missing(name):
1228 1251
     """Check if library that failed to load cannot be found under any
1229 1252
     templatetags directory or does exist but fails to import.
@@ -1240,6 +1263,7 @@ def is_library_missing(name):
1240 1263
     except ImportError:
1241 1264
         return is_library_missing(path)
1242 1265
 
  1266
+
1243 1267
 def import_library(taglib_module):
1244 1268
     """
1245 1269
     Load a template tag library module.
@@ -1268,6 +1292,7 @@ def import_library(taglib_module):
1268 1292
 
1269 1293
 templatetags_modules = []
1270 1294
 
  1295
+
1271 1296
 def get_templatetags_modules():
1272 1297
     """
1273 1298
     Return the list of all available template tag modules.
@@ -1290,6 +1315,7 @@ def get_templatetags_modules():
1290 1315
         templatetags_modules = _templatetags_modules
1291 1316
     return templatetags_modules
1292 1317
 
  1318
+
1293 1319
 def get_library(library_name):
1294 1320
     """
1295 1321
     Load the template library module with the given name.
2  django/template/context.py
@@ -150,6 +150,7 @@ def get(self, key, otherwise=None):
150 150
             return d[key]
151 151
         return otherwise
152 152
 
  153
+
153 154
 # This is a function rather than module-level procedural code because we only
154 155
 # want it to execute if somebody uses RequestContext.
155 156
 def get_standard_processors():
@@ -166,6 +167,7 @@ def get_standard_processors():
166 167
         _standard_context_processors = tuple(processors)
167 168
     return _standard_context_processors
168 169
 
  170
+
169 171
 class RequestContext(Context):
170 172
     """
171 173
     This subclass of template.Context automatically populates itself using
56  django/template/defaultfilters.py
@@ -66,18 +66,21 @@ def addslashes(value):
66 66
     """
67 67
     return value.replace('\\', '\\\\').replace('"', '\\"').replace("'", "\\'")
68 68
 
  69
+
69 70
 @register.filter(is_safe=True)
70 71
 @stringfilter
71 72
 def capfirst(value):
72 73
     """Capitalizes the first character of the value."""
73 74
     return value and value[0].upper() + value[1:]
74 75
 
  76
+
75 77
 @register.filter("escapejs")
76 78
 @stringfilter
77 79
 def escapejs_filter(value):
78 80
     """Hex encodes characters for use in JavaScript strings."""
79 81
     return escapejs(value)
80 82
 
  83
+
81 84
 @register.filter("fix_ampersands", is_safe=True)
82 85
 @stringfilter
83 86
 def fix_ampersands_filter(value):
@@ -96,6 +99,7 @@ def fix_ampersands_filter(value):
96 99
 nan = (1e200 * 1e200) // (1e200 * 1e200)
97 100
 special_floats = [str(pos_inf), str(neg_inf), str(nan)]
98 101
 
  102
+
99 103
 @register.filter(is_safe=True)
100 104
 def floatformat(text, arg=-1):
101 105
     """
@@ -179,12 +183,14 @@ def floatformat(text, arg=-1):
179 183
     except InvalidOperation:
180 184
         return input_val
181 185
 
  186
+
182 187
 @register.filter(is_safe=True)
183 188
 @stringfilter
184 189
 def iriencode(value):
185 190
     """Escapes an IRI value for use in a URL."""
186 191
     return force_text(iri_to_uri(value))
187 192
 
  193
+
188 194
 @register.filter(is_safe=True, needs_autoescape=True)
189 195
 @stringfilter
190 196
 def linenumbers(value, autoescape=None):
@@ -201,12 +207,14 @@ def linenumbers(value, autoescape=None):
201 207
             lines[i] = ("%0" + width + "d. %s") % (i + 1, escape(line))
202 208
     return mark_safe('\n'.join(lines))
203 209
 
  210
+
204 211
 @register.filter(is_safe=True)
205 212
 @stringfilter
206 213
 def lower(value):
207 214
     """Converts a string into all lowercase."""
208 215
     return value.lower()
209 216
 
  217
+
210 218
 @register.filter(is_safe=False)
211 219
 @stringfilter
212 220
 def make_list(value):
@@ -218,6 +226,7 @@ def make_list(value):
218 226
     """
219 227
     return list(value)
220 228
 
  229
+
221 230
 @register.filter(is_safe=True)
222 231
 @stringfilter
223 232
 def slugify(value):
@@ -229,6 +238,7 @@ def slugify(value):
229 238
     from django.utils.text import slugify
230 239
     return slugify(value)
231 240
 
  241
+
232 242
 @register.filter(is_safe=True)
233 243
 def stringformat(value, arg):
234 244
     """
@@ -245,6 +255,7 @@ def stringformat(value, arg):
245 255
     except (ValueError, TypeError):
246 256
         return ""
247 257
 
  258
+
248 259
 @register.filter(is_safe=True)
249 260
 @stringfilter
250 261
 def title(value):
@@ -252,6 +263,7 @@ def title(value):
252 263
     t = re.sub("([a-z])'([A-Z])", lambda m: m.group(0).lower(), value.title())
253 264
     return re.sub("\d([A-Z])", lambda m: m.group(0).lower(), t)
254 265
 
  266
+
255 267
 @register.filter(is_safe=True)
256 268
 @stringfilter
257 269
 def truncatechars(value, arg):
@@ -266,6 +278,7 @@ def truncatechars(value, arg):
266 278
         return value  # Fail silently.
267 279
     return Truncator(value).chars(length)
268 280
 
  281
+
269 282
 @register.filter(is_safe=True)
270 283
 @stringfilter
271 284
 def truncatewords(value, arg):
@@ -282,6 +295,7 @@ def truncatewords(value, arg):
282 295
         return value  # Fail silently.
283 296
     return Truncator(value).words(length, truncate=' ...')
284 297
 
  298
+
285 299
 @register.filter(is_safe=True)
286 300
 @stringfilter
287 301
 def truncatewords_html(value, arg):
@@ -298,12 +312,14 @@ def truncatewords_html(value, arg):
298 312
         return value  # Fail silently.
299 313
     return Truncator(value).words(length, html=True, truncate=' ...')
300 314
 
  315
+
301 316
 @register.filter(is_safe=False)
302 317
 @stringfilter
303 318
 def upper(value):
304 319
     """Converts a string into all uppercase."""
305 320
     return value.upper()
306 321
 
  322
+
307 323
 @register.filter(is_safe=False)
308 324
 @stringfilter
309 325
 def urlencode(value, safe=None):
@@ -320,12 +336,14 @@ def urlencode(value, safe=None):
320 336
         kwargs['safe'] = safe
321 337
     return urlquote(value, **kwargs)
322 338
 
  339
+
323 340
 @register.filter(is_safe=True, needs_autoescape=True)
324 341
 @stringfilter
325 342
 def urlize(value, autoescape=None):
326 343
     """Converts URLs in plain text into clickable links."""
327 344
     return mark_safe(urlize_impl(value, nofollow=True, autoescape=autoescape))
328 345
 
  346
+
329 347
 @register.filter(is_safe=True, needs_autoescape=True)
330 348
 @stringfilter
331 349
 def urlizetrunc(value, limit, autoescape=None):
@@ -338,12 +356,14 @@ def urlizetrunc(value, limit, autoescape=None):
338 356
     return mark_safe(urlize_impl(value, trim_url_limit=int(limit), nofollow=True,
339 357
                             autoescape=autoescape))
340 358
 
  359
+
341 360
 @register.filter(is_safe=False)
342 361
 @stringfilter
343 362
 def wordcount(value):
344 363
     """Returns the number of words."""
345 364
     return len(value.split())
346 365
 
  366
+
347 367
 @register.filter(is_safe=True)
348 368
 @stringfilter
349 369
 def wordwrap(value, arg):
@@ -354,6 +374,7 @@ def wordwrap(value, arg):
354 374
     """
355 375
     return wrap(value, int(arg))
356 376
 
  377
+
357 378
 @register.filter(is_safe=True)
358 379
 @stringfilter
359 380
 def ljust(value, arg):
@@ -364,6 +385,7 @@ def ljust(value, arg):
364 385
     """
365 386
     return value.ljust(int(arg))
366 387
 
  388
+
367 389
 @register.filter(is_safe=True)
368 390
 @stringfilter
369 391
 def rjust(value, arg):
@@ -374,12 +396,14 @@ def rjust(value, arg):
374 396
     """
375 397
     return value.rjust(int(arg))
376 398
 
  399
+
377 400
 @register.filter(is_safe=True)
378 401
 @stringfilter
379 402
 def center(value, arg):
380 403
     """Centers the value in a field of a given width."""
381 404
     return value.center(int(arg))
382 405
 
  406
+
383 407
 @register.filter
384 408
 @stringfilter
385 409
 def cut(value, arg):
@@ -392,6 +416,7 @@ def cut(value, arg):
392 416
         return mark_safe(value)
393 417
     return value
394 418
 
  419
+
395 420
 ###################
396 421
 # HTML STRINGS    #
397 422
 ###################
@@ -404,6 +429,7 @@ def escape_filter(value):
404 429
     """
405 430
     return mark_for_escaping(value)
406 431
 
  432
+
407 433
 @register.filter(is_safe=True)
408 434
 @stringfilter
409 435
 def force_escape(value):
@@ -414,6 +440,7 @@ def force_escape(value):
414 440
     """
415 441
     return escape(value)
416 442
 
  443
+
417 444
 @register.filter("linebreaks", is_safe=True, needs_autoescape=True)
418 445
 @stringfilter
419 446
 def linebreaks_filter(value, autoescape=None):
@@ -425,6 +452,7 @@ def linebreaks_filter(value, autoescape=None):
425 452
     autoescape = autoescape and not isinstance(value, SafeData)
426 453
     return mark_safe(linebreaks(value, autoescape))
427 454
 
  455
+
428 456
 @register.filter(is_safe=True, needs_autoescape=True)
429 457
 @stringfilter
430 458
 def linebreaksbr(value, autoescape=None):
@@ -438,6 +466,7 @@ def linebreaksbr(value, autoescape=None):
438 466
         value = escape(value)
439 467
     return mark_safe(value.replace('\n', '<br />'))
440 468
 
  469
+
441 470
 @register.filter(is_safe=True)
442 471
 @stringfilter
443 472
 def safe(value):
@@ -446,6 +475,7 @@ def safe(value):
446 475
     """
447 476
     return mark_safe(value)
448 477
 
  478
+
449 479
 @register.filter(is_safe=True)
450 480
 def safeseq(value):
451 481
     """
@@ -455,6 +485,7 @@ def safeseq(value):
455 485
     """
456 486
     return [mark_safe(force_text(obj)) for obj in value]
457 487
 
  488
+
458 489
 @register.filter(is_safe=True)
459 490
 @stringfilter
460 491
 def removetags(value, tags):
@@ -462,12 +493,14 @@ def removetags(value, tags):
462 493
     from django.utils.html import remove_tags
463 494
     return remove_tags(value, tags)
464 495
 
  496
+
465 497
 @register.filter(is_safe=True)
466 498
 @stringfilter
467 499
 def striptags(value):
468 500
     """Strips all [X]HTML tags."""
469 501
     return strip_tags(value)
470 502
 
  503
+
471 504
 ###################
472 505
 # LISTS           #
473 506
 ###################
@@ -483,6 +516,7 @@ def dictsort(value, arg):
483 516
     except (TypeError, VariableDoesNotExist):
484 517
         return ''
485 518
 
  519
+
486 520
 @register.filter(is_safe=False)
487 521
 def dictsortreversed(value, arg):
488 522
     """
@@ -494,6 +528,7 @@ def dictsortreversed(value, arg):
494 528
     except (TypeError, VariableDoesNotExist):
495 529
         return ''
496 530
 
  531
+
497 532
 @register.filter(is_safe=False)
498 533
 def first(value):
499 534
     """Returns the first item in a list."""
@@ -502,6 +537,7 @@ def first(value):
502 537
     except IndexError:
503 538
         return ''
504 539
 
  540
+
505 541
 @register.filter(is_safe=True, needs_autoescape=True)
506 542
 def join(value, arg, autoescape=None):
507 543
     """
@@ -516,6 +552,7 @@ def join(value, arg, autoescape=None):
516 552
         return value
517 553
     return mark_safe(data)
518 554
 
  555
+
519 556
 @register.filter(is_safe=True)
520 557
 def last(value):
521 558
     "Returns the last item in a list"
@@ -524,6 +561,7 @@ def last(value):
524 561
     except IndexError:
525 562
         return ''
526 563
 
  564
+
527 565
 @register.filter(is_safe=True)
528 566
 def length(value):
529 567
     """Returns the length of the value - useful for lists."""
@@ -532,6 +570,7 @@ def length(value):
532 570
     except (ValueError, TypeError):
533 571
         return ''
534 572
 
  573
+
535 574
 @register.filter(is_safe=False)
536 575
 def length_is(value, arg):
537 576
     """Returns a boolean of whether the value's length is the argument."""
@@ -540,11 +579,13 @@ def length_is(value, arg):
540 579
     except (ValueError, TypeError):
541 580
         return ''
542 581
 
  582
+
543 583
 @register.filter(is_safe=True)
544 584
 def random(value):
545 585
     """Returns a random item from the list."""
546 586
     return random_module.choice(value)
547 587
 
  588
+
548 589
 @register.filter("slice", is_safe=True)
549 590
 def slice_filter(value, arg):
550 591
     """
@@ -566,6 +607,7 @@ def slice_filter(value, arg):
566 607
     except (ValueError, TypeError):
567 608
         return value  # Fail silently.
568 609
 
  610
+
569 611
 @register.filter(is_safe=True, needs_autoescape=True)
570 612
 def unordered_list(value, autoescape=None):
571 613
     """
@@ -655,6 +697,7 @@ def _helper(list_, tabs=1):
655 697
     value, converted = convert_old_style_list(value)
656 698
     return mark_safe(_helper(value))
657 699
 
  700
+
658 701
 ###################
659 702
 # INTEGERS        #
660 703
 ###################
@@ -670,6 +713,7 @@ def add(value, arg):
670 713
         except Exception:
671 714
             return ''
672 715
 
  716
+
673 717
 @register.filter(is_safe=False)
674 718
 def get_digit(value, arg):
675 719
     """
@@ -690,6 +734,7 @@ def get_digit(value, arg):
690 734
     except IndexError:
691 735
         return 0
692 736
 
  737
+
693 738
 ###################
694 739
 # DATES           #
695 740
 ###################
@@ -709,6 +754,7 @@ def date(value, arg=None):
709 754
         except AttributeError:
710 755
             return ''
711 756
 
  757
+
712 758
 @register.filter(expects_localtime=True, is_safe=False)
713 759
 def time(value, arg=None):
714 760
     """Formats a time according to the given format."""
@@ -724,6 +770,7 @@ def time(value, arg=None):
724 770
         except AttributeError:
725 771
             return ''
726 772
 
  773
+
727 774
 @register.filter("timesince", is_safe=False)
728 775
 def timesince_filter(value, arg=None):
729 776
     """Formats a date as the time since that date (i.e. "4 days, 6 hours")."""
@@ -736,6 +783,7 @@ def timesince_filter(value, arg=None):
736 783
     except (ValueError, TypeError):
737 784
         return ''
738 785
 
  786
+
739 787
 @register.filter("timeuntil", is_safe=False)
740 788
 def timeuntil_filter(value, arg=None):
741 789
     """Formats a date as the time until that date (i.e. "4 days, 6 hours")."""
@@ -746,6 +794,7 @@ def timeuntil_filter(value, arg=None):
746 794
     except (ValueError, TypeError):
747 795
         return ''
748 796
 
  797
+
749 798
 ###################
750 799
 # LOGIC           #
751 800
 ###################
@@ -755,6 +804,7 @@ def default(value, arg):
755 804
     """If value is unavailable, use given default."""
756 805
     return value or arg
757 806
 
  807
+
758 808
 @register.filter(is_safe=False)
759 809
 def default_if_none(value, arg):
760 810
     """If value is None, use given default."""
@@ -762,11 +812,13 @@ def default_if_none(value, arg):
762 812
         return arg
763 813
     return value
764 814
 
  815
+
765 816
 @register.filter(is_safe=False)
766 817
 def divisibleby(value, arg):
767 818
     """Returns True if the value is devisible by the argument."""
768 819
     return int(value) % int(arg) == 0
769 820
 
  821
+
770 822
 @register.filter(is_safe=False)
771 823
 def yesno(value, arg=None):
772 824
     """
@@ -799,6 +851,7 @@ def yesno(value, arg=None):
799 851
         return yes
800 852
     return no
801 853
 
  854
+
802 855
 ###################
803 856
 # MISC            #
804 857
 ###################
@@ -838,6 +891,7 @@ def filesizeformat(bytes):
838 891
 
839 892
     return avoid_wrapping(value)
840 893
 
  894
+
841 895
 @register.filter(is_safe=False)
842 896
 def pluralize(value, arg='s'):
843 897
     """
@@ -882,11 +936,13 @@ def pluralize(value, arg='s'):
882 936
             pass
883 937
     return singular_suffix
884 938
 
  939
+
885 940
 @register.filter("phone2numeric", is_safe=True)
886 941
 def phone2numeric_filter(value):
887 942
     """Takes a phone number and converts it in to its numerical equivalent."""
888 943
     return phone2numeric(value)
889 944
 
  945
+
890 946
 @register.filter(is_safe=True)
891 947
 def pprint(value):
892 948
     """A wrapper around pprint.pprint -- for debugging, really."""
44  django/template/defaulttags.py
@@ -25,6 +25,7 @@
25 25
 
26 26
 register = Library()
27 27
 
  28
+
28 29
 class AutoEscapeControlNode(Node):
29 30
     """Implements the actions of the autoescape tag."""
30 31
     def __init__(self, setting, nodelist):
@@ -40,10 +41,12 @@ def render(self, context):
40 41
         else:
41 42
             return output
42 43
 
  44
+
43 45
 class CommentNode(Node):
44 46
     def render(self, context):
45 47
         return ''
46 48
 
  49
+
47 50
 class CsrfTokenNode(Node):
48 51
     def render(self, context):
49 52
         csrf_token = context.get('csrf_token', None)
@@ -59,6 +62,7 @@ def render(self, context):
59 62
                 warnings.warn("A {% csrf_token %} was used in a template, but the context did not provide the value.  This is usually caused by not using RequestContext.")
60 63
             return ''
61 64
 
  65
+
62 66
 class CycleNode(Node):
63 67
     def __init__(self, cyclevars, variable_name=None, silent=False, escape=False):
64 68
         self.cyclevars = cyclevars
@@ -80,6 +84,7 @@ def render(self, context):
80 84
             value = mark_safe(value)
81 85
         return render_value_in_context(value, context)
82 86
 
  87
+
83 88
 class DebugNode(Node):
84 89
     def render(self, context):
85 90
         from pprint import pformat
@@ -88,6 +93,7 @@ def render(self, context):
88 93
         output.append(pformat(sys.modules))
89 94
         return ''.join(output)
90 95
 
  96
+
91 97
 class FilterNode(Node):
92 98
     def __init__(self, filter_expr, nodelist):
93 99
         self.filter_expr, self.nodelist = filter_expr, nodelist
@@ -113,6 +119,7 @@ def render(self, context):
113 119
                 return render_value_in_context(value, context)
114 120
         return ''
115 121
 
  122
+
116 123
 class ForNode(Node):
117 124
     child_nodelists = ('nodelist_loop', 'nodelist_empty')
118 125
 
@@ -207,6 +214,7 @@ def render(self, context):
207 214
                     context.pop()
208 215
         return mark_safe(''.join(force_text(n) for n in nodelist))
209 216
 
  217
+
210 218
 class IfChangedNode(Node):
211 219
     child_nodelists = ('nodelist_true', 'nodelist_false')
212 220
 
@@ -251,6 +259,7 @@ def _get_context_stack_frame(self, context):
251 259
             # Using ifchanged outside loops. Effectively this is a no-op because the state is associated with 'self'.
252 260
             return context.render_context
253 261
 
  262
+
254 263
 class IfEqualNode(Node):
255 264
     child_nodelists = ('nodelist_true', 'nodelist_false')
256 265
 
@@ -269,6 +278,7 @@ def render(self, context):
269 278
             return self.nodelist_true.render(context)
270 279
         return self.nodelist_false.render(context)
271 280
 
  281
+
272 282
 class IfNode(Node):
273 283
 
274 284
     def __init__(self, conditions_nodelists):
@@ -302,6 +312,7 @@ def render(self, context):
302 312
 
303 313
         return ''
304 314
 
  315
+
305 316
 class RegroupNode(Node):
306 317
     def __init__(self, target, expression, var_name):
307 318
         self.target, self.expression = target, expression
@@ -328,6 +339,7 @@ def render(self, context):
328 339
         ]
329 340
         return ''
330 341
 
  342
+
331 343
 def include_is_allowed(filepath):
332 344
     filepath = os.path.abspath(filepath)
333 345
     for root in settings.ALLOWED_INCLUDE_ROOTS:
@@ -335,6 +347,7 @@ def include_is_allowed(filepath):
335 347
             return True
336 348
     return False
337 349
 
  350
+
338 351
 class SsiNode(Node):
339 352
     def __init__(self, filepath, parsed):
340 353
         self.filepath = filepath
@@ -364,10 +377,12 @@ def render(self, context):
364 377
                     return ''  # Fail silently for invalid included templates.
365 378
         return output
366 379
 
  380
+
367 381
 class LoadNode(Node):
368 382
     def render(self, context):
369 383
         return ''
370 384
 
  385
+
371 386
 class NowNode(Node):
372 387
     def __init__(self, format_string):
373 388
         self.format_string = format_string
@@ -376,6 +391,7 @@ def render(self, context):
376 391
         tzinfo = timezone.get_current_timezone() if settings.USE_TZ else None
377 392
         return date(datetime.now(tz=tzinfo), self.format_string)
378 393
 
  394
+
379 395
 class SpacelessNode(Node):
380 396
     def __init__(self, nodelist):
381 397
         self.nodelist = nodelist
@@ -384,6 +400,7 @@ def render(self, context):
384 400
         from django.utils.html import strip_spaces_between_tags
385 401
         return strip_spaces_between_tags(self.nodelist.render(context).strip())
386 402
 
  403
+
387 404
 class TemplateTagNode(Node):
388 405
     mapping = {'openblock': BLOCK_TAG_START,
389 406
                'closeblock': BLOCK_TAG_END,
@@ -401,6 +418,7 @@ def __init__(self, tagtype):
401 418
     def render(self, context):
402 419
         return self.mapping.get(self.tagtype, '')
403 420
 
  421
+
404 422
 class URLNode(Node):
405 423
     def __init__(self, view_name, args, kwargs, asvar):
406 424
         self.view_name = view_name
@@ -451,6 +469,7 @@ def render(self, context):
451 469
         else:
452 470
             return url
453 471
 
  472
+
454 473
 class VerbatimNode(Node):
455 474
     def __init__(self, content):
456 475
         self.content = content
@@ -458,6 +477,7 @@ def __init__(self, content):
458 477
     def render(self, context):
459 478
         return self.content
460 479
 
  480
+
461 481
 class WidthRatioNode(Node):
462 482
     def __init__(self, val_expr, max_expr, max_width, asvar=None):
463 483
         self.val_expr = val_expr
@@ -490,6 +510,7 @@ def render(self, context):
490 510
         else:
491 511
             return result
492 512
 
  513
+
493 514
 class WithNode(Node):
494 515
     def __init__(self, var, name, nodelist, extra_context=None):
495 516
         self.nodelist = nodelist
@@ -525,6 +546,7 @@ def autoescape(parser, token):
525 546
     parser.delete_first_token()
526 547
     return AutoEscapeControlNode((arg == 'on'), nodelist)
527 548
 
  549
+
528 550
 @register.tag
529 551
 def comment(parser, token):
530 552
     """
@@ -533,6 +555,7 @@ def comment(parser, token):
533 555
     parser.skip_past('endcomment')
534 556
     return CommentNode()
535 557
 
  558
+
536 559
 @register.tag
537 560
 def cycle(parser, token, escape=False):
538 561
     """
@@ -629,10 +652,12 @@ def cycle(parser, token, escape=False):
629 652
         node = CycleNode(values, escape=escape)
630 653
     return node
631 654
 
  655
+
632 656
 @register.tag
633 657
 def csrf_token(parser, token):
634 658
     return CsrfTokenNode()
635 659
 
  660
+
636 661
 @register.tag
637 662
 def debug(parser, token):
638 663
     """
@@ -647,6 +672,7 @@ def debug(parser, token):
647 672
     """
648 673
     return DebugNode()
649 674
 
  675
+
650 676
 @register.tag('filter')
651 677
 def do_filter(parser, token):
652 678
     """
@@ -676,6 +702,7 @@ def do_filter(parser, token):
676 702
     parser.delete_first_token()
677 703
     return FilterNode(filter_expr, nodelist)
678 704
 
  705
+
679 706
 @register.tag
680 707
 def firstof(parser, token, escape=False):
681 708
     """
@@ -723,6 +750,7 @@ def firstof(parser, token, escape=False):
723 750
         raise TemplateSyntaxError("'firstof' statement requires at least one argument")
724 751
     return FirstOfNode([parser.compile_filter(bit) for bit in bits], escape=escape)
725 752
 
  753
+
726 754
 @register.tag('for')
727 755
 def do_for(parser, token):
728 756
     """
@@ -814,6 +842,7 @@ def do_for(parser, token):
814 842
         nodelist_empty = None
815 843
     return ForNode(loopvars, sequence, is_reversed, nodelist_loop, nodelist_empty)
816 844
 
  845
+
817 846
 def do_ifequal(parser, token, negate):
818 847
     bits = list(token.split_contents())
819 848
     if len(bits) != 3:
@@ -830,6 +859,7 @@ def do_ifequal(parser, token, negate):
830 859
     val2 = parser.compile_filter(bits[2])
831 860
     return IfEqualNode(val1, val2, nodelist_true, nodelist_false, negate)
832 861
 
  862
+
833 863
 @register.tag
834 864
 def ifequal(parser, token):
835 865
     """
@@ -849,6 +879,7 @@ def ifequal(parser, token):
849 879
     """
850 880
     return do_ifequal(parser, token, False)
851 881
 
  882
+
852 883
 @register.tag
853 884
 def ifnotequal(parser, token):
854 885
     """
@@ -857,6 +888,7 @@ def ifnotequal(parser, token):
857 888
     """
858 889
     return do_ifequal(parser, token, True)
859 890
 
  891
+
860 892
 class TemplateLiteral(Literal):
861 893
     def __init__(self, value, text):
862 894
         self.value = value
@@ -868,6 +900,7 @@ def display(self):
868 900
     def eval(self, context):
869 901
         return self.value.resolve(context, ignore_failures=True)
870 902
 
  903
+
871 904
 class TemplateIfParser(IfParser):
872 905
     error_class = TemplateSyntaxError
873 906
 
@@ -878,6 +911,7 @@ def __init__(self, parser, *args, **kwargs):
878 911
     def create_var(self, value):
879 912
         return TemplateLiteral(self.template_parser.compile_filter(value), value)
880 913
 
  914
+
881 915
 @register.tag('if')
882 916
 def do_if(parser, token):
883 917
     """
@@ -1006,6 +1040,7 @@ def ifchanged(parser, token):
1006 1040
     values = [parser.compile_filter(bit) for bit in bits[1:]]
1007 1041
     return IfChangedNode(nodelist_true, nodelist_false, *values)
1008 1042
 
  1043
+
1009 1044
 @register.tag
1010 1045
 def ssi(parser, token):
1011 1046
     """
@@ -1036,6 +1071,7 @@ def ssi(parser, token):
1036 1071
     filepath = parser.compile_filter(bits[1])
1037 1072
     return SsiNode(filepath, parsed)
1038 1073
 
  1074
+
1039 1075
 @register.tag
1040 1076
 def load(parser, token):
1041 1077
     """
@@ -1086,6 +1122,7 @@ def load(parser, token):
1086 1122
                                           (taglib, e))
1087 1123
     return LoadNode()
1088 1124
 
  1125
+
1089 1126
 @register.tag
1090 1127
 def now(parser, token):
1091 1128
     """
@@ -1104,6 +1141,7 @@ def now(parser, token):
1104 1141
     format_string = bits[1][1:-1]
1105 1142
     return NowNode(format_string)
1106 1143
 
  1144
+
1107 1145
 @register.tag
1108 1146
 def regroup(parser, token):
1109 1147
     """
@@ -1172,6 +1210,7 @@ def regroup(parser, token):
1172 1210
                                        bits[3])
1173 1211
     return RegroupNode(target, expression, var_name)
1174 1212
 
  1213
+
1175 1214
 @register.tag
1176 1215
 def spaceless(parser, token):
1177 1216
     """
@@ -1202,6 +1241,7 @@ def spaceless(parser, token):
1202 1241
     parser.delete_first_token()
1203 1242
     return SpacelessNode(nodelist)
1204 1243
 
  1244
+
1205 1245
 @register.tag
1206 1246
 def templatetag(parser, token):
1207 1247
     """
@@ -1236,6 +1276,7 @@ def templatetag(parser, token):
1236 1276
                                   (tag, list(TemplateTagNode.mapping)))
1237 1277
     return TemplateTagNode(tag)
1238 1278
 
  1279
+
1239 1280