a *Na)@sddlZddlmZddlmZmZmZmZmZm Z m Z ddl mZ ddl mZddlmZmZgdZGd d d eZGd d d eZGd ddeZGdddeZdS)N) ModuleType)AnyDictIterable NamedTupleOptionalTupleType)types)GitlabParsingError)Gitlab GitlabList)RequiredOptional RESTObjectRESTObjectList RESTManagercseZdZUdZdZeeed<eee fed<e ed<eee fed<dZ eeed<eee fed <d ed <d eee fdd d dZ eee fdddZ eee fddddZee dddZee ddddZedddZedddZeedfd d! Zeedfd"d# Zeedfd$d% Zedfd&d' Zddd(d)Zeee fdd*d+d,Ze dd-d.Zeeee fdd/d0ZZ S)1raxRepresents an object built from server data. It holds the attributes know from the server, and the updated attributes in another. This allows smart updates, if the object allows it. You can redefine ``_id_attr`` in child classes to specify which attribute must be used as uniq ID. ``None`` means that the object can be updated without ID in the url. id_id_attr_attrs_module _parent_attrsN_short_print_attr_updated_attrsrmanager)rattrsreturncCsPt|tstd||j||it|jd|j j |jd<| dS)NzAttempted to initialize RESTObject with a non-dictionary value: {!r} This likely indicates an incorrect or malformed server response.)rrrrr) isinstancedictr format__dict__update importlib import_module __module__r parent_attrs_create_managers)selfrrr(f/private/var/folders/js/6pj4vh5d4zd0k6bxv74qrbhr0000gr/T/pip-target-22xwyzbs/lib/python/gitlab/base.py__init__6s  zRESTObject.__init__rcCs"|j}|d}|j|d<|S)Nr _module_name)r copypop__name__)r'statemoduler(r(r) __getstate__Hs   zRESTObject.__getstate__)r0rcCs*|d}|j|t||jd<dS)Nr,r)r.r r!r"r#)r'r0 module_namer(r(r) __setstate__Ns  zRESTObject.__setstate__)namercCsz|jd|WStyzL|jd|}t|trb|dd|jd|<|jd|WYS|WYStyz|jd|WYYStyt|Yn0Yn0Yn0dSNrrr)r KeyErrorrlistAttributeErrorr'r5valuer(r(r) __getattr__Ss     zRESTObject.__getattr__)r5r;rcCs||jd|<dS)Nrr r:r(r(r) __setattr__pszRESTObject.__setattr__cCs&|j}||jdt||fS)Nz%s => %s)rr-r!rtyper'datar(r(r)__str__ss  zRESTObject.__str__cCs.|jrd|jj|j|fSd|jjSdS)Nz <%s %s:%s>z<%s>)r __class__r/get_idr'r(r(r)__repr__xszRESTObject.__repr__)otherrcs<t|tstS|r.|r.||kStt||kSNrrNotImplementedrDsuperr'rGrCr(r)__eq__s  zRESTObject.__eq__cs<t|tstS|r.|r.||kStt||kSrHrIrLrMr(r)__ne__s  zRESTObject.__ne__cst|jtt|SrH)set attributesunionrKr__dir__rErMr(r)rSszRESTObject.__dir__cs"|stt|St|SrH)rDrKr__hash__hashrErMr(r)rTszRESTObject.__hash__cCsRt|dd}|durdS|jD].\}}t|j|}||jj|d}||j|<qdS)N _managers)parent)getattrrVrrgitlabr )r'Zmanagersattrcls_nameclsrr(r(r)r&s  zRESTObject._create_managers) new_attrsrcCsi|jd<||jd<dS)Nrrr=)r'r]r(r(r) _update_attrss zRESTObject._update_attrscCs&|jdust||jsdSt||jS)zReturns the id of the resource.N)rhasattrrXrEr(r(r)rDszRESTObject.get_idcCs2|jd}||jd||jd|Sr6)r r-r!)r'dr(r(r)rQszRESTObject.attributes)!r/r$ __qualname____doc__rrstr__annotations__rrrrr*r2r4r<r>rBrFobjectboolrNrOrrSintrTr&r^rDpropertyrQ __classcell__r(r(rMr)r#s0    rc@seZdZdZdeeeddddZdddd Ze dd d Z edd d Z edddZ e e dddZe ee dddZe ee dddZe e dddZe e dddZe e dddZdS)raGenerator object representing a list of RESTObject's. This generator uses the Gitlab pagination system to fetch new data when required. Note: you should not instanciate such objects, they are returned by calls to RESTManager.list() Args: manager: Manager to attach to the created objects obj_cls: Type of objects to create from the json data _list: A GitlabList object rN)robj_cls_listrcCs||_||_||_dS)aOCreates an objects list from a GitlabList. You should not create objects of this type, but use managers list() methods instead. Args: manager: the RESTManager to attach to the objects obj_cls: the class of the created objects _list: the GitlabList holding the data N)r_obj_clsrk)r'rrjrkr(r(r)r*s zRESTObjectList.__init__r+cCs|SrHr(rEr(r(r)__iter__szRESTObjectList.__iter__cCs t|jSrH)lenrkrEr(r(r)__len__szRESTObjectList.__len__cCs|SrH)nextrEr(r(r)__next__szRESTObjectList.__next__cCs|j}||j|SrH)rkrprlrr@r(r(r)rps zRESTObjectList.nextcCs|jjS)zThe current page number.)rk current_pagerEr(r(r)rrszRESTObjectList.current_pagecCs|jjS)zSThe previous page number. If None, the current page is the first. )rk prev_pagerEr(r(r)rsszRESTObjectList.prev_pagecCs|jjS)zNThe next page number. If None, the current page is the last. )rk next_pagerEr(r(r)rtszRESTObjectList.next_pagecCs|jjS)zThe number of items per page.)rkper_pagerEr(r(r)ruszRESTObjectList.per_pagecCs|jjS)zThe total number of pages.)rk total_pagesrEr(r(r)rvszRESTObjectList.total_pagescCs|jjS)zThe total number of items.)rktotalrEr(r(r)rwszRESTObjectList.total)r/r$rarbr rrr*rmrgrorqrprhrrrrsrtrurvrwr(r(r(r)rs(  rc@s:eZdZUeZeedfed<eZeedfed<dS)r.requiredoptionalN) r/r$ratuplerxrrcrdryr(r(r(r)rs rc@seZdZUdZeZeed<eZeed<dZe e ed<dZ e e e ed<iZee efed<iZee e ejfed<e e ed <e e ed <ee efed <eed <dee e dd ddZee ee efdddZde e e e dddZee e dddZdS)rzBase class for CRUD operations on objects. Derived class must define ``_path`` and ``_obj_cls``. ``_path``: Base URL path on which requests will be sent (e.g. '/projects') ``_obj_cls``: The class of objects that will be created _create_attrsr^N_pathrl_from_parent_attrs_types_computed_path_parentrrY)glrWrcCs||_||_||_dS)zREST manager constructor. Args: gl (Gitlab): :class:`~gitlab.Gitlab` connection to use to make requests. parent: REST object to which the manager is attached. N)rYr _compute_pathr)r'rrWr(r(r)r* szRESTManager.__init__r+cCs|jSrH)rrEr(r(r)r%,szRESTManager.parent_attrs)pathrcsZi_|durj}|dur dSjdus0js4|SfddjD}|_||S)Ncs i|]\}}|tj|dqSrH)rXr).0Z self_attrZ parent_attrrEr(r) 9sz-RESTManager._compute_path..)rr|rr}items)r'rrAr(rEr)r0s zRESTManager._compute_pathcCs|jSrH)rrEr(r(r)r@szRESTManager.path)N)N)r/r$rarbrr{rdr^r|rrcrlr rr}rrr~g_typesZGitlabAttributer r*rhr%rrr(r(r(r)r s"    r)r"r rtypingrrrrrrr rYrZgitlab.exceptionsr clientr r__all__rerrrrr(r(r(r)s $  R