#NEWLINE# def _parse_hstore( hstore_str ) : #NEWLINE# #INDENT# "Parse an hstore from its literal string representation.\n\n    Attempts to approximate PG's hstore input parsing rules as closely as\n    possible. Although currently this is not strictly necessary, since the\n    current implementation of hstore's output syntax is stricter than what it\n    accepts as input, the documentation makes no guarantees that will always\n    be the case.\n\n\n\n    " #NEWLINE# result = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# pos = 0 #NEWLINE# pair_match = HSTORE_PAIR_RE . match ( hstore_str ) #NEWLINE# while ( pair_match is not None ) : #NEWLINE# #INDENT# key = pair_match . group ( 'key' ) . replace ( '\\"' , '"' ) . replace ( '\\\\' , '\\' ) #NEWLINE# if pair_match . group ( 'value_null' ) : #NEWLINE# #INDENT# value = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# value = pair_match . group ( 'value' ) . replace ( '\\"' , '"' ) . replace ( '\\\\' , '\\' ) #NEWLINE# #UNINDENT# result [ key ] = value #NEWLINE# pos += pair_match . end ( ) #NEWLINE# delim_match = HSTORE_DELIMITER_RE . match ( hstore_str [ pos : ] ) #NEWLINE# if ( delim_match is not None ) : #NEWLINE# #INDENT# pos += delim_match . end ( ) #NEWLINE# #UNINDENT# pair_match = HSTORE_PAIR_RE . match ( hstore_str [ pos : ] ) #NEWLINE# #UNINDENT# if ( pos != len ( hstore_str ) ) : #NEWLINE# #INDENT# raise ValueError ( _parse_error ( hstore_str , pos ) ) #NEWLINE# #UNINDENT# return result