AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3/dist-packages/apport/crashdb_impl/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /usr/lib/python3/dist-packages/apport/crashdb_impl/__pycache__/launchpad.cpython-310.pyc
o

�v�f�N�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZejjdkr[ddlmZmZmZddlmZddlmZmZeeeeeefd	Zndd
lmZmZmZmZddlmZddlmZdZzdd
lmZddl m!Z!e!Wne"y�dZ!Ynwddl#Z$ddl$Z$ej%�&d�Z'dd�Z(dd�Z)Gdd�de$j*j+�Z+da,Gdd�de�Z-Gdd�de�Z.d!dd�Z/e0dkr�ddl1Z1ddl2Z2ddl3m4Z4da*da5da6da7Gdd �d e1j8�Z9e1�:�dSdS)"z,Crash database implementation for Launchpad.�N)�FailedToDecompressContent)�BytesIO�)�HTTPSHandler�Request�build_opener)�HTTPSConnection)�	urlencode�urlopenT)rrrr
)r	F)�	HTTPError)�	Launchpadz%~/.cache/apport/launchpad.credentialsc
cs`�|D]*}z|j��}Wnttfyt�d�Yqw|j}|�d�s*|�d�r-|VqdS)Nz"Broken attachment on bug, ignoring�.txt�.gz)�data�openrr�apport�error�filename�endswith)�attachments�
attachment�f�name�r�?/usr/lib/python3/dist-packages/apport/crashdb_impl/launchpad.py�filter_filename,s�
���rcCstdd�|D��S)Ncss$�|]
}t|j�d����VqdS)�/N)�int�	self_link�split�pop)�.0�irrr�	<genexpr>:s�"zid_set.<locals>.<genexpr>)�set)�tasksrrr�id_set8sr&c@seZdZdZdd�Zedd��Zdd�Zedd	��ZdAdd�Z	d
d�Z
dd�Zdd�Zdd�Z
		
dBdd�ZdCdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�ZdAd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!e"d?d@��Z#d
S)D�
CrashDatabasez5Launchpad implementation of crash database interface.cCst�d�rt�d�|d<|s$|�d�}|r"td|�dd�d}nt}tjj�|||�|�d�|_	|j	r?d|vs>Jd	��nd|vsGJd
��d|vrSd|d|_
ndtj��|_
||_
||_|jsfJ�d
|_d
|_t�d|�d��|_|js�tjdd�|_tjtj|jdd�d
Sd
S)aInitialize Launchpad crash database.

        You need to specify a launchpadlib-style credentials file to
        access launchpad. If you supply None, it will use
        default_credentials_path (~/.cache/apport/launchpad.credentials).

        Recognized options are:
        - distro: Name of the distribution in Launchpad
        - project: Name of the project in Launchpad
        (Note that exactly one of "distro" or "project" must be given.)
        - launchpad_instance: If set, this uses the given launchpad instance
          instead of production (optional). This can be overriden or set by
          $APPORT_LAUNCHPAD_INSTANCE environment.
        - cache_dir: Path to a permanent cache directory; by default it uses a
          temporary one. (optional). This can be overridden or set by
          $APPORT_LAUNCHPAD_CACHE environment.
        - escalation_subscription: This subscribes the given person or team to
          a bug once it gets the 10th duplicate.
        - escalation_tag: This adds the given tag to a bug once it gets more
          than 10 duplicates.
        - initial_subscriber: The Launchpad user which gets subscribed to newly
          filed bugs (default: "apport"). It should be a bot user which the
          crash-digger instance runs as, as this will get to see all bug
          details immediately.
        - triaging_team: The Launchpad user/team which gets subscribed after
          updating a crash report bug by the retracer (default:
          "ubuntu-crashes-universe")
        - architecture: If set, this sets and watches out for needs-*-retrace
          tags of this architecture. This is useful when being used with
          apport-retrace and crash-digger to process crash reports of foreign
          architectures. Defaults to system architecture.
        �APPORT_LAUNCHPAD_INSTANCE�launchpad_instance�.z://�����distro�projectz/Must not set both "project" and "distro" optionz0Need to have either "project" or "distro" option�architecturezneed-%s-retraceN�APPORT_LAUNCHPAD_CACHE�	cache_dirzlaunchpadlib.cache.)�prefixT)�
ignore_errors)�os�getenv�get�default_credentials_pathrr�crashdbr'�__init__r-�arch_tag�	packaging�get_system_architecture�options�auth�_CrashDatabase__launchpad�_CrashDatabase__lp_distro�_CrashDatabase__lpcache�tempfile�mkdtemp�atexit�register�shutil�rmtree)�selfr>r=�lp_instancerrrr9@s6
!�

�zCrashDatabase.__init__c
Cs|jr|jStdurtrtj�d�ntj�d�t�d�|j�d�r+|j�d�}nd}t	j
�|j�}|rAt	j
�
|�sAt	�|�ztjd||jdg|jd	d
�|_W|jSty�}z"t|d�re|j}nt|�}t�d||j�t�d
�WYd}~|jSd}~ww)zReturn Launchpad instance.Nz^ERROR: The python-launchpadlib package is not installed. This functionality is not available.
z_ERROR: The python3-launchpadlib package is not installed. This functionality is not available.
r+r)�
productionzapport-collect�
WRITE_PRIVATEz1.0)�launchpadlib_dir�allow_access_levels�credentials_file�version�contentzZconnecting to Launchpad failed: %s
You can reset the credentials by removing the file "%s"�c)r?r�_python2�sys�stderr�write�exitr=r6r4�path�dirnamer>�isdir�makedirs�
login_withrA�	Exception�hasattrrP�strrr)rHr)�auth_dir�e�msgrrr�	launchpad�s>


��
��zCrashDatabase.launchpadccsH�|jst�|D]}|j��|jkst�d|j|j���r!|VqdS)Nz^.+\(%s.*\)$)r-�
StopIteration�bug_target_name�lower�re�match)rHr%�trrr�_get_distro_tasks�s����zCrashDatabase._get_distro_taskscCsX|jdur)|jr|jj|j|_|jSd|jvr%|jj|jd|_|jStd��|jS)Nr.z:distro or project needs to be specified in crashdb options)r@r-rb�
distributionsr=�projects�SystemError�rHrrr�	lp_distro�s

��zCrashDatabase.lp_distroNcCs>|�|�sJ�|�|�}t|||��d�}|��|sJ�|S)a�Upload given problem report return a handle for it.

        This should happen noninteractively.

        If the implementation supports it, and a function progress_callback is
        passed, that is called repeatedly with two arguments: the number of
        bytes already sent, and the total number of bytes to send. This can be
        used to provide a proper upload progress indication on frontends.
        )�hostname)�accepts�_generate_upload_blob�upload_blob�get_hostname�close)rH�report�progress_callback�	blob_file�ticketrrr�upload�s

zCrashDatabase.uploadcCs0|j�d�}|r|dkrd}|Sd}|Sd}|S)z/Return the hostname for the Launchpad instance.r)�stagingzstaging.launchpad.netz
launchpad.dev�
launchpad.net)r=r6)rHr)rorrrrs�s��zCrashDatabase.get_hostnamecCs�i}|�d|���}|rt|t�s|�d�}||d<|��}d|vr'|d}n|j�d�}|sLd|vrAd||j|d|t|�fSd||j|t|�fSd|||t|�fS)	a/Return an URL that should be opened after report has been uploaded
        and upload() returned handle.

        Should return None if no URL should be opened (anonymous filing without
        user comments); in that case this function should do whichever
        interactive steps it wants to perform.�Title�UTF-8zfield.title�
SnapSourcer.�
SourcePackagez,https://bugs.%s/%s/+source/%s/+filebug/%s?%sz!https://bugs.%s/%s/+filebug/%s?%s)	r6�standard_title�
isinstance�bytes�encodersr=r-r	)rHru�handle�args�titleror.rrr�get_comment_url�s*


���zCrashDatabase.get_comment_urlcCsdt|�S)z�Return URL for a given report ID.

        The report is passed in case building the URL needs additional
        information from it, such as the SourcePackage name.

        Return None if URL is not available or cannot be determined.
        z https://bugs.launchpad.net/bugs/)r^)rHru�idrrr�
get_id_urlszCrashDatabase.get_id_urlcCs�t��}|jj|}t�d|jtj�}|s!t�d|jtjtjB�}|s'Jd��|�	d��
d��dd��dd	�}d
|vr`d|vrX|�dd�\}}|�d
d	�d|�d
d�d}n|�d
d�d}|�
t|��d
|vr�z	|j��|d
<Wnty�|j|d
<Ynwd|vr�d|jvr�d|d<n'd|jvr�d|d<nd|jvr�d|d<nd|jvr�d|d<n	tdt|j���d�|j�|d<d|vr�|d|d<|j|d<t|j�D]z}tj�|j�\}	}
zd||	<Wn	ty�Yq�w|
dk�r|��||	<z||	�d�||	<Wq�t �yYq�w|
dk�rHzt!j"|d���||	<Wq�t#�yG}zd t|�v�r2�|�$d�|��||	<WYd!}~q�d!}~wwtd"|j��|S)#z>Download the problem report from given ID and return a Report.z(ProblemType:.*)$z^--- \r?$[\r\n]*(.*)z8bug description must contain standard apport format datar+r}s � s
�
s

