HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /proc/1991109/root/usr/lib/python3/dist-packages/reportbug/__pycache__/
Upload File :
Current File : //proc/1991109/root/usr/lib/python3/dist-packages/reportbug/__pycache__/utils.cpython-311.pyc
�

4�Ad���2�ddlZddlZddlZddlZ	ddlZddlmZmZnA#e$r9Z	ej
��dkrnee	��ejd��YdZ	[	ndZ	[	wwxYwddl
Z
ddlZddlZddlZddlZddlZddlZddlmZddlmZdZdgZd	d
ddd
�Zgd
�ZeD]7Zede���e�e��fz���8[ddl m!Z!ddl"m#Z#dZ$gd�Z%dddddddddd�	Z&e'd�e(e&�)����D����Z*ej+��Z,d�Z-gd�Z.d �Z/dVd!�Z0d"�Z1dWd$�Z2d%�Z3dWd&�Z4dXd(�Z5d)�Z6d*�Z7d+�Z8dYd-�Z9dZd/�Z:iZ;dXd0�Z<Gd1�d2e=��Z>d3�Z?d4�Z@d5�ZAd6�ZBdXd7�ZCdXd8�ZDd9�ZEd[d;�ZFdXd<�ZGgd=�ZHd>�ZId?�ZJd@�ZKdA�ZLdB�ZMd,d,dCddd,d,d,d,eNddd'dfdD�ZOGdE�dFe
j
��ZPejQ�RdG��ZSdHeSfZTdIZUdJ�ZVdK�ZWdL�ZXdM�ZYdN�ZZdO�Z[ej
fdP�Z\dQ�Z]dR�Z^dS�Z_dT�Z`dU�ZadS)\�N�)�TempFile�cleanup_temp_file�Windows)�open_url)�MUA)�Package�Source�Version�Severity�File�Tags�
JustificationzFollowup-For�Owner�User�Usertags�	Forwarded�Control�X-Debbugs-Ccrz4Offer simple prompts, bypassing technical questions.z�Offer more extensive prompts, including asking about things that a moderately sophisticated user would be expected to know about Debian.zRLike standard, but assumes you know a bit more about Debian, including "incoming".z�Bypass most handholding measures and preliminary triage routines.  This mode should not be used by people unfamiliar with Debian's policies and operating procedures.)�novice�standard�advanced�expertz
MODE_%s=%d)�debbugs)�
AVAILABLE_UISafDear Maintainer,

*** Reporter, please consider answering these questions, where appropriate ***

   * What led up to the situation?
   * What exactly did you do (or not do) that was effective (or
     ineffective)?
   * What was the outcome of this action?
   * What outcome did you expect instead?

*** End of the template - remove these template lines ***)�/z/usrz
/usr/sharez/varz
/usr/X11R6z/usr/manz/usr/doc�/usr/bin�oldoldoldoldstable�oldoldoldstable�oldoldstable�	oldstable�stable�testingznext-testing�unstable�experimental)	�jessie�stretch�buster�bullseye�bookworm�trixie�forky�sidr%c��g|]	\}}||f��
S�r/)�.0�codename�suites   �1/usr/lib/python3/dist-packages/reportbug/utils.py�
<listcomp>r4bs!��]�]�]�_�X�u��x�(�]�]�]�c��tj�|��}|�d��}t	dt|��dz��D]�}d�|d|���}|tvr�)tj�|��r�tj	|��}tj�|��\}}tj�
tj�||����}tjj|g||d�z�}t|��cS��|S)a�
    Return the real path of file `filename`

    This is similar to ``os.path.realpath()``. The difference is that
    symlinks to a small set of basic directories are not resolved and
    just kept in the path if present.

    This function is a helper function called only by
    :func:`search_path_for()`.

    Parameters
    ----------
    filename : string
        name of a file, may include relative or absolute path

    Returns
    -------
    str
        the real path of the given file
    r�rrN)�os�path�abspath�split�range�len�join�fhs_directories�islink�readlink�normpath�realpath)�filename�bits�i�	component�resolved�dir�file�newpaths        r3rCrCgs��*�w���x�(�(�H��>�>�#���D�
�1�c�$�i�i�!�m�
$�
$�
%�
%���H�H�T�!�A�#�Y�'�'�	���'�'��
�7�>�>�)�$�$�	%��{�9�-�-�H��'�-�-�	�2�2�K�S�$��w�'�'�����S�(�(C�(C�D�D�H��g�l�X�J��a�b�b��$9�:�G��G�$�$�$�$�$�	%��Or5)�	/usr/sbinrz/sbinz/binz/usr/X11R6/binz
/usr/gamesc���tj�|��\}}|rt|��Stj�dtj���d��}tD]}||vr|�|���|D]R}tj�	||��}tj�
|��rt|��cS�SdS)a�
    Searches for a file in PATH and common application directories

    Given the filename of an executable, this function tries to locate
    the file in common application directories (/usr/sbin, /usr/bin/,
    /sbin, /bin, /usr/X11R6/bin, /usr/games) and in any additional
    directories included in PATH.

    :func:`realpath()` is called on the result (if found).

    This function is a helper function called only by
    :func:`find_package_for()`.

    Parameters
    ----------
    filename : string
        name of a file, may include relative or absolute path

    Returns
    -------
    str or None
        the real path of the given file; None if the file was not found
    �PATH�:N)r8r9r;rC�environ�get�defpath�pathdirs�appendr>�exists)rD�d�fr9�fullnames     r3�search_path_forrY�s���0�7�=�=��"�"�D�A�q��"���!�!�!�
�:�>�>�&�"�*�-�-�3�3�C�8�8�D�
�����D�=�=��K�K��N�N�N��
�&�&���7�<�<��1�%�%��
�7�>�>�(�#�#�	&��H�%�%�%�%�%�	&��4r5c��d}|tj�d��tj�d��|fD]}|rn�|S)a
    Determine which editor program to use

    Parameters
    ----------
    specified_editor : str
        Specified editor for reportbug, to be used in preference
        to other settings.

    Returns
    -------
    str
        Command to invoke for selected editor program.
    z/usr/bin/sensible-editor�VISUAL�EDITOR)r8rPrQ)�specified_editor�debian_default_editor�editors   r3�which_editorr`�s^��7��#��:�>�>�(�+�+��:�>�>�(�+�+�(�*�����	��E�	��Mr5c�2�tjdd|��}|S)a8
    Escape globbing pattern characters with backslash

    This function is a helper function used only by
    :func:`query_dpkg_for()`.

    Parameters
    ----------
    filename : str
        filename, possibly using a globbing pattern

    Returns
    -------
    str
        escaped filename (pattern)
    z
([*?\[\]])z\\\1)�re�sub)rDs r3�glob_escaperd�s��"�v�m�W�h�7�7�H��Or5Tc���tj|��}|r7tj�d��rtjd|z��}nd}tjd|z��}||fS)ap
    Search for a file in a debian binary package

    This is done by opening a pipe to capture the output of ``dlocate``
    or ``dpkg``.

    This function is a helper function used only by
    :func:`query_dpkg_for()`.

    Parameters
    ----------
    searchfile : str
        the file to look for
    use_dlocate : bool
        try to search using dlocate (which is fast, but may not be
        available) or always use dpkg (always available, but slow)

    Returns
    -------
    (pipe, bool)
        Tuple with the pipe and a bool, the latter indicating whether
        dlocate was used (True) or not (False)
    z/usr/bin/dlocatez$COLUMNS=79 dlocate -S %s 2>/dev/nullFz'COLUMNS=79 dpkg --search %s 2>/dev/null)�shlex�quoter8r9rU�popen)�
searchfile�use_dlocate�arg�pipes    r3�search_piperm�so��0�+�j�
!�
!�C��I�r�w�~�~�&8�9�9�I��x�>��D�E�E������x�A�C�G�H�H���+��r5c��d}t|t��rd|vrd}tj||tj���j�d���S)a�
    Capture the output of a program

    Since reportbug needs to be able to run in misconfigured locales, we
    need to specify an error handler whenever some external input is
    processed.  This wrapper function avoids having to specify this
    separately for each program invocation.

    Parameters
    ----------
    cmd : str or tuple
        The command to execute including any options and arguments

    Returns
    -------
    str
        The output (stdout) of the command
    F� T)�shell�stdout�backslashreplace��errors)�
isinstance�str�
subprocess�run�PIPErq�decode)�cmd�	use_shells  r3�get_command_outputr}
sV��&�I��#�s�����s�
�
��	��>�#�Y�z��G�G�G�N�U�U�]o�U�p�p�pr5c��	tj��}n$#t$rtjd��YnwxYwt	|��}t||��\}}i}|D]�}|���}d|vr�|�dd��\}}	|	���}	|�d��}
|
D](}||vr||�|	���"|	g||<�)��|�	��|s|rt|d���\}}|s.|�d��r|d	d
�}t|��S||fS)av
    Search for a file in a debian binary package

    This is done using ``dlocate`` or ``dpkg``.

    This function is a helper function used only by
    :func:`find_package_for()`.

    Parameters
    ----------
    filename : str
        the file to look for
    use_dlocate : bool
        try to search using dlocate (which is fast, but may not be
        available) or always use dpkg (always available, but slow)

    Returns
    -------
    (str, dict)
        Tuple with the original filename input parameter and a
        dictionary with matching packages as keys and lists of
        corresponding files as values.
    rzdiversion by�: r�, F)rj)r�/usr/librL�N)r8�getcwd�OSError�chdirrdrm�stripr;rT�close�query_dpkg_for�
