Project

Profile

Help

Issue #2077 ยป test.py

Suggested change - fdobrovo, 07/27/2016 02:36 PM

 
import sys
from django.template import Template, Context

other = """<package arch="noarch" name="python-suds" pkgid="{{ pkgid }}">
<version epoch="0" rel="2.el5" ver="0.4.1" />
<changelog author="jortel &lt;jortel@redhat.com&gt; - 0.3.3-1" date="1228428000">
- Basic ws-security with {{{UsernameToken}}} and clear-text password only.</changelog>
</package>"""
con = Context({'pkgid': u'3201710bf51f8184571da00a060eab1a826cdb113dbe8598f08ff161f50c8ef1'})

out_template = other[:other.find(">")+1] + "{% verbatim %}" + other[other.find(">")+1:other.rfind("</")] + "{% endverbatim %}" + other[other.rfind("</"):]

print(out_template)
# Result:
# '<package arch="noarch" name="python-suds" pkgid="{{ pkgid }}">{% verbatim %}
# <version epoch="0" rel="2.el5" ver="0.4.1" />
# <changelog author="jortel &lt;jortel@redhat.com&gt; - 0.3.3-1" date="1228428000">
# - Basic ws-security with {{{UsernameToken}}} and clear-text password only.</changelog>
# {% endverbatim %}</package>'

t = Template(out_template)
rendered = t.render(con)

print(rendered)

# Rendered:
# u'<package arch="noarch" name="python-suds" pkgid="3201710bf51f8184571da00a060eab1a826cdb113dbe8598f08ff161f50c8ef1">
# <version epoch="0" rel="2.el5" ver="0.4.1" />
# <changelog author="jortel &lt;jortel@redhat.com&gt; - 0.3.3-1" date="1228428000">
# - Basic ws-security with {{{UsernameToken}}} and clear-text password only.</changelog>
# </package>'
    (1-1/1)