def buildLegend(legend=None, text=None, regex=None, key=lambda v: v):
    ''' Helper method to build or extend a legend from a text. The given regex
        will be used to find legend inside the text.

        :param dict legend: Initial legend data
        :param str text: Text from which should legend information extracted.
            None means do no extraction.
        :param str regex: Regex to find legend part inside the given text. The
            regex should have a named group `name` (key) and a named group
            `value` (value).
        :param callable key: function to map the key to a legend key
        :rtype: dict'''
    if legend is None:
        legend = {}
    if text is not None:
        for match in re.finditer(regex or default_legend_regex,
                                 text, re.UNICODE):
            legend[key(match.group('name'))] = match.group('value').strip()
    return legend
def buildLegend ( legend = None , text = None , regex = None , key = lambda v : v ) : if legend is None : legend = { } if text is not None : for match in re . finditer ( regex or default_legend_regex , text , re . UNICODE ) : legend [ key ( match . group ( 'name' ) ) ] = match . group ( 'value' ) . strip ( ) return legend
Helper method to build or extend a legend from a text. The given regex
        will be used to find legend inside the text.

        :param dict legend: Initial legend data
        :param str text: Text from which should legend information extracted.
            None means do no extraction.
        :param str regex: Regex to find legend part inside the given text. The
            regex should have a named group `name` (key) and a named group
            `value` (value).
        :param callable key: function to map the key to a legend key
        :rtype: dict