HEX
Server: Apache
System: Linux infong-uk86 4.4.400-icpu-106 #2 SMP Mon Sep 15 08:23:40 UTC 2025 x86_64
User: u44115835 (4976590)
PHP: 8.4.17
Disabled: NONE
Upload Files
File: //kunden/lib/python3/dist-packages/breezy/__pycache__/trace.cpython-39.pyc
a

�*�^�W�@s�dZddlmZddlZddlZddlZddlZddlZddlmZee	�d�ddl
Z
ee	�d�ddlmZdd	l
mZmZmZdadadae
jZe�d
�Zdd�Zd
d�Zdd�ZGdd�de�Zdd�Zdd�Zdd�Zdd�Z dd�Z!dd�Z"dOdd �Z#d!d"�Z$d#d$�Z%d%d&�Z&d'd(�Z'dPd*d+�Z(dQd,d-�Z)d.d/�Z*d0d1�Z+dRd3d4�Z,d5Z-dSd6d7�Z.d8d9�Z/dTd;d<�Z0d=d>�Z1d?d@�Z2dUdAdB�Z3dCdD�Z4dEdF�Z5dGdH�Z6GdIdJ�dJej7�Z8GdKdL�dLe9�Z:GdMdN�dNe:�Z;dS)Va�Messages and logging.

Messages are supplied by callers as a string-formatting template, plus values
to be inserted into it.  The actual %-formatting is deferred to the log
library so that it doesn't need to be done for messages that won't be emitted.

Messages are classified by severity levels: critical, error, warning, info,
and debug.

They can be sent to two places: stderr, and `$XDG_CACHE_HOME/breezy/brz.log`.
For purposes such as running the test suite, they can also be redirected away
from both of those two places to another location.

`brz.log` gets all messages, and full tracebacks for uncaught exceptions.
This trace file is always in UTF-8, regardless of the user's default encoding,
so that we can always rely on writing any message.

Output to stderr depends on the mode chosen by the user.  By default, messages
of info and above are sent out, which results in progress messages such as the
list of files processed by add and commit.  In debug mode, stderr gets debug messages too.

Errors that terminate an operation are generally passed back as exceptions;
others may be just emitted as messages.

Exceptions are reported in a brief form to stderr so as not to look scary.
BzrErrors are required to be able to format themselves into a properly
explanatory message.  This is not true for builtin exceptions such as
KeyError, which typically just str to "0".  They're printed in a different
form.
�)�absolute_importN�)�lazy_importz"
import tempfile
import traceback
zI
from breezy import (
    bedding,
    debug,
    osutils,
    ui,
    )
)�errors)�PY3�StringIO�	text_type�brzcOstj��tj|i|��dS)zbOutput a note to the user.

    Takes the same parameters as logging.info.

    :return: None
    N)�ui�
ui_factory�
clear_term�_brz_logger�info��args�kwargs�r�./usr/lib/python3/dist-packages/breezy/trace.py�notess

rcOstj��tj|i|��dS�N)r
rrr
�warningrrrrr�s
rcOstj|i|��dS)ziShow an error message to the user.

    Don't use this for exceptions, use report_exception instead.
    N)r
�errorrrrr�
show_error�src@s eZdZdZdd�Zdd�ZdS)�_Bytesz.Compat class for displaying bytes on Python 2.cCsdt�|�S)N�b)�str�__repr__��selfrrrr�sz_Bytes.__repr__cCs|�dd�S)N�ascii�replace)�decoderrrr�__unicode__�sz_Bytes.__unicode__N)�__name__�
__module__�__qualname__�__doc__rr"rrrrr�srcGs�tdurdSttdd�dur&tjr&dSt|t�r<|�dd�}|r`tsVtdd�|D��}||}n|}t��}d|t	|f}t�
|�d��dS)N�closedrr css$|]}t|t�rt|�n|VqdSr)�
isinstance�bytesr)�.0�argrrr�	<genexpr>�szmutter.<locals>.<genexpr>z
%0.3f  %s
�utf-8)�_trace_file�getattrr'r(r)r!r�tuple�time�_brz_log_start_time�write�encode)�fmtr�outZnowrrr�mutter�s 
�
r7cGsft�}|durd}n|d}tj||d�|����}d�|dd��}t|dg||f�R�dS)z�Perform a mutter of fmt and args, logging the call trace.

    :param stacklevel: The number of frames to show. None will show all
        frames.
    :param fmt: The format string to pass to mutter.
    :param args: A list of substitution variables.
    Nr)�limit�file�
