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

Commit9b59adc

Browse files
committed
Make gitlab objects serializable
With current implementation of API v3 and v4 support, some instanceshave properties of type module and are not serializable. Handlethese properties manually with setstate and getstate methods.
1 parent36c023d commit9b59adc

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

‎gitlab/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ def __init__(self, url, private_token=None, email=None, password=None,
138138
manager=getattr(objects,cls_name)(self)
139139
setattr(self,var_name,manager)
140140

141+
def__getstate__(self):
142+
state=self.__dict__.copy()
143+
state.pop('_objects')
144+
returnstate
145+
146+
def__setstate__(self,state):
147+
self.__dict__.update(state)
148+
objects=importlib.import_module('gitlab.v%s.objects'%
149+
self._api_version)
150+
self._objects=objects
151+
141152
@property
142153
defapi_version(self):
143154
returnself._api_version

‎gitlab/base.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,17 @@ def __init__(self, gl, data=None, **kwargs):
416416
ifnothasattr(self,"id"):
417417
self.id=None
418418

419+
def__getstate__(self):
420+
state=self.__dict__.copy()
421+
module=state.pop('_module')
422+
state['_module_name']=module.__name__
423+
returnstate
424+
425+
def__setstate__(self,state):
426+
module_name=state.pop('_module_name')
427+
self.__dict__.update(state)
428+
self._module=importlib.import_module(module_name)
429+
419430
def_set_manager(self,var,cls,attrs):
420431
manager=cls(self.gitlab,self,attrs)
421432
setattr(self,var,manager)
@@ -555,6 +566,17 @@ def __init__(self, manager, attrs):
555566
self.__dict__['_parent_attrs']=self.manager.parent_attrs
556567
self._create_managers()
557568

569+
def__getstate__(self):
570+
state=self.__dict__.copy()
571+
module=state.pop('_module')
572+
state['_module_name']=module.__name__
573+
returnstate
574+
575+
def__setstate__(self,state):
576+
module_name=state.pop('_module_name')
577+
self.__dict__.update(state)
578+
self._module=importlib.import_module(module_name)
579+
558580
def__getattr__(self,name):
559581
try:
560582
returnself.__dict__['_updated_attrs'][name]

‎gitlab/tests/test_gitlab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from __future__importprint_function
2020

21+
importpickle
2122
try:
2223
importunittest
2324
exceptImportError:
@@ -26,7 +27,6 @@
2627
fromhttmockimportHTTMock# noqa
2728
fromhttmockimportresponse# noqa
2829
fromhttmockimporturlmatch# noqa
29-
importpickle
3030
importsix
3131

3232
importgitlab

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp