33
33
import gitlab
34
34
from gitlab import base , cli
35
35
from gitlab import exceptions as exc
36
- from gitlab import types as g_types
37
36
from gitlab import utils
38
37
39
38
__all__ = [
@@ -214,8 +213,8 @@ def list(self, **kwargs: Any) -> Union[base.RESTObjectList, List[base.RESTObject
214
213
GitlabListError: If the server cannot perform the request
215
214
"""
216
215
217
- # Duplicate data to avoid messing with what the user sent us
218
- data = kwargs . copy ()
216
+ data , _ = utils . _transform_types ( kwargs , self . _types , transform_files = False )
217
+
219
218
if self .gitlab .per_page :
220
219
data .setdefault ("per_page" , self .gitlab .per_page )
221
220
@@ -226,13 +225,6 @@ def list(self, **kwargs: Any) -> Union[base.RESTObjectList, List[base.RESTObject
226
225
if self .gitlab .order_by :
227
226
data .setdefault ("order_by" , self .gitlab .order_by )
228
227
229
- # We get the attributes that need some special transformation
230
- if self ._types :
231
- for attr_name , type_cls in self ._types .items ():
232
- if attr_name in data .keys ():
233
- type_obj = type_cls (data [attr_name ])
234
- data [attr_name ] = type_obj .get_for_api ()
235
-
236
228
# Allow to overwrite the path, handy for custom listings
237
229
path = data .pop ("path" , self .path )
238
230
@@ -298,23 +290,7 @@ def create(
298
290
data = {}
299
291
300
292
self ._check_missing_create_attrs (data )
301
- files = {}
302
-
303
- # We get the attributes that need some special transformation
304
- if self ._types :
305
- # Duplicate data to avoid messing with what the user sent us
306
- data = data .copy ()
307
- for attr_name , type_cls in self ._types .items ():
308
- if attr_name in data .keys ():
309
- type_obj = type_cls (data [attr_name ])
310
-
311
- # if the type if FileAttribute we need to pass the data as
312
- # file
313
- if isinstance (type_obj , g_types .FileAttribute ):
314
- k = type_obj .get_file_name (attr_name )
315
- files [attr_name ] = (k , data .pop (attr_name ))
316
- else :
317
- data [attr_name ] = type_obj .get_for_api ()
293
+ data , files = utils ._transform_types (data , self ._types )
318
294
319
295
# Handle specific URL for creation
320
296
path = kwargs .pop ("path" , self .path )
@@ -394,23 +370,7 @@ def update(
394
370
path = f"{ self .path } /{ utils .EncodedId (id )} "
395
371
396
372
self ._check_missing_update_attrs (new_data )
397
- files = {}
398
-
399
- # We get the attributes that need some special transformation
400
- if self ._types :
401
- # Duplicate data to avoid messing with what the user sent us
402
- new_data = new_data .copy ()
403
- for attr_name , type_cls in self ._types .items ():
404
- if attr_name in new_data .keys ():
405
- type_obj = type_cls (new_data [attr_name ])
406
-
407
- # if the type if FileAttribute we need to pass the data as
408
- # file
409
- if isinstance (type_obj , g_types .FileAttribute ):
410
- k = type_obj .get_file_name (attr_name )
411
- files [attr_name ] = (k , new_data .pop (attr_name ))
412
- else :
413
- new_data [attr_name ] = type_obj .get_for_api ()
373
+ new_data , files = utils ._transform_types (new_data , self ._types )
414
374
415
375
http_method = self ._get_update_method ()
416
376
result = http_method (path , post_data = new_data , files = files , ** kwargs )
0 commit comments