text
stringlengths
0
828
lines = text.split(linebreak_txt)
for line in lines:
new_nb_indent = 0
while True:
if line.startswith(indent_txt):
new_nb_indent += 1
line = line[len(indent_txt):]
else:
break
if indent_block:
if (new_nb_indent > nb_indent):
for dummy in range(nb_indent, new_nb_indent):
final_body += tabs_before * ""\t"" + indent_html[0] + ""\n""
tabs_before += 1
elif (new_nb_indent < nb_indent):
for dummy in range(new_nb_indent, nb_indent):
tabs_before -= 1
final_body += (tabs_before) * ""\t"" + indent_html[1] + ""\n""
else:
final_body += (tabs_before) * ""\t""
else:
final_body += tabs_before * ""\t"" + new_nb_indent * indent_html[0]
try:
line = washer.wash(line)
except HTMLParseError:
# Line contained something like ""foo<bar""
line = cgi.escape(line)
if indent_block:
final_body += tabs_before * ""\t""
final_body += line
if not indent_block:
final_body += new_nb_indent * indent_html[1]
final_body += linebreak_html + ""\n""
nb_indent = new_nb_indent
if indent_block:
for dummy in range(0, nb_indent):
tabs_before -= 1
final_body += (tabs_before) * ""\t"" + ""</div>\n""
return final_body"
4637,"def email_quote_txt(text,
indent_txt='>>',
linebreak_input=""\n"",
linebreak_output=""\n""):
""""""
Takes a text and returns it in a typical mail quoted format, e.g.::
C'est un lapin, lapin de bois.
>>Quoi?
Un cadeau.
>>What?
A present.
>>Oh, un cadeau.
will return::
>>C'est un lapin, lapin de bois.
>>>>Quoi?
>>Un cadeau.
>>>>What?
>>A present.
>>>>Oh, un cadeau.
@param text: the string to quote
@param indent_txt: the string used for quoting (default: '>>')
@param linebreak_input: in the text param, string used for linebreaks
@param linebreak_output: linebreak used for output
@return: the text as a quoted string
""""""
if (text == """"):
return """"
lines = text.split(linebreak_input)
text = """"
for line in lines:
text += indent_txt + line + linebreak_output
return text"
4638,"def escape_email_quoted_text(text, indent_txt='>>', linebreak_txt='\n'):
""""""
Escape text using an email-like indenting rule.
As an example, this text::
>>Brave Sir Robin ran away...
<img src=""malicious_script />*No!*
>>bravely ran away away...
I didn't!*<script>malicious code</script>
>>When danger reared its ugly head, he bravely turned his tail and fled.
<form onload=""malicious""></form>*I never did!*
will be escaped like this::
>>Brave Sir Robin ran away...
&lt;img src=""malicious_script /&gt;*No!*
>>bravely ran away away...
I didn't!*&lt;script&gt;malicious code&lt;/script&gt;
>>When danger reared its ugly head, he bravely turned his tail and fled.
&lt;form onload=""malicious""&gt;&lt;/form&gt;*I never did!*
@param text: the string to escape
@param indent_txt: the string used for quoting
@param linebreak_txt: in the text param, string used for linebreaks
""""""
washer = HTMLWasher()
lines = text.split(linebreak_txt)
output = ''
for line in lines: