Ë
    qûàgi-  ã                   ó¢   — d Z ddlZddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZ d	ej                  v Z G d
„ d«      Z G d„ de«      Zy)zÜ
runprofileserver.py

    Starts a lightweight Web server with profiling enabled.

Credits for kcachegrind support taken from lsprofcalltree.py go to:
 David Allouche
 Jp Calderone & Itamar Shtull-Trauring
 Johan Dahlin
é    N)Údatetime)Úsettings)ÚStaticFilesHandler)ÚBaseCommandÚCommandError)Úget_internal_wsgi_application)Úsignalcommandzdjango.contrib.staticfilesc                   ó*   — e Zd Zd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚKCacheGrindc                 ó<   — |j                  «       | _        d | _        y ©N)ÚgetstatsÚdataÚout_file)ÚselfÚprofilers     út/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/django_extensions/management/commands/runprofileserver.pyÚ__init__zKCacheGrind.__init__   s   € Ø×%Ñ%Ó'ˆŒ	Øˆ�ó    c                 ó¬   — || _         | j                   j                  d«       | j                  «        | j                  D ]  }| j	                  |«       Œ y )Nzevents: Ticks
)r   ÚwriteÚ_print_summaryr   Ú_entry)r   r   Úentrys      r   ÚoutputzKCacheGrind.output   sG   € Ø ˆŒØ�‰×ÑÐ-Ô.Ø×ÑÔØ—Y‘Yò 	ˆEØ�K‰K˜Õñ	r   c                 ó°   — d}| j                   D ]&  }t        |j                  dz  «      }t        ||«      }Œ( | j                  j                  d|fz  «       y )Nr   éè  zsummary: %d
)r   ÚintÚ	totaltimeÚmaxr   r   )r   Úmax_costr   r   s       r   r   zKCacheGrind._print_summary&   sT   € ØˆØ—Y‘Yò 	0ˆEÜ˜EŸO™O¨dÑ2Ó3ˆIÜ˜8 YÓ/‰Hð	0ð 	�‰×Ñ˜O¨x¨kÑ9Õ:r   c                 óx  — | j                   }|j                  }t        |t        «      r|j	                  d|z  «       n<|j	                  d|j
                  z  «       |j	                  d|j                  z  «       t        |j                  dz  «      }t        |t        «      r|j	                  d|z  «       n |j	                  d|j                  |fz  «       |j                  r|j                  }ng }t        |t        «      rd}n|j                  }|D ]  }| j                  ||«       Œ |j	                  d«       y )Nzfn=%s
zfl=%s
r   z0  %s
ú%d %d
r   ú
)r   ÚcodeÚ
isinstanceÚstrr   Úco_filenameÚco_namer   Ú
inlinetimeÚco_firstlinenoÚcallsÚ	_subentry)r   r   r   r%   r*   r,   ÚlinenoÚsubentrys           r   r   zKCacheGrind._entry-   s  € Ø—=‘=ˆà�z‰zˆÜ�dœCÔ Ø�N‰N˜9 tÑ+Õ,à�N‰N˜9 t×'7Ñ'7Ñ7Ô8Ø�N‰N˜9 t§|¡|Ñ3Ô4ä˜×)Ñ)¨DÑ0Ó1ˆ
Ü�dœCÔ Ø�N‰N˜9 zÑ1Õ2à�N‰N˜9¨×(;Ñ(;¸ZÐ'HÑHÔIð �;Š;Ø—K‘K‰EàˆEä�dœCÔ Ø‰Fà×(Ñ(ˆFàò 	-ˆHØ�N‰N˜6 8Õ,ð	-à�‰�tÕr   c                 óä  — | j                   }|j                  }t        |t        «      r4|j	                  d|z  «       |j	                  d|j
                  fz  «       nf|j	                  d|j                  z  «       |j	                  d|j                  z  «       |j	                  d|j
                  |j                  fz  «       t        |j                  dz  «      }|j	                  d||fz  «       y )Nzcfn=%s