���z
Called from:
%s)r�	traceback�print_stack�getvalue�
splitlines�joinr7)�
stacklevelr5rZoutfr8Zformatted_linesZformatted_stackrrr�mutter_callsite�srBcCsXddl}z6t�|�|j}|dkr(WdS|d}t�||�WntyRYdS0dS)Nri@z.old)�stat�os�ST_SIZE�osutils�rename�OSError)Ztrace_fnamerC�sizeZ	old_fnamerrr�_rollover_trace_maybe�srJcCs$t�d�}|r|Stj�t��d�S)z�Return the brz log filename.

    :return: A path to the log file
    :raise EnvironmentError: If the cache directory could not be created
    ZBRZ_LOGzbrz.log)rFZpath_from_environrD�pathr@ZbeddingZ	cache_dir)Zbrz_logrrr�_get_brz_log_filename�s
rLc
Cs�dd�}zPt�att�|t�}|�d�|��dkrT|�d�|�d�|�d�|WSty�}ztj�d|f�WYd	}~n
d	}~00d	S)
z�Open the brz.log trace file.

    If the log is more than a particular length, the old file is renamed to
    brz.log.old and a new file is started.  Otherwise, we append to the
    existing file.

    This sets the global _brz_log_filename.
    c
Ss�tjtjBtjB}zt�||�}Wq�Wn2tyX}z|jtjkrD�WYd}~n
d}~00zt�||tj	Btj
Bd�}Wn2ty�}z|jtjkr��WYd}~qd}~00t�|�q�qt�
|dd�S)aOpen existing log file, or create with ownership and permissions

        It inherits the ownership and permissions (masked by umask) from
        the containing directory to cope better with being run under sudo
        with $HOME still set to the user's homedir.
        Ni�Zabr)rD�O_WRONLY�O_APPENDrFZO_TEXT�openrH�errnoZENOENT�O_CREAT�O_EXCLZEEXISTZcopy_ownership_from_path�fdopen)�filename�flags�fd�errr�_open_or_create_log_file�s
z/_open_brz_log.<locals>._open_or_create_log_file�
�s=this is a debug log for diagnosing/reporting problems in brz
s=you can delete or truncate this file, or include sections in
s8bug reports to https://bugs.launchpad.net/brz/+filebug

zfailed to open trace file: %s
N)rL�_brz_log_filenamerJr3�tell�EnvironmentError�sys�stderr)rX�brz_log_filerWrrr�
_open_brz_log�s(
���(racCs�tjtdd�}t�}|dur0|�|�d�d�t|dd�}tjdd	krdt	tj
t��d
tj
d�}ntjtj
d�}t�d
��|�|S)a�Configure default logging: messages to stderr and debug to brz.log

    This should only be called once per process.

    Non-command-line programs embedding breezy do not need to call this.  They
    can instead either pass a file to _push_log_file, or act directly on
    logging.getLogger("brz").

    Output can be redirected away by calling _push_log_file.

    :return: A memento from push_log_file for restoring the log state.
    Zlocal)�timezoneNr-rYzA[%(process)5d] %(asctime)s.%(msecs)03d %(levelname)s: %(message)sz%Y-%m-%d %H:%M:%SrrZr ��level)�streamr	)rFZformat_local_dater2rar3r4�
push_log_filer^�version_info�EncodedStreamHandlerr_Zget_terminal_encoding�logging�INFOZ
StreamHandler�	getLogger�
addHandler)Z
start_timer`ZmementoZstderr_handlerrrr�enable_default_loggings&
���rmcCs~t|dtjd�}|durd}|�t�||��t�d�}|jdd�}|jdd�=|�|�|�tj�t	}|a	d||||fS)z�Intercept log and trace messages and send them to a file.

    :param to_file: A file-like object to which messages will be sent.

    :returns: A memento that should be passed to _pop_log_file to restore the
        previously active logging.
    r-rcNz%(levelname)8s  %(message)sr	Zlog_memento)
rhri�DEBUGZsetFormatterZ	Formatterrk�handlersrl�setLevelr.)Zto_fileZ
log_formatZdate_format�new_handler�
brz_logger�old_handlers�old_trace_filerrrrf?s


rfcCsH|\}}}}}|at�d�}|�|�|��||_|durD|��dS)z�Undo changes to logging/tracing done by _push_log_file.

    This flushes, but does not close the trace file (so that anything that was
    in it is output.

    Takes the memento returned from _push_log_file.r	N)r.rirkZ
removeHandler�closero�flush)�entry�magicrsrqrtZnew_trace_filerrrrr�pop_log_fileas

rycCstt���dS)z�Log the last exception to the trace file only.

    Used for exceptions that occur internally and that may be
    interesting to developers but not to users.  For example,
    errors loading plugins.
    N)r7r<�
format_excrrrr�log_exception_quietlyusr{cCs$|at|dk�tj�|dk�dS)z]Set the verbosity level.

    :param level: -ve for quiet, 0 for normal, +ve for verbose
    rN)�_verbosity_level�_update_logging_levelr
r�be_quietrcrrr�set_verbosity_levelsrcCstS)zHGet the verbosity level.

    See set_verbosity_level() for values.
    �r|rrrr�get_verbosity_level�sr�TcCs|rtd�ntd�dS)N���r)r��quietrrrr~�s
r~cCs"|rt�tj�nt�tj�dS)zHide INFO messages if quiet.N)r
rpriZWARNINGrjr�rrrr}�sr}cCstdkS)z Is the verbosity level negative?rr�rrrr�is_quiet�sr�cCstdkS)z Is the verbosity level positive?rr�rrrr�
is_verbose�sr��cCs6tjdkr&ddlm}|j||d�nt||d�dS)zWrite out a memory dump.Zwin32r)�
win32utils)�message�shortN)r^�platform�breezyr�Zdebug_memory_win32api�_debug_memory_proc)r�r�r�rrr�debug_memory�s
r�)ZVmPeakZVmSizeZVmRSScCs�ztdt��d�}Wnty*YdS0z|��}W|��n
|��0|rXt|�|��D]2}|srt|�q`tD]}|�	|�rvt|�q`qvq`dS)Nz/proc/%s/status�rb)
rOrD�getpid�IOError�readrurr?�
_short_fields�
startswith)r�r�Zstatus_fileZstatus�lineZfieldrrrr��s 


r�c	Cs�z�zFtjddd�\}}t�|d�}ddlm}|�|�|�d|�WnBtyj|�d�t	�Yn"t
y�|�d	�t	�Yn0W|dur�|��q�|dur�t�|�n&|dur�|��n|dur�t�|�0dS)
NZbrz_memdumpz.json)�prefix�suffix�wr)�scannerzMemory dumped to %s
z'Dumping memory requires meliae module.
z Exception while dumping memory.
)ZtempfileZmkstemprDrSZmeliaer�Zdump_gc_objectsr3�ImportErrorr{�
BaseExceptionru)�err_filerV�nameZ	dump_filer�rrr�_dump_memory_usage�s*




�
r�FcCs0|j}|j}|dvs |r$|dkr$|Sd||fS)z�Give name of error class including module for non-builtin exceptions

    If `unqualified_breezy_errors` is True, errors specific to breezy will
    also omit the module prefix.
    )�builtins�
exceptions�__main__z
breezy.errorsz%s.%s)r#r$)ZeclassZunqualified_breezy_errors�
class_nameZmodule_namerrr�_qualified_exception_name�s��r�cCst�dtjvr t||�tjS|\}}}t|t�rD|�d�tjSt|t	�r||�d�dtjvrlt
|�n
|�d�tjSt|t�r�t|��
d�r�t||d�tjSt|dd	�s�t||�tjSt�|��rt|d
d�tjkr�|�d�tjSt||�tjSt||�tjSdS)
z�Report an exception to err_file (typically stderr) and to brz.log.

    This will show either a full traceback or a short message as appropriate.

    :return: The appropriate exit code for this error.
    rzbrz: interrupted
