#NEWLINE# def parse( curl_command ) : #NEWLINE# #INDENT# method = 'get' #NEWLINE# tokens = shlex . split ( curl_command ) #NEWLINE# parsed_args = parser . parse_args ( tokens ) #NEWLINE# base_indent = ( ' ' * 4 ) #NEWLINE# data_token = '' #NEWLINE# post_data = ( parsed_args . data or parsed_args . data_binary ) #NEWLINE# if post_data : #NEWLINE# #INDENT# method = 'post' #NEWLINE# try : #NEWLINE# #INDENT# post_data_json = json . loads ( post_data ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# post_data_json = None #NEWLINE# #UNINDENT# if ( post_data_json and isinstance ( post_data_json , dict ) ) : #NEWLINE# #INDENT# post_data = dict_to_pretty_string ( post_data_json ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# post_data = "'{}',\n" . format ( post_data ) #NEWLINE# #UNINDENT# data_token = '{}data={}' . format ( base_indent , post_data ) #NEWLINE# #UNINDENT# cookie_dict = OrderedDict ( ) #NEWLINE# quoted_headers = OrderedDict ( ) #NEWLINE# for curl_header in parsed_args . header : #NEWLINE# #INDENT# ( header_key , header_value ) = curl_header . split ( ':' , 1 ) #NEWLINE# if ( header_key . lower ( ) == 'cookie' ) : #NEWLINE# #INDENT# cookie = Cookie . SimpleCookie ( header_value ) #NEWLINE# for key in cookie : #NEWLINE# #INDENT# cookie_dict [ key ] = cookie [ key ] . value #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# quoted_headers [ header_key ] = header_value . strip ( ) #NEWLINE# #UNINDENT# #UNINDENT# result = 'requests.{method}("{url}",\n{data_token}{headers_token}{cookies_token})' . format ( method = method , url = parsed_args . url , data_token = data_token , headers_token = '{}headers={}' . format ( base_indent , dict_to_pretty_string ( quoted_headers ) ) , cookies_token = '{}cookies={}' . format ( base_indent , dict_to_pretty_string ( cookie_dict ) ) ) #NEWLINE# return result