sUname:r�Date�ProblemTypez
apport-bug�Bug�apport-crash�Crashzapport-kernelcrash�KernelCrashzapport-package�Packagez(cannot determine ProblemType from tags: � �Tagsr|�
OriginalTitle�r
r)�fileobjz
Not a gzipNzUnknown attachment type: )%r�Reportrb�bugsrf�search�description�S�M�groupr��replacer�loadr�date_created�ctime�AttributeError�tags�
ValueErrorr^�joinr�rrr4rW�splitextrr\�read�decode�UnicodeDecodeError�gzip�GzipFile�IOError�seek)rHr�ru�b�mr��part1�part2r�key�extr`rrr�downloadsz ��








�
�

��zCrashDatabase.downloadFc	Cs�|jj|}|rt|���t|�}nd}t��}	|j|	|d�|	��|	�d�t	r1t
�|	�}
nt
�|	�}
|
�
�}t	r@|��pC|��}|��sJJ�t	rP|��pS|��}|��rZJ�|��dksbJ�|s�|jdd�}
|
�d�d|vr|
|�|d���7}
|
|_|��|jj|}|jdd��d	d
�}|r�|r�|jd||_|��n|s�|j}|j||d�|D]}|j|p�d
|��d|jdd�|��dd�q�|	��dS)ahUpdate the given report ID with all data from report.

        This creates a text comment with the "short" data (see
        ProblemReport.write_mime()), and creates attachments for all the
        bulk/binary data.

        If change_description is True, and the crash db implementation supports
        it, the short data will be put into the description instead (like in a
        new bug).

        comment will be added to the "short" data. If attachment_comment is
        given, it will be added to the attachment uploads.

        If key_filter is a list or set, then only those keys will be added.
        N)�	skip_keysr�
text/plain�apport-collectedr�T�r�r}r�z
--- 
�rP�subjectr�F��commentr��content_typerr�is_patch)rbr�r$�keysrB�
TemporaryFile�
write_mime�flushr�rR�email�message_from_file�message_from_binary_file�walk�next�__next__�is_multipart�get_content_typer��append�_filter_tag_namesr�lp_save�get_payloadr�r�r��
newMessage�
addAttachment�get_filenamert)rHr�rur��change_description�attachment_comment�
key_filter�bugr��mimera�msg_iter�part�x�textrrr�updateasR





�zCrashDatabase.updater�c		Cs�tjj�||||�|jj|}d|vr7|jD]}|jj�	d�r6|j
j|dd�|_|��|jj|}nq|�
�r�|jD]}|jdkrUz|��Wq>tyTYq>wq>z|�|j�}trd|��}n|��}|jdkrtd|_|��Wn	ty~Ynw|��}|r�t�d|j�}|r�|�d�|kr�|�d	�||�d
�|_z|��Wn	ty�Ynw|jj|}|�||�dS)z�Update the given report ID for retracing results.

        This updates Stacktrace, ThreadStacktrace, StacktraceTop,
        and StacktraceSource. You can also supply an additional comment.
        r�
#distribution�r�CoreDump.gz�	Undecided�Mediumz,^(.*crashed with SIG.* in )([^( ]+)(\(\).*$)rr+�N)rr8r'�
update_tracesrbr��	bug_tasks�target�resource_type_linkrrn�getSourcePackager��has_useful_stacktracerr��
removeFromBugrrirRr�r��
importancerc�stacktrace_top_functionrfrgr��_subscribe_triaging_team)	rHr�rur�r��task�a�fnr�rrrr��sV
�

��

���zCrashDatabase.update_tracescCs0|jj|}t�d|j�}|r|�d�Std��)zNGet 'DistroRelease: <release>' from the given report ID and return
        it.z"DistroRelease: ([-a-zA-Z0-9.+/ ]+)r+z)URL does not contain DistroRelease: field)rbr�rfr�r�r�r�)rHr�r�r�rrr�get_distro_release�s

z CrashDatabase.get_distro_releasecCs`t�d|j�}|jj|}g}|jD]}|�|jj�}|sq|j	dvr%q|�
|�d��q|S)z5Return list of affected source packages for given ID.z5/%s/(?:(?P<suite>[^/]+)/)?\+source/(?P<source>[^/]+)$)�Invalid�	Won't Fix�Fix Released�source)rf�compiler-rbr�r�r�r�r�statusr�r�)rHr��
bug_target_rer��resultr�rgrrr�get_affected_packages�s�

z#CrashDatabase.get_affected_packagescCs|jj|}|jj|jjjkS)z3Check whether the user is the reporter of given ID.)rbr��ownerr�me�rHr�r�rrr�is_reporterszCrashDatabase.is_reportercCsZ|jj|}|jrdS|jj|jjjkrdS|jjj}|jjD]}|d|kr*dSqdS)aACheck whether the user is eligible to update a report.

        A user should add additional information to an existing ID if (s)he is
        the reporter or subscribed, the bug is open, not a duplicate, etc. The
        exact policy and checks should be done according to the particular
        implementation.
        FT�person_link)	rbr��duplicate_ofr�rr�r�
subscriptions�entries)rHr�r�r��subrrr�
can_update	s
�zCrashDatabase.can_updatec
Cs^z|jj|jdd�}t|�WSty.}zt�dt|��t�	d�WYd}~dSd}~ww)z}Return an ID set of all crashes which have not been retraced yet and
        which happened on the current host architecture.�
2011-08-01�r��
created_since�"connecting to Launchpad failed: %srQN)
rn�searchTasksr:r&r\rrr^rSrV�rHr�r`rrr�get_unretraced s
��zCrashDatabase.get_unretracedc
Cs\z
|jjddd�}t|�WSty-}zt�dt|��t�d�WYd}~dSd}~ww)a#Return an ID set of all crashes which have not been checked for
        being a duplicate.

        This is mainly useful for crashes of scripting languages such as
        Python, since they do not need to be retraced. It should not return
        bugs that are covered by get_unretraced().�need-duplicate-checkrrrrQN)	rnrr&r\rrr^rSrVr	rrr�get_dup_unchecked*s
��zCrashDatabase.get_dup_uncheckedcCs|jjdd�}t|�S)aOReturn an ID set of all crashes which are not yet fixed.

        The list must not contain bugs which were rejected or duplicate.

        This function should make sure that the returned list is correct. If
        there are any errors with connecting to the crash database, it should
        raise an exception (preferably IOError).r�)r�)rnrr&)rHr�rrr�get_unfixed9s	zCrashDatabase.get_unfixedcCs"|jjjd||jjd�}|djS)z�Return the version of given source package in the latest release of
        given distribution.

        If 'distro' is None, we will look for a launchpad project .
        T)�exact_match�source_name�
distro_seriesr)rn�main_archive�getPublishedSources�current_series�source_package_version)rH�package�sourcesrrr�_get_source_versionEs�
z!CrashDatabase._get_source_versionc	sNz�jj|}Wn
tyYdSw|jrdSt|j�}�jr�d�j���tt�fdd�|��}|sCtt�fdd�|��}|rCdSt	|�dkrSt
�d�j|�dS|ro|��}z��
|j��d	�WStynYdSwtt�fd
d�|��}|r�tt�fdd�|��}|s�dSdSttdd�|��}|r�dSttd
d�|��r�dSdS)aReturn the package version that fixes a given crash.

        Return None if the crash is not yet fixed, or an empty string if the
        crash is fixed, but it cannot be determined by which version. Return
        'invalid' if the crash report got invalidated, such as closed a
        duplicate or rejected.

        This function should make sure that the returned result is correct. If
        there are any errors with connecting to the crash database, it should
        raise an exception (preferably IOError).
        �invalidz(%s)cs|jdko�|j��vS�Nr��r��bug_target_display_namere�r���distro_identifierrr�<lambda>o�
z1CrashDatabase.get_fixed_version.<locals>.<lambda>cs|jdko|j���j��kSr)r�rdrer-rrmrrrss
r�r+zVThere is more than one task fixed in %s %s, using first one to determine fixed versionrcs|jdvo�|j��vS�N)r�r��Expiredrrrrrr�r cs|jdvo�|j��vSr!rrrrrr�r cS�
|jdkSr�r�rrrrr��
cSr#)Nr�r$rrrrr�r%N)rbr��KeyErrorr��listr�r-re�filter�lenr�warningr rrr�
IndexError)	rHr�r�r%�fixed_tasks�fixed_distror��
invalid_tasks�non_invalid_tasksr)rrHr�get_fixed_versionSs\�
����
�
�zCrashDatabase.get_fixed_versioncCs|jj|j}|r|jSdS)zcReturn master ID for a duplicate bug.

        If the bug is not a duplicate, return None.
        N)rbr�r�r�)rHr�r�rrrr��szCrashDatabase.duplicate_ofc	Cs�|jj|}|�rT||ksJdt|���|jj|}|jr2|j}|j}|j|kr2t�d||�dS|jD]}|jdvrLz|�	�Wq5t
yKYq5wq5|jj|}|jd|dd�|jj|}|jrhd|_|jsn||_|j
}t|j�d	kr�d
|jvr�|jd
|vr�|j�dd�|vr�||jd
g|_
|��d
|jvr�|j�dd�|vr�|jj|jd
}|j|d�|���rd|vs�d|v�r|j||d|gd�d�|jj|}|j
dd�}	z|	�d�Wn	ty�Ynwz|	�d�Wn
t�yYnw|	|_
z|��Wn
t
�yYnwdg}
|jjD]}|jdv�r'�q|
�|j��qt|j
�}|j
}|�|�}
|
D]
}||
v�rJ|�|��q>||_
|��n|j�r[d|_|j �re|��dSdS)zlMark a crash id as duplicate of given master ID.

        If master is None, id gets un-duplicated.
        z+cannot mark bug %s as a duplicate of itselfzNBug %i was manually marked as a dupe of newer bug %i, not closing as duplicateN)r�zStacktrace.txtzThreadStacktrace.txtzProcMaps.txtzProcStatus.txtz
Registers.txtzDisassembly.txta�Thank you for taking the time to report this crash and helping to make this software better.  This particular crash has already been reported and is a duplicate of bug #%i, so is being marked as such.  Please look at the other bug report to see if there is any missing information that you can provide, or to see if there is a workaround for the bug.  Additionally, any further discussion regarding the bug should occur in the other report.  Please continue to report any other bugs you may find.zThis bug is a duplicater�F�
�escalation_tag�
escalated_tagz	 invalid �escalation_subscription��personzapport-request-retrace�apport-failed-retracez)Updated stack trace from duplicate bug %i)�
Stacktrace�ThreadStacktracer��Dependencies�ProcMaps�ProcCmdline)r�zbugpattern-needed)zActive DevelopmentzCurrent Stable Release�	SupportedzPre-release Freeze)!rbr�r^r�r�rr*rr�r�rr��privater�r)�
duplicatesr=r6r��people�	subscriber�r��remover�rn�seriesr�r�rr$�
difference�_dirty_attributes)rHrur��	master_idr��masterr��master_tags�pr��tags_to_copyrC�	dupe_tags�missing_tags�tagrrr�close_duplicate�s�
�

��	��	*
����



�
�zCrashDatabase.close_duplicatecCsD|jj|}|jd|dd�|jj|}|jdg|_|��dS)zpMark a crash id as reintroducing an earlier crash which is
        already marked as fixed (having ID 'master').z�This crash has the same stack trace characteristics as bug #%i. However, the latter was already fixed in an earlier package version than the one in this report. This might be a regression or because the problem is in a dependent package.zPossible regression detectedr��regression-retracerN)rbr�r�r�r�)rHr�rGr�rrr�mark_regressions��zCrashDatabase.mark_regressioncCs`|jj|}|j|jvr.|jdd�}|�|j�||_z|��WdSty-YdSwdS)zMark crash id as retraced.N)rbr�r:r�rBr�r)rHr�r�r�rrr�
mark_retraced#s��zCrashDatabase.mark_retracedc	Cs�|jj|}|rUz|�|j�}tr|��}n|��}Wnty)|jd}Ynwd|_|�	�|j
|dd�|jD]}|jdkrRz|�
�Wq;tyQYq;wq;dSd|jvrg|jdg|_|�	�dSdS)z%Mark crash id as 'failed to retrace'.rr�z Crash report cannot be processedr�r�r7N)rbr�rir�rRr�r�rcr�r�r�rr�r�rr�)rHr��invalid_msgr�r�r�rrr�mark_retrace_failed0s:
���

���
�z!CrashDatabase.mark_retrace_failedc	Cs�|jj|}d|vr9|jD]+}|jj�d�r8|jj|dd�|_z|��|jj|}Wn	t	y5Ynwnq
d|j
vrm|j
dd�}|�d�||_
|��d|vrm|jD]}d|jjvrl|jdkrld|_|��qX|�
||�dS)	z/Mark crash id as checked for being a duplicate.rr�r�rN�	Tracebackr�r�)rbr�r�r�r�rrnr�r�rr�rBr�r�)rHr�rur�r�r�rrr�_mark_dup_checkedNs8
���



�zCrashDatabase._mark_dup_checkedcCs�tjj�||�}|s|S||d<zt|d�}Wnty#|YSw|��}|�d�s/dS|D]}|�d�rFd|vs@d|vrCdS|S|��sM|Sq1|S)	a�Check if the crash db already knows about the crash signature.

        Check if the report has a DuplicateSignature, crash_signature(), or
        StacktraceAddressSignature, and ask the database whether the problem is
        already known. If so, return an URL where the user can check the status
        or subscribe (if available), or just return True if the report is known
        but there is no public URL. In that case the report will not be
        uploaded (i. e. upload() will not be called).

        Return None if the report does not have any signature or the crash
        database does not support checking for duplicates on the client side.

        The default implementation uses a text file format generated by
        duplicate_db_publish() at an URL specified by the "dupdb_url" option.
        Subclasses are free to override this with a custom implementation, such
        as a real database lookup.
        �DuplicateOfz/+textsbug:Tstags:sapport-failed-retracesapport-request-retraceN)	rr8r'�knownr
r��readline�
startswith�strip)rHru�urlr�linerrrrWns.�

��zCrashDatabase.knowncCsxd|vr|d��ddkrdSd|jj|j�dd�f}|�t|jj�d��d	�d
d�|jD�vr:|j	|d�dSdS)
z-Subscribe the right triaging team to the bug.�
DistroReleaser�UbuntuNz%s~%s�
triaging_teamzubuntu-crashes-universer��~cSsg|]}t|��d�d�qS)rr,)r^r)r!rrrr�
<listcomp>�sz:CrashDatabase._subscribe_triaging_team.<locals>.<listcomp>r5)
rrb�	_root_urir=r6r�r^rZrrA)rHr�rur6rrrr��s���z&CrashDatabase._subscribe_triaging_teamcCsni}d|d��|d<|�d�}|r|dkr|�d�}|r(|dd|7<d|vr;|dd|�|d�7<d|vr}|rid	|vsMd
|vsMd|vrid|d
<|�d|j�dd��|d<|dd|7<nd|vr}d|d
<d|d<|dd7<d|vr�d|dvr�|dd7<d|vr�|d|d<gd�}t��}|j||gd�|d�|��|�d�|S)z�Generate a multipart/MIME temporary file for uploading.

        You have to close the returned file object after you are done with it.
        z	apport-%sr�r��PackageArchitecture�all�Architecturer�r]�VmCore�CoreDump�LaunchpadPrivate�yes�Private�LaunchpadSubscribe�initial_subscriberr�Subscribersz need-%s-retracerTz need-duplicate-check�DuplicateSignaturer�CheckboxSubmissionzHWDB-Submission)	r�r]r��
Regression�Reproducible�TestedUpstream�ProcVersionSignature�Uname�NonfreeKernelModules)r�rhrk)�
extra_headersr��priority_fieldsr)	rer6r�r=rBr�r�r�r�)rHru�hdrr��orderr�rrrrq�sB

��
z#CrashDatabase._generate_upload_blobcCs`d}|��jddd�D]"}|dvst|�dkr)|dvr)tr"||7}q|t|�7}q|d7}q|S)	zAReplace characters from tags which are not palatable to Launchpadr��ASCII�ignore)�errorss%abcdefghijklmnopqrstuvwxyz0123456789 rs+-.r*)rer�r)rR�chr)�klassr��res�chrrrr��s

zCrashDatabase._filter_tag_names�N)FNN)r�)$�__name__�
__module__�__qualname__�__doc__r9�propertyrbrirnryrsr�r�r�r�r�r�r�r�rr
rr
rr0r�rNrPrQrSrUrWr�rq�classmethodr�rrrrr'=sJB
(	


#
U
�
S4	
Fq

 72r'c@seZdZdZdd�ZdS)�HTTPSProgressConnectionzWImplement a HTTPSConnection with an optional callback function for
    upload progress.cCs�ts
t�||�dSd}t|�}d}||krRt||�t��}t�|||||��||7}t��}|dkrL||dkrB|dK}n
||dkrL|dL}||ksdSdS)Nrig�?r+r)�_https_upload_callbackr�sendr)�time)rHr�sent�total�	chunksize�t1�t2rrrr�s$

�zHTTPSProgressConnection.sendN)r�r�r�r�r�rrrrr�sr�c@seZdZdd�ZdS)�HTTPSProgressHandlercCs|�t|�Sr�)�do_openr�)rH�reqrrr�
https_open$szHTTPSProgressHandler.https_openN)r�r�r�r�rrrrr�"sr�r{c
Csd}d|}|atjj��}tjj�d�}|�dd�|�|�tjj	�
dd�}|�dd�|�|���
d	��|�|�t�}tjjd
krOtjj|dd�}	ntjj|dd�}	|	�|�t||���}
|
�d
d|���tt�}|�|
�}|���d�}|s�J�|S)a
Upload blob (file-like object) to Launchpad.

    progress_callback can be set to a function(sent, total) which is regularly
    called with the number of bytes already sent and total number of bytes to
    send. It is called every 0.5 to 2 seconds (dynamically adapted to upload
    bandwidth).

    Return None on error, or the ticket number on success.

    By default this uses the production Launchpad hostname. Set
    hostname to 'launchpad.dev' or 'staging.launchpad.net' to use another
    instance for testing.
    Nzhttps://%s/+storeblob�1zContent-Dispositionzform-data; name="FORM_SUBMIT"�applicationzoctet-streamz*form-data; name="field.blob"; filename="x"�asciirF)�mangle_from_zContent-Typezmultipart/form-data; boundary=zX-Launchpad-Blob-Token)r�r�r��	multipart�
MIMEMultipartr��MIMEText�
add_header�attach�base�MIMEBase�set_payloadr�r�rrS�version_info�major�	generator�	Generator�BytesGenerator�flattenr�getvalue�get_boundaryrr�r�infor6)
�blobrvrorxr[r�submit�	form_blob�	data_flat�genr��openerr�rrrrr(s.



rr�__main__)�patchc@sTeZdZdZdZdd�Zdd�Zedd��ZdNd	d
�Z	dd�Z
dNd
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Ze�ed/�d0d1��Ze d2d3��Z!d4d5�Z"dOd7d8�Z#d9d:�Z$d;d<�Z%d=d>�Z&d?d@�Z'dAdB�Z(dCdD�Z)dEdF�Z*dGdH�Z+dIdJ�Z,e dPdLdM��Z-d6S)Q�_T�	coreutilscCsHts|��at|_t��|_|j��|j��d|jd<|�d�dS)Nr�r�langpack-o-matic)r8�
_get_instancerr��
ref_report�add_os_info�
add_user_info�_create_projectrmrrr�setUprs



z_T.setUpcCs@|jjj|}|s|jjjj|d|||d|dd�dSdS)z8Create a project using launchpadlib to be used by tests.r��summaryr�)r��display_namerr�r�N)r8rbrk�new_project)rHrr.rrrr��s

��z_T._create_projectcCs
|j��S)z1Get the Launchpad hostname for the given crashdb.)r8rsrmrrrro�s
z_T.hostnameFcCs�|stdurtS|��}|�|j�|��|��|��|�|��d�d|d<d|d<|�	|j
|�}|�|�|�||�}|�|dk�t
j�d|j|f�|sV|a|S)	z�Generate SEGV crash report.

            This is only done once, subsequent calls will return the already
            existing ID, unless force_fresh is True.

            Return the ID.
            N�!crash crashed with SIGSEGV in f()u "]¶"
�ShortGibberish�a
b
c
d
e
ÿÿÿ
�
LongGibberishrz*(Created SEGV report: https://%s/bugs/%i) )�_segv_report�_generate_sigsegv_report�add_package_info�test_packager��add_gdb_infor��assertEqualr��_get_bug_targetr8�
assertTrue�	_file_bugrSrTrUro)rH�force_fresh�r�
bug_targetr�rrr�get_segv_report�s$	
z_T.get_segv_reportcCs�tdurtSt�d�}d|d<d|d<d|d<|�|j�|��|��|�|��d	�|�	|j
|�}|�|�|�||�}|�|d
k�t
j�d|j|f�|a|S)zFGenerate Python crash report.

            Return the ID.
            Nr��/bin/foo�ExecutablePath��Traceback (most recent call last):
  File "/bin/foo", line 67, in fuzz
    print(weird)
