From e4950648fe044b35b8fca1e91a360c05c8d98277 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Fri, 27 Mar 2009 10:55:29 +0100 Subject: [PATCH] Remove \r's. --- tools/templatetags/encode_email.py | 104 ++++++++++++++--------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/tools/templatetags/encode_email.py b/tools/templatetags/encode_email.py index 6a737d1..e7dccf6 100644 --- a/tools/templatetags/encode_email.py +++ b/tools/templatetags/encode_email.py @@ -1,52 +1,52 @@ -import random -from django import template -""" - Randomized string encoding - Inspired by John Gruber's Markdown: - http://daringfireball.net/projects/markdown/syntax#autolink -""" -register = template.Library() - -#@template.stringfilter -def encode_string(value): - """ - Encode a string into it's equivalent html entity. - - The tag will randomly choose to represent the character as a hex digit or - decimal digit. - - Use {{ obj.name|encode_string }} - - {{ "person"|encode_string }} Becomes something like: - person - """ - e_string = "" - for a in value: - type = random.randint(0,1) - if type: - en = "&#x%x;" % ord(a) - else: - en = "&#%d;" % ord(a) - e_string += en - return e_string - -register.filter("encode_string", encode_string) - -def encode_mailto(value, arg): - """ - Encode an e-mail address and its corresponding link name to its equivalent - html entities. - - Use {{ obj.email|encode_mailto:obj.name }} - - {{ "j@j.com"|encode_mailto:"j" }} Becomes something like: - j - """ - address = 'mailto:%s' % value - address = encode_string(address) - name = encode_string(arg) - tag = "%s" % (address, name) - return tag - -register.filter("encode_mailto", encode_mailto) +import random +from django import template +""" + Randomized string encoding + Inspired by John Gruber's Markdown: + http://daringfireball.net/projects/markdown/syntax#autolink +""" +register = template.Library() + +#@template.stringfilter +def encode_string(value): + """ + Encode a string into it's equivalent html entity. + + The tag will randomly choose to represent the character as a hex digit or + decimal digit. + + Use {{ obj.name|encode_string }} + + {{ "person"|encode_string }} Becomes something like: + person + """ + e_string = "" + for a in value: + type = random.randint(0,1) + if type: + en = "&#x%x;" % ord(a) + else: + en = "&#%d;" % ord(a) + e_string += en + return e_string + +register.filter("encode_string", encode_string) + +def encode_mailto(value, arg): + """ + Encode an e-mail address and its corresponding link name to its equivalent + html entities. + + Use {{ obj.email|encode_mailto:obj.name }} + + {{ "j@j.com"|encode_mailto:"j" }} Becomes something like: + j + """ + address = 'mailto:%s' % value + address = encode_string(address) + name = encode_string(arg) + tag = "%s" % (address, name) + return tag + +register.filter("encode_mailto", encode_mailto) -- 2.30.2