startswith)rDrj�_�searchfilenamerl�dlocate_used�packages�line�packager9�packlists           r3r�r�#s���0��I�K�K��������
���
�
�
�
�
����� ��*�*�N�&�~�{�C�C��T�<��H��
+�
+���z�z�|�|���T�!�!���*�*�T�1�-�-���$��z�z�|�|���=�=��&�&���	+�	+�G��(�"�"���!�(�(��.�.�.�.�%)�F���!�!�		+�
	�J�J�L�L�L��B��B�$�X�5�A�A�A���8��(��+�+�,Q�R�R�(��A�B�B�<���h�'�'�'��X��s��7�7Fc�R�i}|�d��rEtjd��}|�|��}d||�d��<||fS|ddkrt|��\}}|r||fSt
|��}|r|s|dfSt|p|��S)av
    Find the package(s) containing this file

    Parameters
    ----------
    filename : str
        The name of the file including any path components
    pathonly : bool
        If no path component is part of the file name, specify if the
        file should be looked for in the ``PATH`` (directories with
        executables) only or if the entire dpkg database should be
        searched.

    Returns
    -------
    (str, dict)
        Tuple with file name (possibly modified from input parameter
        filename) and a dictionary with matching packages as keys and
        lists of corresponding files as values.
    z/var/lib/dpkg/info/z/var/lib/dpkg/info/(.+)\.[^.]+�rrrN)r�rb�compile�match�groupr�rY)rD�pathonlyr��	dpkg_info�m�fn�pkglist�newfilenames        r3�find_package_forr�`s���*�H����0�1�1�$��J�@�A�A�	��O�O�H�%�%��!����������(�#�#���{�c���$�X�.�.���G��	��w�;��!�(�+�+�K�� �� ��$����+�1��2�2�2r5c��d}	t|d���}n#t$rYdSwxYw|5|D]�}|����d��d}|s�2	|�d��\}}|���|kr"|���ccddd��S��#t$r"td|z��Yddd��dSwxYw	ddd��dS#1swxYwYdS)	a�
    Lookup email alias of user `username`

    Checks if there is an email alias for the user `username` configured
    for outgoing mail (in '/etc/email-addresses') and returns that
    alias.

    This is a helper function for :func:`get_user_id()`.

    Parameters
    ----------
    username : str
        the username to look up

    Returns
    -------
    str or None
        an email address (or None if not found)
    z/etc/email-addressesrrrsN�#rrOzInvalid entry in %s)�openr�r�r;�
ValueError�print)�usernamerD�fpr��name�aliass      r3�find_rewrittenr��s���(&�H��
�(�#5�
6�
6�
6���������t�t�����	����
	�
	�D��:�:�<�<�%�%�c�*�*�1�-�D��
��
�"�j�j��o�o���e��:�:�<�<�8�+�+� �;�;�=�=�(�(���������,���
�
�
��+�h�6�7�7�7��t���������
����
	���������������������sH��
$�$�5C/�AB2�"C/�1C/�2C�C/�C�C/�/C3�6C3c�n�d|vrdS|�d��dkrdS|�d��\}}|�d��s|�d��rdSd|vrdS|�d��s|�d��rdS|dvrdS|�d��rdSdS)a7
    Simple check for email validity

    Performs some simple checks on whether the given string looks like
    an email address.

    Parameters
    ----------
    addr : str
        string to check

    Returns
    -------
    bool
        True if the string looks like an email address, otherwise False
    �@Fr�.)�	localhostzexample.comzexample.netzexample.org)z.examplez.invalidz
.localhostz.testz.example.comz.example.netz.example.orgT)�countr;r��endswith)�addr�	localpart�
domainparts   r3�check_email_addrr��s���"�$����u��z�z�#���!����u� �J�J�s�O�O��I�z����C� � ��I�$6�$6�s�$;�$;���u�
�*����u����S�!�!��Z�%8�%8��%=�%=���u��O�O�O��u����L�M�M���u��4r5c�N�tj�|g��dS)a�
    Extract email address from a string

    Email addresses are often accompanied by a name: ``My Name
    <my@domain.org>`` or ``my@address.info (My Name)``. This function
    tries to separate the two parts and returns a (name, address) tuple.

    Parameters
    ----------
    addr : str
        an email address (possibly including a name component)

    Returns
    -------
    (str, str)
        Tuple containing the name (if found, otherwise empty string) and
        the plain email address
    r)�email�utils�getaddresses)r�s r3�get_email_addrr��s!��&�;�#�#�T�H�-�-�a�0�0r5r�c�<�tt||����S)a"
    Get the user's email address and name

    If name and email address are not given, try to obtain the missing
    info for the current user and return the result.

    Parameters
    ----------
    emailaddr : str
        an email address (possibly including a name component)
    realname : str
        Real name (will be ignored if the `emailaddr` string contains a name
        component)

    Returns
    -------
    (str, str)
        Tuple containing the name (if found, otherwise empty string) and
        the plain email address
    )r��get_user_id)�	emailaddr�realnames  r3�	get_emailr��s��*�+�i��:�:�;�;�;r5�utf-8c�(�tj��}tj|��}tj�d|��p=tj�d��ptj�d��}|pt
|d��p|d}d|vr{	tdd��5}|����	��}ddd��n#1swxYwYn##t$rtj��}YnwxYw|dz|z}d	|vsd
|vrt|��\}}|s�tj�d��p=tj�d��ptj�d
��}|sP|d�dd��d}|�d|d�����}|s|St"j�||f��S)a�
    Find email address of the current user

    This is similar to :func:`get_email()`, but returns a single string
    instead of a (name, address) tuple.

    Parameters
    ----------
    emailaddr : str
        address, if already known, possibly including a name component.
        Note that if the 'REPORTBUGEMAIL' environment variable is set,
        its value will overwrite this parameter.
    realname : str
        real name, if already known.
    charset : str
        not used

    Returns
    -------
    str
        email address string, including a name component if available
        (RFC2047-encoded if the name contains non-ASCII characters)
    �REPORTBUGEMAIL�DEBEMAIL�EMAILrr�z
/etc/mailname�rN�<�(�DEBFULLNAME�DEBNAME�NAMEr��,r�&)r8�getuid�pwd�getpwuidrPrQr�r��readliner�r��socket�getfqdnr�r;�replace�
capitalizer�r��
formataddr)r�r��charset�uid�info�mf�
domainnames       r3r�r�s2��0
�)�+�+�C��<����D����� 0�)�<�<�,��J�N�N�:�.�.�,��J�N�N�7�+�+���?�^�D��G�4�4�?��Q��I�
�)���	*��o�s�+�+�
3�r��[�[�]�]�0�0�2�2�
�
3�
3�
3�
3�
3�
3�
3�
3�
3�
3�
3����
3�
3�
3�
3����	*�	*�	*���)�)�J�J�J�	*������O�j�0�	��i���3�)�+�+�,�Y�7�7���)��C��J�N�N�=�1�1�.�R�Z�^�^�I�5N�5N�.��z�~�~�f�-�-�	��	C��A�w�}�}�S�!�,�,�Q�/�H��'�'��T�!�W�-?�-?�-A�-A�B�B�H������;�!�!�8�Y�"7�8�8�8s6�*C9�:'C-�!C9�-C1�1C9�4C1�5C9�9D�Dc��|s|tvr
t|Stjd��}tjd��}tjd��}tjd��}tjd��}tjd��}tjd��}tjd��}	tjd	��}
tjd
��}tjd��}tjd��}
tjd
��}tjd��}dx}x}x}x}}dx}x}x}x}x}}g}g}g}g}g}d} d}!d}"	tj��}#n$#t
$rtjd��YnwxYwtj|��}$|r|tvrtd|$z��}%nQd}%nN	td|$z�����d}$n#t$rYnwxYwtd|$z��}%|%�tj
��D�]�}&|&���}&|&s�|!r$|&ddkr|�|&��nd}!| r)|&dd�dkrd} n|tjd|&��z
}|�|&��r|&�dd��\}'}��|
�|&��r|&�dd��\}'}��|�|&��r|&�dd��\}'}��|�|&��r|&�dd��\}'}��(|�|&��r|&�dd��\}'}��X|�|&��r|&�dd��\}'}���|
�|&��r|s|&�dd��\}'}d}!���|�|&��rO|&�dd��\}'}(d�|(�d��D��}(|�|(���� |�|&��rO|&�dd��\}'}(d �|(�d��D��}(|�|(�����|�|&��rO|&�dd��\}'}(d!�|(�d��D��}(|�|(�����|�|&��rd} ��|	�|&��r|&�dd��\}'}��1|�|&��r5|&�dd��\}'}|���d}��{|�|&��r|&�dd��\}'}���d})|r|���d}"|"d"v})d}*|rt'j|��}*n~|rz|t&jvrWt&j|d#}t&j|�d$d%��t&j|d&f}*n|���}nd}||t1|��t1|��t1|��||)|||*|||tj
�|��|"t1|��|f}+|s
|+t|<|+S)'a�
    Get information on a binary package, including status

    Parameters
    ----------
    package : str
        the name of the package
    avail : bool
        if True, also look up the detailed package information if the
        package is not installed (with apt rather than dpkg)

    Returns
    -------
    (..., ...)
        A tuple with 17 components. The components are:

        0.  package version string or None
        1.  available package name or None
        2.  dependencies as a tuple containing lists, each list
            representing alternative dependencies
        3.  recommended packages as a tuple containing lists, each list
            representing alternative recommends
        4.  conffiles as a tuple containing (filename_str, md5sum_str)
            tuples
        5.  maintainer name and email address string
        6.  bool indicating whether the package is installed
        7.  origin (content of "Origin:" package header if available)
        8.  vendor of the package if available
        9.  reportinfo
        10. priority string
        11. package short description string (summary)
        12. source name if a source header is available
        13. full package description string (without summary line)
        14. package state string
        15. suggested packages as a tuple containing lists, each list
            representing alternative suggests
        16. archive section of the package
    z	Version: z	Package: z
Priority: z(Pre-)?Depends: zRecommends: z
Suggests: z
Conffiles:zMaintainer: zStatus: zOrigin: zBugs: zDescription(?:-[a-zA-Z]+)?: zSource: z	Section: NFr�rz,LC_ALL=C.UTF-8 apt-cache show %s 2>/dev/nullz4dpkg-query -W -f='${binary:Package}
' %s 2>/dev/nullrz'COLUMNS=79 dpkg --status %s 2>/dev/nullror7z /z (.+) ([0-9a-f]+).*$rrTc�L�g|]!}d�|�d��D����"S)c�B�g|]}|���d��S�r�r;�r0�ys  r3r4z1get_package_status.<locals>.<listcomp>.<listcomp>��$��?�?�?�Q�A�G�G�I�I�a�L�?�?�?r5�|r��r0�xs  r3r4z&get_package_status.<locals>.<listcomp>��A��?�?�?� �@�?�!�'�'�#�,�,�?�?�?�?�?�?r5r�c�L�g|]!}d�|�d��D����"S)c�B�g|]}|���d��Sr�r�r�s  r3r4z1get_package_status.<locals>.<listcomp>.<listcomp>�r�r5r�r�r�s  r3r4z&get_package_status.<locals>.<listcomp>�r�r5c�L�g|]!}d�|�d��D����"S)c�B�g|]}|���d��Sr�r�r�s  r3r4z1get_package_status.<locals>.<listcomp>.<listcomp>�r�r5r�r�r�s  r3r4z&get_package_status.<locals>.<listcomp>�r�r5)�config-filesz
not-installedr��typer�btsroot)�statuscacherbr�r8r�r�r�rfrg�
_apt_cacher}r;�
IndexError�linesep�rstriprT�findallr��extendr�
parse_bts_url�SYSTEMSrQr��tupler>),r��avail�	versionre�	packagere�
priorityre�	dependsre�recsre�
suggestsre�conffilesre�maintre�statusre�originre�bugsre�descre�srcre�	sectionre�
pkgversion�pkgavail�
maintainer�status�origin�bugs�vendor�priority�desc�src_name�section�	conffiles�fulldesc�depends�
recommends�suggests�confmode�descmode�stater��packarg�outputr��crud�thisdepends�	installed�
reportinfor�s,                                            r3�get_package_statusrCsj��N�$�W��+�+��7�#�#��
�;�'�'�I��
�;�'�'�I���L�)�)�J��
�-�.�.�I�
�Z��
'�
'�F���L�)�)�J��*�\�*�*�K��j��(�(�G��z�*�%�%�H��z�*�%�%�H�
�Z��
!�
!�F�
�Z�6�
7�
7�F��J�z�"�"�E��
�;�'�'�I�;?�?�J�?��?�J�?��&�;?�?�D�?�6�?�H�?�t�?�h���I��H��G��J��H��H��H��E���I�K�K��������
���
�
�
�
�
������k�'�"�"�G��A��j� � �'�>��H�J�J�F�F��F�F�	�(�G�'�Q�S�S�SX�SX�SZ�SZ�[\�^�G�G���	�	�	��D�	����#�5��?�A�A�����R�Z�(�(�;0�;0���{�{�}�}���	���	!��A�w�#�~�~�����%�%�%�%� ���	G��B�Q�B�x�4��� ����R�Z�(?��F�F�F�	��?�?�4� � �)	0�!%���D�!�!4�!4��T�:�:�
�^�^�D�
!�
!�'	0�!�Z�Z��a�0�0�N�T�6�6�
�
�
�d�
#�
#�%	0�#�z�z�$��2�2��T�8�8�
�_�_�T�
"�
"�#	0�#�z�z�$��2�2��T�8�8�
�^�^�D�
!�
!�!	0�!�Z�Z��a�0�0�N�T�6�6�
�\�\�$�
�
�	0��:�:�d�A�.�.�L�T�4�4�
�\�\�$�
�
�	0��	0��:�:�d�A�.�.�L�T�4��H�H�
�_�_�T�
"�
"�	0�"&�*�*�T�1�"5�"5��T�;�?�?�%0�%6�%6�t�%<�%<�?�?�?�K��N�N�;�'�'�'�'�
�\�\�$�
�
�	0�"&�*�*�T�1�"5�"5��T�;�?�?�%0�%6�%6�t�%<�%<�?�?�?�K����k�*�*�*�*�
�
�
�d�
#�
#�	0�"&�*�*�T�1�"5�"5��T�;�?�?�%0�%6�%6�t�%<�%<�?�?�?�K��O�O�K�(�(�(�(�
�
�
�t�
$�
$�	0��H�H�
�]�]�4�
 �
 �	0�#�z�z�$��2�2��D�*�*�
�[�[��
�
�	0�!�Z�Z��a�0�0�N�D�(��~�~�'�'��*�H�H�
�_�_�T�
"�
"�	0� �J�J�t�Q�/�/�M�D�'���I�
�E������q�!���"C�C�	��J��
��*�4�0�0�
�
�	���W�_�$�$��_�V�,�V�4�F�!�/�&�1�5�5�f�i�H�H�!�/�&�1�)�<�>�J�J��&�&�(�(�F�F�����%��.�.�%�
�2C�2C��)����	�6�6�:�x��(�B�J�O�O�H�5�5�u�e�H�o�o��	�D��$�#��G���Ks$�E,�,F
�F
�*G1�1
G>�=G>c�,�eZdZdZdd�Zd�Zd�Zd�ZdS)�AvailDBz�
    Split a pipe or file into chunks separated by empty lines

    This turns a pipe or file into an iterator that returns chunk by
    chunk on each next() call.
    Nc�J�||_|r	||_dS|r|j|_dSdS�N)�popenobr�rq)�selfr�r s   r3�__init__zAvailDB.__init__s;�����
�	%��D�G�G�G�
�	%��n�D�G�G�G�	%�	%r5c��|Srr/)r!s r3�__iter__zAvailDB.__iter__s���r5c��d}	|jr
|jjrn7|j���}|sn|dkr|S|t	|��z
}�K|r|St
�)Nr�T�
)r �
returncoder�r�rv�
StopIteration)r!�chunkr�s   r3�__next__zAvailDB.__next__s|����	��|�
��<�*����7�#�#�%�%�D��
���t�|�|����S��Y�Y��E�	��	��L��r5c���|jrE	|jjrn|j�d��}|sn�+|j���|jr|j���dSdS)NTi)r r'r��read�waitr�)r!�stuffs  r3�__del__zAvailDB.__del__&s����<�	 �
��<�*�������U�+�+�����
�
�L�������7�	��G�M�M�O�O�O�O�O�	�	r5)NN)�__name__�
__module__�__qualname__�__doc__r"r$r*r/r/r5r3rrs_��������%�%�%�%�������(����r5rc�f�tjddtjd���}t|���S)z�
    Get the dpkg status database as an :class:`AvailDB` object.

    This is a helper function for :func:`get_package_info()`.

    Returns
    -------
    AvailDB
        A :class:`AvailDB` object to access the dpkg status database
    )z
dpkg-queryz--statusrrT)rtrq�text�r �rw�Popenryr��subps r3�get_dpkg_databaser;5s5����6�?Q�Zd�Zi�pt�u�u�u�D��4� � � � r5c�d�tjdtjd���}t|���S)z�
    Get the database of available packages as an :class:`AvailDB` object

    This function is not used anywhere and might be removed soon.

    Returns
    -------
    AvailDB
        A :class:`AvailDB` object to access apt's available database
    )z	apt-cache�	dumpavailT)rqr5r6r7r9s r3�get_avail_databaser>Ds0����6�z��UY�Z�Z�Z�D��4� � � � r5c�B�	t|jdjS#t$rYnwxYw	tj���}|�|��r|jSn4#tjj	$r}td|�d���Yd}~nd}~wwxYwdS)z�
    Get the source package name of a given package

    Parameters
    ----------
    package : str
        the name of a (source or binary) package

    Returns
    -------
    str or None
        the name of the corresponding source package
    r� Cannot look up source package: '�'N)r��versions�source_name�KeyError�apt�apt_pkg�
SourceRecords�lookupr��Errorr�)r��
srcrecords�es   r3�get_source_namerLTs���
��'�"�+�A�.�:�:���
�
�
���
����7��[�.�.�0�0�
����W�%�%�	&��%�%�	&���;��7�7�7�
�5��5�5�5�6�6�6�6�6�6�6�6�����7�����4s#��
,�,�9A+�+B�?B�Bc��g}	tj���}|�|��r:|j|kr|�|j��|�|���:n4#tjj$r}td|�d���Yd}~nd}~wwxYwt|��dkr|dSdS)z�
    Get the package version of a given source package

    Parameters
    ----------
    package : str
        the name of a source package

    Returns
    -------
    str or None
        the version of the source package
    r@rANrr)
rErFrGrHr�rT�versionrIr�r=)�srcnamerBrJrKs    r3�get_source_versionrPps����H�7��[�.�.�0�0�
�����(�(�	4��!�W�,�,����
� 2�3�3�3�����(�(�	4����;��7�7�7�
�5��5�5�5�6�6�6�6�6�6�6�6�����7�����8�}�}������{���4s�A-A2�2B#�B�B#c�J�g}t��}	tj���}n6#tjj$r}td|�d���|cYd}~Sd}~wwxYw|�|��r�|j|vr�|r|j|kr�-|�|j��t|j
��D];}	t|jdj
}n#t$rY�-wxYw|r|||fgz
}�<|d|jzdfgz
}|�|����|S)a�
    Get list of binary packages belonging to a (source) package.

    Parameters
    ----------
    package : str
        the name of a (source or binary) package
    only_source : bool
        should be set to True if only source package names should be
        matched (like apt-cache showsrc --only-source)

    Returns
    -------
    [(str, str), ...]
        A list of (name, short description) tuples describing the binary
        packages belonging to the source package of the given package
    r@rANrzsrc:zSource package)�setrErFrGrIr�rHr��add�sorted�binariesr�rB�summaryrD)r��only_sourcer��foundrJrK�bpr
s        r3�get_source_packagerZ�sy��$�H��E�E�E���[�.�.�0�0�
�
���;�����
�5��5�5�5�6�6�6�����������������
�
�G�
$�
$�F����&�&���	�:�-��8�8��
�	�	�*�$�%�%�%���,�-�-�	)�	)�B�
�!�"�~�.�q�1�9�����
�
�
���
�����
)��b�$�Z�L�(����f�z�1�1�3C�D�E�E��#�
�
�G�
$�
$�F�&�Os-�1�A$�A�A$�A$�C#�#
C0�/C0c���|sgSt��}d}i}g}g}|D]6\}}|||<tj|��}	|�|	dz���7dd�|��zdzd|zdzd�|��zdz|zd	zg}t|�����}
i�d
�|D��}tjdtj��}tjdtj��}
tjd
tj��}tjdtj��}g}|D�]�}|D�]�}|�	|��}|�rw|�	|���
d��}|
�	|���
d��}|���}|dd|ddz}|ddvs|ddkr��|�
d��dkr.|�
d�����d}nd}|�	|���
d��}|�	|���
d��}|||||f}|�|��|�|��}|r
|D]}d�|<�|�vrd�|<������|r|S|
D]a}�fd�|D��}t|��t|��kr1|�vr-|�d�|��ddd df���b|S)!a�
    Collect information about one or more packages

    This is a helper function for :func:`packages_providing()` and
    :func:`get_dependency_info()`.

    Parameters
    ----------
    packages : [((str, ...), str), ...]
        List of ((pkg1, pkg2, ...), package) tuples about which to look
        up information. Each tuple consists of two elements:

        - another tuple specifying a "group" of package names
          representing alternative dependencies
        - one specific package name that should also be part of the
          group. Virtual package names are allowed.

    skip_notfound : bool
        Include information about (group, package) tuples about which no
        information at all was found, indicating just this.

    Returns
    -------
    [(str, str, str, str, str or None), ...]
        List of (name, status, version, shortdescription, provides)
        tuples about each specific package in the input tuples (not
        groups). If multiple packages providing one of the packages are
        found, information on all of these packages is returned and the
        corresponding "provides" field is filled in the output tuples.
    z&(?:[\S]+(?:\s+\(=[^()]+\))?(?:$|,\s+))z(?:\s+\(=[^()]+\))?z^(?P<hdr>Package):\s+(r�z)$z^(?P<hdr>Provides):\s+z	*(?P<pkg>z)(?:$|,\s+)z*$c�L�g|]!}tj|tj����"Sr/)rbr��	MULTILINEr�s  r3r4z$get_package_info.<locals>.<listcomp>�s&��A�A�A����A�r�|�,�,�A�A�Ar5z^Package: (?P<pkg>.*)$z^Status: (?P<stat>.*)$z^Version: (?P<vers>.*)$z*^Description(?:-[a-zA-Z]+)?: (?P<desc>.*)$�pkg�statrr7�ihr�n�hdr�ProvidesN�versr
Tc���g|]}|�v�|��	Sr/r/)r0r�rXs  �r3r4z$get_package_info.<locals>.<listcomp>s���7�7�7�!�����A���r5z | �pnz<none>z(no description available))r;rb�escaperTr>�list�valuesr�r]�searchr�r;rQr=)r��
skip_notfound�packinfo�pkgname�groupfor�
searchpkgs�
searchbitsr�r��escpkg�groups�	searchobs�packob�statob�versob�descob�ret�p�obr��packr_�sinfo�providesrdr
r��item�notfoundrXs                             @r3�get_package_infor��s����>���	� �"�"�H�7�G��H��J��J�$�;�;����!������7�#�#�����&�#9�9�:�:�:�:�	"�C�H�H�Z�$8�$8�8�4�?�!�G�+�l�:�

�(�(�:�
�
�	�!/�	0�29�	:�<@�	A�	�J��(�/�/�#�#�
$�
$�F��E�A�A�j�A�A�A�I�
�Z�0�"�,�
?�
?�F�
�Z�0�"�,�
?�
?�F�
�Z�1�2�<�
@�
@�F�
�Z�D�b�l�
S�
S�F�
�C�
�+�+���	+�	+�B��	�	�!���A��
+��}�}�Q�'�'�-�-�e�4�4���}�}�Q�'�'�-�-�f�5�5���
�
�����Q�x��{�U�1�X�a�[�0��
��7�$�&�&�$�q�'�S�.�.���7�7�5�>�>�Z�/�/� �w�w�u�~�~�3�3�5�5�a�8�H�H�#�H��}�}�Q�'�'�-�-�f�5�5���}�}�Q�'�'�-�-�f�5�5���d�D�$��9���
�
�4� � � � ���T�*�*���+� %�+�+��&*��d����5�(�(�&*�E�(�O��;	+�>���
��A�A��7�7�7�7�u�7�7�7���x�=�=�C��J�J�&�&��E�!�!��
�
�E�J�J�u�-�-�t�X�8�$�@�A�A�A���Jr5c��t|f|fgd���}g}|D]%}|�|d|df���&|S)aw
    Get a list of packages providing a given package name

    Parameters
    ----------
    package : str
        package name to be looked up in 'Package:' and 'Provides:'
        fields

    Returns
    -------
    [(str, str), ...]
        List of (name, shortdescription) tuples for each (non-virtual)
        package providing the given (possibly virtual) package
    T)rkr�)r�rT)r��aretrxr^s    r3�packages_providingr�(s[�� �w�j�'�2�3�4�H�H�H�D�
�C��%�%���
�
�C��F�C��F�#�$�$�$�$��Jr5�
depends onc	��|s	d|�d|�d�Sg}|D]7}d�|D��}|D]&}|�t|��|f���'�8d|�d|�d�}i}t|��D]/}|d}	|	|vr|||	<�|dr||	ds|||	<�0t|�����}
|
���g}|
D]-\}}
}}}|r|d	|zd
zz
}|�|||
f���.|}
t
d�|
D����}t
d�|
D����}t|t
d
|z
d����}t|d
|z
��}dd�}|
D]\}}}
|||
||||���z
}�|S)a

    Provide information on the dependencies of a package

    For each of the provided dependencies, the status and version is
    collected. The result is formatted as a table and returned as a
    single string.

    Parameters
    ----------
    package : str
        name of the package to which the dependency list belongs
    depends : [(str, ...), (str, ...), ...]
        list of tuples, each tuple giving a "dependency group" of simple
        dependencies or groups of alternative dependencies
    rel : str
        should be either "depends on", "recommends", or "suggests" and
        will be printed along with the package name above the dependency
        table

    Returns
    -------
    str
        a table listing the status and versions of dependencies
    r&roz no packages.
c�D�g|]}|�d��d��S)rOrr�)r0rVs  r3r4z'get_dependency_info.<locals>.<listcomp>_s&��,�,�,�1�q�w�w�s�|�|�A��,�,�,r5z
Versions of packages z:
rr�z [�]c�8�g|]}t|d����Sr��r=r�s  r3r4z'get_dependency_info.<locals>.<listcomp>}�"��+�+�+�a��A�a�D�	�	�+�+�+r5c�8�g|]}t|d����S)rr�r�s  r3r4z'get_dependency_info.<locals>.<listcomp>~r�r5�I��$�%c��d�|||||���}||d�s
||d�rY||d�}||d�}|d�||||������dzz
}||d��O||d��Y|S)z)line-wrap long package names and versionsz{:3.3} {:{wp}.{wp}}  {:.{wv}}
��wp�wvNz    {:{wp}.{wp}}  {:.{wv}}r&)�formatr�)rr{rNr�r�r�s      r3�	table_rowz&get_dependency_info.<locals>.table_row�s���0�7�7���g�RT�Y[�7�\�\���2�3�3�i�	e�7�2�3�3�<�	e�����9�D��b�c�c�l�G��0�7�7��g�"�QS�7�T�T�[�[�]�]�`d�d�d�D��2�3�3�i�	e�7�2�3�3�<�	e��r5r�)r�r�)rTr�r�rhri�sort�max�min)r�r�rel�dependencies�dep�bit�depinfo�packsr�r^�deplist�deplist2r{rrdr
r}�maxp�maxv�widthp�widthvr�s                      r3�get_dependency_infor�@s6��2�;�;�,3�G�G�S�S�S�9�:��L��3�3��,�,��,�,�,���	3�	3�C�����s���S� 1�2�2�2�2�	3�3�4;�7�7�C�C�C�@�G��E� ��.�.�"�"���1�g���e����E�#�J�J�
�!�W�	"���:�a�=�
"�!��c�
���5�<�<�>�>�"�"�G��L�L�N�N�N��H�07�.�.�,��v�t�T�8��	*��D�8�O�c�)�)�D�����t�V�,�-�-�-�-��G��+�+�7�+�+�+�,�,�D��+�+�7�+�+�+�,�,�D�
��s�2��9�b�)�)�
*�
*�F�
��r�F�{�
#�
#�F�����!(�G�G���t�V��9�9�V�T�4�F�v�F�F�F�F����Nr5c���i}g}|D]�\}}	t|d���5}|���}ddd��n#1swxYwYn#t$r}|||<Yd}~�Xd}~wwxYwtdt	j|��z�����d}	|	|kr��|�|��d}
|D]"}|s�|dkr|s�|ddkr|s�|
|z
}
�#|
||<��||fS)	a9
    Get information about modified config files

    Parameters
    ----------
    conffiles : [(str, str), ...]
        List of (filename, md5sum) tuples
    nocompress : bool
        determines whether empty lines and comment lines should be
        included in the output

    Returns
    -------
    ({str: str, ... }, [str, ...])
        tuple with two components:

        - dictionary of modified config files, with filenames as keys
          and ("compressed" if desired) config file content as values
        - filename list of the modified config files
    rrrsNzmd5sum rz	changed:
r&r�)r��	readlinesr�r}rfrgr;rT)r
�
nocompress�confinfo�changedrD�md5sumr��lines�msg�filemd5�thisinfor�s            r3�get_changed_config_filesr��s���*�H��G�'�&�&���6�	��h�'9�:�:�:�
'�b�������
'�
'�
'�
'�
'�
'�
'�
'�
'�
'�
'����
'�
'�
'�
'����	�	�	�!$�H�X���H�H�H�H�����	����%�Y���X�1F�1F�%F�G�G�M�M�O�O�PQ�R���f�������x� � � ����		�		�D��
���t�|�|�J�|���A�w�#�~�~�j�~�����H�H�%������W��s7�A�?�A�A	�A�A	�A�
A$�A�A$)r!r"r#r$r%c���dx}x}x}}g}td��}|�rtjdtj��}i}|�|��D]y}|�dd��\}	}
|
tvr*t|	��t�|
��}}n#t|	��tt��}}d||||
f<�z|rct|�����}|���|�
��d�|D��}|dd}	td	d
���5}
|
������}ddd��n#1swxYwYn+#t"$rt%d
t&j���YnwxYw|r|d|zdzz
}|r|d|zdzz
}|r'd�d�|D����}|d|zz
}|r||z
}|S)a
    Collect information about the distribution and release

    Find out which distribution (Debian/Ubuntu/) this is, which release,
    and APT preferences and policy.

    Returns
    -------
    str
        text summarizing the collected information
    r�zapt-cache policy 2>/dev/nullzE\s+(\d+)\s+.*$\s+release\s.*o=(Ubuntu|Debian|Debian Ports),a=([^,]+),rr�Tc�.�g|]}|d|df��S)rr7r/r�s  r3r4z+get_debian_release_info.<locals>.<listcomp>�s$��1�1�1�a�a��d�A�a�D�\�1�1�1r5rz/etc/debian_versionrrrsNz"Unable to open /etc/debian_version)rJzDebian Release: r&z  APT prefers r�c�,�g|]}t|����Sr/)rvr�s  r3r4z+get_debian_release_info.<locals>.<listcomp>�s��5�5�5�!�s�1�v�v�5�5�5r5z  APT policy: %s
)r}rbr�r]�finditerr��	DISTORDER�int�indexr=rh�keysr��reverser�r�r�r�r��sys�stderrr>)�debvers�debinfo�verfile�warn�distsr�mrerXr��pword�distname�pri�dist�fob�	policystrs               r3�get_debian_release_infor��sv��*,�+�G�+�g�+��$��E�
� >�
?�
?�F�
�"��j�a�ce�co�p�p�����\�\�&�)�)�	0�	0�E�#�k�k�!�Q�/�/�O�E�8��9�$�$���J�J�	����(A�(A�T�����J�J��I���T��+/�E�3��h�'�(�(��	"�������&�&�E��J�J�L�L�L��M�M�O�O�O�1�1�5�1�1�1�E��A�h�q�k�G�E�
�'�0B�
C�
C�
C�	-�s��l�l�n�n�*�*�,�,�G�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-����	-�	-�	-�	-����E�E�E�
�2���D�D�D�D�D�D�E�����7��%��/�$�6�6���5��#�g�-��4�4���4��I�I�5�5�u�5�5�5�6�6�	��'�)�3�3�����4����Ns6�3F�'E7�+F�7E;�;F�>E;�?F�%F+�*F+c� �td��S)zl
    Get LSB release information

    Returns
    -------
    str
        Information about LSB release
    zlsb_release -a 2>/dev/null)r}r/r5r3�lsb_release_infor�s���:�;�;�;r5c��td�����}|s]tj��}|d}t	jdd|��}t	jdd|��}t	jdd|��}|S)	z�
    Get the architecture of the current system.

    Returns
    -------
    str
        architecture name (e.g., ``"i386"``)
    z0COLUMNS=79 dpkg --print-architecture 2>/dev/nullr�zi[456]86�i386�s390x�s390�ppc�powerpc)r}r�r8�unamerbrc)�arch�uns  r3�get_archr�
