def encode(self, obj):
if isinstance(obj, int_like_types):<EOL><INDENT>self.result.append("<STR_LIT>" % obj)<EOL><DEDENT>elif isinstance(obj, string_types):<EOL><INDENT>self.result.extend([str(len(obj)), '<STR_LIT::>', str(obj)])<EOL><DEDENT>elif hasattr(obj, "<STR_LIT>"):<EOL><INDENT>self.encode(obj.__bencode__())<EOL><DEDENT>elif hasattr(obj, "<STR_LIT>"):<EOL><INDENT>self.result.append('<STR_LIT:d>')<EOL>for key, val in sorted(obj.items()):<EOL><INDENT>key = str(key)<EOL>self.result.extend([str(len(key)), '<STR_LIT::>', key])<EOL>self.encode(val)<EOL><DEDENT>self.result.append('<STR_LIT:e>')<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>items = iter(obj)<EOL><DEDENT>except TypeError as exc:<EOL><INDENT>raise BencodeError("<STR_LIT>" % (<EOL>obj, type(obj), exc<EOL>))<EOL><DEDENT>else:<EOL><INDENT>self.result.append('<STR_LIT:l>')<EOL>for item in items:<EOL><INDENT>self.encode(item)<EOL><DEDENT>self.result.append('<STR_LIT:e>')<EOL><DEDENT><DEDENT>return self.result<EOL>
Add the given object to the result.