Created
October 21, 2018 01:17
-
-
Save glaszig/c65ae389a5dd8edb8b5ae73d286d990c to your computer and use it in GitHub Desktop.
Jinja plugin (for use with Ansible) to run re.escape against input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (c) 2018, [email protected] | |
# | |
# This is free software: you can redistribute it and/or modify | |
# it under the terms of the MIT license. | |
# | |
# This software is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# MIT License for more details. | |
# | |
# You should have received a copy of the MIT. | |
# If not, see <http://opensource.org/licenses/MIT>. | |
# Usage: | |
# {{ "The (quick) brown fox jump$" | regexp_escape }} | |
# # => "The \(quick\) brown fox jump\$" | |
from re import escape | |
def regexp_escape(collection): | |
''' | |
applies re.escape to collection | |
''' | |
if isinstance(collection, basestring): | |
return escape(collection) | |
elif item in collection: | |
return [escape(i) for i in collection] | |
class FilterModule(object): | |
def filters(self): | |
return { | |
'regexp_escape': regexp_escape | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment