Skip to content

Commit

Permalink
reformat request_helper
Browse files Browse the repository at this point in the history
  • Loading branch information
C0D3D3V committed May 1, 2024
1 parent 1b24590 commit eb5a7b6
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions moodle_dl/moodle/request_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def post_URL(self, url: str, data: Dict[str, str] = None, cookie_jar_path: str =
if data is not None:
data_urlencoded = self.recursive_urlencode(data)

session = SslHelper.custom_requests_session(self.opts.skip_cert_verify, self.opts.allow_insecure_ssl, self.opts.use_all_ciphers)
session = SslHelper.custom_requests_session(
self.opts.skip_cert_verify, self.opts.allow_insecure_ssl, self.opts.use_all_ciphers
)
if cookie_jar_path is not None:
session.cookies = MoodleDLCookieJar(cookie_jar_path)

Expand Down Expand Up @@ -91,7 +93,9 @@ def get_URL(self, url: str, cookie_jar_path: str = None):
@return: The resulting Response object.
"""

session = SslHelper.custom_requests_session(self.opts.skip_cert_verify, self.opts.allow_insecure_ssl, self.opts.use_all_ciphers)
session = SslHelper.custom_requests_session(
self.opts.skip_cert_verify, self.opts.allow_insecure_ssl, self.opts.use_all_ciphers
)
if cookie_jar_path is not None:
session.cookies = MoodleDLCookieJar(cookie_jar_path)

Expand Down Expand Up @@ -123,7 +127,9 @@ async def async_post(self, function: str, data: Dict[str, str] = None, timeout:
data = self._get_POST_DATA(function, self.token, data)
data_urlencoded = self.recursive_urlencode(data)
url = self._get_REST_POST_URL(self.url_base, function)
ssl_context = SslHelper.get_ssl_context(self.opts.skip_cert_verify, self.opts.allow_insecure_ssl, self.opts.use_all_ciphers)
ssl_context = SslHelper.get_ssl_context(
self.opts.skip_cert_verify, self.opts.allow_insecure_ssl, self.opts.use_all_ciphers
)

error_ctr = 0
async with self.semaphore, aiohttp.ClientSession() as session:
Expand Down Expand Up @@ -181,7 +187,9 @@ def post(self, function: str, data: Dict[str, str] = None, timeout: int = 60) ->
data_urlencoded = self.recursive_urlencode(data)
url = self._get_REST_POST_URL(self.url_base, function)

session = SslHelper.custom_requests_session(self.opts.skip_cert_verify, self.opts.allow_insecure_ssl, self.opts.use_all_ciphers)
session = SslHelper.custom_requests_session(
self.opts.skip_cert_verify, self.opts.allow_insecure_ssl, self.opts.use_all_ciphers
)
error_ctr = 0
while error_ctr <= self.MAX_RETRIES:
try:
Expand Down Expand Up @@ -249,7 +257,9 @@ def get_login(self, data: Dict[str, str]) -> object:
@return: The JSON response returned by the Moodle System, already
checked for errors.
"""
session = SslHelper.custom_requests_session(self.opts.skip_cert_verify, self.opts.allow_insecure_ssl, self.opts.use_all_ciphers)
session = SslHelper.custom_requests_session(
self.opts.skip_cert_verify, self.opts.allow_insecure_ssl, self.opts.use_all_ciphers
)
try:
response = session.post(
f'{self.url_base}login/token.php',
Expand Down

0 comments on commit eb5a7b6

Please sign in to comment.