2323import requests .utils
2424from requests_toolbelt .multipart .encoder import MultipartEncoder # type: ignore
2525
26- import gitlab .config
27- import gitlab .const
28- import gitlab .exceptions
29- from gitlab import utils
26+ from . import config as gl_config
27+ from . import const , exceptions , utils
3028
3129REDIRECT_MSG = (
3230 "python-gitlab detected a {status_code} ({reason!r}) redirection. You must update "
@@ -72,7 +70,7 @@ def __init__(
7270 per_page : Optional [int ] = None ,
7371 pagination : Optional [str ] = None ,
7472 order_by : Optional [str ] = None ,
75- user_agent : str = gitlab . const .USER_AGENT ,
73+ user_agent : str = const .USER_AGENT ,
7674 retry_transient_errors : bool = False ,
7775 ) -> None :
7876
@@ -109,9 +107,9 @@ def __init__(
109107 raise ModuleNotFoundError (name = f"gitlab.v{ self ._api_version } .objects" )
110108 # NOTE: We must delay import of gitlab.v4.objects until now or
111109 # otherwise it will cause circular import errors
112- import gitlab .v4 . objects
110+ from .v4 import objects as v4_objects
113111
114- objects = gitlab . v4 . objects
112+ objects = v4_objects
115113 self ._objects = objects
116114
117115 self .broadcastmessages = objects .BroadcastMessageManager (self )
@@ -234,7 +232,7 @@ def from_config(
234232 Raises:
235233 gitlab.config.GitlabDataError: If the configuration is not correct.
236234 """
237- config = gitlab . config .GitlabConfigParser (
235+ config = gl_config .GitlabConfigParser (
238236 gitlab_id = gitlab_id , config_files = config_files
239237 )
240238 return cls (
@@ -287,7 +285,7 @@ def version(self) -> Tuple[str, str]:
287285
288286 return cast (str , self ._server_version ), cast (str , self ._server_revision )
289287
290- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabVerifyError )
288+ @exceptions .on_http_error (exceptions .GitlabVerifyError )
291289 def lint (self , content : str , ** kwargs : Any ) -> Tuple [bool , List [str ]]:
292290 """Validate a gitlab CI configuration.
293291
@@ -308,7 +306,7 @@ def lint(self, content: str, **kwargs: Any) -> Tuple[bool, List[str]]:
308306 assert not isinstance (data , requests .Response )
309307 return (data ["status" ] == "valid" , data ["errors" ])
310308
311- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabMarkdownError )
309+ @exceptions .on_http_error (exceptions .GitlabMarkdownError )
312310 def markdown (
313311 self , text : str , gfm : bool = False , project : Optional [str ] = None , ** kwargs : Any
314312 ) -> str :
@@ -335,7 +333,7 @@ def markdown(
335333 assert not isinstance (data , requests .Response )
336334 return data ["html" ]
337335
338- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabLicenseError )
336+ @exceptions .on_http_error (exceptions .GitlabLicenseError )
339337 def get_license (self , ** kwargs : Any ) -> Dict [str , Any ]:
340338 """Retrieve information about the current license.
341339
@@ -354,7 +352,7 @@ def get_license(self, **kwargs: Any) -> Dict[str, Any]:
354352 return result
355353 return {}
356354
357- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabLicenseError )
355+ @exceptions .on_http_error (exceptions .GitlabLicenseError )
358356 def set_license (self , license : str , ** kwargs : Any ) -> Dict [str , Any ]:
359357 """Add a new license.
360358
@@ -445,7 +443,7 @@ def _get_base_url(self, url: Optional[str] = None) -> str:
445443 The base URL
446444 """
447445 if not url :
448- return gitlab . const .DEFAULT_URL
446+ return const .DEFAULT_URL
449447
450448 return url .rstrip ("/" )
451449
@@ -479,7 +477,7 @@ def _check_redirects(self, result: requests.Response) -> None:
479477 if item .request .method == "GET" :
480478 continue
481479 target = item .headers .get ("location" )
482- raise gitlab . exceptions .RedirectError (
480+ raise exceptions .RedirectError (
483481 REDIRECT_MSG .format (
484482 status_code = item .status_code ,
485483 reason = item .reason ,
@@ -639,13 +637,13 @@ def http_request(
639637 pass
640638
641639 if result .status_code == 401 :
642- raise gitlab . exceptions .GitlabAuthenticationError (
640+ raise exceptions .GitlabAuthenticationError (
643641 response_code = result .status_code ,
644642 error_message = error_message ,
645643 response_body = result .content ,
646644 )
647645
648- raise gitlab . exceptions .GitlabHttpError (
646+ raise exceptions .GitlabHttpError (
649647 response_code = result .status_code ,
650648 error_message = error_message ,
651649 response_body = result .content ,
@@ -691,7 +689,7 @@ def http_get(
691689 try :
692690 return result .json ()
693691 except Exception as e :
694- raise gitlab . exceptions .GitlabParsingError (
692+ raise exceptions .GitlabParsingError (
695693 error_message = "Failed to parse the server message"
696694 ) from e
697695 else :
@@ -788,7 +786,7 @@ def http_post(
788786 if result .headers .get ("Content-Type" , None ) == "application/json" :
789787 return result .json ()
790788 except Exception as e :
791- raise gitlab . exceptions .GitlabParsingError (
789+ raise exceptions .GitlabParsingError (
792790 error_message = "Failed to parse the server message"
793791 ) from e
794792 return result
@@ -836,7 +834,7 @@ def http_put(
836834 try :
837835 return result .json ()
838836 except Exception as e :
839- raise gitlab . exceptions .GitlabParsingError (
837+ raise exceptions .GitlabParsingError (
840838 error_message = "Failed to parse the server message"
841839 ) from e
842840
@@ -856,7 +854,7 @@ def http_delete(self, path: str, **kwargs: Any) -> requests.Response:
856854 """
857855 return self .http_request ("delete" , path , ** kwargs )
858856
859- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabSearchError )
857+ @exceptions .on_http_error (exceptions .GitlabSearchError )
860858 def search (
861859 self , scope : str , search : str , ** kwargs : Any
862860 ) -> Union ["GitlabList" , List [Dict [str , Any ]]]:
@@ -932,7 +930,7 @@ def _query(
932930 try :
933931 self ._data : List [Dict [str , Any ]] = result .json ()
934932 except Exception as e :
935- raise gitlab . exceptions .GitlabParsingError (
933+ raise exceptions .GitlabParsingError (
936934 error_message = "Failed to parse the server message"
937935 ) from e
938936
0 commit comments