o
    QDi                     @   s   d dl Z d dlZd dlZd dlZd dlmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZmZmZ d d	lmZmZ d d
lmZ edddddddZedd ZefddZdd ZG dd deZdS )    N)closingcontextmanager)StringIO)HttpResponse)get_object_or_404)method_decorator)View)	DotWriterPstatsParserTheme)login_possibly_requiredpermissions_possibly_required)Request)g
ףp=
?gRQ?g(\?)gQ?g\(\?g      ?g      ?FiraSansg      @)mincolormaxcolorgammafontnameminfontsizemaxfontsizec              
   c   s    |    t| 9 z(tjdd}t| | W d   n1 s"w   Y  |jV  W t|j nt|j w W d   dS 1 sEw   Y  dS )zF
    Create a temp file containing data from a django file field.
    F)deleteN)	openr   tempfileNamedTemporaryFileshutilcopyfileobjnameosunlink)sourcedestination r!   O/var/www/Datamplify/venv/lib/python3.10/site-packages/silk/views/profile_dot.py_temp_file_from_file_field   s   

"r#   c                 C   s8   || }t | W  d   S 1 sw   Y  dS )z:
    Parse a profile from a django file field source.
    N)r
   parse)r   get_filenamefilenamer!   r!   r"   _create_profile.   s   

$r'   c                 C   sb   |d }d}|  ||g d tt }t|| t | W  d   S 1 s*w   Y  dS )zK
    Create a dot file from pstats data stored in a django file field.
    g      Y@gMbP?FN)pruner   r   r	   graph	COLOR_MAPgetvalue)profilecutoffnode_cutoffedge_cutofffpr!   r!   r"   _create_dot6   s   $r1   c                   @   s$   e Zd Zeeeedd ZdS )ProfileDotViewc                 C   sV   t t|dd}t|jddpd}t|j}tt||d}t	t
|ddd	S )
NF)pkprof_file__isnullr-       )dotzutf-8zapplication/json)content_type)r   r   floatGETgetr'   	prof_filedictr1   r   jsondumpsencode)selfrequest
request_idsilk_requestr-   r,   resultr!   r!   r"   r;   E   s
   
zProfileDotView.getN)__name__
__module____qualname__r   r   r   r;   r!   r!   r!   r"   r2   C   s    r2   )r>   r   r   r   
contextlibr   r   ior   django.httpr   django.shortcutsr   django.utils.decoratorsr   django.views.genericr   	gprof2dotr	   r
   r   	silk.authr   r   silk.modelsr   r*   r#   r'   r1   r2   r!   r!   r!   r"   <module>   s4   

