@register.tag
def cycle(parser, token, escape=False):
 if (not escape):
  warnings.warn(u"'The `cycle` template tag is changing to escape its arguments; the non-autoescaping version is deprecated. Load it from the `future` tag library to start using the new behavior.", PendingDeprecationWarning, stacklevel=2)
 args = token.split_contents()
 if (len(args) < 2):
  raise TemplateSyntaxError(u"'cycle' tag requires at least two arguments")
 if (u',' in args[1]):
  args[1:2] = [(u'"%s"' % arg) for arg in args[1].split(u',')]
 if (len(args) == 2):
  name = args[1]
  if (not hasattr(parser, u'_namedCycleNodes')):
   raise TemplateSyntaxError((u"No named cycles in template. '%s' is not defined" % name))
  if (not (name in parser._namedCycleNodes)):
   raise TemplateSyntaxError((u"Named cycle '%s' does not exist" % name))
  return parser._namedCycleNodes[name]
 as_form = False
 if (len(args) > 4):
  if (args[(-3)] == u'as'):
   if (args[(-1)] != u'silent'):
    raise TemplateSyntaxError((u"Only 'silent' flag is allowed after cycle's name, not '%s'." % args[(-1)]))
   as_form = True
   silent = True
   args = args[:(-1)]
  elif (args[(-2)] == u'as'):
   as_form = True
   silent = False
 if as_form:
  name = args[(-1)]
  values = [parser.compile_filter(arg) for arg in args[1:(-2)]]
  node = CycleNode(values, name, silent=silent, escape=escape)
  if (not hasattr(parser, u'_namedCycleNodes')):
   parser._namedCycleNodes = {}
  parser._namedCycleNodes[name] = node
 else:
  values = [parser.compile_filter(arg) for arg in args[1:]]
  node = CycleNode(values, escape=escape)
 return node

@ register . tag def cycle ( parser , token , escape = False ) : if ( not escape ) : warnings . warn ( u"'The `cycle` template tag is changing to escape its arguments; the non-autoescaping version is deprecated. Load it from the `future` tag library to start using the new behavior." , PendingDeprecationWarning , stacklevel = 2 ) args = token . split_contents ( ) if ( len ( args ) < 2 ) : raise TemplateSyntaxError ( u"'cycle' tag requires at least two arguments" ) if ( u',' in args [ 1 ] ) : args [ 1 : 2 ] = [ ( u'"%s"' % arg ) for arg in args [ 1 ] . split ( u',' ) ] if ( len ( args ) == 2 ) : name = args [ 1 ] if ( not hasattr ( parser , u'_namedCycleNodes' ) ) : raise TemplateSyntaxError ( ( u"No named cycles in template. '%s' is not defined" % name ) ) if ( not ( name in parser . _namedCycleNodes ) ) : raise TemplateSyntaxError ( ( u"Named cycle '%s' does not exist" % name ) ) return parser . _namedCycleNodes [ name ] as_form = False if ( len ( args ) > 4 ) : if ( args [ ( - 3 ) ] == u'as' ) : if ( args [ ( - 1 ) ] != u'silent' ) : raise TemplateSyntaxError ( ( u"Only 'silent' flag is allowed after cycle's name, not '%s'." % args [ ( - 1 ) ] ) ) as_form = True silent = True args = args [ : ( - 1 ) ] elif ( args [ ( - 2 ) ] == u'as' ) : as_form = True silent = False if as_form : name = args [ ( - 1 ) ] values = [ parser . compile_filter ( arg ) for arg in args [ 1 : ( - 2 ) ] ] node = CycleNode ( values , name , silent = silent , escape = escape ) if ( not hasattr ( parser , u'_namedCycleNodes' ) ) : parser . _namedCycleNodes = { } parser . _namedCycleNodes [ name ] = node else : values = [ parser . compile_filter ( arg ) for arg in args [ 1 : ] ] node = CycleNode ( values , escape = escape ) return node
this is the future version of cycle with auto-escaping .