a
    SicÑ  ã                
   @   sÎ   d Z ddlZejZejZejZejZ	ej
ZdZdZdZdZdZdZededed	ed
ediZeeeeeedœZeeeeeeee	eeiZedd„ e ¡ D ƒƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )aI  Module to convert log levels between Abseil Python, C++, and Python standard.

This converter has to convert (best effort) between three different
logging level schemes:

  * **cpp**: The C++ logging level scheme used in Abseil C++.
  * **absl**: The absl.logging level scheme used in Abseil Python.
  * **standard**: The python standard library logging level scheme.

Here is a handy ascii chart for easy mental mapping::

    LEVEL    | cpp |  absl  | standard |
    ---------+-----+--------+----------+
    DEBUG    |  0  |    1   |    10    |
    INFO     |  0  |    0   |    20    |
    WARNING  |  1  |   -1   |    30    |
    ERROR    |  2  |   -2   |    40    |
    CRITICAL |  3  |   -3   |    50    |
    FATAL    |  3  |   -3   |    50    |

Note: standard logging ``CRITICAL`` is mapped to absl/cpp ``FATAL``.
However, only ``CRITICAL`` logs from the absl logger (or absl.logging.fatal)
will terminate the program. ``CRITICAL`` logs from non-absl loggers are treated
as error logs with a message prefix ``"CRITICAL - "``.

Converting from standard to absl or cpp is a lossy conversion.
Converting back to standard will lose granularity.  For this reason,
users should always try to convert to standard, the richest
representation, before manipulating the levels, and then only to cpp
or absl if those level schemes are absolutely necessary.
é    Néýÿÿÿéþÿÿÿéÿÿÿÿé   ÚFATALÚERRORÚWARNINGÚINFOÚDEBUG)r   r   r   ÚWARNr	   r
   c                 c   s   | ]\}}||fV  qd S )N© )Ú.0ÚkÚvr   r   úR/var/www/html/django/DPS/env/lib/python3.9/site-packages/absl/logging/converter.pyÚ	<genexpr>V   ó    r   c                 C   s,   | t k rdS | tk rdS | tk r$dS dS dS )aË  Gets the initial that should start the log line for the given level.

  It returns:

  * ``'I'`` when: ``level < STANDARD_WARNING``.
  * ``'W'`` when: ``STANDARD_WARNING <= level < STANDARD_ERROR``.
  * ``'E'`` when: ``STANDARD_ERROR <= level < STANDARD_CRITICAL``.
  * ``'F'`` when: ``level >= STANDARD_CRITICAL``.

  Args:
    level: int, a Python standard logging level.

  Returns:
    The first initial as it would be logged by the C++ logging module.
  ÚIÚWÚEÚFN)ÚSTANDARD_WARNINGÚSTANDARD_ERRORÚSTANDARD_CRITICAL©Úlevelr   r   r   Úget_initial_for_levelY   s    r   c                 C   s2   t | tƒstd t| ƒ¡ƒ‚| dkr(dS |  S dS )zçConverts an absl log level to a cpp log level.

  Args:
    level: int, an absl.logging level.

  Raises:
    TypeError: Raised when level is not an integer.

  Returns:
    The corresponding integer level for use in Abseil C++.
  úExpect an int level, found {}r   N)Ú
isinstanceÚintÚ	TypeErrorÚformatÚtyper   r   r   r   Úabsl_to_cpps   s
    
r#   c                 C   sD   t | tƒstd t| ƒ¡ƒ‚| tk r(t} | tkr8t|  S t|  d S )a  Converts an integer level from the absl value to the standard value.

  Args:
    level: int, an absl.logging level.

  Raises:
    TypeError: Raised when level is not an integer.

  Returns:
    The corresponding integer level for use in standard logging.
  r   r   )	r   r   r    r!   r"   Ú
ABSL_FATALÚ
ABSL_DEBUGÚABSL_TO_STANDARDÚSTANDARD_DEBUGr   r   r   r   Úabsl_to_standardˆ   s    
r(   c                 C   s   t t |  ¡ ¡ƒS )züConverts a string level to standard logging level value.

  Args:
    level: str, case-insensitive ``'debug'``, ``'info'``, ``'warning'``,
        ``'error'``, ``'fatal'``.

  Returns:
    The corresponding integer level for use in standard logging.
  )r(   Ú
ABSL_NAMESÚgetÚupperr   r   r   r   Ústring_to_standardž   s    
r,   c                 C   st   t | tƒstd t| ƒ¡ƒ‚| dk r(d} | tk r<t|  d S | tk rHtS | tk rTt	S | t
k r`tS | tk rltS tS dS )a	  Converts an integer level from the standard value to the absl value.

  Args:
    level: int, a Python standard logging level.

  Raises:
    TypeError: Raised when level is not an integer.

  Returns:
    The corresponding integer level for use in absl logging.
  r   r   r   N)r   r   r    r!   r"   r'   ÚSTANDARD_INFOr%   r   Ú	ABSL_INFOr   ÚABSL_WARNINGr   Ú
ABSL_ERRORr$   r   r   r   r   Ústandard_to_absl«   s    
r1   c                 C   s   t t| ƒƒS )a  Converts an integer level from the standard value to the cpp value.

  Args:
    level: int, a Python standard logging level.

  Raises:
    TypeError: Raised when level is not an integer.

  Returns:
    The corresponding integer level for use in cpp logging.
  )r#   r1   r   r   r   r   Ústandard_to_cppÊ   s    r2   )Ú__doc__ÚloggingÚCRITICALr   r   r   r   r   r	   r-   r
   r'   r$   r0   r/   Z	ABSL_WARNr.   r%   ÚABSL_LEVELSr)   r&   ÚdictÚitemsZSTANDARD_TO_ABSLr   r#   r(   r,   r1   r2   r   r   r   r   Ú<module>   sL    üûü