zcalls=%d 0
zcfl=%s
zcalls=%d %d
r   r#   )r   r%   r&   r'   r   Ú	callcountr(   r)   r+   r   r   )r   r.   r/   r   r%   r   s         r   r-   zKCacheGrind._subentryL   sÂ   € Ø—=‘=ˆØ�}‰}ˆÜ�dœCÔ Ø�N‰N˜:¨Ñ,Ô-Ø�N‰N˜>¨X×-?Ñ-?Ð,AÑAÕBà�N‰N˜:¨×(8Ñ(8Ñ8Ô9Ø�N‰N˜:¨¯©Ñ4Ô5Ø�N‰N˜?¨h×.@Ñ.@À$×BUÑBUÐ-VÑVÔWä˜×*Ñ*¨TÑ1Ó2ˆ	Ø�‰�y F¨IÐ#6Ñ6Õ7r   N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r-   © r   r   r   r      s   „ òòò;òó>8r   r   c                   ó8   ‡ — e Zd ZdZdZˆ fd„Zedd„«       Zˆ xZS )ÚCommandz7Starts a lightweight Web server with profiling enabled.z&[optional port number, or ipaddr:port]c                 óâ  •— t         ‰| �  |«       |j                  ddd¬«       |j                  ddddd	¬
«       |j                  ddddd¬
«       |j                  dddd¬«       |j                  dddd¬«       |j                  ddddd¬
«       |j                  ddddd¬
«       |j                  ddd dd!¬
«       t        r-|j                  d"dd#dd$¬
«       |j                  d%dd&dd'¬
«       y y )(NÚaddrportú?z$Optional port number, or ipaddr:port)ÚnargsÚhelpz
--noreloadÚstore_falseÚuse_reloaderTz*Tells Django to NOT use the auto-reloader.)ÚactionÚdestÚdefaultr<   z--nothreadingÚuse_threadingz"Tells Django to NOT use threading.z--prof-pathÚ	prof_pathz/tmpz=Specifies the directory which to save profile information in.)r@   rA   r<   z--prof-fileÚ	prof_fileú{path}.{duration:06d}ms.{time}zASet filename format, default if "{path}.{duration:06d}ms.{time}".z	--nomediaÚ
store_trueÚno_mediaFzDo not profile MEDIA_URLz--use-cprofileÚuse_cprofilezUUse cProfile if available, this is disabled per default because of incompatibilities.z--kcachegrindÚ
use_lsprofz]Create kcachegrind compatible lsprof files, this requires and automatically enables cProfile.z
--nostaticÚuse_static_handlerzCTells Django to NOT automatically serve static files at STATIC_URL.z
--insecureÚinsecure_servingz3Allows serving static files even if DEBUG is False.)ÚsuperÚadd_argumentsÚadd_argumentÚUSE_STATICFILES)r   ÚparserÚ	__class__s     €r   rM   zCommand.add_arguments_   sl  ø€ Ü‰Ñ˜fÔ%Ø×ÑØ˜cØ7ð 	ô 	
ð 	×ÑØ °^ØØ=ð 	ô 	?ð 	×ÑØ M¸ÐQUØ5ð 	ô 	
ð 	×ÑØ °Vðð 	ô 	
ð
 	×ÑØ Ø4ð0ð 	ô 	
ð 	×ÑØ °:ÀuØ+ð 	ô 	
ð 	×ÑØ \¸Øð,ð 	ô 	
ð 	×ÑØ L°|Øð2ð 	ô 	
õ Ø×ÑØ ]Ð9MØð!ð  ô "ð
 ×ÑØ \Ð8JØØJð  õ Lð r   c                 óì  ‡ ‡‡‡	‡
‡‡‡‡‡‡— dd l Š	dd lŠdd lŠ
ddlmŠ |sdŠdŠn	 |j                  d«      \  ŠŠ‰sdŠ‰j                  «       st        d‰z  «      ‚‰d   }‰j                  d	d«      Š‰d
   Št        j                  dk(  xr dxs dŠˆˆ	ˆ
ˆˆˆˆˆˆ ˆˆfd„}|r	 ddlm}  ||«       y  |«        y # t        $ r d|cŠŠY Œ’w xY w# t        $ r ddlm} |j#                  |«       Y y w xY w)Nr   )ÚrunÚ Ú8000ú:z	127.0.0.1z%r is not a valid port number.r>   Úshutdown_messagerG   Úwin32z
CTRL-BREAKz	CONTROL-Cc            
      óÚ  •‡‡	‡
‡‡‡‡‡‡— dd l Šdd lŠ	 dd lŠd} ‰d   Š‰d   Š	‰	rdŠ‰r	 dd lŠ
dŠ‰	r‰st        d«      ‚| s‰st        d«      ‚‰d	   Š‰d
   Š‰j                  ddd¬«      sdŠt        d«       d„ Šˆˆ	ˆ
ˆˆˆˆˆˆˆf
d„}t        d«       ‰j                  d¬«       t        d‰j                  «       ›dt        j                  ›�«       t        d‰›d‰›d�«       t        d‰z  «       	 t        «       }t        r)‰d   }‰d   }|rt        j                  s|rt        |«      } ||«      } ‰‰t!        ‰«      |‰d   ¬«       y # t        $ r d} Y �ŒDw xY w# t        $ r t        d«       dŠY �ŒJw xY w# ‰j"                  $ r°}‰j$                  d‰j&                  d ‰j(                  d!i}	 ||j*                     }n # t,        t.        f$ r t1        |«      }Y nw xY wt2        j4                  j7                  ‰j8                  j;                  d"|z  «      d#z   «       ‰j=                  d$«       Y d }~y d }~wt>        $ r% ‰rt        ‰«       t3        j@                  d«       Y y w xY w)%Nr   TFrH   rI   z-cProfile disabled, module cannot be imported!zFKcachegrind compatible output format required cProfile from Python 2.5z;Hotshot profile library not found. (and not using cProfile)rC   rD   Ú1é   é   ©ÚpathÚdurationÚtimerE   zPFilename format is wrong. Default format used: '{path}.{duration:06d}ms.{time}'.c                  óš   — g } t        t        dd «      }|r| j                  |«       t        t        dd «      }|r| j                  |«       | S )NÚ	MEDIA_URLÚ
STATIC_URL)Úgetattrr   Úappend)Úexclude_pathsÚ	media_urlÚ
static_urls      r   Úget_exclude_pathsz<Command.handle.<locals>.inner_run.<locals>.get_exclude_pathsÎ   sK   € Ø "�Ü#¤H¨k¸4Ó@�	ÙØ!×(Ñ(¨Ô3Ü$¤X¨|¸TÓB�
ÙØ!×(Ñ(¨Ô4Ø$Ð$r   c                 ó(   •
‡ — ˆˆˆˆˆˆ ˆˆˆ	ˆ
ˆfd„}|S )Nc           
      ó¦  •‡— | d   Š‰r"t        ˆfd„ ‰«       D «       «      r	 ‰| |«      S ‰j                  d«      j                  dd«      xs d}d|‰j                  «       fz  }‰j                  j                  ‰|«      }‰r‰j                  «       }n‰j                  |«      }t        j                  «       }	 |j                  ‰| |«      t        j                  «       |z
  }|j                  dz  |j                  dz  z   }‰r2t        |«      }t        |d«      5 }	|j                  |	«       d d d «       n‰r|j                  |«       ‰j!                  |t#        |«      t#        ‰j                  «       «      ¬	«      }
‰j                  j                  ‰d
|
z  «      }
‰s|j%                  «        ‰j'                  ||
«       S # 1 sw Y   Œ�xY w# t        j                  «       |z
  }|j                  dz  |j                  dz  z   }‰r>t        |«      }t        |d«      5 }	|j                  |	«       d d d «       n# 1 sw Y   nxY w‰r|j                  |«       ‰j!                  |t#        |«      t#        ‰j                  «       «      ¬	«      }
‰j                  j                  ‰d
|
z  «      }
‰s|j%                  «        ‰j'                  ||
«       w xY w)NÚ	PATH_INFOc              3   ó@   •K  — | ]  }‰j                  |«      –— Œ y ­wr   )Ú
startswith)Ú.0ÚpÚ	path_infos     €r   ú	<genexpr>zdCommand.handle.<locals>.inner_run.<locals>.make_profiler_handler.<locals>.handler.<locals>.<genexpr>Ý   s   øè ø€ Ò']ÀA¨	×(<Ñ(<¸Q×(?Ñ']ùs   ƒú/ú.Úrootz
%s.%d.profg     @�@Úwr]   z%s.prof)ÚanyÚstripÚreplacer`   r^   ÚjoinÚProfiler   ÚnowÚruncallÚsecondsÚmicrosecondsr   Úopenr   Ú
dump_statsÚformatr   ÚcloseÚrename)ÚenvironÚstart_responseÚ	path_nameÚprofnameÚprofÚstartÚelapÚelapmsÚkgÚfÚ	profname2rq   ÚUSE_CPROFILEÚ
USE_LSPROFÚcProfileri   ÚhotshotÚinner_handlerrG   ÚosrD   rC   r`   s              @€€€€€€€€€€€r   ÚhandlerzQCommand.handle.<locals>.inner_run.<locals>.make_profiler_handler.<locals>.handlerÙ   sl  ù€ Ø '¨Ñ 4�Iñ  ¤CÓ']ÑIZÓI\Ô']Ô$]Ù,¨W°nÓEÐEØ )§¡°Ó 4× <Ñ <¸SÀ#Ó FÒ PÈ&�IØ+¨y¸$¿)¹)»+Ð.FÑF�HØ!Ÿw™wŸ|™|¨I°xÓ@�HÙ#Ø'×/Ñ/Ó1™à&Ÿ™¨xÓ8˜Ü$ŸL™L›N�Eð7Ø#Ÿ|™|¨M¸7ÀNÓSô  (Ÿ|™|›~°Ñ5˜Ø!%§¡°Ñ!6¸×9JÑ9JÈVÑ9SÑ!S˜Ù%Ü!,¨TÓ!2˜BÜ!% h°Ó!4ð -¸Ø "§	¡	¨!¤÷-ð -á)Ø ŸO™O¨HÔ5Ø$-×$4Ñ$4¸)ÌcÐRXËkÔ`cÐdh×dmÑdmÓdoÓ`pÐ$4Ó$q˜	Ø$&§G¡G§L¡L°¸IÈ	Ñ<QÓ$R˜	Ù+Ø ŸJ™JœLØŸ	™	 (¨IÕ6÷-ð -ûô	  (Ÿ|™|›~°Ñ5˜Ø!%§¡°Ñ!6¸×9JÑ9JÈVÑ9SÑ!S˜Ù%Ü!,¨TÓ!2˜BÜ!% h°Ó!4ð -¸Ø "§	¡	¨!¤÷-÷ -ñ -úá)Ø ŸO™O¨HÔ5Ø$-×$4Ñ$4¸)ÌcÐRXËkÔ`cÐdh×dmÑdmÓdoÓ`pÐ$4Ó$q˜	Ø$&§G¡G§L¡L°¸IÈ	Ñ<QÓ$R˜	Ù+Ø ŸJ™JœLØŸ	™	 (¨IÕ6ús2   Â;G ÄGÇG	ÇAKÈH9È0	KÈ9IÈ>BKr5   )r”   r–   r�   r‘   r’   ri   r“   rG   r•   rD   rC   r`   s   ` €€€€€€€€€€r   Úmake_profiler_handlerz@Command.handle.<locals>.inner_run.<locals>.make_profiler_handlerØ   s   ù€ ÷7ö 7ð> �r   zPerforming system checks...)Údisplay_num_errorsz
Django version z, using settings z(Development server is running at http://rV   rs   zQuit the server with %s.rJ   rK   rB   )Ú	threadingz.You don't have permission to access that port.zThat port is already in use.z%That IP address can't be assigned-to.z	Error: %sr$   é   )!r•   r`   r“   ÚImportErrorr’   Úprintr   r‚   ÚcheckÚget_versionr   ÚSETTINGS_MODULEr   rO   ÚDEBUGr   r   ÚerrorÚEACCESÚ
EADDRINUSEÚEADDRNOTAVAILÚerrnoÚAttributeErrorÚKeyErrorr'   ÚsysÚstderrr   ÚstyleÚERRORÚ_exitÚKeyboardInterruptÚexit)ÚHAS_HOTSHOTr—   r–   rJ   rK   ÚeÚERRORSÚ
error_textr�   r‘   r’   ri   r“   r•   rD   rC   r`   ÚaddrÚdjangor¥   rG   ÚoptionsÚportÚquit_commandrS   r   rW   Úsockets           @@@@@@@@@€€€€€€€€€€€r   Ú	inner_runz!Command.handle.<locals>.inner_run®   s\  ÿù€ ÛÛð$ÛØ"�ð # >Ñ2ˆLØ  Ñ.ˆJÙØ#�Ùð)Û#Ø#'�Lñ ¡,Ü"Ð#kÓlÐlá¡|Ü"Ð#`ÓaÐaà Ñ,ˆIà Ñ,ˆIØ×#Ñ#¨°q¸qÐ#ÔAØ<�	ÜÐhÔiò%÷ õ  ôD Ð/Ô0Ø�J‰J¨$ˆJÔ/å¸f×>PÑ>PÕ>RÔT\×TlÒTlÐmÔnÝÂdÊDÐQÔRÜÐ,¨|Ñ;Ô<ðÜ7Ó9�Ý"Ø)0Ð1EÑ)FÐ&Ø'.Ð/AÑ'BÐ$Ù)¬x¯~ª~ÑAQÜ"4°WÓ"=˜Ù/°Ó8�Ù�Dœ#˜d›) W¸ÀÑ8PÖQøôi ò $Ø#“ð$ûô #ò )ÜÐIÔJØ#(“Lð)ûðV —<‘<ò ð —L‘LÐ"RØ×$Ñ$Ð&DØ×'Ñ'Ð)Pð�ð
(Ø!'¨¯©¡‘JøÜ&¬Ð1ò (Ü!$ Q£’Jð(úä—
‘
× Ñ  §¡×!1Ñ!1°+À
Ñ2JÓ!KÈdÑ!RÔSà—‘˜—‘ûÜ$ò Ù#ÜÐ*Ô+Ü—‘˜–ðúsf   ”E «E" Ã6AE? ÅEÅEÅ"E<Å;E<Å?I*Æ&H9Æ5GÇH9ÇG"ÇH9Ç!G"Ç"AH9È9.I*É)I*)Úrun_with_reloader)Ú
autoreload)r´   r¸   r¥   Údjango.core.servers.basehttprS   ÚsplitÚ
ValueErrorÚisdigitr   Úgetr¨   ÚplatformÚdjango.utils.autoreloadrº   r›   Údjango.utilsr»   Úmain)r   r9   Úargsrµ   r>   r¹   rº   r»   r³   r´   r¥   rG   r¶   r·   rS   rW   r¸   s   `  `    @@@@@@@@@r   ÚhandlezCommand.handle”   sü   ÿú€ ãÛÛÝ4áØˆDØ‰Dð*Ø%Ÿ^™^¨CÓ0‘
��dñ ØˆDà�|‰|Œ~ÜÐ?À$ÑFÓGÐGà˜~Ñ.ˆØ"Ÿ;™;Ð'9¸2Ó>ÐØ˜:Ñ&ˆÜŸ™¨Ñ/ÒA°\ÒPÀ[ˆ÷l	ö l	ñZ ð+ÝEÙ! )Õ,ñ
 �KøôE ò *Ø �
�’dð*ûô| ò +Ý3Ø—‘ 	Ö*ð+ús#   ¦B< Â%C Â<CÃCÃ C3Ã2C3)rT   )	r2   r3   r4   r<   rÅ   rM   r	   rÆ   Ú__classcell__)rQ   s   @r   r7   r7   [   s*   ø„ ØD€DØ3€Dô3Lðj òNó ôNr   r7   )Ú__doc__r¨   r   Údjango.confr   Ú#django.contrib.staticfiles.handlersr   Údjango.core.management.baser   r   r¼   r   Ú"django_extensions.management.utilsr	   ÚINSTALLED_APPSrO   r   r7   r5   r   r   ú<module>rÎ      sJ   ðñ	ó Ý å  Ý Bß AÝ Få <à.°(×2IÑ2IÐI€÷>8ñ >8ôBHˆkõ Hr   