Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use templatetag to escape Django syntax characters in templates #955

Merged
merged 1 commit into from Aug 9, 2016

Conversation

goosemania
Copy link
Member

end_templatetag = '{%% endverbatim pulp_%s_escape_method %%}' % tag_name
template = template.replace(start_tag, start_templatetag + start_tag)
template = template.replace(end_tag, end_tag + end_templatetag)
def substitute_special_chars(template):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than defining functions within a function, these should be private static methods in the containing namespace (I think it's RpmBase here).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seandst,
My thought was that at least one of them is highly specific, it makes some assumptions about the input and has no use at all outside the outer function. I can probably substitute it with a lambda function in a parameter but it will be less readable, imho:
Instead of this:

template = tag_re.sub(generate_tag_replacement_str, template)

I can write this:

template = tag_re.sub(lambda mobj: mobj.group(1) + substitute_special_chars(mobj.group(2)) + mobj.group(3),
                      template)

And by private do you mean to start the name with two underscores?

@seandst seandst added the LGTM label Aug 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants