
    [efyH                       S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSK	r
SSKJs  Jr  SSKJrJr  SSKJr  SSKJr  \R*                  " \5      rSr\R2                  R5                  \5      (       a  \\R6                  S'   S	rS
rSrSrSSSSSSSS.r  " S S5      r!    S,S jr" S-     S.S jjr#    S/S jr$S0S jr%    S1S jr&S2S jr'S3S jr(S\0r)S4S jr*S5S  jr+S6S! jr,S7S" jr-S#r.S$r/S%r0S&r1S8S' jr2S9S( jr3S:S) jr4S;S* jr5S<S+ jr6g)=z
Query Debian's Bug Tracking System (BTS).

This module provides a layer between Python and Debian's BTS. It provides
methods to query the BTS using the BTS' SOAP interface, and the Bugreport class
which represents a bugreport from the BTS.
    )annotationsN)IterableMapping)datetime)Anyz/etc/ssl/ca-debianSSL_CERT_DIRz(https://bugs.debian.org/cgi-bin/soap.cgizDebbugs/SOAP/V1zhttps://bugs.debian.org/i                       )criticalgraveserious	importantnormalminorwishlistc                  r    \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS jr
SS	 jrSS
 jrSS jrSrg)	Bugreport5   a  Represents a bugreport from Debian's Bug Tracking System.

A bugreport object provides all attributes provided by the SOAP interface.
Most of the attributes are strings, the others are marked.

Attributes
----------
bug_num : int
    The bugnumber
severity : str
    Severity of the bugreport
tags : list[str]
    Tags of the bugreport
subject : str
    The subject/title of the bugreport
originator : str
    Submitter of the bugreport
mergedwith : list[int]
    List of bugnumbers this bug was merged with
package : str
    Package of the bugreport
source : str
    Source package of the bugreport
date : datetime
    Date of bug creation
log_modified : datetime
    Date of update of the bugreport
done : boolean
    Is the bug fixed or not
done_by : str | None
    Name and Email or None
archived : bool
    Is the bug archived or not
unarchived : bool
    Was the bug unarchived or not
fixed_versions : list[str]
    List of versions, can be empty even if bug is fixed
found_versions : list[str]
    List of version numbers where bug was found
forwarded : str
    A URL or email address
blocks: list[int]
    List of bugnumbers this bug blocks
blockedby : list[int]
    List of bugnumbers which block this bug
pending : str
    Either 'pending' or 'done'
msgid : str
    Message ID of the bugreport
owner : str
    Who took responsibility for fixing this bug
location : str
    Either 'db-h' or 'archive'
affects : list[str]
    List of Packagenames
summary : str
    Arbitrary text
c                h    U   U   U   U   U   U   U   U   U   U   U   U   U   U   U   U   U   U   U   U   U   U   U   U   U   g N )selfs    5/usr/lib/python3/dist-packages/debianbts/debianbts.py__init__Bugreport.__init__q   sM        c                l    SR                  S U R                  R                  5        5       5      nUS-   $ )zPrepare string representation.
c              3  4   #    U  H  u  pU S U 3v   M     g7f)z: Nr   ).0keyvalues      r   	<genexpr>$Bugreport.__str__.<locals>.<genexpr>   s!      
0E*#se2eW0Es   )join__dict__items)r   ss     r   __str__Bugreport.__str__   s5    II 
040C0C0E
 
 4xr!   c                D    U R                  5       UR                  5       :  $ )a  Compare a bugreport with another.

The more open and urgent a bug is, the greater the bug is:

    outstanding > resolved > archived

    critical > grave > serious > important > normal > minor > wishlist.

Openness always beats urgency, eg an archived bug is *always* smaller
than an outstanding bug.

This sorting is useful for displaying bugreports in a list and sorting
them in a useful way.


