2424import requests .utils
2525from requests_toolbelt .multipart .encoder import MultipartEncoder # type: ignore
2626
27- import gitlab .config
28- import gitlab .const
29- import gitlab .exceptions
30- from gitlab import utils
27+ from . import config as gl_config
28+ from . import const , exceptions , utils
3129
3230REDIRECT_MSG = (
3331 "python-gitlab detected a {status_code} ({reason!r}) redirection. You must update "
@@ -73,7 +71,7 @@ def __init__(
7371 per_page : Optional [int ] = None ,
7472 pagination : Optional [str ] = None ,
7573 order_by : Optional [str ] = None ,
76- user_agent : str = gitlab . const .USER_AGENT ,
74+ user_agent : str = const .USER_AGENT ,
7775 retry_transient_errors : bool = False ,
7876 ) -> None :
7977
@@ -110,9 +108,9 @@ def __init__(
110108 raise ModuleNotFoundError (name = f"gitlab.v{ self ._api_version } .objects" )
111109 # NOTE: We must delay import of gitlab.v4.objects until now or
112110 # otherwise it will cause circular import errors
113- import gitlab .v4 . objects
111+ from .v4 import objects as v4_objects
114112
115- objects = gitlab . v4 . objects
113+ objects = v4_objects
116114 self ._objects = objects
117115
118116 self .broadcastmessages = objects .BroadcastMessageManager (self )
@@ -202,9 +200,9 @@ def __setstate__(self, state: Dict[str, Any]) -> None:
202200 raise ModuleNotFoundError (name = f"gitlab.v{ self ._api_version } .objects" )
203201 # NOTE: We must delay import of gitlab.v4.objects until now or
204202 # otherwise it will cause circular import errors
205- import gitlab .v4 . objects
203+ from .v4 import objects as v4_objects
206204
207- self ._objects = gitlab . v4 . objects
205+ self ._objects = v4_objects
208206
209207 @property
210208 def url (self ) -> str :
@@ -237,7 +235,7 @@ def from_config(
237235 Raises:
238236 gitlab.config.GitlabDataError: If the configuration is not correct.
239237 """
240- config = gitlab . config .GitlabConfigParser (
238+ config = gl_config .GitlabConfigParser (
241239 gitlab_id = gitlab_id , config_files = config_files
242240 )
243241 return cls (
@@ -371,7 +369,7 @@ def version(self) -> Tuple[str, str]:
371369
372370 return cast (str , self ._server_version ), cast (str , self ._server_revision )
373371
374- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabVerifyError )
372+ @exceptions .on_http_error (exceptions .GitlabVerifyError )
375373 def lint (self , content : str , ** kwargs : Any ) -> Tuple [bool , List [str ]]:
376374 """Validate a gitlab CI configuration.
377375
@@ -392,7 +390,7 @@ def lint(self, content: str, **kwargs: Any) -> Tuple[bool, List[str]]:
392390 assert not isinstance (data , requests .Response )
393391 return (data ["status" ] == "valid" , data ["errors" ])
394392
395- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabMarkdownError )
393+ @exceptions .on_http_error (exceptions .GitlabMarkdownError )
396394 def markdown (
397395 self , text : str , gfm : bool = False , project : Optional [str ] = None , ** kwargs : Any
398396 ) -> str :
@@ -419,7 +417,7 @@ def markdown(
419417 assert not isinstance (data , requests .Response )
420418 return data ["html" ]
421419
422- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabLicenseError )
420+ @exceptions .on_http_error (exceptions .GitlabLicenseError )
423421 def get_license (self , ** kwargs : Any ) -> Dict [str , Any ]:
424422 """Retrieve information about the current license.
425423
@@ -438,7 +436,7 @@ def get_license(self, **kwargs: Any) -> Dict[str, Any]:
438436 return result
439437 return {}
440438
441- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabLicenseError )
439+ @exceptions .on_http_error (exceptions .GitlabLicenseError )
442440 def set_license (self , license : str , ** kwargs : Any ) -> Dict [str , Any ]:
443441 """Add a new license.
444442
@@ -529,7 +527,7 @@ def _get_base_url(self, url: Optional[str] = None) -> str:
529527 The base URL
530528 """
531529 if not url :
532- return gitlab . const .DEFAULT_URL
530+ return const .DEFAULT_URL
533531
534532 return url .rstrip ("/" )
535533
@@ -563,7 +561,7 @@ def _check_redirects(self, result: requests.Response) -> None:
563561 if item .request .method == "GET" :
564562 continue
565563 target = item .headers .get ("location" )
566- raise gitlab . exceptions .RedirectError (
564+ raise exceptions .RedirectError (
567565 REDIRECT_MSG .format (
568566 status_code = item .status_code ,
569567 reason = item .reason ,
@@ -718,13 +716,13 @@ def http_request(
718716 pass
719717
720718 if result .status_code == 401 :
721- raise gitlab . exceptions .GitlabAuthenticationError (
719+ raise exceptions .GitlabAuthenticationError (
722720 response_code = result .status_code ,
723721 error_message = error_message ,
724722 response_body = result .content ,
725723 )
726724
727- raise gitlab . exceptions .GitlabHttpError (
725+ raise exceptions .GitlabHttpError (
728726 response_code = result .status_code ,
729727 error_message = error_message ,
730728 response_body = result .content ,
@@ -770,7 +768,7 @@ def http_get(
770768 try :
771769 return result .json ()
772770 except Exception as e :
773- raise gitlab . exceptions .GitlabParsingError (
771+ raise exceptions .GitlabParsingError (
774772 error_message = "Failed to parse the server message"
775773 ) from e
776774 else :
@@ -867,7 +865,7 @@ def http_post(
867865 if result .headers .get ("Content-Type" , None ) == "application/json" :
868866 return result .json ()
869867 except Exception as e :
870- raise gitlab . exceptions .GitlabParsingError (
868+ raise exceptions .GitlabParsingError (
871869 error_message = "Failed to parse the server message"
872870 ) from e
873871 return result
@@ -915,7 +913,7 @@ def http_put(
915913 try :
916914 return result .json ()
917915 except Exception as e :
918- raise gitlab . exceptions .GitlabParsingError (
916+ raise exceptions .GitlabParsingError (
919917 error_message = "Failed to parse the server message"
920918 ) from e
921919
@@ -935,7 +933,7 @@ def http_delete(self, path: str, **kwargs: Any) -> requests.Response:
935933 """
936934 return self .http_request ("delete" , path , ** kwargs )
937935
938- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabSearchError )
936+ @exceptions .on_http_error (exceptions .GitlabSearchError )
939937 def search (
940938 self , scope : str , search : str , ** kwargs : Any
941939 ) -> Union ["GitlabList" , List [Dict [str , Any ]]]:
@@ -1009,7 +1007,7 @@ def _query(
10091007 try :
10101008 self ._data : List [Dict [str , Any ]] = result .json ()
10111009 except Exception as e :
1012- raise gitlab . exceptions .GitlabParsingError (
1010+ raise exceptions .GitlabParsingError (
10131011 error_message = "Failed to parse the server message"
10141012 ) from e
10151013
0 commit comments