%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/certbot/_internal/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/certbot/_internal/__pycache__/log.cpython-312.pyc

�

M/�e<��n�dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddl
mZddl
m
Z
ddl
mZddl
mZdd	l
mZdd
lmZddlmZddlmZdd
lmZddlmZdd
lmZddlmZdZdZej>e �Z!d+d�Z"dejFddfd�Z$dejFde%de%deejLe%ffd�Z'Gd�dejP�Z)Gd�dejTjV�Z+Gd�dejP�Z,de+d ed!eddfd"�Z-d#ee.d$e.d%e	d&e/d'e/d(e%ddfd)�Z0d(e%ddfd*�Z1y),a�Logging utilities for Certbot.

The best way to use this module is through `pre_arg_parse_setup` and
`post_arg_parse_setup`. `pre_arg_parse_setup` configures a minimal
terminal logger and ensures a detailed log is written to a secure
temporary file if Certbot exits before `post_arg_parse_setup` is called.
`post_arg_parse_setup` relies on the parsed command line arguments and
does the full logging setup with terminal and rotating file handling as
configured by the user. Any logged messages before
`post_arg_parse_setup` is called are sent to the rotating file handler.
Special care is taken by both methods to ensure all errors are logged
and properly flushed before program exit.

The `logging` module is useful for recording messages about about what
Certbot is doing under the hood, but do not necessarily need to be shown
to the user on the terminal. The default verbosity is WARNING.

The preferred method to display important information to the user is to
use `certbot.display.util` and `certbot.display.ops`.

�N)�
TracebackType)�Any)�cast)�IO)�Optional)�Tuple)�Type)�messages)�
configuration)�errors)�util)�	constants)�osz%(message)sz.%(asctime)s:%(levelname)s:%(name)s:%(message)s�returnc��t�}|jtjt��|jtj�t|�}t�}|jtjt��|jtj�tj�}|jtj�|j|�|j|�tjtj�t!j"t$|dt&j(vdt&j(vxsdt&j(v|j*��t&_y)a�Setup logging before command line arguments are parsed.

    Terminal logging is setup using
    `certbot._internal.constants.QUIET_LOGGING_LEVEL` so Certbot is as quiet as
    possible. File logging is setup so that logging messages are
    buffered in memory. If Certbot exits before `post_arg_parse_setup`
    is called, these buffered messages are written to a temporary file.
    If Certbot doesn't exit, `post_arg_parse_setup` writes the messages
    to the normal log files.

    This function also sets `logging.shutdown` to be called on program
    exit which automatically flushes logging handlers and
    `sys.excepthook` to properly log/display fatal exceptions.

    z--debugz--quietz-q��debug�quiet�log_pathN)�TempHandler�setFormatter�logging�	Formatter�FILE_FMT�setLevel�DEBUG�
MemoryHandler�ColoredStreamHandler�CLI_FMT�WARNING�	getLogger�
addHandlerr
�atexit_register�shutdown�	functools�partial�pre_arg_parse_except_hook�sys�argv�path�
excepthook)�temp_handler�memory_handler�stream_handler�root_loggers    �7/usr/lib/python3/dist-packages/certbot/_internal/log.py�pre_arg_parse_setupr17s
�� �=�L����g�/�/��9�:����'�-�-�(�"�<�0�N�)�+�N����� 1� 1�'� :�;����G�O�O�,��#�#�%�K�������'����>�*����>�*�	����)�)�*��&�&�!�>��3�8�8�#��3�8�8�#�7�t�s�x�x�'7��"�"�	$�C�N��configc���t|dt�\}}tj�}dx}}|jD](}t|t�r|}�t|t�s�'|}�*d}|�|�J|��|j|�|j|�t|dd�}|j|�|jd��|j�|r|j�|jrtj }	nV|j"�*tj$t'|j"�dzz
}	n tj$|j(dzz
}	|j+|	�t,j/d|	�|jst1d	|��t2j4�
�t7j8t:|j.|j|��t2_y)a�Setup logging after command line arguments are parsed.

    This function assumes `pre_arg_parse_setup` was called earlier and
    the root logging configuration has not been modified. A rotating
    file logging handler is created and the buffered log messages are
    sent to that handler. Terminal logging output is set to the level
    requested by the user.

    :param certbot.configuration.NamespaceConfig config: Configuration object

    zletsencrypt.logNz9Previously configured logging handlers have been removed!�targetT��force�
zRoot logging level set at %dzSaving debug log to )�filer)�setup_log_file_handlerrrr!�handlers�
isinstancerrr"�
removeHandler�getattr�	setTarget�flush�closerr�QUIET_LOGGING_LEVEL�
verbose_level�DEFAULT_LOGGING_LEVEL�int�
verbose_countr�loggerr�printr(�stderrr%r&�post_arg_parse_except_hookr+)
r3�file_handler�	file_pathr/r-�stderr_handler�handler�msgr,�levels
          r0�post_arg_parse_setuprQbs���5��!�8�-��L�)��#�#�%�K�&*�*�N�^��'�'�%���g�3�4�$�N�
