nodes: 0, module; 1, function_definition; 2, function_name:_modifyInternal; 3, parameters; 4, block; 5, identifier:self; 6, keyword_separator; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, function_definition; 14, function_definition; 15, return_statement; 16, identifier:sort; 17, None; 18, identifier:purge; 19, False; 20, identifier:done; 21, None; 22, comment:"""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.
  
          """; 23, assignment; 24, assignment; 25, function_name:_mark; 26, parameters; 27, block; 28, function_name:_modify; 29, parameters; 30, block; 31, call; 32, pattern_list; 33, boolean_operator; 34, pattern_list; 35, boolean_operator; 36, identifier:v; 37, identifier:i; 38, if_statement; 39, function_definition; 40, try_statement; 41, for_statement; 42, if_statement; 43, return_statement; 44, identifier:submodel; 45, identifier:i; 46, expression_statement; 47, for_statement; 48, expression_statement; 49, for_statement; 50, return_statement; 51, identifier:_modify; 52, argument_list; 53, identifier:sortAll; 54, identifier:sortLevels; 55, boolean_operator; 56, tuple; 57, identifier:doneAll; 58, identifier:doneLevels; 59, boolean_operator; 60, tuple; 61, comparison_operator:done is None; 62, block; 63, function_name:_mark_; 64, parameters; 65, block; 66, block; 67, except_clause; 68, identifier:doneAll_; 69, identifier:doneAll; 70, block; 71, comparison_operator:result is None; 72, block; 73, identifier:result; 74, assignment; 75, identifier:v; 76, identifier:submodel; 77, block; 78, assignment; 79, pattern_list; 80, boolean_operator; 81, block; 82, identifier:_new; 83, attribute; 84, integer:1; 85, comparison_operator:sort is not None; 86, identifier:sort; 87, list; 88, dictionary; 89, comparison_operator:done is not None; 90, identifier:done; 91, list; 92, dictionary; 93, identifier:done; 94, None; 95, return_statement; 96, identifier:index; 97, identifier:regexp; 98, identifier:du; 99, if_statement; 100, if_statement; 101, if_statement; 102, for_statement; 103, if_statement; 104, identifier:KeyError; 105, block; 106, expression_statement; 107, identifier:result; 108, None; 109, return_statement; 110, identifier:_new; 111, call; 112, if_statement; 113, identifier:levels; 114, boolean_operator; 115, identifier:index; 116, identifier:reverse; 117, identifier:levels; 118, identifier:sortAll; 119, expression_statement; 120, identifier:self; 121, identifier:data; 122, identifier:sort; 123, None; 124, identifier:done; 125, None; 126, subscript; 127, comparison_operator:du is None; 128, block; 129, comparison_operator:index is None; 130, block; 131, boolean_operator; 132, block; 133, identifier:doneLevel; 134, subscript; 135, block; 136, comparison_operator:result is not None; 137, block; 138, pass_statement; 139, assignment; 140, subscript; 141, identifier:list; 142, argument_list; 143, identifier:purge; 144, block; 145, else_clause; 146, call; 147, call; 148, assignment; 149, identifier:v; 150, slice; 151, identifier:du; 152, None; 153, return_statement; 154, identifier:index; 155, None; 156, for_statement; 157, return_statement; 158, comparison_operator:regexp is None; 159, call; 160, return_statement; 161, identifier:doneLevels; 162, identifier:i; 163, expression_statement; 164, identifier:result; 165, None; 166, return_statement; 167, identifier:result; 168, call; 169, identifier:v; 170, slice; 171, if_statement; 172, block; 173, attribute; 174, argument_list; 175, attribute; 176, argument_list; 177, identifier:_new; 178, call; 179, integer:4; 180, subscript; 181, identifier:v_; 182, subscript; 183, block; 184, subscript; 185, identifier:regexp; 186, None; 187, attribute; 188, argument_list; 189, binary_operator:v[:3] + [du]; 190, assignment; 191, identifier:result; 192, identifier:_mark_; 193, argument_list; 194, integer:4; 195, not_operator; 196, block; 197, expression_statement; 198, identifier:sortLevels; 199, identifier:get; 200, identifier:i; 201, identifier:sortLevels; 202, identifier:get; 203, call; 204, identifier:sorted; 205, argument_list; 206, identifier:v; 207, slice; 208, identifier:v; 209, slice; 210, if_statement; 211, identifier:v; 212, slice; 213, identifier:re; 214, identifier:match; 215, identifier:regexp; 216, call; 217, subscript; 218, list; 219, identifier:result; 220, call; 221, list_splat; 222, subscript; 223, expression_statement; 224, call; 225, identifier:str; 226, argument_list; 227, identifier:_new; 228, keyword_argument; 229, keyword_argument; 230, integer:4; 231, integer:3; 232, boolean_operator; 233, block; 234, integer:4; 235, identifier:str; 236, argument_list; 237, identifier:v; 238, slice; 239, identifier:du; 240, identifier:_mark_; 241, argument_list; 242, identifier:doneAll_; 243, identifier:v; 244, integer:3; 245, call; 246, attribute; 247, argument_list; 248, identifier:i; 249, identifier:key; 250, lambda; 251, identifier:reverse; 252, identifier:reverse; 253, comparison_operator:regexp is None; 254, call; 255, return_statement; 256, subscript; 257, integer:3; 258, list_splat; 259, attribute; 260, argument_list; 261, identifier:_new; 262, identifier:append; 263, binary_operator:_mark(v, i) + [_modify(v[4], i + 1)]; 264, lambda_parameters; 265, subscript; 266, identifier:regexp; 267, None; 268, attribute; 269, argument_list; 270, binary_operator:v[:3] + [du]; 271, identifier:v; 272, identifier:index; 273, identifier:doneLevel; 274, identifier:_new; 275, identifier:append; 276, binary_operator:_mark(v, i) + [_modify(v[4], i + 1)]; 277, call; 278, list; 279, identifier:e; 280, identifier:e; 281, identifier:index; 282, identifier:re; 283, identifier:match; 284, identifier:regexp; 285, call; 286, subscript; 287, list; 288, call; 289, list; 290, identifier:_mark; 291, argument_list; 292, call; 293, identifier:str; 294, argument_list; 295, identifier:v; 296, slice; 297, identifier:du; 298, identifier:_mark; 299, argument_list; 300, call; 301, identifier:v; 302, identifier:i; 303, identifier:_modify; 304, argument_list; 305, identifier:v_; 306, integer:3; 307, identifier:v; 308, identifier:i; 309, identifier:_modify; 310, argument_list; 311, subscript; 312, binary_operator:i + 1; 313, subscript; 314, binary_operator:i + 1; 315, identifier:v; 316, integer:4; 317, identifier:i; 318, integer:1; 319, identifier:v; 320, integer:4; 321, identifier:i; 322, integer:1
