def expand(self, values):
        """
        Generate concepts based on the template.

        @param values: A L{dict} mapping substitution markers to application
            objects from which to take values for those substitutions.  For
            example, a key might be C{u"target"}.  The associated value will be
            sustituted each place C{u"{target}"} appears in the template
            string.  Or, the value's name will be substituted each place
            C{u"{target:name}"} appears in the template string.
        @type values: L{dict} mapping L{unicode} to L{object}

        @return: An iterator the combined elements of which represent the
            result of expansion of the template.  The elements are adaptable to
            L{IConcept}.
        """
        parts = Formatter().parse(self.templateText)
        for (literalText, fieldName, formatSpec, conversion) in parts:
            if literalText:
                yield ExpressString(literalText)
            if fieldName:
                try:
                    target = values[fieldName.lower()]
                except KeyError:
                    extra = u""
                    if formatSpec:
                        extra = u" '%s'" % (formatSpec,)
                    yield u"<missing target '%s' for%s expansion>" % (
                        fieldName, extra)
                else:
                    if formatSpec:
                        # A nice enhancement would be to delegate this logic to
                        # target
                        try:
                            expander = getattr(
                                self, '_expand_' + formatSpec.upper()
                            )
                        except __HOLE__:
                            yield u"<'%s' unsupported by target '%s'>" % (
                                formatSpec, fieldName)
                        else:
                            yield expander(target)
                    else:
                        yield target
dataset/ETHPy150Open twisted/imaginary/imaginary/language.py/ConceptTemplate.expand