def __init__()

in tools/plisttool/plisttool.py [0:0]


  def __init__(self, target, variable_substitutions=None, raw_substitutions=None):
    """Initialize a SubstitutionEngine.

    Args:
      target: Name of the target being built, used in messages/errors.
      variable_substitutions: A dictionary of variable names to the values
          to use for substitutions.
      raw_substitutions: A dictionary of raw names to the values to use for
          substitutions.
    """
    self._substitutions = {}
    self._substitutions_re = None

    subs = variable_substitutions or {}
    for key, value in subs.items():
      m = VARIABLE_NAME_RE.match(key)
      if not m:
        raise PlistToolError(INVALID_SUBSTITUTION_VARIABLE_NAME % (
            target, key))
      if m.group(2):
        raise PlistToolError(SUBSTITUTION_VARIABLE_CANT_HAVE_QUALIFIER % (
             target, key))
      value_rfc = _ConvertToRFC1034(value)
      for fmt in ('${%s}', '$(%s)'):
        self._substitutions[fmt % key] = value
        self._substitutions[fmt % (key + ':rfc1034identifier')] = value_rfc

    raw_subs = raw_substitutions or {}
    for key, value in raw_subs.items():
      # Raw keys can't overlap any other key (var or raw).
      for existing_key in sorted(self._substitutions.keys()):
        if (key in existing_key) or (existing_key in key):
          ordered = sorted([key, existing_key])
          raise PlistToolError(
              OVERLAP_IN_SUBSTITUTION_KEYS % (target, ordered[0], ordered[1]))
      self._substitutions[key] = value

    # A raw key can't overlap any value.
    raw_keys = sorted(raw_subs.keys())
    for k, v in sorted(self._substitutions.items()):
      for raw_key in raw_keys:
        if raw_key in v:
          raise PlistToolError(
              RAW_SUBSTITUTION_KEY_IN_VALUE % (target, raw_key, v, k))

    # Make _substitutions_re.
    if self._substitutions:
      escaped_keys = [re.escape(x) for x in self._substitutions.keys()]
      self._substitutions_re = re.compile('(%s)' % '|'.join(escaped_keys))