_get_valuer   others     r   __lt__Bugreport.__lt__   s       5#3#3#555r!   c                .    U R                  U5      (       + $ )zCheck if object <= other.)__gt__r3   s     r   __le__Bugreport.__le__       ;;u%%%r!   c                D    U R                  5       UR                  5       :  $ )zCheck if object > other.r1   r3   s     r   r8   Bugreport.__gt__   s     5#3#3#555r!   c                .    U R                  U5      (       + $ )zCheck if object >= other.)r5   r3   s     r   __ge__Bugreport.__ge__   r;   r!   c                z    [        U[        5      (       d  [        $ U R                  5       UR                  5       :H  $ )zCheck if object == other.)
isinstancer   NotImplementedr2   r3   s     r   __eq__Bugreport.__eq__   s0    %++!! E$4$4$666r!   c                d    [        U[        5      (       d  [        $ U R                  U5      (       + $ )zCheck if object != other.)rB   r   rC   rD   r3   s     r   __ne__Bugreport.__ne__   s'    %++!!;;u%%%r!   c                    U R                   (       a  SnOU R                  (       a  SnOSnU[        U R                     -  nU$ )Nr   
      )archiveddone
SEVERITIESseverity)r   vals     r   r2   Bugreport._get_value   s9    ==CYYC Cz$--((
r!   r   N)returnNone)rR   str)r4   r   rR   bool)r4   objectrR   rU   )rR   int)__name__
__module____qualname____firstlineno____doc__r   r.   r5   r9   r8   r?   rD   rG   r2   __static_attributes__r   r!   r   r   r   5   s6    9vD6$&6&7&r!   r   c                @   [        U [        [        45      (       d  U /nO[        U 5      n/ n[        S[	        U5      [
        5       HS  nXU[
        -    n[        S[         S3U5      nUR                  5        H  nUR                  [        U5      5        M     MU     U$ )zReturn a list of Bugreport objects.

Given a list of bug numbers this method returns a list of Bugreport
objects.

Parameters
----------
nrs
    The bugnumbers

Returns
-------
list[Bugreport]
    list of Bugreport objects

r   {z}get_status)rB   listtuplerangelen
BATCH_SIZE_soap_client_callNSvaluesappend_parse_status)nrsnumbersbugsislice_result_dictbugs          r   
get_statusrq      s    ( cD%=))%s) D1c'lJ/Q^,'"RD(=vF%%'CKKc*+ ( 0
 Kr!   c                    Uc  / n[        S[         S3U /UQ76 nUR                  5        VVs0 s H  u  p4U[        [	        [
        U5      5      _M!     snn$ s  snnf )a  Get buglists by usertags.

Parameters
----------
email
tags
    If tags are given the dictionary is limited to the matching tags, if no
    tags are given all available tags are returned.

Returns
-------
dict[str, list[int]]
    a mapping of usertag -> buglist

r_   z}get_usertag)re   rf   r,   r`   maprW   )emailtagsresultkvs        r   get_usertagry      sX    & |B4}5uDtDF-3\\^<^TQAtCQK  ^<<<s   &Ac                   [        S[         S3U 5      n/ nU H  nUS   nUS   n[        US   5      n/ n[        R                  R                  [        R                  R                  S9nUR                  UR                  5       5        UR                  S5        UR                  UR                  5       5        UR                  5       n	UUUUU	S.n
UR                  U
5        M     U$ )	aN  Get Buglogs.

A buglog is a dictionary with the following mappings:

* "header": `string`
* "body": `string`
* "attachments": `list`
* "msg_num": `int`
* "message": `email.message.Message`

Parameters
----------
nr
    the bugnumber

Returns
-------
list[dict[str, str | list[Any] | int | email.message.Message]]
    list of buglogs

r_   z}get_bug_logheaderbodymsg_num)policys   

)r{   r|   r}   attachmentsmessage)re   rf   rW   rt   
feedparserBytesFeedParserr~   SMTPfeedencodecloserh   )nrr,   buglogsitemr{   r|   r}   r   mail_parserr   buglogs              r   get_bug_logr     s    0 2$m4b9EGhF|d9o&!#&&66<<$$ 7 
 	)!'##% &
 	v/ 0 Nr!   c                \    [        S[         S3U 5      n[        [        [        U5      5      $ )a  Return the newest bugs.

This method can be used to query the BTS for the n newest bugs.

Parameters
----------
amount
    the number of desired bugs. E.g. if `amount` is 10 the method will
    return the 10 latest bugs.

Returns
-------
list[int]
    the bugnumbers

r_   z}newest_bugsre   rf   r`   rs   rW   )amountrv   s     r   newest_bugsr   E  s+    " B4}5v>FC !!r!   c                 \    [        S[         S3U 5      n[        [        [        U5      5      $ )a  Get list of bugs matching certain criteria.

The conditions are defined by the keyword arguments.

Parameters
----------
**kwargs
    Possible keywords are:

    * `package`: bugs for the given package
    * `submitter`: bugs from the submitter
    * `maint`: bugs belonging to a maintainer
    * `src`: bugs belonging to a source package
    * `severity`: bugs with a certain severity
    * `status`: can be either "done", "forwarded", or "open"
    * `tag`: see http://www.debian.org/Bugs/Developer#tags for available
      tags
    * `owner`: bugs which are assigned to `owner`
    * `bugs`: takes single int or list of bugnumbers, filters the list
      according to given criteria
    * `correspondent`: bugs where `correspondent` has sent a mail to
    * `archive`: takes a string: "0" (unarchived), "1" (archived) or "both"
      (un- and archived). if omitted, only returns un-archived bugs.

Returns
-------
list[int]
    the bugnumbers

Examples
--------
    >>> get_bugs(package='gtk-qt-engine', severity='normal')
    [12345, 23456]

r_   z	}get_bugsr   )kwargsrv   s     r   get_bugsr   Z  s,    L B4z2F;FC !!r!   c                @   [        5       nS H  n[        XX   5        M     [        R                  " [	        U S   5      5      Ul        [        R                  " [	        U S   5      5      Ul        [        U S   5      R                  5       Ul	        [        U S   5      Ul        UR                  (       a  U S   OSUl        [        U S   5      Ul        [        U S   5      Ul        [        U S	   5      Ul        [        U S
   5      R                  5        Vs/ s H  n[        U5      PM     snUl        [        U S   5      R                  5        Vs/ s H  n[        U5      PM     snUl        [        U S   5      R                  5        Vs/ s H  n[        U5      PM     snUl        [        U S   5      R                  S5       Vs/ s H  oD(       d  M  UPM     nnU Vs/ s H  ofR)                  5       PM     snUl        U$ s  snf s  snf s  snf s  snf s  snf )zReturn a bugreport object from a given status xml element.

Parameters
----------
bug_el
    a dict containing a debbugs bug description

Returns
-------
Bugreport
    a Bugreport object

)
originatorsubjectmsgidpackagerO   ownersummarylocationsourcepending	forwardedfound_versionsfixed_versionsdatelog_modifiedru   rM   NrL   
unarchivedbug_num
mergedwith	blockedbyblocksaffects,)r   setattrr   utcfromtimestampfloatr   r   rT   splitru   _parse_boolrM   done_byrL   r   rW   r   r   r   r   stripr   )bug_elrp   fieldrm   _fr   as          r   ri   ri     s    +C 	FM*" ((vf~)>?CH00vn7M1NOC6&>"((*CH6&>*CH$'HH&.$CKvj12CL !56CNfY'(CK&)&*>&?&E&E&GH&Gc!f&GHCN%()<%=%C%C%EF%ESV%EFCM"%fX&6"7"="="?@"?Q#a&"?@CJy 1288=D=br=GD&-.g779g.CK
 J IF@D.s$   HHH

HH$Hc                    U S;  $ )zParse a boolean value, according to Perl's rules.

Parameters
----------
x
    the string to parse

Returns
-------
bool
    the parsed value

) 0r   )xs    r   r   r     s     Ir!   r   c                    U [         S'   g)zvSet proxy for SOAP client.

You must use this method after import to set the proxy.

Parameters
----------
proxy_arg

proxyN_soap_client_kwargs)	proxy_args    r   set_soap_proxyr     s     $- r!   c                    U [         S'   g)zSet location URL for SOAP client.

You may use this method after import to override the default URL.

Parameters
----------
url
    default URL

r   Nr   )urls    r   set_soap_locationr     s     '*
#r!   c                     [         $ )zWReturn SOAP client kwargs.

Returns
-------
dict[str, str]
    the SOAP client kwargs

r   r   r!   r   get_soap_client_kwargsr     s
     r!   c           	        / nS[         ;   a=  UR                  [        R                  R	                  [         S   [         S   S.S95        [        R                  R
                  " U6 n[        X5      n[        R                  SU5         UR                  [        R                  R                  [         S   SSSS	.US
95       nUR                  5       nSSS5        [        R                  SW5        [%        U5      $ ! , (       d  f       N/= f! [        R                  R                   aU  nUR                  R                  SS5      R!                  S5      (       a  UR"                  R                  5       n SnANe SnAff = f)zkPerform a SOAP request.

Parameters
----------
method_name
    the method name
*args

Returns
-------
Any

r   )httphttps)proxieszRequest: %sr   POSTztext/xml; charset="utf-8"r   )Content-Type
SOAPAction)r   methodheadersdataNr   ztext/xmlzResponse: %s)r   rh   urllibrequestProxyHandlerbuild_opener_encode_soap_requestloggerdebugopenRequestreaderror	HTTPErrorr   get
startswithfp_decode_soap_response)method_nameargshandlersopenerencoded_requestfencoded_responsees           r   re   re     sG    H%%NN''/809 ( 	
 ^^(((3F*;=O
LL0[[NN""'
3$?"$ % # 

  vvx

& LL!12 !122)

 

 <<!! 99==,77
CC ttyy{s=   	9D C<D <
D
D 
D F +A
E;:E;;F z)http://schemas.xmlsoap.org/soap/envelope/z)http://schemas.xmlsoap.org/soap/encoding/z http://www.w3.org/2001/XMLSchemaz)http://www.w3.org/2001/XMLSchema-instancec                <   [         R                  " S[         S35      nUR                  S[         S3[        5        [         R
                  " US[         S35      n[         R
                  " X05      nU H  n[        USU5        M     [         R                  " U5      $ )zBuild a SOAP request.

Parameters
----------
method_name
    the function to call (including namespace)
args
    the function arguments

Returns
-------
bytes

r_   z	}Envelopez}encodingStylez}Bodyarg)ETElementSOAPENVsetSOAPENC
SubElement_encode_valuetostring)r   r   rootr|   msgr   s         r   r   r   4  s~     ::7):./DHHr'/*G4==G9F34D
--
*Cc5#& ;;tr!   c                $   [         R                  " U 5      nUR                  S[         S[         S35      nUb0  UR                  S5      nUb  UR                  OSn[        SU 35      eUR                  S[         S35      nUc  g[        U5      $ )	zExtract the returned value from a SOAP response.

Parameters
----------
response
    the response from the SOAP service

Returns
-------
Any
    the returned value

r_   z}Body/{z}FaultNfaultstringUnknownzSOAP fault: z}Body/*[1]/*[1])r   
fromstringfindr   textRuntimeError_decode_value)responser   fault
message_elr   answers         r   r   r   L  s     =="DII7)9WIW=>EZZ.
%/%;*//\'344YYG9$456F~  r!   c           
        [        U[        5      (       aZ  [        R                  " X5      nUR	                  S[
         S3[        R                  " [        S5      5        [        U5      Ul        g
[        U[        5      (       ac  [        R                  " X5      nUR	                  S[
         S3[        R                  " [        S5      5        [        [        U5      5      Ul        g
[        U[        5      (       a  [        U[        5      (       a*  UR                  5        VVs/ s H  oD  H  oUPM     M     nnn[        R                  " X5      nUR	                  S[
         S3[        R                  " [        S5      5        UR	                  S[         S3[        R                  " [        S[        U5      -  5      5        U H  n[        USU5        M     g
[!        S	U< 35      es  snnf )zAppend the encoded representation of a value to the parent element.

Parameters
----------
parent
    the parent element
name
    the tag of the new element
value
    the value to be encoded

r_   }typestringrW   Arrayz
}arrayTypezanyType[%d]r   zCan't encode N)rB   rT   r   r   r   XSIQNameXSDr   rW   r   r   r,   r   rc   r   
ValueError)parentnamer'   elpairr   s         r   r   r   h  se    %]]6(
C5#x!89e*	E3		]]6(
C5#u!56c%j/	E8	$	$eW%%#(;;=?=4$QQ$Q=E?]]6(
C5'7!;<
	%HHS-#e*45	
 A"fa(  =	233 @s   %G*c                   U R                  S[         S35      nU(       a  XR                  S5      S-   S nU R                  =(       d    SnUS;   a  U$ US:X  a$  [        R
                  " U5      R                  S	S
S9$ US:X  a  U  Vs/ s H  n[        U5      PM     sn$ US:X  aE  [        S U  5       5      (       d   eU  Vs0 s H  n[        US   5      [        US   5      _M      sn$ Uc0  U  Vs0 s H"  n[        UR                  5      [        U5      _M$     sn$ [        S[        R                  " U 5      R                  5        35      es  snf s  snf s  snf )aQ  Decode an XML encoded representation.

Note: Perl does not have separate types for strings and numbers.
The server assigns a type based on heuristics. To get consistent
behavior, this function returns all numeric values as strings.

Parameters
----------
element
    the XML element to decode

Returns
-------
Any
    the decoded value

r_   r   :r   Nr   )r   rW   r   base64Binaryzutf-8replace)errorsr  Mapc              3  >   #    U  H  n[        U5      S :H  v   M     g7f)r   N)rc   )r%   r   s     r   r(    _decode_value.<locals>.<genexpr>  s     6gd3t9>gs   r   zCan't decode )r   r  r   r   base64	b64decodedecoder   all_remove_namespacetagr  r   r   )elementtypr   r  r   s        r   r   r     sa   $ ++3%v&
'C
 ((3-!#%&<<2D
((		%,,WY,GG	,34Gbb!G44	6g66666GN
GNtM$q'"M$q'$::w
 	
 
  
 dhh't)<<
 	

 =W)=)D)D)F(GHII 5

s   E%E2)Ec                .    X R                  S5      S-   S $ )z-Remove the namespace from an ElementTree tag.}r   N)r   )r  s    r   r  r    s    xx}q "##r!   )rj   z!int | list[int] | tuple[int, ...]rR   zlist[Bugreport]r   )rt   rT   ru   z"None | list[str] | tuple[str, ...]rR   zdict[str, list[int]])r   rW   rR   z>list[dict[str, str | list[Any] | int | email.message.Message]])r   rW   rR   	list[int])r   zstr | int | list[int]rR   r  )r   zdict[str, Any]rR   r   )r   rT   rR   rU   )r   rT   rR   rS   )r   rT   rR   rS   )rR   zdict[str, str])r   rT   r   r   rR   r   )r   rT   r   zIterable[Any]rR   bytes)r   r  rR   r   )r  
ET.Elementr  rT   r'   r   rR   rS   )r  r  rR   r   )r  rT   rR   rT   )7r\   
__future__r   r  email.feedparserrt   email.policyloggingosurllib.requestr   xml.etree.ElementTreeetreeElementTreer   collections.abcr   r   r   typingr   	getLoggerrX   r   ca_pathpathisdirenvironURLrf   BTS_URLrd   rN   r   rq   ry   r   r   r   ri   r   r   r   r   r   re   r   r   r  r  r   r   r   r   r  r   r!   r   <module>r1     su   #     	  " " -  			8	$ 77==!(BJJ~
 1
$
 
Z Zz!	*!!L 04==
,= =422C2j"*'"#'"'"T4n$  

-*	23l 6
5(10!8#4L+J\$r!   