avoid for loop

This commit is contained in:
adbenitez
2021-04-06 17:50:34 -04:00
parent 1cd53aafff
commit 72ddd33adf

View File

@@ -359,21 +359,21 @@ class Message(object):
# some code for handling DC_MSG_* view types # some code for handling DC_MSG_* view types
_view_type_mapping = { _view_type_mapping = {
const.DC_MSG_TEXT: 'text', 'text': const.DC_MSG_TEXT,
const.DC_MSG_IMAGE: 'image', 'image': const.DC_MSG_IMAGE,
const.DC_MSG_GIF: 'gif', 'gif': const.DC_MSG_GIF,
const.DC_MSG_AUDIO: 'audio', 'audio': const.DC_MSG_AUDIO,
const.DC_MSG_VIDEO: 'video', 'video': const.DC_MSG_VIDEO,
const.DC_MSG_FILE: 'file' 'file': const.DC_MSG_FILE,
} }
def get_viewtype_code_from_name(view_type_name): def get_viewtype_code_from_name(view_type_name):
for code, value in _view_type_mapping.items(): code = _view_type_mapping.get(view_type_name)
if value == view_type_name: if code is not None:
return code return code
raise ValueError("message typecode not found for {!r}, " raise ValueError("message typecode not found for {!r}, "
"available {!r}".format(view_type_name, list(_view_type_mapping.values()))) "available {!r}".format(view_type_name, list(_view_type_mapping.keys())))
# #