
    eiz                         d dl Z d dlZd dlZddlmZ ddlmZmZ ddlm	Z	m
Z
mZmZ ddlmZ g dZde j        d	dfd
Zde j        d	dfdZddZd	e j        fdZddZdS )    N   )print_doctor)
handle_runparse_http_file)SUPPORTED_METHODSParsedItemsparse_request_itemsprocess_url)handle_request)
build_parsermainr   r   r   r	   r
   r   r   r   parserreturnc                    |                                  }|                    ddddd           |                    dddd	
           |                    ddd
           |                                  }|                    dddd           |                    dddd           |                    dddd
           |                    ddddd           |                     dddd
           |                     dd dd!"           |                     d#d$dd%"           |                     d&t          j        d'd()           |                     d*dd+"           |                     d,t          dd-.           |                     d/t          j        d'd0)           |                     d1t
          d2d3.           |                     d4d5d6d7"           |                                  }|                    d8d9d:d;d<=           |                    d>d9d?d;d@=           |                    dAd9dBd;dC=           |                    dDd9dEd;dF=           dS )Gz.Add flags shared by all HTTP verb subcommands.z--jsonz-j
store_true	json_modez/(default) Serialize data items as a JSON object)actiondesthelpz--formz-fz#Serialize data items as form fields)r   r   z--multipartzForce multipart form dataz	--headersheaders_onlyzPrint response headers onlyz--body	body_onlyzPrint response body onlyz	--verbosez-vz+Print request and response headers and bodyz--printz-p
print_specNzGOutput control: H(req headers) B(req body) h(resp headers) b(resp body))r   defaultr   z
--downloadz-dzDownload response body to filez--outputz-ozOutput file path)r   r   z--authz-azuser:passwordz--verifyTzSSL certificate verificationr   r   r   z--proxyz	Proxy URLz	--timeoutzRequest timeout in seconds)typer   r   z--followzFollow redirectsz--max-redirects   zMaximum number of redirectsz--impersonatez-ichromezBrowser to impersonatez	--http1.1store_constv1http_versionzUse HTTP/1.1)r   constr   r   z--http2v2z
Use HTTP/2z--http3v3z
Use HTTP/3z--http3-onlyv3onlyz3Use HTTP/3 only (no fallback to HTTP/2 or HTTP/1.1))add_mutually_exclusive_groupadd_argumentargparseBooleanOptionalActionfloatint)r   content_groupoutput_grouphttp_version_groups       A/usr/local/lib/python3.11/dist-packages/curl_cffi/cli/__init__.py_add_common_flagsr/      s   7799M>     2	     (     6688L*	     '	     :	     V     -	     
D$=OPPP
$?KKK
-+	     	4kBBB
)	     -	     *	     %	      <<>>## $    ## $    ## $    ##B $         c                 h    |                      ddd           |                      dddd	           d
S )z*Add URL and request items positional args.urlURLzRequest URLmetavarr   itemsITEM*zYRequest items: Header:Value, param==value, field=value, field:=json, @file, +cookie=value)r5   nargsr   N)r&   )r   s    r.   _add_request_positionalsr:      sR    
u=AAA
#      r0   c                      t           j                            t          j        d                   } | dv rd} t          d|  d|  d           d S )Nr   )z__main__.pyz-m	curl-cffizUsage: a+   <command> [options]

HTTP request CLI with browser impersonation.

HTTP verbs:
  get, post, put, delete, patch    Make an HTTP request
  head, options, trace, query      (case-insensitive)

Request items (for HTTP verb commands):
  Header:Value   HTTP header
  param==value   Query parameter
  field=value    Data field
  field:=json    Raw JSON field
  @file          File upload
  +key=value     Cookie

Tools:
  run FILE                         Run requests from .http or .har file
  doctor                           Dump diagnostic information

Run 'z5 <command> --help' for details on a specific command.)ospathbasenamesysargvprint)progs    r.   _print_helprD      s{    7CHQK((D$$$	 DD D* +D D D E E E E Er0   c                     t          j        dd          } |                     dddd           |                     d	
          }t	          t
                    D ]j}|                                |fD ]Q}|                    |d| d          }t          |           t          |           |
                    |           Rk|                    dd          }|
                    d            |                    ddt           j                  }|                    ddd           |                    dt           j        dd           t          |           |
                    d            | S )Nr<   F)rC   add_helpz-hz--helpr   	show_help)r   r   command)r   zMake an HTTP z	 request.)description)methoddoctorz*Dump diagnostic information for debugging.runa%  Run requests from a file.

Supported formats (auto-detected by extension):
  .http / .rest   HTTP Request in Editor format
  .har            HAR (HTTP Archive) format

HTTP file format:
  ### (request separator)
  POST http://example.com/api
  Content-Type: application/json

  {"key": "value"}
  ###
  GET http://example.com

Har file:
  Chrome exported HAR files do not contain cookies and auth headers by default. To include them:

  In DevTools settings: Gear Icon -> Preferences -> Network -> select "Allow to generate HAR with sensitive data"
)rI   formatter_classfileFILEzPath to .http or .har filer4   z	--sessionTzYUse a single session for all requests, sharing cookies and connections (default: enabled)r   )r'   ArgumentParserr&   add_subparserssortedr   lower
add_parserr:   r/   set_defaultsRawDescriptionHelpFormatterr(   )r   
subparsersrJ   namesubs        r.   r   r      s   $  F h|+NNN&&I&66J*++ , ,\\^^V, 	, 	,D''=F=== (  C %S)))c"""F++++	, 

@    C D!!!


* !</    C2 VV2NOOO-!     cD!!!Mr0   c                  V   t                      } |                                 }|j        t          |dd          r"t	                       t          j        d           |j        dk    rt                       d S |j        dk    rt          |           d S t          ||j
                   d S )NrG   Fr   rK   rL   )r   
parse_argsrH   getattrrD   r@   exitr   r   r   rJ   )r   argss     r.   r   r     s    ^^FD|wt[%@@|x|u44%%%%%r0   )r   N)r'   r=   r@   rK   r   rL   r   r   parser   r   r	   r
   requestr   __all__rP   r/   r:   rD   r   r    r0   r.   <module>rc      sQ    				 



             , , , , , , , ,            $ # # # # #  wh5 w$ w w w wtX%<     E E E E8?h- ? ? ? ?D& & & & & &r0   