#NEWLINE# def _unserialize( self , data , offset = 0 ) : #NEWLINE# #INDENT# '\n    Find the next token and unserialize it.\n    Recurse on array.\n\n    offset = raw offset from start of data\n    \n    return (type, offset, value)\n    ' #NEWLINE# buf = [ ] #NEWLINE# dtype = string . lower ( data [ offset : ( offset + 1 ) ] ) #NEWLINE# dataoffset = ( offset + 2 ) #NEWLINE# typeconvert = ( lambda x : x ) #NEWLINE# chars = datalength = 0 #NEWLINE# if ( dtype == 'i' ) : #NEWLINE# #INDENT# typeconvert = ( lambda x : int ( x ) ) #NEWLINE# ( chars , readdata ) = self . read_until ( data , dataoffset , ';' ) #NEWLINE# dataoffset += ( chars + 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( dtype == 'b' ) : #NEWLINE# #INDENT# typeconvert = ( lambda x : ( int ( x ) == 1 ) ) #NEWLINE# ( chars , readdata ) = self . read_until ( data , dataoffset , ';' ) #NEWLINE# dataoffset += ( chars + 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( dtype == 'd' ) : #NEWLINE# #INDENT# typeconvert = ( lambda x : float ( x ) ) #NEWLINE# ( chars , readdata ) = self . read_until ( data , dataoffset , ';' ) #NEWLINE# dataoffset += ( chars + 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( dtype == 'n' ) : #NEWLINE# #INDENT# readdata = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( dtype == 's' ) : #NEWLINE# #INDENT# ( chars , stringlength ) = self . read_until ( data , dataoffset , ':' ) #NEWLINE# dataoffset += ( chars + 2 ) #NEWLINE# ( chars , readdata ) = self . read_chars ( data , ( dataoffset + 1 ) , int ( stringlength ) ) #NEWLINE# dataoffset += ( chars + 2 ) #NEWLINE# if ( chars != int ( stringlength ) != int ( readdata ) ) : #NEWLINE# #INDENT# raise Exception ( 'String length mismatch' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( dtype == 'a' ) : #NEWLINE# #INDENT# readdata = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# ( chars , keys ) = self . read_until ( data , dataoffset , ':' ) #NEWLINE# dataoffset += ( chars + 2 ) #NEWLINE# for i in range ( 0 , int ( keys ) ) : #NEWLINE# #INDENT# ( ktype , kchars , key ) = self . _unserialize ( data , dataoffset ) #NEWLINE# dataoffset += dataoffset #NEWLINE# ( vtype , vchars , value ) = self . _unserialize ( data , dataoffset ) #NEWLINE# dataoffset += vchars #NEWLINE# readdata [ key ] = value #NEWLINE# #UNINDENT# dataoffset += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise Exception ( ( 'Unknown / Unhandled data type (%s)!' % dtype ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return ( dtype , ( dataoffset - offset ) , typeconvert ( readdata ) )