Commit 19a2fc00 by Michael DeHaan

Clean up imports in utils, add nicer recursion depth limit check.

parent 60d64251
...@@ -25,7 +25,9 @@ import codecs ...@@ -25,7 +25,9 @@ import codecs
import jinja2 import jinja2
import yaml import yaml
import optparse import optparse
from operator import methodcaller import operator
from ansible import errors
import ansible.constants as C
try: try:
import json import json
...@@ -37,8 +39,6 @@ try: ...@@ -37,8 +39,6 @@ try:
except ImportError: except ImportError:
from md5 import md5 as _md5 from md5 import md5 as _md5
from ansible import errors
import ansible.constants as C
############################################################### ###############################################################
# UTILITY FUNCTIONS FOR COMMAND LINE TOOLS # UTILITY FUNCTIONS FOR COMMAND LINE TOOLS
...@@ -278,7 +278,11 @@ def template(text, vars, setup_cache=None): ...@@ -278,7 +278,11 @@ def template(text, vars, setup_cache=None):
''' run a text buffer through the templating engine ''' run a text buffer through the templating engine
until it no longer changes ''' until it no longer changes '''
prev_text = '' prev_text = ''
depth = 0
while prev_text != text: while prev_text != text:
depth = depth + 1
if (depth > 20):
raise errors.AnsibleError("template recursion depth exceeded")
prev_text = text prev_text = text
text = _template(text, vars, setup_cache) text = _template(text, vars, setup_cache)
return text return text
...@@ -343,7 +347,7 @@ def md5(filename): ...@@ -343,7 +347,7 @@ def md5(filename):
class SortedOptParser(optparse.OptionParser): class SortedOptParser(optparse.OptionParser):
'''Optparser which sorts the options by opt before outputting --help''' '''Optparser which sorts the options by opt before outputting --help'''
def format_help(self, formatter=None): def format_help(self, formatter=None):
self.option_list.sort(key=methodcaller('get_opt_string')) self.option_list.sort(key=operator.methodcaller('get_opt_string'))
return optparse.OptionParser.format_help(self, formatter=None) return optparse.OptionParser.format_help(self, formatter=None)
def base_parser(constants=C, usage="", output_opts=False, runas_opts=False, async_opts=False, connect_opts=False): def base_parser(constants=C, usage="", output_opts=False, runas_opts=False, async_opts=False, connect_opts=False):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment