
    ڌh5                         d Z ddlmZmZ ddlZddlmZ ddlmZ ddl	m
Z
 ddlZddlmZ 	 dd	lmZmZmZmZmZ n# e$ r Y nw xY wd
 Zeej        fd            ZdS )zh
Provides a context manager that writes extended debugging info
in the Kodi log on unhandled exceptions
    )absolute_importunicode_literalsN)contextmanager)uname)pformat   )logger)Text	GeneratorCallableDictAnyc           	         d |                                  D             }|                    d            g }|D ];\  }}|                    d                    |t	          |                               <d                    |          S )z
    Format variables dictionary

    :param variables: variables dict
    :type variables: dict
    :return: formatted string with sorted ``var = val`` pairs
    :rtype: str
    c                 p    g | ]3\  }}|                     d           |                    d           /||f4S )__)
startswithendswith).0varvals      l/Users/chudy/Library/Application Support/Kodi/addons/metadata.tvshows.themoviedb.org.python/libs/debugger.py
<listcomp>z _format_vars.<locals>.<listcomp>4   s\     E E ExsCt,,E03T0B0BEc
 E E E    c                     | d         S )Nr    )is    r   <lambda>z_format_vars.<locals>.<lambda>6   s
    ! r   )keyz	{0} = {1}
)itemssortappendformatr   join)	variablesvar_listlinesr   r   s        r   _format_varsr(   *   s    E E9??+<+< E E EHMMnnM%%%E < <S[''WS\\::;;;;99Ur   c              #   n  K   	 dV  dS # t           $ r}t          j        d          d         } | d                    t	          |          |                      | d            | d                    t                                            | d                    t          j        d                                | d	                    t          j        d
                                | d                    |d                              d}|d         t          |d         |d         |d         z
            D ]\  }}||d         k    r:|d                    t          |          
                    d          |          z  }K|d                    t          |          
                    d          |          z  } | d|z               | dt          |d         j                  z               | dt          |d         j                  z               | d           |d}~ww xY w)a  
    Diagnostic helper context manager

    It controls execution within its context and writes extended
    diagnostic info to the Kodi log if an unhandled exception
    happens within the context. The info includes the following items:

    - System info
    - Kodi version
    - Module path.
    - Code fragment where the exception has happened.
    - Global variables.
    - Local variables.

    After logging the diagnostic info the exception is re-raised.

    Example::

        with debug_exception():
            # Some risky code
            raise RuntimeError('Fatal error!')

    :param logger_func: logger function which must accept a single argument
        which is a log message.
    N   z+*** Unhandled exception detected: {} {} ***z*** Start diagnostic info ***zSystem info: {0}zOS info: {0}zSystem.OSVersionInfozKodi version: {0}zSystem.BuildVersionz	File: {0}r          z{0}:>{1}z{0}: {1}zCode context:
zGlobal variables:
r   zLocal variables:
z**** End diagnostic info ****)	Exceptioninspecttracer#   typer   xbmcgetInfoLabel	enumeratestrrjustr(   	f_globalsf_locals)logger_funcexc
frame_infocontextr   lines         r   debug_exceptionr?   =   sj     8   ]1%%b)
9@@cCPP	R 	R 	R3444&--egg66777N))4557 7 	8 	8 	8'..3446 6 	7 	7 	7K&&z!}55666a=$$Z]JqMJqM4QRR H H4
1%%z00Qa$GGGGGz00Qa$GGGGG%/000) A!899: 	; 	; 	;( A!7889 	: 	: 	:3444	1s   
 H4HH//H4)__doc__
__future__r   r   r0   
contextlibr   platformr   pprintr   r3   utilsr	   typingr
   r   r   r   r   ImportErrorr(   errorr?   r   r   r   <module>rI      s  *  9 8 8 8 8 8 8 8  % % % % % %                   	;;;;;;;;;;;;;;; 	 	 	D	  &  & 5 5 5 5 5 5s   ; AA