���
/�$�N�	%�
F�C��%�.�*D�I�c�I�D����<�(����n�-��>�8�T�:�L����\�*����t��$����������
�|�|��-�-��	�	�	�	)��/�/�#�f�6J�6J�2K�b�2P�P���/�/�&�2F�2F��2K�K�����E�"�
�L�L�/��7��<�<�
�$�Y�K�0�s�z�z�B��&�&�"��l�l�&�,�,��D�C�Nr2�logfile�fmtc�@�tj|jd|j�tj
j
|j|�}	tjj|d|j��}|j!�|j#tj$�tj&|��}|j)|�||fS#t$r7}tjtjj|���d}~wwxYw)aSetup file debug logging.

    :param certbot.configuration.NamespaceConfig config: Configuration object
    :param str logfile: basename for the log file
    :param str fmt: logging format string

    :returns: file handler and absolute path to the log file
    :rtype: tuple

    i�i)�maxBytes�backupCountN)rS)r
�set_up_core_dir�logs_dir�strict_permissionsrr*�joinrr;�RotatingFileHandler�max_log_backups�IOErrorr�Error�PERM_ERR_FMT�format�
doRolloverrrrr)r3rRrS�
log_file_pathrN�error�handler_formatters       r0r:r:�s���	������%��1J�1J�K��G�G�L�L����'�:�M�<��"�"�6�6��G��.�.�7�0���������W�]�]�#��)�)�c�2�����*�+��M�!�!���<��l�l�4�,�,�3�3�E�:�;�;��<�s�,C�	D�&2D�Dc�\��eZdZdZddeeddf�fd�
Zdejde	f�fd�Z
�xZS)	ra6Sends colored logging output to a stream.

    If the specified stream is not a tty, the class works like the
    standard `logging.StreamHandler`. Default red_level is
    `logging.WARNING`.

    :ivar bool colored: True if output should be colored
    :ivar bool red_level: The level at which to output

    N�streamrc���t�|�|�|�tjj	�n|j	�|_tj|_y�N)	�super�__init__r(rI�isatty�coloredrr �	red_level��selfrf�	__class__s  �r0rjzColoredStreamHandler.__init__�s?���
���� �/5�~��
�
�)�)�+��
�
��	
�� ����r2�recordc����t�|�|�}|jrI|j|jk\r0djtj|tjf�S|S)z�Formats the string representation of record.

        :param logging.LogRecord record: Record to be formatted

        :returns: Formatted, string representation of record
        :rtype: str

        �)	rir`rl�levelnormrZr
�ANSI_SGR_RED�ANSI_SGR_RESET)rorq�outrps   �r0r`zColoredStreamHandler.format�sP����g�n�V�$���<�<�F�N�N�d�n�n�<��7�7�D�-�-�s�D�4G�4G�H�I�I��
r2rh)�__name__�
__module__�__qualname__�__doc__rrrjr�	LogRecord�strr`�
__classcell__�rps@r0rr�s=���	�)�x��|�)�t�)��W�.�.��3��r2rc���eZdZdZ		ddeejdeddf�fd�
Zd
�fd�Z	dde
ddf�fd	�
Zd
ejde
fd�Z
�xZS)rz�Buffers logging messages in memory until the buffer is flushed.

    This differs from `logging.handlers.MemoryHandler` in that flushing
    only happens when flush(force=True) is called.

    Nr5�capacityrc�(��t�|�||��y)N)r5)rirj)ror5r�rps   �r0rjzMemoryHandler.__init__�s���	����&��1r2c�H��t|d�}t�|�	�||_y)z;Close the memory handler, but don't set the target to None.r5N)r>rirAr5)ror5rps  �r0rAzMemoryHandler.close�s!�����x�(��
��
����r2r7c�(��|rt�|��yy)z�Flush the buffer if force=True.

        If force=False, this call is a noop.

        :param bool force: True if the buffer should be flushed.

        N)rir@)ror7rps  �r0r@zMemoryHandler.flush�s�����G�M�O�r2rqc��y)z�Should the buffer be automatically flushed?

        :param logging.LogRecord record: log record to be considered

        :returns: False because the buffer should never be auto-flushed
        :rtype: bool

        F�)rorqs  r0�shouldFlushzMemoryHandler.shouldFlush�s��r2)Ni'�rN)F)rxryrzr{rr�HandlerrErjrA�boolr@r|r�r~rs@r0rr�sg����<@�!&�2�x����8�2��2�+/�2�
��4��D��	�'�"3�"3�	��	r2rc�X��eZdZdZd�fd�Zdejddf�fd�Zd�fd�Z�xZ	S)	raSafely logs messages to a temporary file.

    The file is created with permissions 600. If no log records are sent
    to this handler, the temporary file is deleted when the handler is
    closed.

    :ivar str path: file system path to the temporary log file

    rNc���tjd��|_tjj|jd�|_t
j|jdd��}t�|�%|�|d|_
y)Nzcertbot-log-)�prefix�log�wi�)�mode�chmodT)�tempfile�mkdtemp�_workdirrr*rZr
�	safe_openrirj�_deleterns  �r0rjzTempHandler.__init__
s^��� �(�(��?��
��G�G�L�L�����6��	�����	�	��5�A��
���� �	
���r2rqc�2��d|_t�|�	|�y)zlLog the specified logging record.

        :param logging.LogRecord record: Record to be formatted

        FN)r�ri�emit)rorqrps  �r0r�zTempHandler.emits������
���V�r2c�&��|j�	|jj�|jrt	j
|j�d|_t�|�	�|j�y#|j�wxYw)zuClose the handler and the temporary log file.

        The temporary log file is deleted if it wasn't used.

        FN)	�acquirerfrAr��shutil�rmtreer�ri�release)rorps �r0rAzTempHandler.close s_���	
����		�
�K�K�����|�|��
�
�d�m�m�,� �D�L��G�M�O��L�L�N��D�L�L�N�s�AA>�>Br�)
rxryrzr{rjrr|r�rAr~rs@r0rrs0������7�,�,�����r2rr-�args�kwargsc�n�	t|i|��|jd��y#|jd��wxYw)aA simple wrapper around post_arg_parse_except_hook.

    The additional functionality provided by this wrapper is the memory
    handler will be flushed before Certbot exits. This allows us to
    write logging messages to a temporary file if we crashed before
    logging was fully configured.

    Since sys.excepthook isn't called on SystemExit exceptions, the
    memory handler will not be flushed in this case which prevents us
    from creating temporary log files when argparse exits because a
    command line argument was invalid or -h, --help, or --version was
    provided on the command line.

    :param MemoryHandler memory_handler: memory handler to flush
    :param tuple args: args for post_arg_parse_except_hook
    :param dict kwargs: kwargs for post_arg_parse_except_hook

    Tr6N)rJr@)r-r�r�s   r0r'r'3s9��()�"�D�3�F�3�	���4��(�����4��(�s� �4�exc_type�	exc_value�tracerrrc�@���|||f}d	��fd�}|st|t�sntjtj
ksJ�|tur*tjd�tjd�tjd|���n	tjd|��t|tj�r%tjt|��|�tjd�tj |�rAtjt#j$t'tj|���nHt)j*||�}tjdj-|�j/��|�y)
aaLogs fatal exceptions and reports them to the user.

    If debug is True, the full exception and traceback is shown to the
    user, otherwise, it is suppressed. sys.exit is always called with a
    nonzero status.

    :param type exc_type: type of the raised exception
    :param BaseException exc_value: raised exception
    :param traceback trace: traceback of where the exception was raised
    :param bool debug: True if the traceback should be shown to the user
    :param bool quiet: True if Certbot is running in quiet mode
    :param str log_path: path to file or directory containing the log

    Nc�L���rtjd�yt��y)N�)r(�exit�exit_with_advice)rrs��r0�	exit_funcz-post_arg_parse_except_hook.<locals>.exit_funcbs�����H�H�Q�K��X�&r2zExiting due to user request.r�zExiting abnormally:)�exc_infozAn unexpected error occurred:rsr�)�
issubclass�	ExceptionrrBr�ERROR�KeyboardInterruptrGrcr(r�rrr^r}r
�
is_acme_error�display_util�describe_acme_errorr�	traceback�format_exception_onlyrZ�rstrip)	r�r�r�rrrr�r��outputs	    ``   r0rJrJOs���"�)�U�+�H�'�
�J�x��3��,�,��
�
�=�=�=��(�(��L�L�7�8��H�H�Q�K����*�X��>����*�X��>��h����-��L�L��Y��(��K����4�5��!�!�)�,��L�L��9�9�$�x�~�~�y�:Y�Z�[��4�4�X�y�I�F�

�L�L������/�/�1�2�
�Kr2c��d}tjj|�r
|d|�d�z
}n	|d|�d�z
}|dz
}tj|�y)z�Print a link to the community forums, the debug log path, and exit

    The message is printed to stderr and the program will exit with a
    nonzero status.

    :param str log_path: path to file or directory containing the log

    zSAsk for help or search for solutions at https://community.letsencrypt.org. See the zlogfiles in � zlogfile z+or re-run Certbot with -v for more details.N)rr*�isdirr(r�)rrOs  r0r�r��sU���C�	�w�w�}�}�X����h�Z�q�)�)����(��1�%�%���8�8�C��H�H�S�Mr2r�)2r{r%r�logging.handlersr�r(r�r��typesr�typingrrrrrr	�acmer
�certbotrrr
�certbot._internalr�certbot._internal.displayr��certbot.compatrrrr!rxrGr1�NamespaceConfigrQr}r�r:�
StreamHandlerrr;rrr'�
BaseExceptionr�rJr�r�r2r0�<module>r�s}���.���
�
�����������!���'�:����;��
��	�	�8�	$��($�V1D��!>�!>�1D�4�1D�h"�=�#@�#@�"�3�"� #�"�(-�g�o�o�s�.B�(C�"�@�7�0�0��@*�G�$�$�2�2�*�Z-�'�'�'�-�`)�m�)�%(�)�47�)�<@�)�82��m�)<�2��2�&3�2�<@�2�IM�2�),�2�15�2�j�s��t�r2

Zerion Mini Shell 1.0