def __init__(self):
        super(RewritePlugin, self).__init__()

        self.config.add({})

        # Gather all the rewrite rules for each field.
        rules = defaultdict(list)
        for key, view in self.config.items():
            value = view.get(unicode)
            try:
                fieldname, pattern = key.split(None, 1)
            except __HOLE__:
                raise ui.UserError(u"invalid rewrite specification")
            if fieldname not in library.Item._fields:
                raise ui.UserError(u"invalid field name (%s) in rewriter" %
                                   fieldname)
            self._log.debug(u'adding template field {0}', key)
            pattern = re.compile(pattern.lower())
            rules[fieldname].append((pattern, value))
            if fieldname == 'artist':
                # Special case for the artist field: apply the same
                # rewrite for "albumartist" as well.
                rules['albumartist'].append((pattern, value))

        # Replace each template field with the new rewriter function.
        for fieldname, fieldrules in rules.iteritems():
            getter = rewriter(fieldname, fieldrules)
            self.template_fields[fieldname] = getter
            if fieldname in library.Album._fields:
                self.album_template_fields[fieldname] = getter
dataset/ETHPy150Open beetbox/beets/beetsplug/rewrite.py/RewritePlugin.__init__