#NEWLINE# def loads( s ) : #NEWLINE# #INDENT# stack = [ ] #NEWLINE# chars = iter ( s ) #NEWLINE# value = None #NEWLINE# currCharIsNext = False #NEWLINE# try : #NEWLINE# #INDENT# while 1 : #NEWLINE# #INDENT# skip = False #NEWLINE# if ( not currCharIsNext ) : #NEWLINE# #INDENT# c = chars . next ( ) #NEWLINE# #UNINDENT# while ( c in [ ' ' , '\t' , '\r' , '\n' ] ) : #NEWLINE# #INDENT# c = chars . next ( ) #NEWLINE# #UNINDENT# currCharIsNext = False #NEWLINE# if ( c == '"' ) : #NEWLINE# #INDENT# value = '' #NEWLINE# try : #NEWLINE# #INDENT# c = chars . next ( ) #NEWLINE# while ( c != '"' ) : #NEWLINE# #INDENT# if ( c == '\\' ) : #NEWLINE# #INDENT# c = chars . next ( ) #NEWLINE# try : #NEWLINE# #INDENT# value += EscapeCharToChar [ c ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# if ( c == 'u' ) : #NEWLINE# #INDENT# hexCode = ( ( ( chars . next ( ) + chars . next ( ) ) + chars . next ( ) ) + chars . next ( ) ) #NEWLINE# value += unichr ( int ( hexCode , 16 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise JSONDecodeException ( 'Bad Escape Sequence Found' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# value += c #NEWLINE# #UNINDENT# c = chars . next ( ) #NEWLINE# #UNINDENT# #UNINDENT# except StopIteration : #NEWLINE# #INDENT# raise JSONDecodeException ( 'Expected end of String' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( c == '{' ) : #NEWLINE# #INDENT# stack . append ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# skip = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( c == '}' ) : #NEWLINE# #INDENT# value = stack . pop ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( s == '[' ) : #NEWLINE# #INDENT# stack . append ( [ ] ) #NEWLINE# skip = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( c == ']' ) : #NEWLINE# #INDENT# value = stack . pop ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( c in [ ',' , ':' ] ) : #NEWLINE# #INDENT# skip = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( c in Digits ) or ( c == '-' ) ) : #NEWLINE# #INDENT# digits = [ c ] #NEWLINE# c = chars . next ( ) #NEWLINE# numConv = int #NEWLINE# try : #NEWLINE# #INDENT# while ( c in Digits ) : #NEWLINE# #INDENT# digits . append ( c ) #NEWLINE# c = chars . next ( ) #NEWLINE# #UNINDENT# if ( c == '.' ) : #NEWLINE# #INDENT# numConv = float #NEWLINE# digits . append ( c ) #NEWLINE# c = chars . next ( ) #NEWLINE# while ( c in Digits ) : #NEWLINE# #INDENT# digits . append ( c ) #NEWLINE# c = chars . next ( ) #NEWLINE# #UNINDENT# if ( c . upper ( ) == 'E' ) : #NEWLINE# #INDENT# digits . append ( c ) #NEWLINE# c = chars . next ( ) #NEWLINE# if ( c in [ '+' , '-' ] ) : #NEWLINE# #INDENT# digits . append ( c ) #NEWLINE# c = chars . next ( ) #NEWLINE# while ( c in Digits ) : #NEWLINE# #INDENT# digits . append ( c ) #NEWLINE# c = chars . next ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise JSONDecodeException ( 'Expected + or -' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# except StopIteration : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# value = numConv ( '' . join ( digits ) ) #NEWLINE# currCharIsNext = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( c in [ 't' , 'f' , 'n' ] ) : #NEWLINE# #INDENT# kw = ( ( ( c + chars . next ( ) ) + chars . next ( ) ) + chars . next ( ) ) #NEWLINE# if ( kw == 'null' ) : #NEWLINE# #INDENT# value = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( kw == 'true' ) : #NEWLINE# #INDENT# value = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( kw == 'fals' ) and ( chars . next ( ) == 'e' ) ) : #NEWLINE# #INDENT# value = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise JSONDecodeException ( 'Expected Null, False or True' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise JSONDecodeException ( 'Expected []{}," or Number, Null, False or True' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( not skip ) : #NEWLINE# #INDENT# if len ( stack ) : #NEWLINE# #INDENT# top = stack [ ( - 1 ) ] #NEWLINE# if ( type ( top ) is ListType ) : #NEWLINE# #INDENT# top . append ( value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( type ( top ) is DictionaryType ) : #NEWLINE# #INDENT# stack . append ( value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( type ( top ) in StringTypes ) : #NEWLINE# #INDENT# key = stack . pop ( ) #NEWLINE# stack [ ( - 1 ) ] [ key ] = value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise JSONDecodeException ( 'Expected dictionary key, or start of a value' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# return value #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# except StopIteration : #NEWLINE# #INDENT# raise JSONDecodeException ( 'Unexpected end of JSON source' )