NameError: global name 'weird' is not definedrTzboogus pybogusr��Hfoo crashed with NameError in fuzz(): global name 'weird' is not definedrz,(Created Python report: https://%s/bugs/%i) )�_python_reportrr�r�r�r�r�r�r�r�r8r�r�rSrTrUro)rHr�r�r�rrr�get_python_report�s&

�
z_T.get_python_reportcCsV|stdurtSd}|jjjjd||jjd�}tj�d|j	|j
f�|s(|j
a|j
S)a�File a bug report with an uncommon description.

            This is only done once, subsequent calls will return the already
            existing ID, unless force_fresh is True.

            Example taken from real LP bug 269539. It contains only
            ProblemType/Architecture/DistroRelease in the description, and has
            free-form description text after the Apport data.

            Return the ID.
            Nzbproblem

ProblemType: Package
Architecture: amd64
DistroRelease: Ubuntu 8.10

more text

and more
zmixed description bug)r�r�r�z3(Created uncommon description: https://%s/bugs/%i) )�_uncommon_description_reportr8rbr��	createBugrnrSrTrUror�)rHr��descr�rrr�get_uncommon_description_report�s


�z"_T.get_uncommon_description_reportc
Cs�|j�|���}|�|dd�|�|dd�|�|d|jd�|�|d|jd�|�|d|jd�|�|�d�|j�d��|�|�d	�|j�d	��t|d
���}|�|t|jjdt	j
��g��|�|dd
�|�|d�
d��|�|d|j�|�|d�|jd��|�d|d�|�d|d�|�d|d�|�t|d�d�|�d|�|�d|�|�d|�|j�|���}t|d
���}|�|tddddt	j
��g��dS) z
download()r�r�r|r�r]rertru�
UserGroupsr�r��Signal�11r�z/crashrr�r�zf (x=42)r8�
StacktraceTopr9rgi�r:�Disassembly�	Registers�boogus�pybogusrN)r8r�r�r�r�r6r$rr:rr;r<r�r�test_srcpackagerYr��assertIn�
assertGreaterr)r�)rHr�r�rrr�test_1_download�s<
��
�z_T.test_1_downloadcCs�|j�|���}|�d|�|�d|�|�d|�|�d|�|�d|�|�d|�|�|dd�d	|d
<d|d<d|d<d
|d<|j�|��|d�|j�|���}|�d|�|�d|�|�d|�|�d|�|�d|�|�d|�|�d|�|�|dd�|jjj|��j	}|�d|�|�d|�d|d
<d|d<d|d<|j�|��|d�|j�|���}|�d|�|�d|�|�d|�|�d|�|�d|�|�d|�|�d|�|�|dd�|jjj|��}d|_
z|��Wn
t�y
Ynwd|d
<|j�|��|d�|j�|���}|�|dd�|jjj|��}d|_
z|��Wn
t�yEYnwd|d
<|j�|��|d�|j�|���}|�|dd�d|d<d|d<d|d<|j�|��|d�dS) zupdate_traces()rgr:r�r�r8r9r|r�z?? ()r��
long
trace�thread
even longer
trace�bogus�FooBarzI can has a better retrace?r�r��=read () from /lib/libc.6.so
foo (i=1) from /usr/lib/libfoo.so�
good retrace!z$crash crashed with SIGSEGV in read()z)crash crashed with SIGSEGV in f() on exitz!good retrace with title amendmentz,crash crashed with SIGSEGV in read() on exitzcrash is crashyzgood retrace with custom titler�u"]¶"
r��StacktraceSource�testsN)
r8r�r�r�r�r��assertNotInrbr�r�r�r�r)rHr�r�r�rrr�test_2_update_tracess���z_T.test_2_update_tracescCs�d}t�d�}||d<|j�|d�}|�|�d��|�d�|d<|j�|d�}|�|�d��d|d<|j�|d�}|�|�d	��d
S)z&get_comment_url() for non-ASCII titless1ä♥2r�r|�*z1/ubuntu/+filebug/42?field.title=1%C3%A4%E2%99%A52r}r�rzC/ubuntu/+source/coreutils/+filebug/42?field.title=1%C3%A4%E2%99%A52N)rr�r8r�r�rr�)rHr�r�r[rrr�test_get_comment_urlms
z_T.test_get_comment_urlcCs|jjjdd�}|jjjjd|dd�}|j}|�|dk�tj	�
d|j|f�t�
d�}d	�d
�|d<d|d
<d|d<d|d<d|d<|jj||ddd�|j�|�}|�|dd	�d
��|�|dd�|�|dd�|�|dd�|�|jjj|jdg�dS)z"update() with changing description�bashr�ztest description for test bug.�testbug�r�r�r�r�(https://%s/bugs/%i) r�sbogus→r}�OneLiner�f()
g()
h(1)r��lineone
linetwo�ShortGoo�one
two
three
four
five
six�DpkgTerminalLogs�VarLogDistupgradeBinGoo�NotMeT�r�r�N)r8rnr�rbr�r�r�r�rSrTrUrorr�r�r�r�r�r��rHr�r�r�r�rrr�test_update_description�s0
�
�z_T.test_update_descriptioncCs|jjjdd�}|jjjjd|dd�}|j}|�|dk�tj	�
d|j|f�t�
d�}d	|d
<d|d<d
|d<d|d<d|d<|jj||ddd�|j�|�}|�d
|�|�d|�|�|dd�|�|dd�|�|dd�|�|jjj|jdg�dS)zupdate() with appending commentr�r�zPr0blem

