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 )
@@ -201,9 +199,9 @@ def __setstate__(self, state: Dict[str, Any]) -> None:
201199 raise ModuleNotFoundError (name = f"gitlab.v{ self ._api_version } .objects" )
202200 # NOTE: We must delay import of gitlab.v4.objects until now or
203201 # otherwise it will cause circular import errors
204- import gitlab .v4 . objects
202+ from .v4 import objects as v4_objects
205203
206- self ._objects = gitlab . v4 . objects
204+ self ._objects = v4_objects
207205
208206 @property
209207 def url (self ) -> str :
@@ -236,7 +234,7 @@ def from_config(
236234 Raises:
237235 gitlab.config.GitlabDataError: If the configuration is not correct.
238236 """
239- config = gitlab . config .GitlabConfigParser (
237+ config = gl_config .GitlabConfigParser (
240238 gitlab_id = gitlab_id , config_files = config_files
241239 )
242240 return cls (
@@ -289,7 +287,7 @@ def version(self) -> Tuple[str, str]:
289287
290288 return cast (str , self ._server_version ), cast (str , self ._server_revision )
291289
292- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabVerifyError )
290+ @exceptions .on_http_error (exceptions .GitlabVerifyError )
293291 def lint (self , content : str , ** kwargs : Any ) -> Tuple [bool , List [str ]]:
294292 """Validate a gitlab CI configuration.
295293
@@ -310,7 +308,7 @@ def lint(self, content: str, **kwargs: Any) -> Tuple[bool, List[str]]:
310308 assert not isinstance (data , requests .Response )
311309 return (data ["status" ] == "valid" , data ["errors" ])
312310
313- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabMarkdownError )
311+ @exceptions .on_http_error (exceptions .GitlabMarkdownError )
314312 def markdown (
315313 self , text : str , gfm : bool = False , project : Optional [str ] = None , ** kwargs : Any
316314 ) -> str :
@@ -337,7 +335,7 @@ def markdown(
337335 assert not isinstance (data , requests .Response )
338336 return data ["html" ]
339337
340- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabLicenseError )
338+ @exceptions .on_http_error (exceptions .GitlabLicenseError )
341339 def get_license (self , ** kwargs : Any ) -> Dict [str , Any ]:
342340 """Retrieve information about the current license.
343341
@@ -356,7 +354,7 @@ def get_license(self, **kwargs: Any) -> Dict[str, Any]:
356354 return result
357355 return {}
358356
359- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabLicenseError )
357+ @exceptions .on_http_error (exceptions .GitlabLicenseError )
360358 def set_license (self , license : str , ** kwargs : Any ) -> Dict [str , Any ]:
361359 """Add a new license.
362360
@@ -447,7 +445,7 @@ def _get_base_url(self, url: Optional[str] = None) -> str:
447445 The base URL
448446 """
449447 if not url :
450- return gitlab . const .DEFAULT_URL
448+ return const .DEFAULT_URL
451449
452450 return url .rstrip ("/" )
453451
@@ -481,7 +479,7 @@ def _check_redirects(self, result: requests.Response) -> None:
481479 if item .request .method == "GET" :
482480 continue
483481 target = item .headers .get ("location" )
484- raise gitlab . exceptions .RedirectError (
482+ raise exceptions .RedirectError (
485483 REDIRECT_MSG .format (
486484 status_code = item .status_code ,
487485 reason = item .reason ,
@@ -641,13 +639,13 @@ def http_request(
641639 pass
642640
643641 if result .status_code == 401 :
644- raise gitlab . exceptions .GitlabAuthenticationError (
642+ raise exceptions .GitlabAuthenticationError (
645643 response_code = result .status_code ,
646644 error_message = error_message ,
647645 response_body = result .content ,
648646 )
649647
650- raise gitlab . exceptions .GitlabHttpError (
648+ raise exceptions .GitlabHttpError (
651649 response_code = result .status_code ,
652650 error_message = error_message ,
653651 response_body = result .content ,
@@ -693,7 +691,7 @@ def http_get(
693691 try :
694692 return result .json ()
695693 except Exception as e :
696- raise gitlab . exceptions .GitlabParsingError (
694+ raise exceptions .GitlabParsingError (
697695 error_message = "Failed to parse the server message"
698696 ) from e
699697 else :
@@ -790,7 +788,7 @@ def http_post(
790788 if result .headers .get ("Content-Type" , None ) == "application/json" :
791789 return result .json ()
792790 except Exception as e :
793- raise gitlab . exceptions .GitlabParsingError (
791+ raise exceptions .GitlabParsingError (
794792 error_message = "Failed to parse the server message"
795793 ) from e
796794 return result
@@ -838,7 +836,7 @@ def http_put(
838836 try :
839837 return result .json ()
840838 except Exception as e :
841- raise gitlab . exceptions .GitlabParsingError (
839+ raise exceptions .GitlabParsingError (
842840 error_message = "Failed to parse the server message"
843841 ) from e
844842
@@ -858,7 +856,7 @@ def http_delete(self, path: str, **kwargs: Any) -> requests.Response:
858856 """
859857 return self .http_request ("delete" , path , ** kwargs )
860858
861- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabSearchError )
859+ @exceptions .on_http_error (exceptions .GitlabSearchError )
862860 def search (
863861 self , scope : str , search : str , ** kwargs : Any
864862 ) -> Union ["GitlabList" , List [Dict [str , Any ]]]:
@@ -934,7 +932,7 @@ def _query(
934932 try :
935933 self ._data : List [Dict [str , Any ]] = result .json ()
936934 except Exception as e :
937- raise gitlab . exceptions .GitlabParsingError (
935+ raise exceptions .GitlabParsingError (
938936 error_message = "Failed to parse the server message"
939937 ) from e
940938
0 commit comments