Skip to content

Commit

Permalink
Fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
timvlaer committed Jul 18, 2024
1 parent 47be794 commit 1684f36
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
4 changes: 0 additions & 4 deletions huawei_lte_api/Session.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from types import TracebackType
from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar, Union, Type, cast
from urllib.parse import urlparse, urlunparse
from time import sleep

import requests
import xmltodict
Expand Down Expand Up @@ -244,9 +243,6 @@ def _post(self,
else:
headers['__RequestVerificationToken'] = self.request_verification_tokens[0]

if is_json is True:
headers["_ResponseFormat"] = "JSON"

if data:
data_encoded = json.dumps(data).encode() if is_json else self._create_request_xml(data)
else:
Expand Down
14 changes: 8 additions & 6 deletions huawei_lte_api/api/App.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import json

from huawei_lte_api.ApiGroup import ApiGroup
from huawei_lte_api.Session import GetResponseType, SetResponseType
from huawei_lte_api.exceptions import RequestFormatException
from huawei_lte_api.exceptions import ResponseErrorException


class App(ApiGroup):
Expand All @@ -21,7 +19,11 @@ def accept_privacypolicy(self, approve: bool = False) -> SetResponseType:
}
},
is_json=True)
if response["errcode"] == 0:
error_code = response["errcode"]
if error_code == 0:
return "OK"
else:
raise RequestFormatException("Unexpected response: " + response)

raise ResponseErrorException(
message="Unexpected response: " + str(response),
code=int(error_code)
)
24 changes: 12 additions & 12 deletions huawei_lte_api/api/User.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@ def state_login_with_retry(self) -> GetResponseType:
if i == tries - 1:
raise
time.sleep((i + 1) / 10)
except ResponseErrorNotSupportedException:
raise

raise ResponseErrorException(message="Tries exhausted", code=0)

def _encode_password(self, username: str, password: Optional[str], password_type: PasswordTypeEnum = PasswordTypeEnum.BASE_64):
if not password:
return b''
else:
if password_type == PasswordTypeEnum.SHA256:
concentrated = b''.join([
username.encode('UTF-8'),
base64.b64encode(hashlib.sha256(password.encode('UTF-8')).hexdigest().encode('ascii')),
self._session.request_verification_tokens[0].encode('UTF-8')
])
return base64.b64encode(hashlib.sha256(concentrated).hexdigest().encode('ascii'))
else:
return base64.b64encode(password.encode('UTF-8'))

if password_type == PasswordTypeEnum.SHA256:
concentrated = b''.join([
username.encode('UTF-8'),
base64.b64encode(hashlib.sha256(password.encode('UTF-8')).hexdigest().encode('ascii')),
self._session.request_verification_tokens[0].encode('UTF-8')
])
return base64.b64encode(hashlib.sha256(concentrated).hexdigest().encode('ascii'))

return base64.b64encode(password.encode('UTF-8'))

def _login(self, username: str, password: Optional[str], password_type: PasswordTypeEnum = PasswordTypeEnum.BASE_64) -> bool:
password_encoded = self._encode_password(username, password, password_type)
Expand Down

0 comments on commit 1684f36

Please sign in to comment.