in tools/plisttool/plisttool.py [0:0]
def validate_no_variable_references(self, target, key_name, value, msg_additions=None):
"""Ensures there are no variable references left in value (recursively).
Args:
target: The name of the target for which the plist is being built.
key_name: The name of the key this value is part of.
value: The value to check.
msg_additions: Dictionary of variable names to custom strings to add to the
error messages.
Raises:
PlistToolError: If there is a variable substitution that wasn't resolved.
"""
additions = {}
if msg_additions:
for k, v in msg_additions.items():
additions[k] = v
additions[k + ':rfc1034identifier'] = v
def _helper(key_name, value):
if isinstance(value, str):
m = VARIABLE_REFERENCE_RE.search(value)
if m:
variable_name = ExtractVariableFromMatch(m)
if not variable_name:
# Reference wasn't property formed, raise that issue.
raise PlistToolError(INVALID_SUBSTITUTATION_REFERENCE_MSG % (
target, m.group(0), key_name, value))
err_msg = UNKNOWN_SUBSTITUTATION_REFERENCE_MSG % (
target, m.group(0), key_name, value)
msg_addition = additions.get(variable_name)
if msg_addition:
err_msg = err_msg + ' ' + msg_addition
raise PlistToolError(err_msg)
return
if isinstance(value, dict):
key_prefix = key_name + ':' if key_name else ''
for k, v in value.items():
_helper(key_prefix + k, v)
m = VARIABLE_REFERENCE_RE.search(k)
if m:
raise PlistToolError(
UNSUPPORTED_SUBSTITUTATION_REFERENCE_IN_KEY_MSG % (
target, m.group(0), key_prefix + k))
return
if isinstance(value, list):
for i, v in enumerate(value):
reporting_key = '%s[%d]' % (key_name, i)
_helper(reporting_key, v)
return
# Off we go...
_helper(key_name, value)