--- 
ProblemType: Bugr�r�rr�r��bogus→r�r�r�r�r�r�r��r��meowFr�r�r�N�r8rnr�rbr�r�r�r�rSrTrUrorr�r�r�r�r�r�r�rrr�test_update_comment�s2
�
�z_T.test_update_commentcCs|jjjdd�}|jjjjd|dd�}|j}|�|dk�tj	�
d|j|f�t�
d�}d	|d
<d|d<d
|d<d|d<d|d<|jj||ddgd�d�|j�|�}|�d
|�|�|dd
�|�|dd�|�|dd�|�d|�|�|jjj|jg�dS)zupdate() with a key filterr�r�ztest description for test bugr�r�rr�r�rr�r�r�r�r�r�r�rr�r�T)r�r�r�)r�r�r�Nrr�rrr�test_update_filter�s2
�
�z_T.test_update_filtercCs"|�|j�|���|jd�dS)zget_distro_release()r]N)r�r8r�r�r�rmrrr�test_get_distro_release�s�z_T.test_get_distro_releasecCs$|�|j�|���|jdg�dS)zget_affected_packages()rN)r�r8r�r�r�rmrrr�test_get_affected_packages�s
�z_T.test_get_affected_packagescC�,|�|j�|����|�|j�d��dS)z
is_reporter()r+N)r�r8r�r��assertFalsermrrr�test_is_reporter��z_T.test_is_reportercCr)zcan_update()r+N)r�r8rr�r	rmrrr�test_can_update�rz_T.test_can_updatecCs�|�|j�|���d�|�|j�|���d�|��}|��}|jdd�}|j�|�}|j�|||�|�|j�|�|�|j�|||�|�|j�|�|�|�|j�|�d�|j�||d�|�|j�|�d�|�|j�|�d�|j�|���}|�d|�|�d|�|�d|�|�d|�|�d	|�|�d
|�|j�t	�
�||�|j�|||�|�|j�|�|�|j�t	�
�|d�|j�t	�
�|d�|j�||d�|j�t	�
�|d�|�|j�|�d�|j�||�|�|�dS)zduplicate handlingNT�r�rrgr�r;�
ProcStatusr�r9)
r�r8r�r�r0r�r�rNr�rr�rP�_verify_marked_regression)rH�segv_id�
known_test_id�known_test_id2r�rrr�test_duplicates�sF��z_T.test_duplicatescCs�|j��}|�|��|�|�|��|�|j�|���|j��}|�|��|�|�||�t	|��g���|�|j�
|���d�|�|���|j�|���|j�|���|j��}|�|��|�|�||�t	|��g���|�|j�
|���d�|�|���|j�|���|j�|��d�|j��}|�|��|�|�||�t	|��g���|�|j�
|���d�dS)z-processing status markings for signal crashesNzI don't like your)
r8r
r�r�r�r�rQr��unionr$r0�_mark_needs_retracerS)rH�unretraced_before�unretraced_afterrrr�test_marking_segv5s<

�
�
��z_T.test_marking_segvcCs�|jjjjd|jj|jjdd�}tj�d�pd}t	tj�d�d|d��}|jjjd	|j|jd
d�}|�
�}|�|j|�|�
|j|�|�|j�|�
�}|�
|j|�|�||�t|jg���|�|j�|j�d�dS)�0processing status markings for a project CrashDB�foozubuntu distro retrace bug�r�r�r�r�r(rz�LP_CREDENTIALSr��r.r)�barzproject retrace bugN)r8rbr�r�r:rnr4�environr6r'r
r�r�r�rQr�rr$r0)rH�
distro_bugr)�
project_db�project_bugrrrrr�test_marking_projectXs6
�
���z_T.test_marking_projectcCs�tj�d�pd}ttj�d�d|dd��}|��}|j��}|jjjjddg|jj	d	d
�}t
d|j�|��}|j��}|�||�|�||�
t|jg���dS)
rr(rzr�ubuntu�fakearch)r-r)r/rzneed-fakearch-retracez&ubuntu distro retrace bug for fakearchrz4fake arch bug: https://staging.launchpad.net/bugs/%iN)r4rr6r'r
r8rbr�r�rn�printr�r�rr$)rHr)�fakearch_db�fakearch_unretraced_before�systemarch_unretraced_beforer��fakearch_unretraced_after�systemarch_unretraced_afterrrr�test_marking_foreign_arch{s,
��

�
�z_T.test_marking_foreign_archcCs�|j��}|�|��|�|�|��|�|j�|��|j�|j��}|�|��|�|�||�	t
|��g���|�|j�|���d�dS)z2processing status markings for interpreter crashesN)r8rr�r�r�r�rUr�r�rr$r0)rH�unchecked_before�unchecked_afterrrr�test_marking_python�s

�z_T.test_marking_pythoncCsp|jdd�}|j�|�}|j�|||���d|d<d|d<d|d<|j�||d	�|j�|�}|�d
|�dS)z�updating an invalid crash

            This simulates a race condition where a crash being processed gets
            invalidated by marking it as a duplicate.
            Tr
r�r�r�r8r�r9r�rgN)r�r8r�rNr�r�)rHr�r�rrr�test_update_traces_invalid�sz_T.test_update_traces_invalidrcGs\dtj_|�|���|j�|���}|�|d�|�|���|�|j�|���d�dS)z�get_fixed_version() for fixed bugs

            Other cases are already checked in test_marking_segv() (invalid
            bugs) and test_duplicates (duplicate bugs) for efficiency.
            z3.14N)	r'r�return_value�_mark_report_fixedr�r8r0r��_mark_report_new)rHr��	fixed_verrrr�test_get_fixed_version�s	z_T.test_get_fixed_versioncCs(tj�d�pd}ttj�d�d|d��S)zCreate a CrashDB instancer(rzrr$)r-r))r4rr6r')r~r)rrrr��s��z_T._get_instancecCs<|j�d�}d|vr|jj|dd�S|r|jj|S|jS)z&Return the bug_target for this report.r.rr�)r=r6rnr�rbrk)rH�dbrur.rrrr��sz_T._get_bug_targetNc	CsL|durd}|j�|�}trt�|�}nt�|�}|��|��}tr'|��p*|�	�}|�
�s1J�tr7|��p:|�	�}|�
�rAJ�|��dksIJ�|d|jdd��
dd�7}|jjjj||d	��||�d
|���d�}	|D]}|�
�rwJ�|	jd|��d|jdd�|��d
d�qo|d��D]}
|jjj|
}|r�|	j|d�q�|	jS)zLFile a bug report for a report.

            Return the bug ID.
            Nzsome descriptionr�z

