mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-13 04:56:35 +03:00
Simplify TLObject.pretty_format since Telegram returns no dicts
This commit is contained in:
parent
2873dcf1c6
commit
4a83784fe8
|
@ -23,15 +23,10 @@ class TLObject:
|
||||||
obj = obj.to_dict()
|
obj = obj.to_dict()
|
||||||
|
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
if '_' in obj:
|
return '{}({})'.format(obj.get('_', 'dict'), ', '.join(
|
||||||
pre, left, right, sep = obj['_'], '(', ')', '{}={}'
|
'{}={}'.format(k, TLObject.pretty_format(v))
|
||||||
else:
|
for k, v in obj.items() if k != '_'
|
||||||
pre, left, right, sep = '', '{', '}', '{}: {}'
|
))
|
||||||
|
|
||||||
mid = ', '.join(sep.format(k, TLObject.pretty_format(v))
|
|
||||||
for k, v in obj.items() if not pre or k != '_')
|
|
||||||
return '{}{}{}{}'.format(pre, left, mid, right)
|
|
||||||
|
|
||||||
elif isinstance(obj, str) or isinstance(obj, bytes):
|
elif isinstance(obj, str) or isinstance(obj, bytes):
|
||||||
return repr(obj)
|
return repr(obj)
|
||||||
elif hasattr(obj, '__iter__'):
|
elif hasattr(obj, '__iter__'):
|
||||||
|
@ -50,29 +45,24 @@ class TLObject:
|
||||||
obj = obj.to_dict()
|
obj = obj.to_dict()
|
||||||
|
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
if '_' in obj:
|
result.append(obj.get('_', 'dict'))
|
||||||
pre, left, right, sep = obj['_'], '(', ')', '{}={}'
|
result.append('(')
|
||||||
else:
|
|
||||||
pre, left, right, sep = '', '{', '}', '{}: {}'
|
|
||||||
|
|
||||||
result.append(pre)
|
|
||||||
result.append(left)
|
|
||||||
if obj:
|
if obj:
|
||||||
result.append('\n')
|
result.append('\n')
|
||||||
indent += 1
|
indent += 1
|
||||||
for k, v in obj.items():
|
for k, v in obj.items():
|
||||||
if pre and k == '_':
|
if k == '_':
|
||||||
continue
|
continue
|
||||||
result.append('\t' * indent)
|
result.append('\t' * indent)
|
||||||
result.append(sep.format(
|
result.append(k)
|
||||||
k, TLObject.pretty_format(v, indent)
|
result.append('=')
|
||||||
))
|
result.append(TLObject.pretty_format(v, indent))
|
||||||
result.append(',\n')
|
result.append(',\n')
|
||||||
result.pop() # last ',\n'
|
result.pop() # last ',\n'
|
||||||
indent -= 1
|
indent -= 1
|
||||||
result.append('\n')
|
result.append('\n')
|
||||||
result.append('\t' * indent)
|
result.append('\t' * indent)
|
||||||
result.append(right)
|
result.append(')')
|
||||||
|
|
||||||
elif isinstance(obj, str) or isinstance(obj, bytes):
|
elif isinstance(obj, str) or isinstance(obj, bytes):
|
||||||
result.append(repr(obj))
|
result.append(repr(obj))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user