403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /lib64/python3.9/site-packages/hgext/__pycache__/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /lib64/python3.9/site-packages/hgext/__pycache__/bugzilla.cpython-39.pyc
a

�+�b;��@s|dZddlmZddlZddlZddlZddlmZddlm	Z	ddl
mZmZm
Z
mZmZmZmZddlmZmZejZdZiZe�e�Zed	d
dd�ed	d
dd�ed	ddd�ed	ddd�ed	ddd�ed	ddd�ed	ddd�ed	ddd�ed	ddd�ed	ddd�ed	dejd�ed	ddd�ed	dd d�ed	d!dd�ed	d"dd�ed	d#dd�ed	d$d%d�ed	d&dd�ed	d'dd�ed	d(dd�Gd)d*�d*e�ZGd+d,�d,e�ZGd-d.�d.e�ZGd/d0�d0e�ZGd1d2�d2e�ZGd3d4�d4eej �Z!Gd5d6�d6eej"�Z#Gd7d8�d8e�Z$Gd9d:�d:e$�Z%Gd;d<�d<e&�Z'Gd=d>�d>e�Z(Gd?d@�d@e�Z)dCdAdB�Z*dS)Da�)hooks for integrating with the Bugzilla bug tracker

This hook extension adds comments on bugs in Bugzilla when changesets
that refer to bugs by Bugzilla ID are seen. The comment is formatted using
the Mercurial template mechanism.

The bug references can optionally include an update for Bugzilla of the
hours spent working on the bug. Bugs can also be marked fixed.

Four basic modes of access to Bugzilla are provided:

1. Access via the Bugzilla REST-API. Requires bugzilla 5.0 or later.

2. Access via the Bugzilla XMLRPC interface. Requires Bugzilla 3.4 or later.

3. Check data via the Bugzilla XMLRPC interface and submit bug change
   via email to Bugzilla email interface. Requires Bugzilla 3.4 or later.

4. Writing directly to the Bugzilla database. Only Bugzilla installations
   using MySQL are supported. Requires Python MySQLdb.

Writing directly to the database is susceptible to schema changes, and
relies on a Bugzilla contrib script to send out bug change
notification emails. This script runs as the user running Mercurial,
must be run on the host with the Bugzilla install, and requires
permission to read Bugzilla configuration details and the necessary
MySQL user and password to have full access rights to the Bugzilla
database. For these reasons this access mode is now considered
deprecated, and will not be updated for new Bugzilla versions going
forward. Only adding comments is supported in this access mode.

Access via XMLRPC needs a Bugzilla username and password to be specified
in the configuration. Comments are added under that username. Since the
configuration must be readable by all Mercurial users, it is recommended
that the rights of that user are restricted in Bugzilla to the minimum
necessary to add comments. Marking bugs fixed requires Bugzilla 4.0 and later.

Access via XMLRPC/email uses XMLRPC to query Bugzilla, but sends
email to the Bugzilla email interface to submit comments to bugs.
The From: address in the email is set to the email address of the Mercurial
user, so the comment appears to come from the Mercurial user. In the event
that the Mercurial user email is not recognized by Bugzilla as a Bugzilla
user, the email associated with the Bugzilla username used to log into
Bugzilla is used instead as the source of the comment. Marking bugs fixed
works on all supported Bugzilla versions.

Access via the REST-API needs either a Bugzilla username and password
or an apikey specified in the configuration. Comments are made under
the given username or the user associated with the apikey in Bugzilla.

Configuration items common to all access modes:

bugzilla.version
  The access type to use. Values recognized are:

  :``restapi``:      Bugzilla REST-API, Bugzilla 5.0 and later.
  :``xmlrpc``:       Bugzilla XMLRPC interface.
  :``xmlrpc+email``: Bugzilla XMLRPC and email interfaces.
  :``3.0``:          MySQL access, Bugzilla 3.0 and later.
  :``2.18``:         MySQL access, Bugzilla 2.18 and up to but not
                     including 3.0.
  :``2.16``:         MySQL access, Bugzilla 2.16 and up to but not
                     including 2.18.

bugzilla.regexp
  Regular expression to match bug IDs for update in changeset commit message.
  It must contain one "()" named group ``<ids>`` containing the bug
  IDs separated by non-digit characters. It may also contain
  a named group ``<hours>`` with a floating-point number giving the
  hours worked on the bug. If no named groups are present, the first
  "()" group is assumed to contain the bug IDs, and work time is not
  updated. The default expression matches ``Bug 1234``, ``Bug no. 1234``,
  ``Bug number 1234``, ``Bugs 1234,5678``, ``Bug 1234 and 5678`` and
  variations thereof, followed by an hours number prefixed by ``h`` or
  ``hours``, e.g. ``hours 1.5``. Matching is case insensitive.

bugzilla.fixregexp
  Regular expression to match bug IDs for marking fixed in changeset
  commit message. This must contain a "()" named group ``<ids>` containing
  the bug IDs separated by non-digit characters. It may also contain
  a named group ``<hours>`` with a floating-point number giving the
  hours worked on the bug. If no named groups are present, the first
  "()" group is assumed to contain the bug IDs, and work time is not
  updated. The default expression matches ``Fixes 1234``, ``Fixes bug 1234``,
  ``Fixes bugs 1234,5678``, ``Fixes 1234 and 5678`` and
  variations thereof, followed by an hours number prefixed by ``h`` or
  ``hours``, e.g. ``hours 1.5``. Matching is case insensitive.

bugzilla.fixstatus
  The status to set a bug to when marking fixed. Default ``RESOLVED``.

bugzilla.fixresolution
  The resolution to set a bug to when marking fixed. Default ``FIXED``.

bugzilla.style
  The style file to use when formatting comments.

bugzilla.template
  Template to use when formatting comments. Overrides style if
  specified. In addition to the usual Mercurial keywords, the
  extension specifies:

  :``{bug}``:     The Bugzilla bug ID.
  :``{root}``:    The full pathname of the Mercurial repository.
  :``{webroot}``: Stripped pathname of the Mercurial repository.
  :``{hgweb}``:   Base URL for browsing Mercurial repositories.

  Default ``changeset {node|short} in repo {root} refers to bug
  {bug}.\ndetails:\n\t{desc|tabindent}``

bugzilla.strip
  The number of path separator characters to strip from the front of
  the Mercurial repository path (``{root}`` in templates) to produce
  ``{webroot}``. For example, a repository with ``{root}``
  ``/var/local/my-project`` with a strip of 2 gives a value for
  ``{webroot}`` of ``my-project``. Default 0.

web.baseurl
  Base URL for browsing Mercurial repositories. Referenced from
  templates as ``{hgweb}``.

Configuration items common to XMLRPC+email and MySQL access modes:

bugzilla.usermap
  Path of file containing Mercurial committer email to Bugzilla user email
  mappings. If specified, the file should contain one mapping per
  line::

    committer = Bugzilla user

  See also the ``[usermap]`` section.

The ``[usermap]`` section is used to specify mappings of Mercurial
committer email to Bugzilla user email. See also ``bugzilla.usermap``.
Contains entries of the form ``committer = Bugzilla user``.

XMLRPC and REST-API access mode configuration:

bugzilla.bzurl
  The base URL for the Bugzilla installation.
  Default ``http://localhost/bugzilla``.

bugzilla.user
  The username to use to log into Bugzilla via XMLRPC. Default
  ``bugs``.

bugzilla.password
  The password for Bugzilla login.

REST-API access mode uses the options listed above as well as:

bugzilla.apikey
  An apikey generated on the Bugzilla instance for api access.
  Using an apikey removes the need to store the user and password
  options.

XMLRPC+email access mode uses the XMLRPC access mode configuration items,
and also:

bugzilla.bzemail
  The Bugzilla email address.

In addition, the Mercurial email settings must be configured. See the
documentation in hgrc(5), sections ``[email]`` and ``[smtp]``.

MySQL access mode configuration:

bugzilla.host
  Hostname of the MySQL server holding the Bugzilla database.
  Default ``localhost``.

bugzilla.db
  Name of the Bugzilla database in MySQL. Default ``bugs``.

bugzilla.user
  Username to use to access MySQL server. Default ``bugs``.

bugzilla.password
  Password to use to access MySQL server.

bugzilla.timeout
  Database connection timeout (seconds). Default 5.

bugzilla.bzuser
  Fallback Bugzilla user name to record comments with, if changeset
  committer cannot be found as a Bugzilla user.

bugzilla.bzdir
   Bugzilla install directory. Used by default notify. Default
   ``/var/www/html/bugzilla``.

bugzilla.notify
  The command to run to get Bugzilla to send bug change notification
  emails. Substitutes from a map with 3 keys, ``bzdir``, ``id`` (bug
  id) and ``user`` (committer bugzilla email). Default depends on
  version; from 2.18 it is "cd %(bzdir)s && perl -T
  contrib/sendbugmail.pl %(id)s %(user)s".

Activating the extension::

    [extensions]
    bugzilla =

    [hooks]
    # run bugzilla hook on every change pulled or pushed in here
    incoming.bugzilla = python:hgext.bugzilla.hook

Example configurations:

XMLRPC example configuration. This uses the Bugzilla at
``http://my-project.org/bugzilla``, logging in as user
``bugmail@my-project.org`` with password ``plugh``. It is used with a
collection of Mercurial repositories in ``/var/local/hg/repos/``,
with a web interface at ``http://my-project.org/hg``. ::

    [bugzilla]
    bzurl=http://my-project.org/bugzilla
    user=bugmail@my-project.org
    password=plugh
    version=xmlrpc
    template=Changeset {node|short} in {root|basename}.
             {hgweb}/{webroot}/rev/{node|short}\n
             {desc}\n
    strip=5

    [web]
    baseurl=http://my-project.org/hg

XMLRPC+email example configuration. This uses the Bugzilla at
``http://my-project.org/bugzilla``, logging in as user
``bugmail@my-project.org`` with password ``plugh``. It is used with a
collection of Mercurial repositories in ``/var/local/hg/repos/``,
with a web interface at ``http://my-project.org/hg``. Bug comments
are sent to the Bugzilla email address
``bugzilla@my-project.org``. ::

    [bugzilla]
    bzurl=http://my-project.org/bugzilla
    user=bugmail@my-project.org
    password=plugh
    version=xmlrpc+email
    bzemail=bugzilla@my-project.org
    template=Changeset {node|short} in {root|basename}.
             {hgweb}/{webroot}/rev/{node|short}\n
             {desc}\n
    strip=5

    [web]
    baseurl=http://my-project.org/hg

    [usermap]
    user@emaildomain.com=user.name@bugzilladomain.com

MySQL example configuration. This has a local Bugzilla 3.2 installation
in ``/opt/bugzilla-3.2``. The MySQL database is on ``localhost``,
the Bugzilla database name is ``bugs`` and MySQL is
accessed with MySQL username ``bugs`` password ``XYZZY``. It is used
with a collection of Mercurial repositories in ``/var/local/hg/repos/``,
with a web interface at ``http://my-project.org/hg``. ::

    [bugzilla]
    host=localhost
    password=XYZZY
    version=3.0
    bzuser=unknown@domain.com
    bzdir=/opt/bugzilla-3.2
    template=Changeset {node|short} in {root|basename}.
             {hgweb}/{webroot}/rev/{node|short}\n
             {desc}\n
    strip=5

    [web]
    baseurl=http://my-project.org/hg

    [usermap]
    user@emaildomain.com=user.name@bugzilladomain.com

All the above add a comment to the Bugzilla bug record of the form::

    Changeset 3b16791d6642 in repository-name.
    http://my-project.org/hg/repository-name/rev/3b16791d6642

    Changeset commit comment. Bug 1234.
�)�absolute_importN)�_)�short)�error�
logcmdutil�mail�pycompat�	registrar�url�util)�procutil�
stringutilsships-with-hg-core�bugzilla�apikey�)�default�bzdirs/var/www/html/bugzilla�bzemail�bzurlshttp://localhost/bugzilla/�bzuser�db�bugs�	fixregexps�fix(?:es)?\s*(?:bugs?\s*)?,?\s*(?:nos?\.?|num(?:ber)?s?)?\s*(?P<ids>(?:#?\d+\s*(?:,?\s*(?:and)?)?\s*)+)\.?\s*(?:h(?:ours?)?\s*(?P<hours>\d*(?:\.\d+)?))?�
fixresolutionsFIXED�	fixstatussRESOLVED�hosts	localhost�notify�password�regexps�bugs?\s*,?\s*(?:#|nos?\.?|num(?:ber)?s?)?\s*(?P<ids>(?:\d+\s*(?:,?\s*(?:and)?)?\s*)+)\.?\s*(?:h(?:ours?)?\s*(?P<hours>\d*(?:\.\d+)?))?�strip�style�template�timeout��user�usermap�versionc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�bzaccessz"Base class for access to Bugzilla.cCs.||_|j�dd�}|r*|jj|dgd�dS)Nrr%)Zsections)�ui�configZ
readconfig)�selfr(Zusermap�r+�4/usr/lib64/python3.9/site-packages/hgext/bugzilla.py�__init__�szbzaccess.__init__cCs2|j�d�D] \}}|��|��kr|Sq|S)z,map name of committer to Bugzilla user name.r%)r(Zconfigitems�lower)r*�user�	committerZbzuserr+r+r,�
map_committer�s
zbzaccess.map_committercCsdS)�7remove bug IDs that do not exist in Bugzilla from bugs.Nr+)r*�bugsr+r+r,�filter_real_bug_ids�szbzaccess.filter_real_bug_idscCsdS)�;remove bug IDs where node occurs in comment text from bugs.Nr+)r*�noder3r+r+r,�filter_cset_known_bug_ids�sz"bzaccess.filter_cset_known_bug_idscCsdS)��update the specified bug. Add comment text and set new states.

        If possible add the comment as being from the committer of
        the changeset. Otherwise use the default Bugzilla user.
        Nr+)r*�bugid�newstate�textr0r+r+r,�	updatebug�szbzaccess.updatebugcCsdS�z�Force sending of Bugzilla notification emails.

        Only required if the access method does not trigger notification
        emails automatically.
        Nr+�r*r3r0r+r+r,�notify�szbzaccess.notifyN)
�__name__�
__module__�__qualname__�__doc__r-r1r4r7r<r?r+r+r+r,r'�sr'c@sheZdZdZedd��ZdZdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�ZdS)�bzmysqlz�Support for direct MySQL access to Bugzilla.

    The earliest Bugzilla version this is tested with is version 2.16.

    If your Bugzilla is version 3.4 or above, you are strongly
    recommended to use the XMLRPC access method instead.
    cCsdd�tt|��dS)z#return SQL-friendly list of bug ids�(�,�))�join�map�str)�idsr+r+r,�sql_buglist�szbzmysql.sql_buglistNc	
Cszddl}|t_Wn6tyH}zt�td�|��WYd}~n
d}~00t�||�|j	�
dd�}|j	�
dd�}|j	�
dd�}|j	�
dd�}t|j	�
dd��}|j	�td	�|||d
t
|�f�tjj|||||d�|_|j��|_|��|_i|_d|_dS)
Nrs&python mysql support not available: %srrr$rrr"s'connecting to %s:%s as %s, password %s
�*)�hostr/�passwd�dbZconnect_timeouts-cd %(bzdir)s && ./processmail %(id)s %(user)s)ZMySQLdbrD�_MySQLdb�ImportErrorr�Abortrr'r-r(r)�int�note�len�connect�conn�cursor�get_longdesc_id�longdesc_id�user_ids�default_notify)	r*r(Zmysql�errrNr/rOrP�timeoutr+r+r,r-�s2

���
�
zbzmysql.__init__cOsd|j�td�||f�z|jj|i|��Wn0tjjy^|j�td�||f��Yn0dS)zrun a query.s
query: %s %s
sfailed query: %s %s
N)r(rUrrYZexecuterDrQZ
MySQLError)r*�args�kwargsr+r+r,�runszbzmysql.runcCs:|�d�|j��}t|�dkr.t�td���|ddS)�get identity of longdesc fields5select fieldid from fielddefs where name = "longdesc"��unknown database schemar�rbrY�fetchallrVrrSr�r*rKr+r+r,rZs


zbzmysql.get_longdesc_idcCs`|�dt�|����dd�|j��D�}|��D]&}||vr4|j�td�|�||=q4dS)z"filter not-existing bugs from set.s*select bug_id from bugs where bug_id in %scSsg|]
\}|�qSr+r+)�.0�idr+r+r,�
<listcomp>(rz/bzmysql.filter_real_bug_ids.<locals>.<listcomp>�bug %d does not exist
N)	rbrDrL�keysrYrgr(�statusr)r*r3�existingrjr+r+r,r4"s��zbzmysql.filter_real_bug_idscCsX|�dt�|���t|�f�|j��D](\}|j�t	d�|t|�f�||=q*dS)z=filter bug ids that already refer to this changeset from set.z]select bug_id from longdescs where
                    bug_id in %s and thetext like "%%%s%%"�(bug %d already knows about changeset %s
N)
rbrDrLrmrrYrgr(rnr�r*r6r3rjr+r+r,r7.s��
��z!bzmysql.filter_cset_known_bug_idsc	Cs|j�td��|�|�\}}|��D]�}|j�td�|�|j�dd|j�}|j�dd�}z||}Wn"ty�||||d�}Yn0|j�td�|�t	�
d|d	�}	t�|	�
��}
|	��}|r&|j�|
�t�td
�t	�|���q&|j�td��dS)
ztell bugzilla to send mail.stelling bugzilla to send mail:
s	  bug %s
rrr)r�idr$srunning notify command %s
s	(%s) 2>&1srbsbugzilla notify command %ssdone
N)r(rnr�get_bugzilla_userrmr)r]�	TypeErrorrUr�popenrZ
fromnativeeol�read�close�warnrrSZexplainexit)r*r3r0r/�useridrjZcmdfmtZbzdir�cmd�fp�out�retr+r+r,r?<s(�zbzmysql.notifycCs�z|j|WSty�zt|�}Wn`ty�|j�td�|�|�d|�|j�	�}t
|�dkrrt|��t|dd�}Yn0||j|<|YS0dS)z!look up numeric bugzilla user id.slooking up user %s
zPselect userid from profiles
                            where login_name like %srdrN)r\�KeyErrorrT�
ValueErrorr(rUrrbrYrgrV)r*r/ry�allr+r+r,�get_user_idVs"�

zbzmysql.get_user_idcCs�|�|�}z|�|�}Wnrty�z6|j�dd�}|sLt�td�|��|�|�}|}Wn(ty�t�td�||f��Yn0Yn0||fS)z�See if committer is a registered bugzilla user. Return
        bugzilla username and userid if so. If not, return default
        bugzilla username and userid.rrs#cannot find bugzilla user id for %ss)cannot find bugzilla user id for %s or %s)r1r�r~r(r)rrSr)r*r0r/ryZdefaultuserr+r+r,rsks&

�
��zbzmysql.get_bugzilla_usercCslt|�dkr|j�td��|�|�\}}t�d�}|�d||||f�|�d||||jf�|j	�
�dS)z�update bug state with comment text.

        Try adding comment as committer of changeset, otherwise as
        default bugzilla user.rs'Bugzilla/MySQL cannot update bug state
z%Y-%m-%d %H:%M:%Szvinsert into longdescs
                    (bug_id, who, bug_when, thetext)
                    values (%s, %s, %s, %s)zfinsert into bugs_activity (bug_id, who, bug_when, fieldid)
                    values (%s, %s, %s, %s)N)rVr(rxrrs�time�strftimerbr[rXZcommit)r*r9r:r;r0r/ryZnowr+r+r,r<�s

��zbzmysql.updatebug)r@rArBrC�staticmethodrLrQr-rbrZr4r7r?r�rsr<r+r+r+r,rD�s
	rDc@seZdZdZdd�ZdS)�bzmysql_2_18z!support for bugzilla 2.18 series.cCst�||�d|_dS)Ns>cd %(bzdir)s && perl -T contrib/sendbugmail.pl %(id)s %(user)s)rDr-r]�r*r(r+r+r,r-�s�zbzmysql_2_18.__init__N)r@rArBrCr-r+r+r+r,r��sr�c@s eZdZdZdd�Zdd�ZdS)�bzmysql_3_0z support for bugzilla 3.0 series.cCst�||�dS)N)r�r-r�r+r+r,r-�szbzmysql_3_0.__init__cCs:|�d�|j��}t|�dkr.t�td���|ddS)rcs0select id from fielddefs where name = "longdesc"rdrerrfrhr+r+r,rZ�s


zbzmysql_3_0.get_longdesc_idN)r@rArBrCr-rZr+r+r+r,r��sr�c@s&eZdZdZgZdd�Zddd�ZdS)	�cookietransportrequesta�A Transport request method that retains cookies over its lifetime.

    The regular xmlrpclib transports ignore cookies. Which causes
    a bit of a problem when you need a cookie-based login, as with
    the Bugzilla XMLRPC interface prior to 4.4.3.

    So this is a helper for defining a Transport which looks for
    cookies being set in responses and saves them to add to all future
    requests.
    cCs"|jr|jD]}|�d|�qdS)NsCookie)�cookiesZ	putheader)r*Z
connection�cookier+r+r,�send_cookies�s
z#cookietransportrequest.send_cookiesrc
Cs||_d|_|�|�}|r$|�d�|�|||�|�||�|�|�|�|�|�||�z|�	�}Wnt
y�|j�	�}Yn0|j�
d�D]0}|�dd�d}|�dd�d}	|j�|	�q�|jdkr�t�|||j|j|jj��|��}
|��\}}|�|
�|��|��S)NFrds
Set-Cookies: �;r��)�verboseZaccept_gzip_encodingZmake_connectionZset_debuglevelZsend_requestZ	send_hostr�Zsend_user_agentZsend_contentZgetresponse�AttributeErrorZ_conn�msgZgetallmatchingheaders�splitr��appendrn�	xmlrpclibZ
ProtocolError�reasonZheadersrvZ	getparserZfeedrw)
r*rNZhandlerZrequest_bodyr��hZresponse�header�valr�Zpayload�parserZunmarshallerr+r+r,�request�s<




�
zcookietransportrequest.requestN)r)r@rArBrCr�r�r�r+r+r+r,r��sr�c@seZdZddd�ZdS)�cookietransportrcCs t�tjd�rtj�||�dS�Nr-)r�safehasattrr��	Transportr-�r*Zuse_datetimer+r+r,r-szcookietransport.__init__N)r�r@rArBr-r+r+r+r,r�sr�c@seZdZddd�ZdS)�cookiesafetransportrcCs t�tjd�rtj�||�dSr�)rr�r�r��
SafeTransportr-r�r+r+r,r-szcookiesafetransport.__init__N)rr�r+r+r+r,r�sr�c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�bzxmlrpcznSupport for access to Bugzilla via the Bugzilla XMLRPC API.

    Requires a minimum Bugzilla version 3.4.
    cCs�t�||�|j�dd�}|�d�d}|j�dd�}|j�dd�}|j�dd�|_|j�dd�|_t�t	�
|�|�|��|_|jj
��d	�d
�}t|d�|_t|d�|_|jj�||d
d��}|�dd�|_dS)Nrr�/s/xmlrpc.cgir$rrrr&�.rrdT)�loginrsrestrict_login�tokenr)r'r-r(r)�rstrip�	fixstatus�
fixresolutionr�ZServerProxyrZstrurl�	transport�bzproxyZBugzilla�versionr�rT�
bzvermajorZ
bzverminor�User�login�get�bztoken)r*r(Zbzwebr/rOZverr�r+r+r,r-s"�
�zbzxmlrpc.__init__cCs&tj�|d�ddkrt�St�SdS)Nshttprshttps)r�urlreq�urlparser�r�)r*Zurir+r+r,r�)szbzxmlrpc.transportcCs@|jj�|gdg|jd��}d�dd�|dd|dD��S)	z0Return a string with all comment text for a bug.�text)�ids�include_fieldsr�rcSsg|]}|d�qS)r�r+�ri�tr+r+r,rk5rz-bzxmlrpc.get_bug_comments.<locals>.<listcomp>rs%d�comments)r��Bug�commentsr�rH)r*rj�cr+r+r,�get_bug_comments/s��zbzxmlrpc.get_bug_commentscCsV|jj�t|���gd|jd��}|dD]&}|d}|j�td�|�||=q*dS)NT)r�r�s
permissiver�sfaultsrrrl)	r�r�r��sortedrmr�r(rnr)r*r3ZprobeZbadbugrjr+r+r,r48s
��zbzxmlrpc.filter_real_bug_idscCsPt|���D]>}|�|��t|��dkr|j�td�|t|�f�||=qdS)N���rp)r�rmr��findrr(rnrrqr+r+r,r7Fs
��z"bzxmlrpc.filter_cset_known_bug_idscCs�i}d|vr|d|d<|jdkrn|g|d<d|i|d<d|vrT|j|d<|j|d	<|j|d
<|jj�|�n6d|vr�|j�t	d��||d<||d<|jj�
|�dS)
N�hours�	work_time�r�sbody�comment�fix�status�
resolutionr�s?Bugzilla/XMLRPC needs Bugzilla 4.0 or later to mark bugs fixed
rr)r�r�r�r�r�r��updater(rxrZadd_comment)r*r9r:r;r0r`r+r+r,r<Os(




��zbzxmlrpc.updatebugN)
r@rArBrCr-r�r�r4r7r<r+r+r+r,r�s		r�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�
bzxmlrpcemaila�Read data from Bugzilla via XMLRPC, send updates via email.

    Advantages of sending updates via email:
      1. Comments can be added as any user, not just logged in user.
      2. Bug statuses or other fields not accessible via XMLRPC can
         potentially be updated.

    There is no XMLRPC function to change bug status before Bugzilla
    4.0, so bugs cannot be marked fixed via XMLRPC before Bugzilla 4.0.
    But bugs can be marked fixed via email from 3.4 onwards.
    cCs@t�||�|j�dd�|_|js0t�td���t�	|j�dS)Nrrsconfiguration 'bzemail' missing)
r�r-r(r)�bzemailrrSrrZvalidateconfigr�r+r+r,r-}s
zbzxmlrpcemail.__init__cCs>|jdkrd|t�|�fS|dkr(d}d|t�|�fSdS)Nr�s@%s %srrsbug_ids@%s = %s)r�r�bytestr)r*Z	fieldname�valuer+r+r,�makecommandline�s

zbzxmlrpcemail.makecommandlinecCs |�|�}|jj�|g|jd��}|dsj|j�dd�}|jj�|g|jd��}|dsjt�t	d�|��|ddd}|�
|�d|��d	�|�d
|}t
�|j�}t
�|j||�}t
�|j|j|�}	t
�|j||�}
||
d<|	|
d<t
�|jd
|�|
d<t
�|j�}|||	|
���dS)a�send modification message to Bugzilla bug via email.

        The message format is documented in the Bugzilla email_in.pl
        specification. commands is a list of command lines, comment is the
        comment text.

        To stop users from crafting commit comments with
        Bugzilla commands, specify the bug ID via the message body, rather
        than the subject line, and leave a blank line after it.
        )smatchr�susersrr$s(default bugzilla user %s email not foundrsemailrr�
s

sFromsTosBug modificationsSubjectN)r1r�r�r�r�r(r)rrSrr�r�rHr�	_charsetsZ
addressencoder�Z
mimeencodeZ
headencoderWZ	as_string)r*r9ZcommandsZcommentr0r/�matchesr;r�r�r�Zsendmailr+r+r,�send_bug_modify_email�s6
��
��z#bzxmlrpcemail.send_bug_modify_emailcCsfg}d|vr"|�|�d|d��d|vrR|�|�d|j��|�|�d|j��|�||||�dS)Nr�r�r�s
bug_statusr�)r�r�r�r�r�)r*r9r:r;r0Zcmdsr+r+r,r<�szbzxmlrpcemail.updatebugN)r@rArBrCr-r�r�r<r+r+r+r,r�is
)r�c@seZdZdS)�NotFoundN)r@rArBr+r+r+r,r��sr�c@sTeZdZdZdd�Zddd�Zdd�Zdd
d�Zdd
�Zdd�Z	dd�Z
dd�ZdS)�	bzrestapizVRead and write bugzilla data using the REST API available since
    Bugzilla 5.0.
    cCs~t�||�|j�dd�}d�|dg�|_|j�dd�|_|j�dd�|_|j�dd�|_|j�dd�|_	|j�dd	�|_
dS)
Nrrr�srestrr$rrr)r'r-r(r)rH�bzroot�apikeyr/rOr�r�)r*r(�bzr+r+r,r-�szbzrestapi.__init__NcCszd�|jgdd�|D��}i}|jr2|j|d<n |jrR|jrR|j|d<|j|d<|r^||d<|rvd|tj�|�f}|S)	Nr�cSsg|]}t�|��qSr+)rr�r�r+r+r,rk�rz$bzrestapi.apiurl.<locals>.<listcomp>sapi_keyr�rr�s%s?%s)rHr�r�r/rOrr��	urlencode)r*�targets�include_fieldsr
Zqvr+r+r,�apiurl�s

zbzrestapi.apiurlc
Csxzt�|j|�}t�|���WStjjyr}z8|j	dkrJt
�td���|j	dkr\t
��n�WYd}~n
d}~00dS)N��authorization failed�)r
�openr(r�
json_loadsrvr�urlerr�	httperror�coderrSrr�)r*�burl�resp�instr+r+r,�_fetch�s

zbzrestapi._fetch�POSTc	
Cs�t�|�}|dkr,Gdd�dtjj�}|}ntjj}|||ddi�}z"t�|j��|�}t	�
|���WStjj
y�}z8|jdkr�t�td���|jdkr�t��n�WYd}~n
d}~00dS)	N�PUTc@seZdZdd�ZdS)z%bzrestapi._submit.<locals>.putrequestcSsdS)Nr�r+�r*r+r+r,�
get_method�sz0bzrestapi._submit.<locals>.putrequest.get_methodN)r@rArBr�r+r+r+r,�
putrequest�sr�sContent-Typesapplication/jsonr�r�r�)�json�dumpsrr�r�r
�openerr(r�rr�rvr�r�r�rrSrr�)	r*r��data�methodr�Zrequest_typeZreqr�r�r+r+r,�_submit�s


zbzrestapi._submitc	Csbt�}|D]B}|jd|fdd�}z|�|�Wq
tyJ|�|�Yq
0q
|D]
}||=qRdS)r2�bugr��r�N)�setr�r�r��add)r*r3Zbadbugsr9r�r+r+r,r4szbzrestapi.filter_real_bug_idscs�t|��|��D]l}|jd|dfdd�}|�|�}|dt�|�d}t�fdd�|D��r|j�t	d	�|�f�||=qd
S)r5r�r�r�r�rr�c3s|]}�|dvVqdS)r�Nr+)rir��Zsnr+r,�	<genexpr>rz6bzrestapi.filter_cset_known_bug_ids.<locals>.<genexpr>rpN)
rrmr�r�rr��anyr(rnr)r*r6r3r9r��resultr�r+r�r,r7s
�
��z#bzrestapi.filter_cset_known_bug_idscCs�i}d|vr|d|d<d|vr4|j|d<|j|d<|rx|ddd�|d<|�d	|f�}|j||d
d�|j�d|�n4|�d	|df�}|�||ddd��|j�d
|�dS)r8r�r�r�r�r�F)r�s
is_privatesis_markdownr�r�r�)r�supdated bug %s
sadded comment to bug %s
N)r�r�r�r�r(�debug)r*r9r:r;r0Zbugmodr�r+r+r,r< s.