Tr�r}r�r�r|rr�Fr�rmr5)r8rqrRr�r�r�rtr�r�r�r�r�r�r�rbr�r�rr6r�r�r�r@rAr�)rHr�rur�r�rar��headerr�r��
subscriberrrrrr��sD



�

��z_T._file_bugcCs>|jjj|}|jj|jvr|j|jjg|_|��dSdS)z$Mark a report ID as needing retrace.N)r8rbr�r:r�r�r�rrrrs
�z_T._mark_needs_retracecCs6|jjj|}d|jvr|jdg|_|��dSdS)z,Mark a report ID as needing duplicate check.rN)r8rbr�r�r�r�rrr�_mark_needs_dupcheck$s

�z_T._mark_needs_dupcheckcC�B|jjj|}t|j�}t|�dksJ�|d}d|_|��dS)zClose a report ID as "fixed".r+rr�N�r8rbr�r'r�r)r�r��rHr�r�r%rhrrrr2,�
z_T._mark_report_fixedcCr:)zReopen a report ID as "new".r+r�NewNr;r<rrrr36r=z_T._mark_report_newcCs |jjj|}|�d|j�dS)z.Verify that report ID is marked as regression.rON)r8rbr�r�r�r�rrrr@sz_T._verify_marked_regressioncCsvtj�d�pd}ttj�d�d|d��}|�|jd�t�d�}d|d	<d
|d<|��|�	�|�|�
�d�|�||�}|�|jd�|�
||�}|�|d
k�tj�d|j|f�|�|�}d|d<d|d<d|d<|�||d�|�|�}|�|�|�d�|�|||���|�|�|�|���|�|�|�d�|�||d�|�|�|�d�|�|�|�d�dS)z7reporting crashes against a project instead of a distror(rzrr�rNr�r�r�r�rTr�rr�r�r�r�r8r�r9r�r)r4rr6r'r�r-rr�r�r�r�r�rr�r�rSrTrUror�r�r0rNr�r�)rHr)r8r�r�r�rrr�test_projectFsB��

�

z_T.test_projectcCsH|j�|���}|�|dd�|�|dd�|�|d�d��dS)z*download() of uncommon description formatsr�r�re�amd64r]zUbuntu N)r8r�r�r�r�rY)rHr�rrr�test_download_robustnessvsz_T.test_download_robustnesscsxtj�d�pd}ttj�d�d|ddd��}d}|jj|jd	j�d
}zst||d�D]N}|d7}t	j
�d
|�|�t
��||���|jj|��}|jd|jv}t�fdd�|jD��}|dkrp|�|�|�|�q,|�|�|�|�q,Wt|||�D]}t	j
�d|�|�t
��|d�q�nt|||�D]}t	j
�d|�|�t
��|d�q�wt	j
�d�dS)z,Escalating bugs with more than 10 duplicatesr(rzrr$�
omgkittenszapport-hackers)r-r)r2r4rr4iV'�
r+z%i r2csg|]}|j�k�qSr)r�)r!�s�rIrrra�sz&_T.test_escalation.<locals>.<listcomp>r1zR%i N�
)r4rr6r'rbr@r=r�rangerSrTrUrNrr�r�r�r��anyrr	r�)rHr)r6�count�	first_dupr��has_escalation_tag�has_escalation_subscriptionrrEr�test_escalationsB��

���z_T.test_escalationcCs�|�|���|j��}|�|��|�|jjj|��}|jr'd|_|��|j	d}|jjj
d|_|��|j|jjj
dd�|j�|���}|j�|��|�|j��}|�|��|�|�||�t|��g���|jjj|��}|�|j	djd�|�|j	djd�|�|j	djd�|�|j	djd	�|�|j	djd�|�|j	djd
�|�|j�|���d�dS)z9source package task fixup for marking interpreter crashesFrr$r�)r�r>r�r+zcoreutils (Ubuntu)r�N)r9r�r8rr�rbr�r>r�r�rjr��addTaskrkr�rUr�r�rr$rdr�r�r0)rHr-r�rhr�r.rrr�test_marking_python_task_mangle�s4


�z"_T.test_marking_python_task_mangler�c	Cs0d}t��}tj��}z�t��}t�t	j
|�t�|�tdd��
}|�
d�Wd�n1s1wYt�gd��dksAJ�tj�d�sIJ�tjgd�tjd	�tj�d
�s[J�t�dg�tjgd�tjd	�dksoJ�tj�|d�|d
<tj�|d
�f|d<||d<|��Wt�|�|St�|�w)aCreate a test executable which will die with a SIGSEGV, generate a
            core dump for it, create a problem report with those two arguments
            (ExecutablePath and CoreDump) and call add_gdb_info().

            Return the apport.report.Report.
            N�crash.c�wzS
int f(x) {
    int* p = 0; *p = x;
    return x+1;
}
int main() { return f(42); }
)�gccz-grPz-o�crashrrS)�gdbz--batch�--ex�runrUzgenerate-core-file corez./crash)�stdout�core�sync)�readelfz-nrXr�rgr�)r4�getcwdrrur�rBrCrDrErFrG�chdirrrU�
subprocess�callrW�exists�PIPE�
check_callr�r�)r~�signal�workdir�orig_cwd�pr�fdrrrr��s:

�
�
��

�z_T._generate_sigsegv_report)Fr�)r�).r�r�r�r�r�r�r�r�ror�r�r�r�r�r�r�rrrrr
rrrr#r,r/r0r��objectr'r5r�r�r�r�rr9r2r3rr?rArMrOr�rrrrr�hsV

#
$"Q #!6##


	
:

0	")r�)Nr{);r�rBrD�os.pathr4rfr�rSr�r�rF�httplib2r�iorr�r��urllib2rrr�httplibr�urllibr	r
rR�urllib.request�urllib.parse�http.client�launchpadlib.errorsr�launchpadlib.launchpadr�ImportError�apport.crashdbrrW�
expanduserr7rr&r8r'r�r�r�rrr��unittestr]�
unittest.mockr�r�r�r��TestCaser��mainrrrr�<module>s|H�F
7��������

Anon7 - 2022
AnonSec Team