code: def _modifyInternal(self, *, sort=None, purge=False, done=None):
          """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.
  
          """
          sortAll, sortLevels = sort is not None and sort or ([], {})
          doneAll, doneLevels = done is not None and done or ([], {})
  
          def _mark(v, i):
              if done is None:
                  return v[:4]
  
              def _mark_(index, regexp, du):
                  if du is None:
                      return v[:4]
                  if index is None:
                      for v_ in v[:3]:
                          if regexp is None or re.match(regexp, str(v_)):
                              return v[:3] + [du]
                      return v[:4]
                  if regexp is None or re.match(regexp, str(v[index])):
                      return v[:3] + [du]
              try:
                  for doneLevel in doneLevels[i]:
                      result = _mark_(*doneLevel)
                  if result is not None:
                      return result
              except KeyError:
                  pass
              for doneAll_ in doneAll:
                  result = _mark_(*doneAll_)
              if result is None:
                  return v[:4]
              return result
  
          def _modify(submodel, i):
              _new = list()
              for v in submodel:
                  if purge:
                      if not v[3]:
                          _new.append(_mark(v, i) + [_modify(v[4], i + 1)])
                  else:
                      _new.append(_mark(v, i) + [_modify(v[4], i + 1)])
              levels = sortLevels.get(i) or sortLevels.get(str(i))
              for index, reverse in levels or sortAll:
                  _new = sorted(_new, key=lambda e: e[index], reverse=reverse)
              return _new
          return _modify(self.data, 1)