mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Separate errors needing regex from those which don't
This commit is contained in:
parent
463847ad50
commit
fbf3bf119c
|
@ -55,12 +55,11 @@ def rpc_message_to_error(rpc_error, report_method=None):
|
|||
).start()
|
||||
|
||||
# Try to get the error by direct look-up, otherwise regex
|
||||
# TODO Maybe regexes could live in a separate dictionary?
|
||||
cls = rpc_errors_all.get(rpc_error.error_message, None)
|
||||
cls = rpc_errors_dict.get(rpc_error.error_message, None)
|
||||
if cls:
|
||||
return cls()
|
||||
|
||||
for msg_regex, cls in rpc_errors_all.items():
|
||||
for msg_regex, cls in rpc_errors_re:
|
||||
m = re.match(msg_regex, rpc_error.error_message)
|
||||
if m:
|
||||
capture = int(m.group(1)) if m.groups() else None
|
||||
|
|
|
@ -45,8 +45,10 @@ def generate_errors(errors, f):
|
|||
f.write(')\n')
|
||||
|
||||
# Create the actual {CODE: ErrorClassName} dict once classes are defined
|
||||
# TODO Actually make a difference between regex/exact
|
||||
f.write('\n\nrpc_errors_all = {\n')
|
||||
for error in itertools.chain(regex_match, exact_match):
|
||||
f.write('\n\nrpc_errors_dict = {\n')
|
||||
for error in exact_match:
|
||||
f.write(' {}: {},\n'.format(repr(error.pattern), error.name))
|
||||
f.write('}\n')
|
||||
f.write('}\n\nrpc_errors_re = (\n')
|
||||
for error in regex_match:
|
||||
f.write(' ({}, {}),\n'.format(repr(error.pattern), error.name))
|
||||
f.write(')\n')
|
||||
|
|
Loading…
Reference in New Issue
Block a user