�
��zbzrestapi.updatebugcCsdSr=r+r>r+r+r,r?Bszbzrestapi.notify)N)r�)r@rArBrCr-r�r�r�r4r7r<r?r+r+r+r,r��s


"r�c@s>eZdZeeeeeed�Z	dd�Z
dd�Zdd�Zdd	�Z
d
S)�bugzilla)s2.16s2.18s3.0sxmlrpcsxmlrpc+emailsrestapicCs�||_||_|j�dd�}ztj|}Wn$tyLt�td�|��Yn0||j�|_	t
�|j�dd�t
j�|_
t
�|j�dd�t
j�|_t
�d�|_dS)Nrr&s!bugzilla version %s not supportedrrs\D+)r(�repor)r��	_versionsr~rrSr�bzdriver�re�compile�
IGNORECASE�bug_re�fix_re�split_re)r*r(r�Z	bzversionZbzclassr+r+r,r-Ws"
�
��zbugzilla.__init__c	Cs�d}i}|j�|��|�}|j�|��|�}i}|s<|s<�q||sF|}n$|sP|}n|��|��krf|}n|}|��}||ur�|j�|��|�}d|vr�|d=n|j�|��|�}d|d<z|�d�}Wnty�|�d�}Yn0zt|�d��}	|	|d<WnRt�yYn@t	�y"Yn.t
�yN|j�t
d�|�d��Yn0|j�|�D]}
|
�sj�q\||t|
�<�q\q,|�r�|j�|�|�r�|j�|��|�|S)z�return bugs dictionary created from commit comment.

        Extract bug info from changeset comments. Filter out any that are
        not known to Bugzilla, and any that already have a reference to
        the given changeset in their comments.
        rr�Nr�rdr�s%s: invalid hours
)r�search�descriptionr�start�end�group�
IndexError�floatrtrr(rnrrr�rTr�r4r7r6)r*�ctxrr3ZbugmatchZfixmatchZ
bugattribs�mrKZhoursrjr+r+r,�	find_bugslsV zbugzilla.find_bugsc
	s��fdd�}d}�j�dd�}|s0�j�dd�}|s@|s@td�}t�||�}t��j�j|�}�j��|j||�	�t
