def decode(self, check_trailer=False): 
try:<EOL><INDENT>kind = self.data[self.offset]<EOL><DEDENT>except IndexError:<EOL><INDENT>raise BencodeError("<STR_LIT>" % (<EOL>self.offset, len(self.data),<EOL>))<EOL><DEDENT>if kind.isdigit():<EOL><INDENT>try:<EOL><INDENT>end = self.data.find('<STR_LIT::>', self.offset)<EOL>length = int(self.data[self.offset:end], <NUM_LIT:10>)<EOL><DEDENT>except (ValueError, TypeError):<EOL><INDENT>raise BencodeError("<STR_LIT>" % (<EOL>self.offset, self.data[self.offset:self.offset+<NUM_LIT:32>]<EOL>))<EOL><DEDENT>self.offset = end+length+<NUM_LIT:1><EOL>obj = self.data[end+<NUM_LIT:1>:self.offset]<EOL>if self.char_encoding:<EOL><INDENT>try:<EOL><INDENT>obj = obj.decode(self.char_encoding)<EOL><DEDENT>except (UnicodeError, AttributeError):<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>elif kind == '<STR_LIT:i>':<EOL><INDENT>try:<EOL><INDENT>end = self.data.find('<STR_LIT:e>', self.offset+<NUM_LIT:1>)<EOL>obj = int(self.data[self.offset+<NUM_LIT:1>:end], <NUM_LIT:10>)<EOL><DEDENT>except (ValueError, TypeError):<EOL><INDENT>raise BencodeError("<STR_LIT>" % (<EOL>self.offset, self.data[self.offset:self.offset+<NUM_LIT:32>]<EOL>))<EOL><DEDENT>self.offset = end+<NUM_LIT:1><EOL><DEDENT>elif kind == '<STR_LIT:l>':<EOL><INDENT>self.offset += <NUM_LIT:1><EOL>obj = []<EOL>while self.data[self.offset:self.offset+<NUM_LIT:1>] != '<STR_LIT:e>':<EOL><INDENT>obj.append(self.decode())<EOL><DEDENT>self.offset += <NUM_LIT:1><EOL><DEDENT>elif kind == '<STR_LIT:d>':<EOL><INDENT>self.offset += <NUM_LIT:1><EOL>obj = {}<EOL>while self.data[self.offset:self.offset+<NUM_LIT:1>] != '<STR_LIT:e>':<EOL><INDENT>key = self.decode()<EOL>obj[key] = self.decode()<EOL><DEDENT>self.offset += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>raise BencodeError("<STR_LIT>" % (<EOL>self.offset, self.data[self.offset:self.offset+<NUM_LIT:32>]<EOL>))<EOL><DEDENT>if check_trailer and self.offset != len(self.data):<EOL><INDENT>raise BencodeError("<STR_LIT>" % (<EOL>self.offset, self.data[self.offset:self.offset+<NUM_LIT:32>]<EOL>))<EOL><DEDENT>return obj<EOL>
Decode data in C{self.data} and return deserialized object.

            @param check_trailer: Raise error if trailing junk is found in data?
            @raise BencodeError: Invalid data.