Skip to content

Commit

Permalink
Merge branch 'develop': v1.4.0. Safe kwargs for the entry AliceObject…
Browse files Browse the repository at this point in the history
… - AliceRequest

+ imports refactoring
+ minor fixes
+ additional tests
  • Loading branch information
mahenzon committed Feb 24, 2021
2 parents acb3d05 + 86ab1d3 commit c8c102a
Show file tree
Hide file tree
Showing 33 changed files with 253 additions and 99 deletions.
File renamed without changes.
6 changes: 3 additions & 3 deletions aioalice/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio

from .dispatcher import Dispatcher
from .dispatcher.webhook import get_new_configured_app, configure_app
from aioalice.dispatcher import Dispatcher
from aioalice.dispatcher.webhook import get_new_configured_app, configure_app

try:
import uvloop
Expand All @@ -11,4 +11,4 @@
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())


__version__ = '1.3.0'
__version__ = '1.4.0'
33 changes: 15 additions & 18 deletions aioalice/dispatcher/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import aiohttp
import asyncio
# import logging

from . import api
from .handler import Handler, SkipHandler
from .storage import DisabledStorage, MemoryStorage, DEFAULT_STATE
from .filters import generate_default_filters, ExceptionsFilter
from ..utils import json, exceptions

from ..types import UploadedImage, Quota
# log = logging.getLogger(__name__)
from aioalice.dispatcher import api
from aioalice.dispatcher.handler import Handler, SkipHandler
from aioalice.dispatcher.storage import DisabledStorage, MemoryStorage, DEFAULT_STATE
from aioalice.dispatcher.filters import generate_default_filters, ExceptionsFilter
from aioalice.utils import json, exceptions
from aioalice.types import UploadedImage, Quota


class Dispatcher:

def __init__(self, loop=None, storage=None, *, skill_id=None, oauth_token=None):
# TODO: inculde default handler for 'test' commands
# TODO: include default handler for 'test' commands
# TODO: create default handler for exceptions handler
self.loop = loop or asyncio.get_event_loop()
self.storage = storage or DisabledStorage()
Expand Down Expand Up @@ -165,7 +162,7 @@ def _check_auth(self, skill_id, oauth_token):
return skill_id, oauth_token