sx���P�Q�Q�W�W�Y�Y�D��/�
�X�Z�Z���!�u���v�k�6�4�0�0���v�h���-�-���v�f�i��.�.���Kr5c�n�td��}d�|�����S)z�
    Check if multiarch is used (foreign architecture(s) defined)

    Returns
    -------
    str
        comma-separated list of foreign architectures
    z9COLUMNS=79 dpkg --print-foreign-architectures 2>/dev/nullr�)r}r>�
splitlines)�outs r3�
get_multiarchr� s.���X�
Y�
Y�C��9�9�S�^�^�%�%�&�&�&r5c�P�tj�d��dkrdndS)z�
    Check if the system is merged-usr

    Returns
    -------
    str
        Empty if merged-usr, a note that the system is not merged-usr otherwise
    z/libr�r�zmerged-usr: no
)r8r9rCr/r5r3�get_merged_usrr�-s)����!�!�&�)�)�Z�7�7�2�2�=O�Or5�debianc��ddlm}|tjvo	|o|j}|�||||||||
|||	|
|||||||���}t|��S)a�
    Generate a bug report template

    Parameters
    ----------
    package : str
        package name
    pkgversion: str
        package version
    severity : str
        bug severity
    justification : str
        reason why critical severity is justified (if applicable)
    depinfo : str
        dependency information (like from
        :func:`get_dependency_info():func:`)
    confinfo : str
        config file information
    foundfile : str, optional
        the name of the file where the bug is
    incfiles : str, optional
        files to include in the report
    system : str, optional
        most often "debian"
    exinfo : int, debianbts.Bugreport or False
        number of the bug for which this message provides extra
        information
    type : str, optional
        should be either 'debbugs' or 'launchpad'
    klass : str, optional
        unused
    subject : str, optional
        could be bug report mail subject
    tags : str, optional
        tags to be set for this bug
    body : str, optional
        main report message text
    mode : int, optional
        reportbug mode (novice, expert, etc.)
    pseudos : str, optional
        pseudo-headers to include inline in the report body
    debsumsoutput : str, optional
        debsums error output text
    issource : bool, optional
        flag whether this report is on a source or binary package

    Returns
    -------
    str
        bug report message template with inline system information
    r)�	bugreport)rN�severity�
justificationrD�mode�subject�tags�body�
pseudoheaders�followupr��systemr��sysinfor��incfiles�
debsumsoutput�issource)r�r�r�debother�
buildd_formatrv)r�rr�r�r�r��	foundfiler�r��exinfor��klassr�r�r�r��pseudosr�r��optionsr�r��reps                       r3�generate_blank_reportr�9s���t�������g�.�.�Z�G�4Y�G�DY�@Y�G��
�
�g�z�H�,9�I�#'��t�$�,3�f�4�%+�W�g�'/�(�,9�H�
�N�N�C��s�8�8�Or5c��eZdZdZd�ZdS)�our_lexz&Quote-removing lexical analyzer objectc��tj�|��}|�t|��s|S|d|dkr|d|jvr
|dd�}|S)z'Get token by token, with quotes removedNr���r)rf�	get_tokenr=�quotes)r!�tokens  r3r�zour_lex.get_token�s`����%�%�d�+�+���=��E�
�
�=��L��!�H��b�	�!�!�u�Q�x�4�;�'>�'>��!�B�$�K�E��r5N)r0r1r2r3r�r/r5r3r�r��s)������0�0�����r5r�z~/.reportbugrcz/etc/reportbug.conf)(�sendtor��mua�mtar�r��bts�verify�replyto�
http_proxy�smtphostr_�debconfr��sign�noccr��	dontquery�noconf�mirrors�keyid�headers�	interface�templater��check_available�	query_src�	printonly�offline�	check_uid�smtptls�smtpuser�
smtppasswd�paranoid�mbox_reader_cmd�max_attachment_size�listccme�outfile�	draftpath�timeoutc�L�tj�t��S)z�
    Check if user configuration file exists

    Unless reportbug is run for the first time, the user config file
    will often exist.

    Returns
    -------
    bool
        True if reportbug is run for the first time
    )r8r9rU�USERFILEr/r5r3�	first_runr�s���w�~�~�h�'�'�'�'r5c�	�i}tD�]�}tj�|���r�	t	t|d���d���}n#t$rY�QwxYw|jdz|_|���}|�r<|�	��}|dvr||d<�n|dkrZ|����	��}|ttj�
����vr||d<�n�|d	kr1|�d
g��|���gz|d
<�no|dvr|dk|d
<�n`|dvr|dk|d<�nQ|dvr|dk|d<�nB|dvr|dk|d<�n3|dvr|dk|d<�n$|dvrd||<�n|dvr|���}|||<�n�|dvr|dk|d<�n�|dkrK|����	��}|dvr||d<�n�|d krd!|d<�n�|d"krd#|d<�n�|d$krW|����	��}|d%krd&}|ttj
����vr||d'<�n=|d(krU|����	��}|tt �
����vr|||<�n�|d)krZ|����	��}|ttj�
����vr||d)<�n�|d*kr1|�d+g��|���gz|d+<�nK|d,vr|d-k|d.<�n<|d/kr(|����	��}�n|t$vrt$||d0<n�|d1vr
|d2k|d3<n�|d4vr
|d5k|d5<n�|d6vr
|d7k|d7<n�|d8vr
|d9k|d:<n�|d;vr
|d<k|d<<n�|d=kr'|���}t'|��|d=<n�|d>kr'|���}t'|��|d><nT|d?kr,|����	��}||d?<n"t(j�d@|z��|���}|��<���|S)Az�
    Parse the reportbug configuration files

    Returns
    -------
    dict
        dictionary with configuration parameter and their settings
    rrrsT)�posixz-.@/:<>)�quiet�	maintonly�submitr�r��headerr)�no-cc�ccr&r)�no-compress�compressr(r�)z
no-list-cc-me�
list-cc-mer*r)�no-query-btsz	query-btsr+r)r��no-config-filesr,r)rr
r)r�r�rrrr_r�r�rrr�r
rrr)z
no-smtptlsrrr)�pgp�gpg�gnupgr.�noner��ui�gtk2�gtkrr�r��mirrorr	)zno-check-available�check-availabler5r�reportbug_versionr�)�query-sourcezno-query-sourcer7r)rz
no-debconfr)rz	no-verifyr)�	check-uidzno-check-uidr8r)rzno-paranoidrrr�envelopefromzUnrecognized token: %s
)�FILESr8r9rUr�r�r��	wordcharsr��lowerrhr�
SEVERITIESr�rQr�MODESr�rr�r�r��write)�argsrD�lexr�r�rkr�s       r3�parse_config_filesrB�ss���D��^(�^(��
�7�>�>�(�#�#�]	(�
��d�8�4F�G�G�G�t�T�T�T�����
�
�
���
���� �M�I�5�C�M��M�M�O�O�E��T
(����
�
���<�<�<�%*�D��N�N��j�(�(��M�M�O�O�1�1�3�3�E���W�%7�%<�%<�%>�%>� ?� ?�?�?�+0��Z�(���h�&�&�&*�h�h�y�"�&=�&=������@Q�&Q�D��O�O��o�-�-�$)�W�$4�D��L�L��9�9�9�*/�=�*@�D��&�&��=�=�=�(-��(=�D��$�$��;�;�;�).�.�)@�D��%�%��A�A�A�&+�/@�&@�D��N�N��B�B�B�"&�D��K�K��J�J�J��-�-�/�/�C�"%�D��K�K��7�7�7�',�	�'9�D��O�O��f�_�_��M�M�O�O�1�1�3�3�E���.�.�',��V����'�)�)�',��V����&���')��V����d�]�]��M�M�O�O�1�1�3�3�E����� %����]�%7�%9�%9� :� :�:�:�,1��[�)���f�_�_��-�-�/�/�/�/�1�1�C��d�5�:�:�<�<�0�0�0�0�&)��U����e�^�^��M�M�O�O�1�1�3�3�E���W�_�%9�%9�%;�%;� <� <�<�<�&+��U����h�&�&�&*�h�h�y�"�&=�&=������@Q�&Q�D��O�O��G�G�G�/4�8I�/I�D�*�+�+��1�1�1��
�
���-�-�/�/�A�A��c�\�\�"%�e�*�D��K�K��A�A�A�).�.�)@�D��%�%��7�7�7�',�	�'9�D��O�O��5�5�5�&+�x�&7�D��N�N��;�;�;�).�+�)=�D��%�%��9�9�9�(-��(;�D��$�$��3�3�3��-�-�/�/�C�25�c�(�(�D�.�/�/��i�'�'��-�-�/�/�C�&)�#�h�h�D��O�O��n�,�,��M�M�O�O�1�1�3�3�E�+0�D��(�(��J�$�$�%?�%�%G�H�H�H��
�
����i�T
(��l�Ks� A�
A�Ac��dx}}g}g}t|d���5}|���}ddd��n#1swxYwY|D]�}|���}|�d��}t	|��dkr�?|d���|d}
}	|	dkr|
}�j|	d	kr|
}�s|	d
kr||
�d��z
}��|	dkr||
�d��z
}��||||fS)
a
    Parse a packages bug control file

    Parameters
    ----------
    filename : str
        bug control file name

    Returns
    -------
    (str, str, [str, ...] , [str, ...])
        tuple with (submit-as, send-to, report-with, package-status)
        control field values
    Nrrrsrr7rrz	submit-aszsend-tozreport-withrozpackage-status)r�r�r�r;r=r<)rD�submitas�submitto�
reportwith�supplementalr�r�r��partsr%�datas           r3�parse_bug_control_filerJsZ����H�x��J��L�	
�h�1�	2�	2�	2��b��������������������������,�,���z�z�|�|���
�
�4� � ���u�:�:��?�?���Q�x�~�~�'�'��q�����[� � ��H�H�
�y�
 �
 ��H�H�
�}�
$�
$��$�*�*�S�/�/�)�J�J�
�'�
'�
'��D�J�J�s�O�O�+�L���X�z�<�7�7s
�;�?�?c����g}g}g}tjdtj��}d}dx}	}
|D]@}|�|��}|r'|�|������Ad���fd�tD��}
|D]P}|�|��}|r7�|�d����}||
vr|
�|���Q|�tj
��D�]H}|	�r|sd}	�|�|��}|ru|dkr �|�d����|
vs%|d	krI|�d��d
dkr*|�|�����d}
��|rHd}
|���\}}|d
dkr�|��}|�||f����|
s>t|��r/|d
dkr#|d
}|d
|ddz|zf|d
<��!��#|���tkr||dzz
}��J|d	kr!|D]\}}|r||�d|��gz
}�||gz
}�|||fSi}g}|D]=\}}|tvr||�d|��gz
}�|dkr||vr||xxd|zz
cc<�8|||<�>|
D]}||vr||�d||��gz
}�|�|��|||fS)ad
    Clean up the bug report message

    Cleaning up consists of splitting off the headers and pseudo-headers
    from the message body. Two variants are distinguished, determined by
    the value of parameter `btstype`:

    - In "debbugs"-mode, pseudo-headers are recognized based on an
      internal list of known pseudoheader fields. This list can be
      extended using the `pseudos` parameter. Cleaning up includes
      making sure that only a single instance of non-repeatable
      pseudo-headers is present. If multiple instances are present in
      the input, the last one is used.

    - In "gnats"-mode, pseudo-headers start with the character '>'; the
      `pseudos` parameter is ignored.

    Headers not recognized as known pseudoheader fields are assumed to
    be proper headers.

    Parameters
    ----------
    dmessage : str
        raw message. Headers and pseudoheaders found in the message will
        be split off and returned separately.
    headers : [str, ...]
        list of header strings. Headers and header content provided here
        are passed to the output.
    pseudos : [str, ...]
        list of additional fields to recognize as pseudoheaders. The
        field strings must include a colon; any further content after
        the colon is discarded. Field names must be capitalized.
    btstype : str
        should be either "debbugs" or "gnats"

    Returns
    -------
    (str, [(str, str), ...], [str, ...])
        tuple with three components:

        - "cleaned" message string
        - list of (header, content) tuples representing headers
        - list of pseudoheaders
    z^([^:]+):\s*(.*)$r�Tc�f�d�d�|�d��D����S)N�-c�6�g|]}|�����Sr/)r�r�s  r3r4z/cleanup_msg.<locals>.normph.<locals>.<listcomp>{s ��@�@�@�A������@�@�@r5)r>r;)�aphs r3�normphzcleanup_msg.<locals>.normphzs-���x�x�@�@����3���@�@�@�A�A�Ar5c�&��g|]
}�|����Sr/r/)r0�phrPs  �r3r4zcleanup_msg.<locals>.<listcomp>}s!���A�A�A�R�f�f�R�j�j�A�A�Ar5rFr�gnatsr�>ror�r&rrr�)rbr��Ir�rTrr�
PSEUDOHEADERSr�r;r8r�r=r��
NEWBIELINE�REPEATABLE_PSEUDOHEADERSr�)�dmessagerr��btstype�
newheaders�collected_pseudoheaders�clean_pseudoheaders�headerre�message�parsing�
lastpseudor%�mob�accepted_pseudoheadersrRr��key�value�
lastheader�content�	unique_ph�
repeatable_phrPs                      @r3�cleanup_msgrj?s����Z�J� �����z�.���5�5�H��G���G�j��,�,���n�n�V�$�$���	,����c�j�j�l�l�+�+�+��B�B�B�B�A�A�A�=�A�A�A���2�2���n�n�R� � ���	2����	�	�!���%�%�B��/�/�/�&�-�-�b�1�1�1�����r�z�*�*�!#�!#��� 	#��
�����.�.��&�&�C��
��I�-�-�#�V�C�I�I�a�L�L�1�1�9O�O�O�#�w�.�.�3�9�9�Q�<�<��?�c�3I�3I��!�!�#�*�*�,�,�/�/�/�"�
�
��
�!�
�!�Z�Z�\�\�
��U��q�6�S�=�=� �&��+�+�C�'�.�.��U�|�<�<�<�<��
�C�
�O�O�
��Q��3���'��^�
�",�Q�-��A���1E��1L�!M�
�2����
�Z�Z�\�\�Z�
'�
'��t�d�{�"�G���'���6�	0�	0�O�F�G��
0�#�F�F�F�G�G�(D�'E�E�#�#�#��x�/�#�#��
�$7�7�7��I��M�2�(�(�����-�-�-��&�&�&�'�'�:�;�;�M���^�#�#��)�(;�(;��f�������/�����!(�I�f���)�L�L���Y�������	�&�8I�8I�$J�#K�K������}�-�-�-��J� 3�3�3r5c��t|||��}|�dSt��\}}	|���D]}|�|dz���|���|�K	||z}n#t
$r
|�d|��}YnwxYwt
j|��}|s	t
j|��dSt
jd|z��t
j|��dS#t
j|��wxYw)a

    Download an mbox and open it in a mail user agent.

    Runs the command specified by cmd, passing the mbox file
    downloaded from url as a parameter. If cmd is None or fails, then
    fallback to mail program.

    Parameters
    ----------
    cmd : str
        command to open the mbox file with, 'mail -f' if None
    url : str
        URL to download the mbox file from
    http_proxy : str
        http proxy
    timeout : int
        download connection timeout in seconds

    Returns
    -------
    None
    Nr&rozmail -f )	rrr�r?r��	TypeErrorr8r��unlink)	r{�urlrr�mbox�fd�fnamer��errors	         r3�launch_mbox_readerrs�s'��.�C��W�-�-�D��|����*�*�K�R����O�O�%�%�	"�	"�D��H�H�T�D�[�!�!�!�!�
���
�
�
��?�
-��E�k�����
-�
-�
-�!$���e�e�,����
-�����I�c�N�N�E��
��	�	�%������	�	�*�u�$�%�%�%�
�	�%��������	�%�������s6�AC%�.A4�3C%�4B�C%�B�C%�8C%�%C;c�~�tj��}tj��}|dkrd|zS|dkrd|zSdS)a
    Get the package of the currently running kernel

    Identifying the running kernel is needed to force
    assignment for 'kernel' package to a real one.

    Returns
    -------
    str or None
        the name of the kernel package, unless it could not be
        determined
    �Linuxzlinux-image-zGNU/kFreeBSDzkfreebsd-image-N)�platformr��release)r�rws  r3�get_running_kernel_pkgrx�sP���_�
�
�F��� � �G�
������'�'�	�>�	!�	!� �7�*�*��tr5c
�r�t��\}}|���|d|�dtj|���dtj|������}d}d}d}dx}	x}
}g}t	|d���5}
|
���}ddd��n#1swxYwY|D]w}|dkrd	}�|d
krd}�|dkrd	}�|dkrd}�&|d
krd	}�/|dkrd}�8|r|	|z
}	�@|r|
|z
}
�H|r(|�|������r||z
}�xt|��||	|
||fS)a�
    Execute and parse the output of the package bugscript

    Package bugscripts generate output that can be split into the
    following sections: headers, pseudo-headers, text, and a list of
    attachments. All sections are optional.

    This function executes a package bugscript and parses the ouput,
    identifying the section blocks, if present.

    Parameters
    ----------
    handler : str
        name of an executable
    bugscript : str
        bugscript filename

    Returns
    -------
    (int, str, str, [str, ...])
        Tuple with 5 components: (returncode, headers, pseudoheaders,
        remaining text, list of attachments)
    z	LC_ALL=C roFr�rrrsNz-- BEGIN HEADERS --
Tz-- END HEADERS --
z-- BEGIN PSEUDOHEADERS --
z-- END PSEUDOHEADERS --
z-- BEGIN ATTACHMENTS --
z-- END ATTACHMENTS --
)	rr�rfrgr�r�rTr�r)�handler�	bugscript�runner�fhrD�rc�	isheaders�ispseudoheaders�
isattachmentsrr�r5�attachmentsr�r�r�s                r3�exec_and_parse_bugscriptr�s���0�:�:�L�B���H�H�J�J�J�	���w�w�w���I�0F�0F�0F�0F�',�{�8�'<�'<�'<�>�
?�
?�B��I��O��M�%'�'�G�'�m�d��K�	
�h�1�	2�	2�	2��b������������������������������*�*�*��I�I�
�*�
*�
*��I�I�
�2�
2�
2�"�O�O�
�0�
0�
0�#�O�O�
�0�
0�
0� �M�M�
�.�
.�
.�!�M�M��
��4���� �
���%�
�
��
��"�"�4�:�:�<�<�0�0�0�0�������h��������k�:�:s�=B�B"�%B"c�\�tjd��}|�|��rdndS)a
    Check the package name against Debian Policy

    Package names must comply with the policy requirements:
    https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Source

    Returns
    -------
    bool
        True if the package name is valid.
    z^[a-z0-9][a-z0-9+-\.]+$TF)rbr�r�)r^�pkg_res  r3�check_package_namer�Us/���Z�2�
3�
3�F��<�<��$�$�/�4�4�%�/r5c�T�d}tj�d��rd}�ntjdd���sd}n�tj�d��rd	}n�tj�d
��rhd}	t
dd
��5}|d|��������z
}ddd��n#1swxYwYnP#t$rYnDwxYwtj�d��r!tj�
d��sd}|S)z�
    Determines the init system on the current machine

    Returns
    -------
    str
        the name of the init system, and how it was determined
    zunable to detectz/run/systemd/systemz!systemd (via /run/systemd/system)z+. /lib/lsb/init-functions ; init_is_upstartT)rpzupstart (via init_is_upstart())z/run/runit.stopitzrunit (via /run/runit.stopit)z/run/openrczOpenRC (via /run/openrc)z/proc/1/commr�z	, PID 1: Nz
/sbin/initzsysvinit (via /sbin/init))r8r9�isdirrw�call�isfiler�r,r��	Exceptionr@)�init�pfs  r3�get_init_systemr�fsb���D�	�w�}�}�*�+�+�+�2���
�_�J�RV�
W�
W�
W�+�0���	����+�	,�	,�
+�.���	����}�	%�	%�+�)��	��n�c�*�*�
8�b��7�B�G�G�I�I�O�O�$5�$5�7�7�7��
8�
8�
8�
8�
8�
8�
8�
8�
8�
8�
8����
8�
8�
8�
8����	�	�	��D�	����	�����	%�	%�+�b�g�n�n�\�.J�.J�+�*���Ks6�C�-C�C�C�C�C�C�
C%�$C%c�v�d}tj�d��rtjddg��dkrd}tj�d��r�tjdg��dkr�|�d}n|dz
}tjd	g���d
��}|d|dd�zz
}td
d��5}|���}|D]B}|�	d��r+|d|�
d��ddd�zz
}n�Cddd��n#1swxYwY|S)z�
    Determines the linux security module enabled on the current machine

    Returns
    -------
    str or None
        Description of LSM info; None if there is no LSM enabled on the
        machine or if the state cannot be determined
    Nz/usr/bin/aa-enabledz--quietrzAppArmor: enabledz/usr/sbin/selinuxenabledzSELinux: enabled - z; SELinux: enabled - z/usr/sbin/getenforce�asciizMode: %s - r�z/etc/selinux/configr�zSELINUXTYPE=zPolicy name: %s�=r)r8r9rUrwr��check_outputrzr�r�r�r;)�lsminfo�enforce_statusrWr�r�s     r3�get_lsm_infor��s����G�	�w�~�~�+�,�,�&��O�2�I�>�?�?�1�D�D�%��	�w�~�~�0�1�1��z��Hb�Gc�7d�7d�hi�7i�7i��?�+�G�G��.�.�G�#�0�2H�1I�J�J�Q�Q�RY�Z�Z���=�>�#�2�#�#6�6�6��
�'��
-�
-�	���K�K�M�M�E��
�
���?�?�>�2�2���0�4�:�:�c�?�?�1�3E�c�r�c�3J�J�J�G��E��	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��Ns�AD.�.D2�5D2c�D�gd�}g}tj�d��rztd��5}t	|�����}ddd��n#1swxYwYt
|��D]"\}}|d|zzr|�|���#|S)zX
    Determines the kernel taint flags

    Returns
    -------
    list of strings
    )�TAINT_PROPRIETARY_MODULE�TAINT_FORCED_MODULE�TAINT_CPU_OUT_OF_SPEC�TAINT_FORCED_RMMOD�TAINT_MACHINE_CHECK�TAINT_BAD_PAGE�
TAINT_USER�	TAINT_DIE�TAINT_OVERRIDDEN_ACPI_TABLE�
TAINT_WARN�
TAINT_CRAP�TAINT_FIRMWARE_WORKAROUND�TAINT_OOT_MODULE�TAINT_UNSIGNED_MODULE�TAINT_SOFTLOCKUP�TAINT_LIVEPATCH�	TAINT_AUX�TAINT_RANDSTRUCT�
TAINT_TESTz/proc/sys/kernel/taintedNr7)r8r9rUr�r�r,�	enumeraterT)�TAINT_FLAGS�flagsr��taintedrF�flags      r3�get_kernel_taint_flagsr��s������K�,
�E�	�w�~�~�0�1�1�#�
�,�
-�
-�	%���"�'�'�)�)�n�n�G�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%����	%�	%�	%�	%�
!��-�-�	#�	#�G�A�t���A��~�
#����T�"�"�"���Ls�"A#�#A'�*A'c�8�tjd��}|�|��}|sdS	t|}dd�|j|jD��vrdSn#t$rYnwxYwd}d�|��d�|��fD]#}tj	�
|��rn�$	tj|d	��5}|�
��}||vrt�|���D]j}|���d
kr,|�d��s|�d��sn%d
|���vrddd��dS�kddd��n#1swxYwYn#t$rYnwxYwdS)a
    Determine whether a given package is a security update

    Detection of security update versions works most reliably if the
    package version under investigation is the currently installed
    version.  If this is not the case, the probability of false
    negatives increases.

    Parameters
    ----------
    pkgname : str
        package name
    pkgversion : str
        package version

    Returns
    -------
    bool
        True if there is evidence that this version is a security
        update, otherwise False
    z(\+|~)deb(\d+)u(\d+)FzDebian-Securityc��g|]	}|j��
Sr/)�label)r0�os  r3r4z&is_security_update.<locals>.<listcomp>�s,��!A�!A�!A�Q���!A�!A�!Ar5TNz%/usr/share/doc/{}/changelog.Debian.gzz/usr/share/doc/{}/changelog.gz�rtr�z -- rozCVE-20)rbr�rjr�rB�originsr�r�r8r9rU�gzipr�r�rDr�r�r��upper)rmr�regex�
secversionry�clrW�lns        r3�is_security_updater��sH��8
�J�.�/�/�E����j�)�)�J����u�
��w����!A�!A�!"��J�!7�!?�!A�!A�!A�A�A��4�A���
�
�
���
����
�B�6�=�=�g�F�F�/�6�6�w�?�?�A����
�7�>�>�"���	��E�	�
�
�Y�r�4�
 �
 �	 �A������B���#�#����k�k�m�m�
 �
 ���9�9�;�;�"�$�$�"�-�-��*?�*?�$�r�}�}�UX�GY�GY�$��E��r�x�x�z�z�)�)��	 �	 �	 �	 �	 �	 �	 �	 �*�	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 ����
�
�
���
�����5sT�+A�
A*�)A*�>F
�BE>�$F
�1E>�2F
�>F�F
�F�F
�

F�Fr)T)F)r�r�)r�r�r�)r�)br�r8rbrvr��	tempfilesrr�ImportErrorrKr�r��exitrfr��email.policyr�rwrEr��urlutilsr�mailerrrVrXr>�MODELISTr��execr�r�r�r�reportbug.uirrWr?�CODENAME2SUITE�dictrh�items�SUITE2CODENAME�Cacher�rCrSrYr`rdrmr}r�r�r�r�r�r�r�r�r�objectrr;r>rLrPrZr�r�r�r�r�r�r�r�r�r��MODE_EXPERTr�r�r9�
expanduserrr:�CONFIG_ARGSrrBrJrjrsrxr�r�r�r�r�r�r/r5r3�<module>r�s���.�
�
�
�	�	�	�	�	�	�	�	�������J�J�J�6�6�6�6�6�6�6�6�6�������x����I�%�%��
��a������������������������
������������
�
�
�
�����
�
�
�
�����������������9�
�&�=��I�*�5�B�
	C�	C��8�7�7���>�>�D��D�������x�~�~�d�';�';�<�	<�=�=�=�=��������&�&�&�&�&�&�
=�
�7�7�7��1�.�*�)�&�%�)�#�"0�2�2����]�]���^�EY�EY�E[�E[�@\�@\�]�]�]�^�^��
�S�Y�[�[�
�$�$�$�N����%�%�%�P����4���*����Bq�q�q�2:�:�:�:�z'3�'3�'3�'3�T$�$�$�N#�#�#�L1�1�1�,<�<�<�<�089�89�89�89�v��w�w�w�w�|1�1�1�1�1�f�1�1�1�h!�!�!�
!�
!�
!� ���8���8-�-�-�-�`i�i�i�i�X���0N�N�N�N�b2�2�2�2�j
K�J�J�	�5�5�5�p	<�	<�	<����&
'�
'�
'�	P�	P�	P�8:�B�!)�$�T��"$�2�B�[�"&�d�U�"&�G�G�G�G�T	�	�	�	�	�e�k�	�	�	��7���.�/�/��	��)��'��(�(�(�j�j�j�Z$8�$8�$8�NN4�N4�N4�b*�*�*�Z���09;�	�=;�=;�=;�=;�@0�0�0�"���<���B-�-�-�`J�J�J�J�Js��A�/A�A