def write(self, text):
if self.disabled:<EOL><INDENT>self.write_with_encoding(self.encoding, text)<EOL>return<EOL><DEDENT>to_write, text = split_writable_text(self.encoder, text, self.encoding)<EOL>if to_write:<EOL><INDENT>self.write_with_encoding(self.encoding, to_write)<EOL><DEDENT>while text:<EOL><INDENT>encoding = self.encoder.find_suitable_encoding(text[<NUM_LIT:0>])<EOL>if not encoding:<EOL><INDENT>self._handle_character_failed(text[<NUM_LIT:0>])<EOL>text = text[<NUM_LIT:1>:]<EOL>continue<EOL><DEDENT>to_write, text = split_writable_text(self.encoder, text, encoding)<EOL>if to_write:<EOL><INDENT>self.write_with_encoding(encoding, to_write)<EOL><DEDENT><DEDENT>
Write the text, automatically switching encodings.