zbrz: out of memory
Zmem_dumpz)Use -Dmem_dump to dump memory to a file.
zNo module named z7You may need to install this Python library separately.Zinternal_errorTrPNzbrz: broken pipe
)r{�debugZdebug_flags�print_exceptionrZ
EXIT_ERRORr(�KeyboardInterruptr3�MemoryErrorr�r�rr��report_user_errorr/rFZis_environment_errorrP�EPIPE�
report_bugZEXIT_INTERNAL_ERROR��exc_infor��exc_typeZ
exc_object�exc_tbrrr�report_exception�sB










��



r�cCs@|\}}}|�dt|�|f�|�d�tj||||d�dS)Nzbrz: ERROR: %s: %s
r:)r9)r3r�r<r�r�rrrr�s
�
r�cCs.|�dt|d�f�|r*|�d|�dS)aReport to err_file an error that's not an internal error.

    These don't get a traceback unless -Derror was given.

    :param exc_info: 3-tuple from sys.exc_info()
    :param advice: Extra advice to the user to be printed following the
        exception.
    zbrz: ERROR: %s
rz%s
N)r3r)r�r�Zadvicerrrr�%s	r�cCsddlm}|||�dS)z8Report an exception that probably indicates a bug in brzr)r�N)Zbreezy.crashr�)r�r�r�rrrr�3sr�c
Cspztj��tj��WnRty*YnBtyj}z*ddl}|j|j|jfvrTn�WYd}~n
d}~00dS)Nr)	r^�stdoutrvr_�
ValueErrorr�rPZEINVALr�)rWrPrrr�_flush_stdout_stderr9s
r�cCstrt��dSr)r.rvrrrr�_flush_traceJsr�c@s*eZdZdZddd�Zdd�Zd	d
�ZdS)rhawRobustly write logging events to a stream using the specified encoding

    Messages are expected to be formatted to unicode, but UTF-8 byte strings
    are also accepted. An error during formatting or a str message in another
    encoding will be quitely noted as an error in the Bazaar log file.

    The stream is not closed so sys.stdout or sys.stderr may be passed.
    N�strictrcCs8tj�||�||_|dur(t|dd�}||_||_dS)N�encodingr)ri�Handler�__init__rer/r�r)rrer�rrdrrrr�[szEncodedStreamHandler.__init__cCs t|jdd�}|dur|�dS)Nrv)r/re)rrvrrrrvcszEncodedStreamHandler.flushcCs�z`t|jt�s$|j�d�}tr$||_|�|�}t|t�sB|�d�}|j�|�|j	|j
�d�WnXty�t�d}}zt
|j�}t
|j�}Wnty�Yn0td||�Yn0dS)Nr-rYz<Unformattable>z&Logging record unformattable: %s %% %s)r(�msgrr!r�formatrer3r4r�r�	Exceptionr{�reprrr7)r�recordr�r�rrrr�emiths$


 
zEncodedStreamHandler.emit)Nr�r)r#r$r%r&r�rvr�rrrrrhQs	
rhc@s eZdZdZdd�Zdd�ZdS)�ConfigaConfiguration of message tracing in breezy.

    This implements the context manager protocol and should manage any global
    variables still used. The default config used is DefaultConfig, but
    embedded uses of breezy may wish to use a custom manager.
    cCs|Srrrrrr�	__enter__�szConfig.__enter__cCsdS�NFr�rr�Zexc_valr�rrr�__exit__�szConfig.__exit__N�r#r$r%r&r�r�rrrrr��sr�c@s eZdZdZdd�Zdd�ZdS)�
DefaultConfigzrA default configuration for tracing of messages in breezy.

    This implements the context manager protocol.
    cCst|_t�|_|Sr)r[�_original_filenamerm�_original_staterrrrr��szDefaultConfig.__enter__cCst|j�|jadSr�)ryr�r�r[r�rrrr��s
zDefaultConfig.__exit__Nr�rrrrr��sr�)NN)T)T)r�T)r�T)F)N)<r&Z
__future__rrPrirDr^r1r�globalsr�r�rZsixishrrrr|r.r[Z_start_timer2rkr
rrrrrr7rBrJrLrarmrfryr{rr�r~r}r�r�r�r�r�r�r�r�r�r�r�r�r�r�rh�objectr�r�rrrr�<module>sd	

A"
"



	

-	
/