3 @qhc)@sddlZddlmZddlmZmZmZmZmZm Z m Z ddl mZ ddl mZddlmZmZdd d d gZGd d d eZGd d d eZGdddeZGdd d eZdS)N) ModuleType)AnyDictIterable NamedTupleOptionalTupleType)types)GitlabParsingError)Gitlab GitlabListRequiredOptional RESTObjectRESTObjectList RESTManagercs~eZdZUdZdZeeeeef e  eeef dZ ee eeefddeeefddddZeeefdd d Zeeefdd d d ZeedddZeeddddZedddZedddZeedfdd Zeedfdd Zeedfdd Zedfdd Zddd!d"Zeeefdd#d$d%Z edd&d'Z!e"eeefdd(d)Z#Z$S)*raxRepresents 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. idNr)managerattrsreturncCsPt|tstdj||jj||itj|jd|j j |jd<|j dS)NzAttempted to initialize RESTObject with a non-dictionary value: {!r} This likely indicates an incorrect or malformed server response.)r_attrs_updated_attrs_module _parent_attrs) isinstancedictr format__dict__update importlib import_module __module__r parent_attrs_create_managers)selfrrr&J/home/ec2-user/environment/venv/lib/python3.6/dist-packages/gitlab/base.py__init__6s zRESTObject.__init__)rcCs"|jj}|jd}|j|d<|S)Nr _module_name)rcopypop__name__)r%statemoduler&r&r' __getstate__Hs   zRESTObject.__getstate__)r-rcCs*|jd}|jj|tj||jd<dS)Nr)r)r+rrr r!)r%r- module_namer&r&r' __setstate__Ns  zRESTObject.__setstate__)namercCsy|jd|Stk ry@|jd|}t|tr\|dd|jd|<|jd|S|Stk ry|jd|Stk rt|YnXYnXYnXdS)Nrrr)rKeyErrorrlistAttributeError)r%r2valuer&r&r' __getattr__Ss zRESTObject.__getattr__)r2r6rcCs||jd|<dS)Nr)r)r%r2r6r&r&r' __setattr__pszRESTObject.__setattr__cCs&|jj}|j|jdt||fS)Nz%s => %s)rr*rrtype)r%datar&r&r'__str__ss  zRESTObject.__str__cCs.|jrd|jj|j|jfSd|jjSdS)Nz <%s %s:%s>z<%s>)_id_attr __class__r,get_id)r%r&r&r'__repr__xs  zRESTObject.__repr__)otherrcs<t|tstS|jr.|jr.|j|jkStt||kS)N)rrNotImplementedr>super)r%r@)r=r&r'__eq__s  zRESTObject.__eq__cs<t|tstS|jr.|jr.|j|jkStt||kS)N)rrrAr>rB)r%r@)r=r&r'__ne__s  zRESTObject.__ne__cst|jjtt|jS)N)set attributesunionrBr__dir__)r%)r=r&r'rHszRESTObject.__dir__cs"|jstt|jSt|jS)N)r>rBr__hash__hash)r%)r=r&r'rIszRESTObject.__hash__cCsVt|dd}|dkrdSx8|jD].\}}t|j|}||jj|d}||j|<q WdS)N _managers)parent)getattrrKrrgitlabr)r%managersattrZcls_nameclsrr&r&r'r$s  zRESTObject._create_managers) new_attrsrcCsi|jd<||jd<dS)Nrr)r)r%rRr&r&r' _update_attrss zRESTObject._update_attrscCs(|jdkst||j rdSt||jS)zReturns the id of the resource.N)r<hasattrrM)r%r&r&r'r>szRESTObject.get_idcCs2|jdj}|j|jd|j|jd|S)Nrrr)rr*r)r%dr&r&r'rFszRESTObject.attributes)%r,r" __qualname____doc__r<rstrrrrrrrZ_short_print_attrrrr(r/r1r7r8r;r?objectboolrCrDrrHintrIr$rSr>propertyrF __classcell__r&r&)r=r'r#s0        c@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_clsr_)r%rr^r_r&r&r'r(s zRESTObjectList.__init__)rcCs|S)Nr&)r%r&r&r'__iter__szRESTObjectList.__iter__cCs t|jS)N)lenr_)r%r&r&r'__len__szRESTObjectList.__len__cCs|jS)N)next)r%r&r&r'__next__szRESTObjectList.__next__cCs|jj}|j|j|S)N)r_rdr`r)r%r:r&r&r'rds zRESTObjectList.nextcCs|jjS)zThe current page number.)r_ current_page)r%r&r&r'rfszRESTObjectList.current_pagecCs|jjS)zSThe previous page number. If None, the current page is the first. )r_ prev_page)r%r&r&r'rgszRESTObjectList.prev_pagecCs|jjS)zNThe next page number. If None, the current page is the last. )r_ next_page)r%r&r&r'rhszRESTObjectList.next_pagecCs|jjS)zThe number of items per page.)r_per_page)r%r&r&r'riszRESTObjectList.per_pagecCs|jjS)zThe total number of pages.)r_ total_pages)r%r&r&r'rjszRESTObjectList.total_pagescCs|jjS)zThe total number of items.)r_total)r%r&r&r'rkszRESTObjectList.total)r,r"rVrWr rrr(rar[rcrerdr\rfrrgrhrirjrkr&r&r&r'rs&  c@s2eZdZUeZeedfeZeedfdS)r.N)r,r"rVtuplerequiredrrXoptionalr&r&r&r'rs c@seZdZUdZeZeeZedZee dZ ee e  iZ ee ef iZee e ejfee ee ee efedeee ddddZeeee efdddZdee ee d d d Zeee dd d ZdS)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 N)glrLrcCs||_||_|j|_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)rN_parent _compute_path_computed_path)r%rorLr&r&r'r( szRESTManager.__init__)rcCs|jS)N)r)r%r&r&r'r#,szRESTManager.parent_attrs)pathrcs\i_|dkrj}|dkr dSjdks2j r6|SfddjjD}|_||S)Ncs i|]\}}tj|d|qS)N)rMrp).0Z self_attrZ parent_attr)r%r&r' 9sz-RESTManager._compute_path..)r_pathrp_from_parent_attrsitems)r%rsr:r&)r%r'rq0s zRESTManager._compute_pathcCs|jS)N)rr)r%r&r&r'rs@szRESTManager.path)N)N)r,r"rVrWrZ _create_attrsrSrvrrXr`r rrwrr_typesg_typesZGitlabAttributerrrprr rNr(r\r#rqrsr&r&r&r'r s"      )r r rtypingrrrrrrr rNrzZgitlab.exceptionsr clientr r__all__rYrrrrr&r&r&r's $  R