o
    PDi                     @   s>   d dl Z d dlmZ d dlmZmZ dZdd Zd	ddZdS )
    N)	urlencode)ContextTemplatea&  curl {% if method %}-X {{ method }}{% endif %}
{% if content_type %}-H 'content-type: {{ content_type }}'{% endif %}
{% if modifier %}{{ modifier }} {% endif %}{% if body %}'{{ body }}'{% endif %}
{{ url }}{% if query_params %}{{ query_params }}{% endif %}
{% if extra %}{{ extra }}{% endif %}
c                 C   s   d }|r!zt dd | D }W n	 ty   Y nw dt| }d|v s)d|v r6t| tr3t| } d}n4d|v s>d|v r]zd	d
d |  D } W n t	yW   d}Y nw d }d}n| rft| } d}nd }d }|| |||fS )Nc                 S   s   g | ]\}}|| d fqS )utf8)encode.0kv r   R/var/www/Datamplify/venv/lib/python3.10/site-packages/silk/code_generation/curl.py
<listcomp>       z(_curl_process_params.<locals>.<listcomp>?json
javascriptz-d	multipartzx-www-form-urlencoded c                 S   s   g | ]\}}| d | qS )=r   r   r   r   r   r   #   r   z-F)
r   items	TypeErrorstr
isinstancedictr   dumpsjoinAttributeError)bodycontent_typequery_paramsextramodifierr   r   r   _curl_process_params   s8   

r"   c           	      C   sT   |sd}t |||\}}}}}tt}| ||||||d}|t|ddddS )Nz
text/plain)urlmethodr   r   r!   r   r    F)
autoescape
r   )r"   r   curl_templaterenderr   replace)	r#   r$   r   r   r   r!   r    tcontextr   r   r   curl_cmd3   s"   	r,   )NNNN)	r   urllib.parser   django.templater   r   r'   r"   r,   r   r   r   r   <module>   s    	$