a *Na@sddlZddlmZddlmZmZmZmZmZm Z m Z m Z m Z ddl Z ddlZddlmZmZddlmZddlmZddlmZgdZe rejZejZneZeZGd d d eZGd d d eZGd ddeZGdddeZGdddeeZGdddeZ GdddeZ!GdddeZ"GdddeZ#Gdddeee e!e#Z$Gdddeee e#Z%Gdd d eZ&Gd!d"d"eZ'Gd#d$d$eZ(Gd%d&d&eZ)Gd'd(d(eZ*Gd)d*d*eZ+Gd+d,d,eZ,Gd-d.d.eZ-Gd/d0d0eZ.Gd1d2d2eZ/Gd3d4d4eZ0dS)5N) ModuleType) AnyCallableDictListOptionalTupleType TYPE_CHECKINGUnion)basecli) exceptions)types)utils)GetMixinGetWithoutIdMixin RefreshMixin ListMixin RetrieveMixin CreateMixin UpdateMixinSetMixin DeleteMixin CRUDMixin NoUpdateMixin SaveMixinObjectDeleteMixinUserAgentDetailMixinAccessRequestMixin DownloadMixinSubscribableMixin TodoMixinTimeTrackingMixinParticipantsMixinBadgeRenderMixinc@seZdZUeeed<eeefed<eee j ed<dZ e edfed<ee j ed<eeefed<eeed <e jed <eejdeeefeee j d d dZdS)r_computed_path_from_parent_attrs_obj_cls._optional_get_attrs_parent _parent_attrs_pathgitlabF)idlazykwargsreturncKst|tst|}d|j|f}tr4|jdus4J|durdtrP|jjdusPJ|||jj|iS|jj |fi|}trt|t j rJ|||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 %s/%sNT) isinstanceintr clean_str_idpathr r(_id_attrr.http_getrequestsResponse)selfr/r0r1r7 server_datar)r)h/private/var/folders/js/6pj4vh5d4zd0k6bxv74qrbhr0000gr/T/pip-target-22xwyzbs/lib/python/gitlab/mixins.pygetSs  z GetMixin.getN)F)__name__ __module__ __qualname__rstr__annotations__rrr r RESTObjectr*rr.Gitlabexc on_http_errorGitlabGetErrorr r5boolr?r)r)r)r>rIs     rc@seZdZUeeed<eeefed<eee j ed<dZ e edfed<ee j ed<eeefed<eeed <e jed <eejdeeeefeee j d d dZd S)rr&r'r(r).r*r+r,r-r.Nr/r1r2cKsbtr|jdusJ|jj|jfi|}|dur4dStrVt|tjrHJ|jdusVJ|||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 r7r.r9r4r:r;r()r<r/r1r=r)r)r>r?szGetWithoutIdMixin.get)N)r@rArBrrCrDrrr r rEr*rr.rFrGrHrIr r5r?r)r)r)r>rvs     rc@sxeZdZUeeed<eeefed<eed<eeefed<eeefed<e j ed<e e j eddd d ZdS) rr8_attrs_moduler,_updated_attrsmanagerNr1r2cKsn|jrd|jj|jf}ntr.|jjdus.J|jj}|jjj|fi|}tr`t|tj r`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 r3N) r8rOr7r/r r.r9r4r:r; _update_attrsr<r1r7r=r)r)r>refreshs zRefreshMixin.refresh)r@rArBrrCrDrrrr RESTManagerrGrHrIrSr)r)r)r>rs    rc@seZdZUeeed<eeefed<dZe edfed<ee e j ed<ee j ed<eeefed<eeed <e jed <eejeee jee j fd d d ZdS)rr&r'r). _list_filtersr(r+r,r-r.rPc s|}jjr |djjjjr8|djjjjrP|djjjrjD],\}}||vr`|||}| ||<q`| dj }t rj dusJjj|fi|}t|trއfdd|DStj |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_byr7Ncsg|]}|qSr)r(.0itemr<r)r> z"ListMixin.list..)copyr.rV setdefaultrWrX_typesitemskeys get_for_apipopr7r r( http_listr4listr RESTObjectList)r<r1data attr_nametype_clstype_objr7objr)r]r>rhs&   zListMixin.listN)r@rArBrrCrDrrrUrr r rEr.rFrGrHGitlabListErrorr rirrhr)r)r)r>rs     rc@speZdZUeeed<eeefed<eee j ed<ee j ed<eeefed<eeed<e j ed<dS) rr&r'r(r+r,r-r.N r@rArBrrCrDrrr r rEr.rFr)r)r)r>rs    rc@seZdZUeeed<eeefed<eee j ed<ee j ed<eeefed<eeed<e j ed<eeefdd d d Z eejdeeeefee j d d dZdS)rr&r'r(r+r,r-r.Nrjr2cCs@g}|jjD]}||vr ||q q |r_check_missing_create_attrss  z'CreateMixin._check_missing_create_attrs)rjr1r2c Ks|dur i}||i}|jr|}|jD]V\}}||vr2|||}t|tjr|||}|| |f||<q2| ||<q2| d|j }|j j |f||d|} trt| tjrJ|jdusJ||| 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 Nr7 post_datafiles)rzrbr`rcrdr4g_types FileAttribute get_file_namerfrer7r. http_postr r:r;r() r<rjr1r}rkrlrmkr7r=r)r)r>creates&     zCreateMixin.create)N)r@rArBrrCrDrrr r rEr.rFrzrGrHZGitlabCreateErrorrr)r)r)r>rs     rc@seZdZUeeed<eeefed<eee j ed<ee j ed<eeefed<eeed<dZ e ed<e jed <eeefd d d d ZedeeeefejffdddZeejdeeeefeeeefeeeefdddZd S)rr&r'r(r+r,r-F_update_uses_postr.NrqcshtrjdusJtfddjjD}g}|D]}||vr4||q4q4|rdtdd|dS)Ncsg|]}|jjkr|qSr))r(r8)r[rr]r)r>r^Yr_z;UpdateMixin._check_missing_update_attrs..rrrs)r r(tuplerQrtrurvrw)r<rjrtrxryr)r]r>_check_missing_update_attrsSs z'UpdateMixin._check_missing_update_attrs.r2cCs|jr|jj}n|jj}|S)zmReturn the HTTP method to use. Returns: object: http_put (default) or http_post )rr.rhttp_put)r< http_methodr)r)r>_get_update_methodcs zUpdateMixin._get_update_method)r/new_datar1r2c Ks|pi}|dur|j}nd|j|f}||i}|jr|}|jD]V\}}||vrL|||}t|tjr| |} | | |f||<qL| ||<qL| } | |f||d|} t rt| tjrJ| 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 Nr3r{)r7rrbr`rcrdr4r~rrrfrerr r:r;) r<r/rr1r7r}rkrlrmrrresultr)r)r>updateqs(     zUpdateMixin.update)NN)r@rArBrrCrDrrr r rErrJr.rFrrr r:r;rrGrHGitlabUpdateErrorr5rr)r)r)r>rIs(        rc@seZdZUeeed<eeefed<eee j ed<ee j ed<eeefed<eeed<e j ed<e e jeeee j dd d Zd S) rr&r'r(r+r,r-r.)keyvaluer1r2cKsbd|jt|f}d|i}|jj|fd|i|}trVt|tjrHJ|j dusVJ| ||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 r3rr|N) r7rr6r.rr r4r:r;r()r<rrr1r7rjr=r)r)r>setsz SetMixin.setN)r@rArBrrCrDrrr r rEr.rFrGrHZGitlabSetErrorrr)r)r)r>rs     rc@seZdZUeeed<eeefed<eee j ed<ee j ed<eeefed<eeed<e j ed<e e jeeefedd d d ZdS) rr&r'r(r+r,r-r.NrKcKsJ|dur|j}n"t|ts$t|}d|j|f}|jj|fi|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 Nr3)r7r4r5rr6r.Z http_delete)r<r/r1r7r)r)r>deletes   zDeleteMixin.delete)r@rArBrrCrDrrr r rEr.rFrGrHZGitlabDeleteErrorr r5rr)r)r)r>rs     rc@speZdZUeeed<eeefed<eee j ed<ee j ed<eeefed<eeed<e j ed<dS) rr&r'r(r+r,r-r.Nrpr)r)r)r>rs    rc@speZdZUeeed<eeefed<eee j ed<ee j ed<eeefed<eeed<e j ed<dS) rr&r'r(r+r,r-r.Nrpr)r)r)r>rs    rc@seZdZUdZeeed<eeefed<e ed<eeefed<eeefed<e j ed<eeefdd d Z ed d d dZ d S)rz+Mixin for RESTObject's that can be updated.r8rLrMr,rNrOrcCs2i}|jjjD]}t||||<q||j|S)N)rOrQrtgetattrrrN)r< updated_dataryr)r)r>_get_updated_data s  zSaveMixin._get_updated_dataNrPcKsX|}|sdS|}tr,t|jts,J|jj||fi|}|durT||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 r4rOrrrQ)r<r1rZobj_idr=r)r)r>saves zSaveMixin.save)r@rArB__doc__rrCrDrrrr rTrrr)r)r)r>rs    rc@speZdZUdZeeed<eeefed<e ed<eeefed<eeefed<e j ed<edd d d Z dS) rz+Mixin for RESTObject's that can be deleted.r8rLrMr,rNrONrPcKs0trt|jtsJ|jj|fi|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 r4rOrrr)r<r1r)r)r>r7s zObjectDeleteMixin.delete) r@rArBrrrCrDrrrr rTrr)r)r)r>r-s   rc@seZdZUeeed<eeefed<eed<eeefed<eeefed<e j ed<e de e jeeeefdd d Zd S) rr8rLrMr,rNrO)ZSnippetZProjectSnippet ProjectIssuerPcKsBd|jj|f}|jjj|fi|}tr>t|tjr>J|S)aGet the user agent detail. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabGetError: If the server cannot perform the request z%s/%s/user_agent_detail rOr7rr.r9r r4r:r;r<r1r7rr)r)r>user_agent_detailNs z&UserAgentDetailMixin.user_agent_detailN)r@rArBrrCrDrrrr rTr register_custom_actionrGrHrIrr)r)r)r>rFs    rc@seZdZUeeed<eeefed<eed<eeefed<eeefed<e j ed<e de deejejfeed d d d Zd S) rr8rLrMr,rNrO)ZProjectAccessRequestZGroupAccessRequest) access_levelN)rr1r2cKsVd|jj|jf}d|i}|jjj|fd|i|}trHt|tjrHJ| |dS)aYApprove an access request. Args: access_level (int): The access level for the user **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabUpdateError: If the server fails to perform the request z %s/%s/approverr|N) rOr7r/r.rr r4r:r;rQ)r<rr1r7rjr=r)r)r>approveis zAccessRequestMixin.approve)r@rArBrrCrDrrrr rTr rrrGrHrr.ZDEVELOPER_ACCESSr5rr)r)r)r>ras    rc @seZdZUeeed<eeefed<eed<eeefed<eeefed<e j ed<e de e jdeeeeeeed d d Zd S)r r8rLrMr,rNrO)Z GroupExportZ ProjectExportFN)streamedaction chunk_sizer1r2cKsLd|jj}|jjj|f|dd|}trdownloads zDownloadMixin.download)FNr)r@rArBrrCrDrrrr rTr rrGrHrIrJrr5bytesrr)r)r)r>r s$    r c@seZdZUeeed<eeefed<eed<eeefed<eeefed<e j ed<e de e jedd d d Ze de e jedd d d ZdS)r!r8rLrMr,rNrO)rProjectMergeRequestZ ProjectLabelZ GroupLabelNrPcKsLd|jj|f}|jjj|fi|}tr>t|tjr>J| |dS)a"Subscribe to the object notifications. Args: **kwargs: Extra options to send to the server (e.g. sudo) raises: GitlabAuthenticationError: If authentication is not correct GitlabSubscribeError: If the subscription cannot be done z%s/%s/subscribeN rOr7rr.rr r4r:r;rQrRr)r)r> subscribes zSubscribableMixin.subscribecKsLd|jj|f}|jjj|fi|}tr>t|tjr>J| |dS)a*Unsubscribe from the object notifications. Args: **kwargs: Extra options to send to the server (e.g. sudo) raises: GitlabAuthenticationError: If authentication is not correct GitlabUnsubscribeError: If the unsubscription cannot be done z%s/%s/unsubscribeNrrRr)r)r> unsubscribes zSubscribableMixin.unsubscribe)r@rArBrrCrDrrrr rTr rrGrHZGitlabSubscribeErrorrZGitlabUnsubscribeErrorrr)r)r)r>r!s     r!c@seZdZUeeed<eeefed<eed<eeefed<eeefed<e j ed<e de e jedd d d ZdS) r"r8rLrMr,rNrOrrNrPcKs.d|jj|f}|jjj|fi|dS)aCreate a todo associated to the object. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabTodoError: If the todo cannot be set z %s/%s/todoN)rOr7rr.r)r<r1r7r)r)r>todos zTodoMixin.todo)r@rArBrrCrDrrrr rTr rrGrHZGitlabTodoErrorrr)r)r)r>r"s    r"c@sJeZdZUeeed<eeefed<eed<eeefed<eeefed<e j ed<e de e jeeeefdd d Ze dd e e jeeeeefd d dZe de e jeeeefdddZe dd e e jeeeeefd ddZe de e jeeeefdddZdS)r#r8rLrMr,rNrOrrPcKsVd|jvr|jdSd|jj|f}|jjj|fi|}trRt|tj rRJ|S)a%Get time stats for the object. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabTimeTrackingError: If the time tracking update cannot be done time_statsz%s/%s/time_stats) attributesrOr7rr.r9r r4r:r;rr)r)r>rs  zTimeTrackingMixin.time_stats)duration)rr1r2cKsNd|jj|f}d|i}|jjj|fd|i|}trJt|tjrJJ|S)auSet an estimated time of work for the object. Args: duration (str): Duration in human format (e.g. 3h30) **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabTimeTrackingError: If the time tracking update cannot be done z%s/%s/time_estimaterr| rOr7rr.rr r4r:r;r<rr1r7rjrr)r)r> time_estimates zTimeTrackingMixin.time_estimatecKsBd|jj|f}|jjj|fi|}tr>t|tjr>J|S)a9Resets estimated time for the object to 0 seconds. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabTimeTrackingError: If the time tracking update cannot be done z%s/%s/reset_time_estimaterrr)r)r>reset_time_estimate+s z%TimeTrackingMixin.reset_time_estimatecKsNd|jj|f}d|i}|jjj|fd|i|}trJt|tjrJJ|S)amAdd time spent working on the object. Args: duration (str): Duration in human format (e.g. 3h30) **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabTimeTrackingError: If the time tracking update cannot be done z%s/%s/add_spent_timerr|rrr)r)r>add_spent_time=s z TimeTrackingMixin.add_spent_timecKsBd|jj|f}|jjj|fi|}tr>t|tjr>J|S)a3Resets the time spent working on the object. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabTimeTrackingError: If the time tracking update cannot be done z%s/%s/reset_spent_timerrr)r)r>reset_spent_timeQs z"TimeTrackingMixin.reset_spent_timeN)r@rArBrrCrDrrrr rTr rrGrHZGitlabTimeTrackingErrorrrrrrr)r)r)r>r#s*          r#c@seZdZUeeed<eeefed<eed<eeefed<eeefed<e j ed<e de e jeeeefdd d Zd S) r$r8rLrMr,rNrO)rrrPcKsBd|jj|f}|jjj|fi|}tr>t|tjr>J|S)aList the participants. 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) Raises: GitlabAuthenticationError: If authentication is not correct GitlabListError: If the list could not be retrieved Returns: RESTObjectList: The list of participants z%s/%s/participantsrrr)r)r> participantsls zParticipantsMixin.participantsN)r@rArBrrCrDrrrr rTr rrGrHrorr)r)r)r>r$ds    r$c@s@eZdZeddeejeee e ee fdddZ dS)r%)ZGroupBadgeManagerZProjectBadgeManagerlink_url image_url)rrr1r2cKsBd|j}||d}|jj||fi|}tr>t|tjr>J|S)aPreview link_url and image_url after interpolation. Args: link_url (str): URL of the badge link image_url (str): URL of the badge image **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabRenderError: If the rendering failed Returns: dict: The rendering properties z %s/renderr)r7r.r9r r4r:r;)r<rrr1r7rjrr)r)r>renders   zBadgeRenderMixin.renderN) r@rArBr rrGrHZGitlabRenderErrorrCrrrr)r)r)r>r%s  r%c@seZdZUdZeeed<eeefed<ee e j ed<ee j ed<eeefed<eeed<e j ed<ed eejeee j d d d Zd S)MemberAllMixinzThis mixin is deprecated.r&r'r(r+r,r-r.)ZGroupMemberManagerZProjectMemberManagerrPc sNtdtdj}tr(jdus(Jjj|fi|}fdd|DS)aList all the members, included inherited ones. This Method is deprecated. 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) Raises: GitlabAuthenticationError: If authentication is not correct GitlabListError: If the list could not be retrieved Returns: RESTObjectList: The list of members zThe all() method for this object is deprecated and will be removed in a future version. Use .members_all.list(all=True), instead.z%s/allNcsg|]}|qSr)rYrZr]r)r>r^r_z&MemberAllMixin.all..)warningswarnDeprecationWarningr7r r(r.rg)r<r1r7rnr)r]r>alls zMemberAllMixin.allN)r@rArBrrrCrDrrr r rEr.rFr rrGrHrorrr)r)r)r>rs     r)1rrrtypingrrrrrrr r r r:r.r r rrGr~r__all__rTZ_RestManagerBaserEZ_RestObjectBaseobjectrrrrrrrrrrrrrrrr r!r"r#r$r%rr)r)r)r>sH ,    -%!= D^"  .",1l$