#NEWLINE# def _expand( self , expression , safe = None , prefix = '' , separator = ',' , with_keys = False , trim_empty_equals = False ) : #NEWLINE# #INDENT# items = self . collect ( * expression . split ( ',' ) ) #NEWLINE# encode = ( lambda x : percent_encode ( x , safe = safe ) ) #NEWLINE# for ( i , ( key , value ) ) in enumerate ( items ) : #NEWLINE# #INDENT# if isinstance ( value , tuple ) : #NEWLINE# #INDENT# items [ i ] = '=' . join ( map ( encode , value ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( value , dict ) : #NEWLINE# #INDENT# items [ i ] = ',' . join ( ( ',' . join ( map ( encode , item ) ) for item in value . items ( ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( value , list ) : #NEWLINE# #INDENT# items [ i ] = ',' . join ( map ( encode , value ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# items [ i ] = encode ( value ) #NEWLINE# #UNINDENT# #UNINDENT# if with_keys : #NEWLINE# #INDENT# if ( ( item [ i ] is None ) or ( ( items [ i ] == '' ) and trim_empty_equals ) ) : #NEWLINE# #INDENT# items [ i ] = encode ( key ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# items [ i ] = ( ( encode ( key ) + '=' ) + ( items [ i ] or '' ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# out = [ ] #NEWLINE# for ( i , item ) in enumerate ( items ) : #NEWLINE# #INDENT# out . append ( ( prefix if ( i == 0 ) else separator ) ) #NEWLINE# out . append ( item ) #NEWLINE# #UNINDENT# return '' . join ( out )