You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2020/03/10 15:58:50 UTC
[allura] 02/16: [#8354] replace webhelpers literal with Markup
(already inherited from it,
we already use it aka jinja2.Markup elsewhere too)
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch db/8354
in repository https://gitbox.apache.org/repos/asf/allura.git
commit 9ad951bd6a6f4c54abb1d88707962180579a4abe
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Fri Mar 6 12:23:56 2020 -0500
[#8354] replace webhelpers literal with Markup (already inherited from it, we already use it aka jinja2.Markup elsewhere too)
---
Allura/allura/config/app_cfg.py | 4 ++--
Allura/allura/lib/app_globals.py | 14 +++++++-------
Allura/allura/lib/markdown_extensions.py | 4 +++-
Allura/allura/lib/utils.py | 4 ++--
Allura/allura/lib/widgets/forms.py | 7 ++++---
Allura/allura/tasks/mail_tasks.py | 2 +-
ForgeTracker/forgetracker/widgets/ticket_form.py | 6 +++---
7 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/Allura/allura/config/app_cfg.py b/Allura/allura/config/app_cfg.py
index e93b09b..fc9eb3e 100644
--- a/Allura/allura/config/app_cfg.py
+++ b/Allura/allura/config/app_cfg.py
@@ -40,7 +40,7 @@ from tg import app_globals as g
from tg.renderers.jinja import JinjaRenderer
import jinja2
from tg.configuration import AppConfig, config
-from webhelpers.html import literal
+from markupsafe import Markup
import ew
import allura
@@ -133,7 +133,7 @@ class JinjaEngine(ew.TemplateEngine):
context = self.context(context)
with ew.utils.push_context(ew.widget_context, render_context=context):
text = template.render(**context)
- return literal(text)
+ return Markup(text)
base_config = ForgeConfig()
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 3809ad8..5af35ea 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -83,7 +83,7 @@ class ForgeMarkdown(markdown.Markdown):
# so we return it as a plain text
log.info('Text is too big. Skipping markdown processing')
escaped = cgi.escape(h.really_unicode(source))
- return h.html.literal('<pre>%s</pre>' % escaped)
+ return Markup('<pre>%s</pre>' % escaped)
try:
return markdown.Markdown.convert(self, source)
except Exception:
@@ -91,7 +91,7 @@ class ForgeMarkdown(markdown.Markdown):
''.join(traceback.format_stack()), exc_info=True)
escaped = h.really_unicode(source)
escaped = cgi.escape(escaped)
- return h.html.literal("""<p><strong>ERROR!</strong> The markdown supplied could not be parsed correctly.
+ return Markup("""<p><strong>ERROR!</strong> The markdown supplied could not be parsed correctly.
Did you forget to surround a code snippet with "~~~~"?</p><pre>%s</pre>""" % escaped)
def cached_convert(self, artifact, field_name):
@@ -117,7 +117,7 @@ class ForgeMarkdown(markdown.Markdown):
if cache.md5 is not None:
md5 = hashlib.md5(source_text.encode('utf-8')).hexdigest()
if cache.md5 == md5 and getattr(cache, 'fix7528', False) == bugfix_rev:
- return h.html.literal(cache.html)
+ return Markup(cache.html)
# Convert the markdown and time the result.
start = time.time()
@@ -418,8 +418,8 @@ class Globals(object):
def highlight(self, text, lexer=None, filename=None):
if not text:
if lexer == 'diff':
- return h.html.literal('<em>File contents unchanged</em>')
- return h.html.literal('<em>Empty file</em>')
+ return Markup('<em>File contents unchanged</em>')
+ return Markup('<em>Empty file</em>')
# Don't use line numbers for diff highlight's, as per [#1484]
if lexer == 'diff':
formatter = pygments.formatters.HtmlFormatter(cssclass='codehilite', linenos=False)
@@ -439,9 +439,9 @@ class Globals(object):
# no highlighting, but we should escape, encode, and wrap it in
# a <pre>
text = cgi.escape(text)
- return h.html.literal('<pre>' + text + '</pre>')
+ return Markup('<pre>' + text + '</pre>')
else:
- return h.html.literal(pygments.highlight(text, lexer, formatter))
+ return Markup(pygments.highlight(text, lexer, formatter))
def forge_markdown(self, **kwargs):
'''return a markdown.Markdown object on which you can call convert'''
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index 7575d1e..c2050f7 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -21,6 +21,7 @@ from __future__ import unicode_literals
from __future__ import absolute_import
import re
import logging
+
from six.moves.urllib.parse import urljoin
from tg import config
@@ -30,6 +31,7 @@ import html5lib.serializer
import html5lib.filters.alphabeticalattributes
import markdown
import emoji
+from markupsafe import Markup
from . import macro
from . import helpers as h
@@ -431,7 +433,7 @@ class ForgeLinkTreeProcessor(markdown.treeprocessors.Treeprocessor):
class MarkAsSafe(markdown.postprocessors.Postprocessor):
def run(self, text):
- return h.html.literal(text)
+ return Markup(text)
class AddCustomClass(markdown.postprocessors.Postprocessor):
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index 14c6575..2494c8b 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -50,7 +50,7 @@ from tg import redirect, app_globals as g
from tg.decorators import before_validate
from tg.controllers.util import etag_cache
from paste.deploy.converters import asbool, asint
-from webhelpers.html import literal
+from markupsafe import Markup
from webob import exc
from pygments.formatters import HtmlFormatter
from setproctitle import getproctitle
@@ -294,7 +294,7 @@ class AntiSpam(object):
for fldno in range(self.num_honey):
fld_name = self.enc('honey%d' % (fldno))
fld_id = self.enc('honey%d%d' % (self.counter, fldno))
- yield literal(self.honey_field_template.substitute(
+ yield Markup(self.honey_field_template.substitute(
honey_class=self.honey_class,
fld_id=fld_id,
fld_name=fld_name))
diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py
index a528269..888baa5 100644
--- a/Allura/allura/lib/widgets/forms.py
+++ b/Allura/allura/lib/widgets/forms.py
@@ -29,6 +29,7 @@ from pytz import common_timezones, country_timezones, country_names
from paste.deploy.converters import aslist, asint, asbool
import tg
from tg import config
+from markupsafe import Markup
from allura.lib import validators as V
from allura.lib import helpers as h
@@ -108,7 +109,7 @@ class ForgeForm(ew.SimpleForm):
or ctx['name'])
html = '<label for="%s">%s</label>' % (
ctx['id'], label_text)
- return h.html.literal(html)
+ return Markup(html)
def context_for(self, field):
ctx = super(ForgeForm, self).context_for(field)
@@ -122,7 +123,7 @@ class ForgeForm(ew.SimpleForm):
if ctx['errors'] and field.show_errors and not ignore_errors:
display = "%s<div class='error'>%s</div>" % (display,
ctx['errors'])
- return h.html.literal(display)
+ return Markup(display)
class ForgeFormResponsive(ForgeForm):
@@ -900,7 +901,7 @@ class NeighborhoodOverviewForm(ForgeForm):
display = "%s<div class='error'>%s</div>" % (display,
ctx['errors'])
- return h.html.literal(display)
+ return Markup(display)
else:
return super(NeighborhoodOverviewForm, self).display_field(field, ignore_errors)
diff --git a/Allura/allura/tasks/mail_tasks.py b/Allura/allura/tasks/mail_tasks.py
index c2774af..779cd0f 100644
--- a/Allura/allura/tasks/mail_tasks.py
+++ b/Allura/allura/tasks/mail_tasks.py
@@ -44,7 +44,7 @@ def mail_meta_content(metalink):
:param metalink: url to the page the action button links to
'''
- return h.html.literal("""\
+ return markupsafe.Markup("""\
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
<link itemprop="url" href="%s"></link>
diff --git a/ForgeTracker/forgetracker/widgets/ticket_form.py b/ForgeTracker/forgetracker/widgets/ticket_form.py
index 4778a36..f1f04e1 100644
--- a/ForgeTracker/forgetracker/widgets/ticket_form.py
+++ b/ForgeTracker/forgetracker/widgets/ticket_form.py
@@ -17,10 +17,10 @@
from __future__ import unicode_literals
from __future__ import absolute_import
+
from tg import tmpl_context as c
from formencode import validators as fev
-from webhelpers.html.builder import literal
-
+from markupsafe import Markup
import ew as ew_core
import ew.jinja2_ew as ew
@@ -81,7 +81,7 @@ class GenericTicketForm(ew.SimpleForm):
display = field.display(**ctx)
if ctx['errors'] and field.show_errors and not ignore_errors:
- display += literal("<div class='error'>") + ctx['errors'] + literal("</div>")
+ display += Markup("<div class='error'>") + ctx['errors'] + Markup("</div>")
return display
def _add_current_value_to_user_field(self, field, user):