�|��j�dd	��jj|�jj�d
��j�
�}	�j�|||	t�|����dS)z0update bugzilla bug with reference to changeset.csVt�j�dd��}t�|�}|dkrR|�d�}|dkr8qR||dd�}|d8}q|S)zJstrip leading prefix of repo root and turn into
            url-safe path.rrrr�r�rdN)rTr(r)rZpconvertr�)�root�countr�r�r+r,�webroot�s


z bugzilla.update.<locals>.webrootNrr!r sUchangeset {node|short} in repo {root} refers to bug {bug}.
details:
	{desc|tabindent}swebsbaseurl)Zchanges�bugZhgwebrr)r(r)rrZtemplatespecZchangesettemplaterr�Z
pushbufferZshowZ	changesetrr�rZ	popbufferr�r<r
�emailr/)
r*r9r:rrZmapfileZtmpl�specr�r�r+r�r,r��s0
�

�
�zbugzilla.updatecCs|j�||�dS)z1ensure Bugzilla users are notified of bug change.N)r�r?r>r+r+r,r?�szbugzilla.notifyN)r@rArBrDr�r�r�r�r�r�r-rr�r?r+r+r+r,r�Ks�	9)r�c

Ks�|durt�td�|��zVt||�}||}|�|�}|rn|D]}|�||||�q@|�|t�|�	���Wn<t
y�}	z$t�td�t�|	���WYd}	~	n
d}	~	00dS)z�add comment to bugzilla for each changeset that refers to a
    bugzilla bug id. only add a comment once per bug, so same change
    seen multiple times does not fill bug with duplicate data.Ns)hook type %s does not pass a changeset idsBugzilla error: %s)rrSrr�rr�r?r
rr/�	ExceptionZforcebytestr)
r(r�Zhooktyper6rar�rr3r�er+r+r,�hook�s
�

r)N)+rCZ
__future__rr�r�r�Zmercurial.i18nrZmercurial.noderZ	mercurialrrrrr	r
rZmercurial.utilsrr
r�Z
testedwithZconfigtableZ
configitemZdynamicdefault�objectr'rDr�r�r�r�r�r�r�r�r��LookupErrorr�r�r�rr+r+r+r,�<module>	s$	
�������
������	�������.7
J]W	

Youez - 2016 - github.com/yon3zu
LinuXploit