def rewrite(self):
self._sort()<EOL>self._check()<EOL>rewritten, pos = [], <NUM_LIT:0><EOL>for range, replacement in self.ranges:<EOL><INDENT>rewritten.append(self.buffer.source[pos:range.begin_pos])<EOL>rewritten.append(replacement)<EOL>pos = range.end_pos<EOL><DEDENT>rewritten.append(self.buffer.source[pos:])<EOL>return Buffer("<STR_LIT>".join(rewritten), self.buffer.name, self.buffer.first_line)<EOL>
Return the rewritten source. May raise :class:`RewriterConflict`.