Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0748c89

Browse files
author
Gauvain Pocentek
committed
Move the mixins in their own module
1 parent29e0bae commit0748c89

File tree

3 files changed

+208
-189
lines changed

3 files changed

+208
-189
lines changed

‎gitlab/base.py

Lines changed: 0 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -641,195 +641,6 @@ def next(self):
641641
returnself._obj_cls(self.manager,data)
642642

643643

644-
classGetMixin(object):
645-
defget(self,id,**kwargs):
646-
"""Retrieve a single object.
647-
648-
Args:
649-
id (int or str): ID of the object to retrieve
650-
**kwargs: Extra data to send to the Gitlab server (e.g. sudo)
651-
652-
Returns:
653-
object: The generated RESTObject.
654-
655-
Raises:
656-
GitlabGetError: If the server cannot perform the request.
657-
"""
658-
path='%s/%s'% (self._path,id)
659-
server_data=self.gitlab.http_get(path,**kwargs)
660-
returnself._obj_cls(self,server_data)
661-
662-
663-
classGetWithoutIdMixin(object):
664-
defget(self,**kwargs):
665-
"""Retrieve a single object.
666-
667-
Args:
668-
**kwargs: Extra data to send to the Gitlab server (e.g. sudo)
669-
670-
Returns:
671-
object: The generated RESTObject.
672-
673-
Raises:
674-
GitlabGetError: If the server cannot perform the request.
675-
"""
676-
server_data=self.gitlab.http_get(self._path,**kwargs)
677-
returnself._obj_cls(self,server_data)
678-
679-
680-
classListMixin(object):
681-
deflist(self,**kwargs):
682-
"""Retrieves a list of objects.
683-
684-
Args:
685-
**kwargs: Extra data to send to the Gitlab server (e.g. sudo).
686-
If ``all`` is passed and set to True, the entire list of
687-
objects will be returned.
688-
689-
Returns:
690-
RESTObjectList: Generator going through the list of objects, making
691-
queries to the server when required.
692-
If ``all=True`` is passed as argument, returns
693-
list(RESTObjectList).
694-
"""
695-
696-
obj=self.gitlab.http_list(self._path,**kwargs)
697-
ifisinstance(obj,list):
698-
return [self._obj_cls(self,item)foriteminobj]
699-
else:
700-
returnRESTObjectList(self,self._obj_cls,obj)
701-
702-
703-
classGetFromListMixin(ListMixin):
704-
defget(self,id,**kwargs):
705-
"""Retrieve a single object.
706-
707-
Args:
708-
id (int or str): ID of the object to retrieve
709-
**kwargs: Extra data to send to the Gitlab server (e.g. sudo)
710-
711-
Returns:
712-
object: The generated RESTObject.
713-
714-
Raises:
715-
GitlabGetError: If the server cannot perform the request.
716-
"""
717-
gen=self.list()
718-
forobjingen:
719-
ifstr(obj.get_id())==str(id):
720-
returnobj
721-
722-
723-
classRetrieveMixin(ListMixin,GetMixin):
724-
pass
725-
726-
727-
classCreateMixin(object):
728-
def_check_missing_attrs(self,data):
729-
required,optional=self.get_create_attrs()
730-
missing= []
731-
forattrinrequired:
732-
ifattrnotindata:
733-
missing.append(attr)
734-
continue
735-
ifmissing:
736-
raiseAttributeError("Missing attributes: %s"%", ".join(missing))
737-
738-
defget_create_attrs(self):
739-
"""Returns the required and optional arguments.
740-
741-
Returns:
742-
tuple: 2 items: list of required arguments and list of optional
743-
arguments for creation (in that order)
744-
"""
745-
ifhasattr(self,'_create_attrs'):
746-
return (self._create_attrs['required'],
747-
self._create_attrs['optional'])
748-
return (tuple(),tuple())
749-
750-
defcreate(self,data,**kwargs):
751-
"""Created a new object.
752-
753-
Args:
754-
data (dict): parameters to send to the server to create the
755-
resource
756-
**kwargs: Extra data to send to the Gitlab server (e.g. sudo)
757-
758-
Returns:
759-
RESTObject: a new instance of the manage object class build with
760-
the data sent by the server
761-
"""
762-
self._check_missing_attrs(data)
763-
ifhasattr(self,'_sanitize_data'):
764-
data=self._sanitize_data(data,'create')
765-
server_data=self.gitlab.http_post(self._path,post_data=data,**kwargs)
766-
returnself._obj_cls(self,server_data)
767-
768-
769-
classUpdateMixin(object):
770-
def_check_missing_attrs(self,data):
771-
required,optional=self.get_update_attrs()
772-
missing= []
773-
forattrinrequired:
774-
ifattrnotindata:
775-
missing.append(attr)
776-
continue
777-
ifmissing:
778-
raiseAttributeError("Missing attributes: %s"%", ".join(missing))
779-
780-
defget_update_attrs(self):
781-
"""Returns the required and optional arguments.
782-
783-
Returns:
784-
tuple: 2 items: list of required arguments and list of optional
785-
arguments for update (in that order)
786-
"""
787-
ifhasattr(self,'_update_attrs'):
788-
return (self._update_attrs['required'],
789-
self._update_attrs['optional'])
790-
return (tuple(),tuple())
791-
792-
defupdate(self,id=None,new_data={},**kwargs):
793-
"""Update an object on the server.
794-
795-
Args:
796-
id: ID of the object to update (can be None if not required)
797-
new_data: the update data for the object
798-
**kwargs: Extra data to send to the Gitlab server (e.g. sudo)
799-
800-
Returns:
801-
dict: The new object data (*not* a RESTObject)
802-
"""
803-
804-
ifidisNone:
805-
path=self._path
806-
else:
807-
path='%s/%s'% (self._path,id)
808-
809-
self._check_missing_attrs(new_data)
810-
ifhasattr(self,'_sanitize_data'):
811-
data=self._sanitize_data(new_data,'update')
812-
server_data=self.gitlab.http_put(self._path,post_data=data,
813-
**kwargs)
814-
returnserver_data
815-
816-
817-
classDeleteMixin(object):
818-
defdelete(self,id,**kwargs):
819-
"""Deletes an object on the server.
820-
821-
Args:
822-
id: ID of the object to delete
823-
**kwargs: Extra data to send to the Gitlab server (e.g. sudo)
824-
"""
825-
path='%s/%s'% (self._path,id)
826-
self.gitlab.http_delete(path,**kwargs)
827-
828-
829-
classCRUDMixin(GetMixin,ListMixin,CreateMixin,UpdateMixin,DeleteMixin):
830-
pass
831-
832-
833644
classRESTManager(object):
834645
"""Base class for CRUD operations on objects.
835646

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp