def wrapped(env, context, value): expr = lambda x: env.get_attribute(x, attribute) return sorted([{ 'grouper': a, 'list': list(b) } for a, b in groupby(sorted(value, key=expr), expr)], key=itemgetter('grouper'))
def wrapped(env, context, value): return sorted(value, reverse=reverse)
'!=': 'ne', '>': 'gt', '>=': 'gteq', '<': 'lt', '<=': 'lteq', '=': 'assign', '.': 'dot', ':': 'colon', '|': 'pipe', ',': 'comma' } reverse_operators = dict([(v, k) for k, v in operators.iteritems()]) assert len(operators) == len(reverse_operators), 'operators dropped' operator_re = re.compile('(%s)' % '|'.join([re.escape(x) for x in sorted(operators, key=lambda x: -len(x))])) simple_escapes = { 'a': '\a', 'n': '\n', 'r': '\r', 'f': '\f', 't': '\t', 'v': '\v', '\\': '\\', '"': '"', "'": "'", '0': '\x00' } unicode_escapes = { 'x': 2,
'>': 'gt', '>=': 'gteq', '<': 'lt', '<=': 'lteq', '=': 'assign', '.': 'dot', ':': 'colon', '|': 'pipe', ',': 'comma' } reverse_operators = dict([(v, k) for k, v in operators.iteritems()]) assert len(operators) == len(reverse_operators), 'operators dropped' operator_re = re.compile( '(%s)' % '|'.join([re.escape(x) for x in sorted(operators, key=lambda x: -len(x))])) def unescape_string(lineno, filename, s): r""" Unescape a string. Supported escapes: \a, \n, \r\, \f, \v, \\, \", \', \0 \x00, \u0000, \U00000000, \N{...} Not supported are \101 because imho redundant. """ result = [] write = result.append simple_escapes = { 'a': '\a',