Rewrite Bot classes. Add moooooore pydocs.

This commit is contained in:
Alex Root Junior 2017-07-24 21:46:43 +03:00
parent a6e90655bc
commit ffbb89100c
5 changed files with 2030 additions and 967 deletions

View file

@ -86,12 +86,7 @@ def _compose_data(params=None, files=None):
if params:
for key, value in params.items():
# TODO: Normalize data in other place.
if value.__class__ is dict:
value = json.dumps(value)
elif hasattr(value, 'to_json'):
value = json.dumps(value.to_json())
data.add_field(key, value)
data.add_field(key, str(value))
if files:
for key, f in files.items():

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -47,7 +47,10 @@ from .video_note import VideoNote
from .voice import Voice
from .webhook_info import WebhookInfo
from . import base
__all__ = [
'base',
'Animation',
'Audio',
'CallbackQuery',

View file

@ -1,3 +1,5 @@
from aiogram.utils import json
DEFAULT_FILTER = ['self']
@ -8,3 +10,11 @@ def generate_payload(exclude=None, **kwargs):
key not in exclude + DEFAULT_FILTER
and value
and not key.startswith('_')}
def prepare_arg(value):
if isinstance(value, (list, dict)):
return json.dumps(value)
elif hasattr(value, 'to_json'):
return json.dumps(value.to_json())
return value