minor 3.7 fixes

This commit is contained in:
Devaev Maxim
2020-09-05 05:58:33 +03:00
parent e106aaebed
commit 0c85248987
6 changed files with 34 additions and 30 deletions

View File

@@ -64,17 +64,16 @@ async def check_request_auth(auth_manager: AuthManager, exposed: HttpExposed, re
return
basic_auth = request.headers.get("Authorization", "")
if basic_auth:
if basic_auth[:6].lower() == "basic ":
try:
(user, passwd) = base64.b64decode(basic_auth[6:]).decode("utf-8").split(":")
except Exception:
raise UnauthorizedError()
user = valid_user(user)
set_request_auth_info(request, f"{user} (basic)")
if not (await auth_manager.authorize(user, valid_passwd(passwd))):
raise ForbiddenError()
return
if basic_auth and basic_auth[:6].lower() == "basic ":
try:
(user, passwd) = base64.b64decode(basic_auth[6:]).decode("utf-8").split(":")
except Exception:
raise UnauthorizedError()
user = valid_user(user)
set_request_auth_info(request, f"{user} (basic)")
if not (await auth_manager.authorize(user, valid_passwd(passwd))):
raise ForbiddenError()
return
raise UnauthorizedError()

View File

@@ -216,7 +216,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
("resolution", valid_stream_resolution, StreamerResolutionNotSupported),
]:
value = request.query.get(name)
if (value):
if value:
if name not in current_params:
assert exc_cls is not None, name
raise exc_cls()

View File

@@ -258,18 +258,20 @@ class UserGpio:
"type": "label",
"text": item[1:].strip(),
})
elif (parts := list(map(str.strip, item.split(",", 1)))):
if parts[0] in self.__inputs:
items.append({
"type": "input",
"channel": parts[0],
})
elif parts[0] in self.__outputs:
items.append({
"type": "output",
"channel": parts[0],
"text": (parts[1] if len(parts) > 1 else "Click"),
})
else:
parts = list(map(str.strip, item.split(",", 1)))
if parts:
if parts[0] in self.__inputs:
items.append({
"type": "input",
"channel": parts[0],
})
elif parts[0] in self.__outputs:
items.append({
"type": "output",
"channel": parts[0],
"text": (parts[1] if len(parts) > 1 else "Click"),
})
table.append(items)
return {
"header": self.__view["header"],