forked from uniborg/uniborg
Compare commits
No commits in common. "35b6e7d1e405d6ab1cefe51263fffd9c85839e14" and "5935c19387a616acdd1c756265d9e3ab6c63a66e" have entirely different histories.
35b6e7d1e4
...
5935c19387
|
@ -10,7 +10,7 @@ from telethon.tl.types import MessageEntityPre
|
||||||
from telethon.tl.tlobject import TLObject
|
from telethon.tl.tlobject import TLObject
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
PRINTABLE_SET = set(string.printable.encode())
|
PRINTABLE_SET = set(bytes(string.printable, 'ascii'))
|
||||||
STR_LEN_MAX = 256
|
STR_LEN_MAX = 256
|
||||||
BYTE_LEN_MAX = 64
|
BYTE_LEN_MAX = 64
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ def parse_pre(text):
|
||||||
text = text.strip()
|
text = text.strip()
|
||||||
return (
|
return (
|
||||||
text,
|
text,
|
||||||
[MessageEntityPre(offset=0, length=len(add_surrogate(text)), language='')]
|
[MessageEntityPre(offset=0, length=len(add_surrogate(text)), language='potato')]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,9 +33,8 @@ def yaml_format(obj, indent=0):
|
||||||
obj = obj.to_dict()
|
obj = obj.to_dict()
|
||||||
|
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
if not obj:
|
|
||||||
return 'dict:'
|
|
||||||
result.append(obj.get('_', 'dict') + ':')
|
result.append(obj.get('_', 'dict') + ':')
|
||||||
|
if obj:
|
||||||
items = obj.items()
|
items = obj.items()
|
||||||
has_multiple_items = len(items) > 2
|
has_multiple_items = len(items) > 2
|
||||||
if has_multiple_items:
|
if has_multiple_items:
|
||||||
|
@ -55,32 +54,34 @@ def yaml_format(obj, indent=0):
|
||||||
result.append(' ' * indent)
|
result.append(' ' * indent)
|
||||||
elif isinstance(obj, str):
|
elif isinstance(obj, str):
|
||||||
# truncate long strings and display elipsis
|
# truncate long strings and display elipsis
|
||||||
result = repr(obj[:STR_LEN_MAX])
|
result.append(repr(obj[:STR_LEN_MAX]))
|
||||||
if len(obj) > STR_LEN_MAX:
|
if len(obj) > STR_LEN_MAX:
|
||||||
result += '…'
|
result.append('…')
|
||||||
return result
|
|
||||||
elif isinstance(obj, bytes):
|
elif isinstance(obj, bytes):
|
||||||
# repr() bytes if it's printable, hex like "FF EE BB" otherwise
|
# repr() bytes if it's printable, hex like "FF EE BB" otherwise
|
||||||
if all(c in PRINTABLE_SET for c in obj):
|
if all(c in PRINTABLE_SET for c in obj):
|
||||||
return repr(obj)
|
result.append(repr(obj))
|
||||||
else:
|
else:
|
||||||
return ('<…>' if len(obj) > BYTE_LEN_MAX else
|
if len(obj) > BYTE_LEN_MAX:
|
||||||
' '.join(f'{b:02X}' for b in obj))
|
result.append('<…>')
|
||||||
|
else:
|
||||||
|
result.append(' '.join(f'{b:02X}' for b in obj))
|
||||||
elif isinstance(obj, datetime.datetime):
|
elif isinstance(obj, datetime.datetime):
|
||||||
# ISO-8601 without timezone offset (telethon dates are always UTC)
|
# ISO-8601 without timezone offset (telethon dates are always UTC)
|
||||||
return obj.strftime('%Y-%m-%d %H:%M:%S')
|
result.append(obj.strftime('%Y-%m-%d %H:%M:%S'))
|
||||||
elif hasattr(obj, '__iter__'):
|
elif hasattr(obj, '__iter__'):
|
||||||
# display iterables one after another at the base indentation level
|
# display iterables one after another at the base indentation level
|
||||||
result.append('\n')
|
result.append('\n')
|
||||||
indent += 2
|
indent += 2
|
||||||
for x in obj:
|
for x in obj:
|
||||||
result.append(f"{' ' * indent}- {yaml_format(x, indent + 2)}")
|
result.append(' ' * indent)
|
||||||
|
result.append(yaml_format(x, indent))
|
||||||
result.append('\n')
|
result.append('\n')
|
||||||
result.pop()
|
result.pop()
|
||||||
indent -= 2
|
indent -= 2
|
||||||
result.append(' ' * indent)
|
result.append(' ' * indent)
|
||||||
else:
|
else:
|
||||||
return repr(obj)
|
result.append(repr(obj))
|
||||||
|
|
||||||
return ''.join(result)
|
return ''.join(result)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue