<s> """<STR_LIT>""" <EOL> try : <EOL> from collections . abc import MutableSequence , MutableMapping <EOL> except ImportError : <EOL> from collections import MutableSequence , MutableMapping <EOL> try : <EOL> from urllib import urlencode <EOL> from urlparse import parse_qsl <EOL> from urlparse import urlsplit <EOL> from urlparse import urlunsplit <EOL> except ImportError : <EOL> from urllib . parse import parse_qsl <EOL> from urllib . parse import urlencode <EOL> from urllib . parse import urlsplit <EOL> from urllib . parse import urlunsplit <EOL> from six import string_types , text_type <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> def append_qs ( url , query_string ) : <EOL> """<STR_LIT>""" <EOL> parsed_url = urlsplit ( url ) <EOL> parsed_qs = parse_qsl ( parsed_url . query , True ) <EOL> if isstr ( query_string ) : <EOL> parsed_qs += parse_qsl ( query_string ) <EOL> elif isdict ( query_string ) : <EOL> for item in list ( query_string . items ( ) ) : <EOL> if islist ( item [ <NUM_LIT:1> ] ) : <EOL> for val in item [ <NUM_LIT:1> ] : <EOL> parsed_qs . append ( ( item [ <NUM_LIT:0> ] , val ) ) <EOL> else : <EOL> parsed_qs . append ( item ) <EOL> elif islist ( query_string ) : <EOL> parsed_qs += query_string <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> return urlunsplit ( ( <EOL> parsed_url . scheme , <EOL> parsed_url . netloc , <EOL> parsed_url . path , <EOL> urlencode_unicode ( parsed_qs ) , <EOL> parsed_url . fragment , <EOL> ) ) <EOL> def urlencode_unicode ( data , doseq = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> data_iter = None <EOL> if isdict ( data ) : <EOL> data_iter = list ( data . items ( ) ) <EOL> elif islist ( data ) : <EOL> data_iter = data <EOL> if data_iter : <EOL> for i , ( key , value ) in enumerate ( data_iter ) : <EOL> if isinstance ( value , text_type ) : <EOL> try : <EOL> safe_val = str ( value ) <EOL> except UnicodeEncodeError : <EOL> safe_val = value . encode ( '<STR_LIT:utf-8>' ) <EOL> finally : <EOL> if isdict ( data ) : <EOL> data [ key ] = safe_val <EOL> else : <EOL> data [ i ] = ( key , safe_val ) <EOL> return urlencode ( data , doseq = doseq ) <EOL> def _is_leaf ( value ) : <EOL> """<STR_LIT>""" <EOL> return not ( isdict ( value ) or islist ( value ) ) <EOL> def to_nested_php_args ( data , prefix_key = None ) : <EOL> """<STR_LIT>""" <EOL> is_root = prefix_key is None <EOL> prefix_key = prefix_key if prefix_key else '<STR_LIT>' <EOL> if islist ( data ) : <EOL> data_iter = data if is_root else enumerate ( data ) <EOL> new_data = [ ] if is_root else { } <EOL> elif isdict ( data ) : <EOL> data_iter = list ( data . items ( ) ) <EOL> new_data = { } <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' . format ( type ( data ) ) ) <EOL> if islist ( new_data ) : <EOL> def data_set ( k , v ) : <EOL> new_data . append ( ( k , v ) ) <EOL> def data_update ( d ) : <EOL> for k , v in list ( d . items ( ) ) : <EOL> new_data . append ( ( k , v ) ) <EOL> else : <EOL> def data_set ( k , v ) : <EOL> new_data [ k ] = v <EOL> data_update = new_data . update <EOL> for key , value in data_iter : <EOL> end_key = prefix_key + ( str ( key ) if is_root else '<STR_LIT>' . format ( key ) ) <EOL> if _is_leaf ( value ) : <EOL> data_set ( end_key , value ) <EOL> else : <EOL> nested_args = to_nested_php_args ( value , end_key ) <EOL> data_update ( nested_args ) <EOL> return new_data <EOL> def prepend_base ( base ) : <EOL> """<STR_LIT>""" <EOL> return lambda call : '<STR_LIT:.>' . join ( ( base , call ) ) <EOL> def isdict ( value ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( value , MutableMapping ) <EOL> def islist ( value ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( value , MutableSequence ) <EOL> def isstr ( value ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( value , string_types ) <EOL> def get_filename ( disposition ) : <EOL> """<STR_LIT>""" <EOL> if disposition : <EOL> params = [ param . strip ( ) for param in disposition . split ( '<STR_LIT:;>' ) [ <NUM_LIT:1> : ] ] <EOL> for param in params : <EOL> if '<STR_LIT:=>' in param : <EOL> name , value = param . split ( '<STR_LIT:=>' , <NUM_LIT:1> ) <EOL> if name == '<STR_LIT:filename>' : <EOL> return value . strip ( '<STR_LIT:">' ) </s>
