| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,7 @@ | |||
| 20 | 20 | from typing import Any, Dict, Optional, Type | |
| 21 | 21 | ||
| 22 | 22 | from .client import Gitlab, GitlabList | |
| 23 | + from gitlab import types as g_types | ||
| 23 | 24 | ||
| 24 | 25 | __all__ = [ | |
| 25 | 26 | "RESTObject", | |
@@ -260,6 +261,7 @@ class RESTManager(object): | |||
| 260 | 261 | _path: Optional[str] = None | |
| 261 | 262 | _obj_cls: Optional[Type[RESTObject]] = None | |
| 262 | 263 | _from_parent_attrs: Dict[str, Any] = {} | |
| 264 | + _types: Dict[str, Type[g_types.GitlabAttribute]] = {} | ||
| 263 | 265 | ||
| 264 | 266 | _computed_path: Optional[str] | |
| 265 | 267 | _parent: Optional[RESTObject] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -226,9 +226,8 @@ def list(self, **kwargs: Any) -> Union[base.RESTObjectList, List[base.RESTObject | |||
| 226 | 226 | data.setdefault("order_by", self.gitlab.order_by) | |
| 227 | 227 | ||
| 228 | 228 | # We get the attributes that need some special transformation | |
| 229 | - types = getattr(self, "_types", {}) | ||
| 230 | - if types: | ||
| 231 | - for attr_name, type_cls in types.items(): | ||
| 229 | + if self._types: | ||
| 230 | + for attr_name, type_cls in self._types.items(): | ||
| 232 | 231 | if attr_name in data.keys(): | |
| 233 | 232 | type_obj = type_cls(data[attr_name]) | |
| 234 | 233 | data[attr_name] = type_obj.get_for_api() | |
@@ -311,17 +310,16 @@ def create( | |||
| 311 | 310 | files = {} | |
| 312 | 311 | ||
| 313 | 312 | # We get the attributes that need some special transformation | |
| 314 | - types = getattr(self, "_types", {}) | ||
| 315 | - if types: | ||
| 313 | + if self._types: | ||
| 316 | 314 | # Duplicate data to avoid messing with what the user sent us | |
| 317 | 315 | data = data.copy() | |
| 318 | - for attr_name, type_cls in types.items(): | ||
| 316 | + for attr_name, type_cls in self._types.items(): | ||
| 319 | 317 | if attr_name in data.keys(): | |
| 320 | 318 | type_obj = type_cls(data[attr_name]) | |
| 321 | 319 | ||
| 322 | 320 | # if the type if FileAttribute we need to pass the data as | |
| 323 | 321 | # file | |
| 324 | - if issubclass(type_cls, g_types.FileAttribute): | ||
| 322 | + if isinstance(type_obj, g_types.FileAttribute): | ||
| 325 | 323 | k = type_obj.get_file_name(attr_name) | |
| 326 | 324 | files[attr_name] = (k, data.pop(attr_name)) | |
| 327 | 325 | else: | |
@@ -414,17 +412,16 @@ def update( | |||
| 414 | 412 | files = {} | |
| 415 | 413 | ||
| 416 | 414 | # We get the attributes that need some special transformation | |
| 417 | - types = getattr(self, "_types", {}) | ||
| 418 | - if types: | ||
| 415 | + if self._types: | ||
| 419 | 416 | # Duplicate data to avoid messing with what the user sent us | |
| 420 | 417 | new_data = new_data.copy() | |
| 421 | - for attr_name, type_cls in types.items(): | ||
| 418 | + for attr_name, type_cls in self._types.items(): | ||
| 422 | 419 | if attr_name in new_data.keys(): | |
| 423 | 420 | type_obj = type_cls(new_data[attr_name]) | |
| 424 | 421 | ||
| 425 | 422 | # if the type if FileAttribute we need to pass the data as | |
| 426 | 423 | # file | |
| 427 | - if issubclass(type_cls, g_types.FileAttribute): | ||
| 424 | + if isinstance(type_obj, g_types.FileAttribute): | ||
| 428 | 425 | k = type_obj.get_file_name(attr_name) | |
| 429 | 426 | files[attr_name] = (k, new_data.pop(attr_name)) | |
| 430 | 427 | else: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,9 +42,8 @@ def __init__(self, gl, what, action, args): | |||
| 42 | 42 | self.mgr_cls._path = self.mgr_cls._path % self.args | |
| 43 | 43 | self.mgr = self.mgr_cls(gl) | |
| 44 | 44 | ||
| 45 | - types = getattr(self.mgr_cls, "_types", {}) | ||
| 46 | - if types: | ||
| 47 | - for attr_name, type_cls in types.items(): | ||
| 45 | + if self.mgr_cls._types: | ||
| 46 | + for attr_name, type_cls in self.mgr_cls._types.items(): | ||
| 48 | 47 | if attr_name in self.args.keys(): | |
| 49 | 48 | obj = type_cls() | |
| 50 | 49 | obj.set_from_cli(self.args[attr_name]) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments