def _modifyInternal(self, *, sort=None, purge=False, done=None):
sortAll, sortLevels = sort is not None and sort or ([], {})<EOL>doneAll, doneLevels = done is not None and done or ([], {})<EOL>def _mark(v, i):<EOL><INDENT>if done is None:<EOL><INDENT>return v[:<NUM_LIT:4>]<EOL><DEDENT>def _mark_(index, regexp, du):<EOL><INDENT>if du is None:<EOL><INDENT>return v[:<NUM_LIT:4>]<EOL><DEDENT>if index is None:<EOL><INDENT>for v_ in v[:<NUM_LIT:3>]:<EOL><INDENT>if regexp is None or re.match(regexp, str(v_)):<EOL><INDENT>return v[:<NUM_LIT:3>] + [du]<EOL><DEDENT><DEDENT>return v[:<NUM_LIT:4>]<EOL><DEDENT>if regexp is None or re.match(regexp, str(v[index])):<EOL><INDENT>return v[:<NUM_LIT:3>] + [du]<EOL><DEDENT><DEDENT>try:<EOL><INDENT>for doneLevel in doneLevels[i]:<EOL><INDENT>result = _mark_(*doneLevel)<EOL><DEDENT>if result is not None:<EOL><INDENT>return result<EOL><DEDENT><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>for doneAll_ in doneAll:<EOL><INDENT>result = _mark_(*doneAll_)<EOL><DEDENT>if result is None:<EOL><INDENT>return v[:<NUM_LIT:4>]<EOL><DEDENT>return result<EOL><DEDENT>def _modify(submodel, i):<EOL><INDENT>_new = list()<EOL>for v in submodel:<EOL><INDENT>if purge:<EOL><INDENT>if not v[<NUM_LIT:3>]:<EOL><INDENT>_new.append(_mark(v, i) + [_modify(v[<NUM_LIT:4>], i + <NUM_LIT:1>)])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>_new.append(_mark(v, i) + [_modify(v[<NUM_LIT:4>], i + <NUM_LIT:1>)])<EOL><DEDENT><DEDENT>levels = sortLevels.get(i) or sortLevels.get(str(i))<EOL>for index, reverse in levels or sortAll:<EOL><INDENT>_new = sorted(_new, key=lambda e: e[index], reverse=reverse)<EOL><DEDENT>return _new<EOL><DEDENT>return _modify(self.data, <NUM_LIT:1>)<EOL>
Creates a whole new database from existing one, based on given
        modifiers.

        :sort: pattern should look like this:
        ([(<index>, True|False)], {<level_index>: [(<index>, True|False)]}),
        where True|False indicate whether to reverse or not,
        <index> are one of Model.indexes and <level_index> indicate
        a number of level to sort.
        Of course, the lists above may contain multiple items.

        :done: patterns looks similar to :sort:, except that it has additional
        <regexp> values and that True|False means to mark as done|undone.

        @note: Should not be used directly. It was defined here, because
        :save: decorator needs undecorated version of Model.modify.

        :sort: Pattern on which to sort the database.
        :purge: Whether to purge done items.
        :done: Pattern on which to mark items as done/undone.
        :returns: New database, modified according to supplied arguments.