3 @qhc@s@ddlZddlmZddlmZmZmZmZmZm Z m Z m Z m Z ddl Z ddlZddlmZmZddlmZddlmZddlmZdd d d d d dddddddddddddddgZe rejZejZneZeZGdddeZGdd d eZGdd d eZGd d d eZGd!d d eeZGd"d d eZ Gd#ddeZ!Gd$ddeZ"Gd%ddeZ#Gd&ddeee e!e#Z$Gd'ddeee e#Z%Gd(ddeZ&Gd)ddeZ'Gd*ddeZ(Gd+ddeZ)Gd,ddeZ*Gd-ddeZ+Gd.ddeZ,Gd/ddeZ-Gd0ddeZ.Gd1ddeZ/Gd2d3d3eZ0dS)4N) ModuleType) AnyCallableDictListOptionalTupleType TYPE_CHECKINGUnion)basecli) exceptions)types)utilsGetMixinGetWithoutIdMixin RefreshMixin ListMixin RetrieveMixin CreateMixin UpdateMixinSetMixin DeleteMixin CRUDMixin NoUpdateMixin SaveMixinObjectDeleteMixinUserAgentDetailMixinAccessRequestMixin DownloadMixinSubscribableMixin TodoMixinTimeTrackingMixinParticipantsMixinBadgeRenderMixinc@seZdZUeeeeefee e j  fZ eedf ee j eeefeeejejejdeeefeee j dddZdS)r.F)idlazykwargsreturncKst|tstj|}d|j|f}tr4|jdk s4t|dkrdtrP|jjdk sPt|j||jj|iS|j j |f|}trt|t j  st|j||S)avRetrieve a single object. Args: id (int or str): ID of the object to retrieve lazy (bool): If True, don't request the server, but create a shallow object giving access to the managers. This is useful if you want to avoid useless calls to the API. **kwargs: Extra options to send to the server (e.g. sudo) Returns: object: The generated RESTObject. Raises: GitlabAuthenticationError: If authentication is not correct GitlabGetError: If the server cannot perform the request z%s/%sNT) isinstanceintr clean_str_idpathr _obj_clsAssertionError_id_attrgitlabhttp_getrequestsResponse)selfr&r'r(r- server_datar7L/home/ec2-user/environment/venv/lib/python3.6/dist-packages/gitlab/mixins.pygetSs  z GetMixin.getN)F)__name__ __module__ __qualname__rstr_computed_pathrr_from_parent_attrsr r RESTObjectr._optional_get_attrsr_parent _parent_attrs_pathr1Gitlabexc on_http_errorGitlabGetErrorr r+boolr9r7r7r7r8rIs     c@seZdZUeeeeefee e j  fZ eedf ee j eeefeeejejejdeeeefeee j dddZdS)r.N)r&r(r)cKs`tr|jdk st|jj|jf|}|dkr0dStrTt|tj sFt|jdk sTt|j||S)aTRetrieve a single object. Args: **kwargs: Extra options to send to the server (e.g. sudo) Returns: object: The generated RESTObject Raises: GitlabAuthenticationError: If authentication is not correct GitlabGetError: If the server cannot perform the request N) r r-r/r1r2r*r3r4r.)r5r&r(r6r7r7r8r9szGetWithoutIdMixin.get)N)r:r;r<rr=r>rrr?r r r@r.rArrBrCrDr1rErFrGrHr r+r9r7r7r7r8rvs     c@s`eZdZUeeeeefe  eeef eeef e jejejeddddZdS)rN)r(r)cKsl|jrd|jj|jf}ntr.|jjdk s.t|jj}|jjj|f|}tr^t|t j  s^t|j |dS)aKRefresh a single object from server. Args: **kwargs: Extra options to send to the server (e.g. sudo) Returns None (updates the object) Raises: GitlabAuthenticationError: If authentication is not correct GitlabGetError: If the server cannot perform the request z%s/%sN) r0managerr-r&r r/r1r2r*r3r4 _update_attrs)r5r(r-r6r7r7r8refreshs zRefreshMixin.refresh)r:r;r<rr=r0rr_attrsr_modulerC_updated_attrsr RESTManagerrJrFrGrHrLr7r7r7r8rs     c@seZdZUeeeeeffZ e edf ee e j ee j eeefeeejejejeee jee j fdddZdS)r.)r(r)c s|j}jjr |jdjjjjr8|jdjjjjrP|jdjjjrx:jjD],\}}||jkrb|||}|j ||<qbW|j dj }t rj dk stjj|f|}t|trއfdd|DStjj |SdS)aRetrieve a list of objects. Args: all (bool): If True, return all the items, without pagination per_page (int): Number of items to retrieve per request page (int): ID of the page to return (starts with page 1) as_list (bool): If set to False and no pagination option is defined, return a generator instead of a list **kwargs: Extra options to send to the server (e.g. sudo) Returns: list: The list of objects, or a generator if `as_list` is False Raises: GitlabAuthenticationError: If authentication is not correct GitlabListError: If the server cannot perform the request per_page paginationorder_byr-Ncsg|]}j|qSr7)r.).0item)r5r7r8 sz"ListMixin.list..)copyr1rQ setdefaultrRrS_typesitemskeys get_for_apipopr-r r.r/ http_listr*listr RESTObjectList)r5r(data attr_nametype_clstype_objr-objr7)r5r8r_s&   zListMixin.listN)r:r;r<rr=r>rrr?Z _list_filtersrr r r@r.rBrCrDr1rErFrGGitlabListErrorr r`rr_r7r7r7r8rs     c@sTeZdZUeeeeefee e j  ee j  eeefeeejdS)rN)r:r;r<rr=r>rrr?r r r@r.rBrCrDr1rEr7r7r7r8rs    c@seZdZUeeeeefee e j  ee j  eeefeeejeeefddddZejejdeeeefee j dddZdS) rN)rar)cCsDg}x$|jjD]}||kr|j|qqW|r@tddj|dS)NzMissing attributes: %sz, )Z _create_attrsrequiredappendAttributeErrorjoin)r5ramissingattrr7r7r8_check_missing_create_attrss z'CreateMixin._check_missing_create_attrs)rar(r)c Ks|dkr i}|j|i}|jr|j}xd|jjD]V\}}||jkr4|||}t|tjr~|j|}||j |f||<q4|j ||<q4W|j d|j }|j j |f||d|} trt| tj st|jdk st|j|| S)a Create a new object. Args: data (dict): parameters to send to the server to create the resource **kwargs: Extra options to send to the server (e.g. sudo) Returns: RESTObject: a new instance of the managed object class built with the data sent by the server Raises: GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server cannot perform the request Nr-) post_datafiles)rmrYrWrZr[r*g_types FileAttribute get_file_namer]r\r-r1 http_postr r3r4r/r.) r5rar(rorbrcrdkr-r6r7r7r8creates&     zCreateMixin.create)N)r:r;r<rr=r>rrr?r r r@r.rBrCrDr1rErmrFrGZGitlabCreateErrorrur7r7r7r8rs     c@seZdZUeeeeefee e j  ee j  eeefeedZeejeeefddddZedeeeefejffddd Zejejd eeeefeeeefeeeefd d d ZdS)rFN)rar)csltrjdk sttfddjjD}g}x |D]}||kr6|j|q6q6W|rhtddj|dS)Ncsg|]}|jjkr|qSr7)r.r0)rTrt)r5r7r8rVYsz;UpdateMixin._check_missing_update_attrs..zMissing attributes: %sz, ) r r.r/tuplerKrgrhrirj)r5rargrkrlr7)r5r8_check_missing_update_attrsSs  z'UpdateMixin._check_missing_update_attrs.)r)cCs|jr|jj}n|jj}|S)zmReturn the HTTP method to use. Returns: object: http_put (default) or http_post )_update_uses_postr1rshttp_put)r5 http_methodr7r7r8_get_update_methodcs zUpdateMixin._get_update_method)r&new_datar(r)c Ks|pi}|dkr|j}nd|j|f}|j|i}|jr|j}xd|jjD]V\}}||jkrN|||}t|tjr|j |} | |j |f||<qN|j ||<qNW|j } | |f||d|} t rt| tj st| S)aUpdate an object on the server. Args: id: ID of the object to update (can be None if not required) new_data: the update data for the object **kwargs: Extra options to send to the server (e.g. sudo) Returns: dict: The new object data (*not* a RESTObject) Raises: GitlabAuthenticationError: If authentication is not correct GitlabUpdateError: If the server cannot perform the request Nz%s/%s)rnro)r-rwrYrWrZr[r*rprqrrr]r\r{r r3r4r/) r5r&r|r(r-rorbrcrdrtrzresultr7r7r8updateqs(     zUpdateMixin.update)NN)r:r;r<rr=r>rrr?r r r@r.rBrCrDrxrIr1rErwrr r3r4r{rFrGGitlabUpdateErrorr+r~r7r7r7r8rIs    ( c@sveZdZUeeeeefee e j  ee j  eeefeeejejejeeee j dddZdS)r)keyvaluer(r)cKsdd|jtj|f}d|i}|jj|fd|i|}trXt|tj sJt |j dk sXt |j ||S)aCreate or update the object. Args: key (str): The key of the object to create/update value (str): The value to set for the object **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabSetError: If an error occured Returns: obj: The created/updated attribute z%s/%srrnN) r-rr,r1ryr r*r3r4r/r.)r5rrr(r-rar6r7r7r8setsz SetMixin.setN)r:r;r<rr=r>rrr?r r r@r.rBrCrDr1rErFrGZGitlabSetErrorrr7r7r7r8rs     c@szeZdZUeeeeefee e j  ee j  eeefeeejejejeeefeddddZdS)rN)r&r(r)cKsF|dkr|j}n"t|ts$tj|}d|j|f}|jj|f|dS)aIDelete an object on the server. Args: id: ID of the object to delete **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server cannot perform the request Nz%s/%s)r-r*r+rr,r1Z http_delete)r5r&r(r-r7r7r8deletes   zDeleteMixin.delete)r:r;r<rr=r>rrr?r r r@r.rBrCrDr1rErFrGZGitlabDeleteErrorr r+rr7r7r7r8rs     c@sTeZdZUeeeeefee e j  ee j  eeefeeejdS)rN)r:r;r<rr=r>rrr?r r r@r.rBrCrDr1rEr7r7r7r8rs    c@sTeZdZUeeeeefee e j  ee j  eeefeeejdS)rN)r:r;r<rr=r>rrr?r r r@r.rBrCrDr1rEr7r7r7r8rs    c@sneZdZUdZeeeeef e  eeef eeef ejeeefdddZeddddZdS) rz+Mixin for RESTObject's that can be updated.)r)cCs6i}x |jjjD]}t||||<qW|j|j|S)N)rJrKrggetattrr~rO)r5 updated_datarlr7r7r8_get_updated_data s  zSaveMixin._get_updated_dataN)r(r)cKsT|j}|sdS|j}tr,t|jts,t|jj||f|}|dk rP|j|dS)aqSave the changes made to the object to the server. The object is updated to match what the server returns. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raise: GitlabAuthenticationError: If authentication is not correct GitlabUpdateError: If the server cannot perform the request N) rget_idr r*rJrr/r~rK)r5r(rZobj_idr6r7r7r8saves zSaveMixin.save)r:r;r<__doc__rr=r0rrrMrrNrCrOr rPrJrrr7r7r7r8rs     c@sXeZdZUdZeeeeef e  eeef eeef ejeddddZdS)rz+Mixin for RESTObject's that can be deleted.N)r(r)cKs,trt|jtst|jj|jf|dS)a!Delete the object from the server. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server cannot perform the request N)r r*rJrr/rr)r5r(r7r7r8r7s zObjectDeleteMixin.delete)r:r;r<rrr=r0rrrMrrNrCrOr rPrJrr7r7r7r8r-s    c@sreZdZUeeeeefe  eeef eeef e jejdejejeeeefdddZdS) rSnippetProjectSnippet ProjectIssue)r(r)cKs@d|jj|jf}|jjj|f|}tr.) warningswarnDeprecationWarningr-r r.r/r1r^)r5r(r-rer7)r5r8alls zMemberAllMixin.allN)rr)r:r;r<rrr=r>rrr?r r r@r.rBrCrDr1rEr rrFrGrfrrr7r7r7r8rs     r)1rrrtypingrrrrrrr r r r3r1r r rrFrpr__all__rPZ_RestManagerBaser@Z_RestObjectBaseobjectrrrrrrrrrrrrrrrr r!r"r#r$r%rr7r7r7r8sp ,    -%!= D^"  .",1l$