async def get_images(self, skill_id=None, oauth_token=None):
'''
"""
Get uploaded images
:param skill_id: Provide if was not set at the Dispatcher init
Expand All @@ -174,7 +171,7 @@ async def get_images(self, skill_id=None, oauth_token=None):
:type oauth_token: :obj:`str`
:return: list of UploadedImage instances
'''
"""
skill_id, oauth_token = self._check_auth(skill_id, oauth_token)
result = await api.request(
self.session, oauth_token, skill_id,
Expand All @@ -185,7 +182,7 @@ async def get_images(self, skill_id=None, oauth_token=None):
return [UploadedImage(**dct) for dct in result['images']]

async def upload_image(self, image_url_or_bytes, skill_id=None, oauth_token=None):
'''
"""
Upload image by either url or bytes
:param image_url_or_bytes: Image URL or bytes
Expand All @@ -196,7 +193,7 @@ async def upload_image(self, image_url_or_bytes, skill_id=None, oauth_token=None
:type oauth_token: :obj:`str`
:return: UploadedImage
'''
"""
skill_id, oauth_token = self._check_auth(skill_id, oauth_token)
json = None
file = None
Expand All @@ -213,14 +210,14 @@ async def upload_image(self, image_url_or_bytes, skill_id=None, oauth_token=None
return UploadedImage(**result['image'])

async def get_images_quota(self, oauth_token=None):
'''
"""
Get images storage quota
:param oauth_token: Provide if was not set at the Dispatcher init
:type oauth_token: :obj:`str`
:return: Quota
'''
"""
oauth_token = oauth_token or self.oauth_token
if oauth_token is None:
raise exceptions.AuthRequired('Please provide oauth_token')
Expand All @@ -234,7 +231,7 @@ async def get_images_quota(self, oauth_token=None):
return Quota(**result['images']['quota'])

async def delete_image(self, image_id, skill_id=None, oauth_token=None):
'''
"""
Delete image by id
:param image_id: Image id to be deleted
Expand All @@ -245,7 +242,7 @@ async def delete_image(self, image_id, skill_id=None, oauth_token=None):
:type oauth_token: :obj:`str`
:return: True if result is ok
'''
"""
skill_id, oauth_token = self._check_auth(skill_id, oauth_token)
url = api.Methods.api_url(skill_id, api.Methods.IMAGES) + image_id
result = await api.request(
Expand Down
4 changes: 2 additions & 2 deletions aioalice/dispatcher/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import logging
from http import HTTPStatus

from ..utils import json, exceptions
from ..utils.helper import Helper, HelperMode, Item
from aioalice.utils import json, exceptions
from aioalice.utils.helper import Helper, HelperMode, Item

BASE_URL = 'https://dialogs.yandex.net/api/v1/'
API_URL = BASE_URL + 'skills/{skill_id}/{method}/'
Expand Down
2 changes: 1 addition & 1 deletion aioalice/dispatcher/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import inspect
import logging

from ..utils.helper import Helper, HelperMode, Item
from aioalice.utils.helper import Helper, HelperMode, Item

log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion aioalice/dispatcher/handler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .filters import check_filters
from aioalice.dispatcher.filters import check_filters


class SkipHandler(BaseException):
Expand Down
6 changes: 4 additions & 2 deletions aioalice/dispatcher/webhook.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import asyncio
import logging
import functools

from aiohttp import web
from ..utils import json, generate_json_payload
from ..types import AliceRequest, AliceResponse, Response

from aioalice.utils import json, generate_json_payload
from aioalice.types import AliceRequest, AliceResponse, Response


log = logging.getLogger(__name__)
Expand Down
42 changes: 21 additions & 21 deletions aioalice/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
from .base import AliceObject
from .interfaces import Interfaces
from .meta import Meta
from .markup import Markup
from .entity_tokens import EntityTokens
from .entity_value import EntityValue
from .entity import Entity, EntityType
from .natural_language_understanding import NaturalLanguageUnderstanding
from .request import Request, RequestType
from .session import BaseSession, Session
from aioalice.types.base import AliceObject
from aioalice.types.interfaces import Interfaces
from aioalice.types.meta import Meta
from aioalice.types.markup import Markup
from aioalice.types.entity_tokens import EntityTokens
from aioalice.types.entity_value import EntityValue
from aioalice.types.entity import Entity, EntityType
from aioalice.types.natural_language_understanding import NaturalLanguageUnderstanding
from aioalice.types.request import Request, RequestType
from aioalice.types.session import BaseSession, Session

from .quota import Quota
from .uploaded_image import UploadedImage
from .media_button import MediaButton
from .image import Image
from .card_header import CardHeader
from .card_footer import CardFooter
from .card import Card, CardType
from aioalice.types.quota import Quota
from aioalice.types.uploaded_image import UploadedImage
from aioalice.types.media_button import MediaButton
from aioalice.types.image import Image
from aioalice.types.card_header import CardHeader
from aioalice.types.card_footer import CardFooter
from aioalice.types.card import Card, CardType

from .button import Button
from .response import Response
from aioalice.types.button import Button
from aioalice.types.response import Response

from .alice_response import AliceResponse
from .alice_request import AliceRequest
from aioalice.types.alice_response import AliceResponse
from aioalice.types.alice_request import AliceRequest
15 changes: 12 additions & 3 deletions aioalice/types/alice_request.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
from attr import attrs, attrib
from aiohttp.web import Request as WebRequest
from . import AliceObject, Meta, Session, \
Card, Request, Response, AliceResponse
from ..utils import ensure_cls

from aioalice.types import (
AliceObject,
Meta,
Session,
Card,
Request,
Response,
AliceResponse,
)
from aioalice.utils import ensure_cls, safe_kwargs


@safe_kwargs
@attrs
class AliceRequest(AliceObject):
"""AliceRequest is a request from Alice API"""
Expand Down
4 changes: 2 additions & 2 deletions aioalice/types/alice_response.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from attr import attrs, attrib

from . import AliceObject, BaseSession, Response
from ..utils import ensure_cls
from aioalice.types import AliceObject, BaseSession, Response
from aioalice.utils import ensure_cls


@attrs
Expand Down
3 changes: 2 additions & 1 deletion aioalice/types/button.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from attr import attrs, attrib
from . import AliceObject

from aioalice.types import AliceObject


@attrs
Expand Down
6 changes: 3 additions & 3 deletions aioalice/types/card.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from attr import attrs, attrib

from . import AliceObject, MediaButton, Image, CardHeader, CardFooter
from ..utils import ensure_cls
from ..utils.helper import Helper, HelperMode, Item
from aioalice.types import AliceObject, MediaButton, Image, CardHeader, CardFooter
from aioalice.utils import ensure_cls
from aioalice.utils.helper import Helper, HelperMode, Item


@attrs
Expand Down
4 changes: 2 additions & 2 deletions aioalice/types/card_footer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from attr import attrs, attrib

from . import AliceObject, MediaButton
from ..utils import ensure_cls
from aioalice.types import AliceObject, MediaButton
from aioalice.utils import ensure_cls


@attrs
Expand Down
3 changes: 2 additions & 1 deletion aioalice/types/card_header.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from attr import attrs, attrib
from . import AliceObject

from aioalice.types import AliceObject


@attrs
Expand Down
6 changes: 3 additions & 3 deletions aioalice/types/entity.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging
from attr import attrs, attrib

from . import AliceObject, EntityTokens, EntityValue
from ..utils import ensure_cls
from ..utils.helper import Helper, HelperMode, Item
from aioalice.types import AliceObject, EntityTokens, EntityValue
from aioalice.utils import ensure_cls
from aioalice.utils.helper import Helper, HelperMode, Item

log = logging.getLogger(__name__)

Expand Down
3 changes: 2 additions & 1 deletion aioalice/types/entity_tokens.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from attr import attrs, attrib
from . import AliceObject

from aioalice.types import AliceObject


@attrs
Expand Down
3 changes: 2 additions & 1 deletion aioalice/types/entity_value.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from attr import attrs, attrib
from . import AliceObject

from aioalice.types import AliceObject


@attrs
Expand Down
4 changes: 2 additions & 2 deletions aioalice/types/image.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from attr import attrs, attrib

from . import AliceObject, MediaButton
from ..utils import ensure_cls
from aioalice.types import AliceObject, MediaButton
from aioalice.utils import ensure_cls


@attrs
Expand Down
3 changes: 2 additions & 1 deletion aioalice/types/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from attr import attrs, attrib
from . import AliceObject

from aioalice.types import AliceObject


@attrs
Expand Down
4 changes: 2 additions & 2 deletions aioalice/types/markup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from attr import attrs, attrib

from . import AliceObject
from ..utils import safe_kwargs
from aioalice.types import AliceObject
from aioalice.utils import safe_kwargs


@safe_kwargs
Expand Down
3 changes: 2 additions & 1 deletion aioalice/types/media_button.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from attr import attrs, attrib
from . import AliceObject

from aioalice.types import AliceObject


@attrs
Expand Down
4 changes: 2 additions & 2 deletions aioalice/types/meta.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from attr import attrs, attrib

from . import AliceObject, Interfaces
from ..utils import ensure_cls
from aioalice.types import AliceObject, Interfaces
from aioalice.utils import ensure_cls


@attrs
Expand Down
4 changes: 2 additions & 2 deletions aioalice/types/natural_language_understanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from attr import attrs, attrib

from . import AliceObject, Entity
from ..utils import ensure_cls
from aioalice.types import AliceObject, Entity
from aioalice.utils import ensure_cls


@attrs
Expand Down
3 changes: 2 additions & 1 deletion aioalice/types/quota.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from attr import attrs, attrib
from . import AliceObject

from aioalice.types import AliceObject


@attrs
Expand Down
6 changes: 3 additions & 3 deletions aioalice/types/request.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from attr import attrs, attrib

from . import AliceObject, Markup, NaturalLanguageUnderstanding
from ..utils import ensure_cls
from ..utils.helper import Helper, HelperMode, Item
from aioalice.types import AliceObject, Markup, NaturalLanguageUnderstanding
from aioalice.utils import ensure_cls
from aioalice.utils.helper import Helper, HelperMode, Item


@attrs
Expand Down
4 changes: 2 additions & 2 deletions aioalice/types/response.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from attr import attrs, attrib

from . import AliceObject, Card, Button
from ..utils import ensure_cls
from aioalice.types import AliceObject, Card, Button
from aioalice.utils import ensure_cls


@attrs
Expand Down
3 changes: 2 additions & 1 deletion aioalice/types/session.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from attr import attrs, attrib
from . import AliceObject

from aioalice.types import AliceObject


@attrs
Expand Down
Loading

0 comments on commit c8c102a

Please sign in to comment.