|
50 | 50 | from aleph.sdk.types import Account, GenericMessage, StorageEnum |
51 | 51 | from aleph.sdk.utils import Writable, copy_async_readable_to_buffer |
52 | 52 |
|
53 | | -from .base import AlephClientBase, AuthenticatedAlephClientBase |
| 53 | +from .base import BaseAlephClient, BaseAuthenticatedAlephClient |
54 | 54 | from .conf import settings |
55 | 55 | from .exceptions import ( |
56 | 56 | BroadcastError, |
|
59 | 59 | MessageNotFoundError, |
60 | 60 | MultipleMessagesError, |
61 | 61 | ) |
62 | | -from .models import MessagesResponse, PostsResponse |
| 62 | +from .models import MessagesResponse, PostsResponse, Post |
63 | 63 | from .utils import check_unix_socket_valid, get_message_type_value |
64 | 64 |
|
65 | 65 | logger = logging.getLogger(__name__) |
@@ -469,7 +469,7 @@ def submit( |
469 | 469 | ) |
470 | 470 |
|
471 | 471 |
|
472 | | -class AlephClient(AlephClientBase): |
| 472 | +class AlephClient(BaseAlephClient): |
473 | 473 | api_server: str |
474 | 474 | http_session: aiohttp.ClientSession |
475 | 475 |
|
@@ -618,26 +618,15 @@ async def get_posts( |
618 | 618 | response_json = await resp.json() |
619 | 619 | posts_raw = response_json["posts"] |
620 | 620 |
|
621 | | - # All posts may not be valid according to the latest specification in |
622 | | - # aleph-message. This allows the user to specify how errors should be handled. |
623 | | - posts: List[AlephMessage] = [] |
| 621 | + posts: List[Post] = [] |
624 | 622 | for post_raw in posts_raw: |
625 | 623 | try: |
626 | | - message = parse_message(post_raw) |
627 | | - posts.append(message) |
628 | | - except KeyError as e: |
629 | | - if not ignore_invalid_messages: |
630 | | - raise e |
631 | | - logger.log( |
632 | | - level=invalid_messages_log_level, |
633 | | - msg=f"KeyError: Field '{e.args[0]}' not found", |
634 | | - ) |
| 624 | + posts.append(Post.parse_obj(post_raw)) |
635 | 625 | except ValidationError as e: |
636 | 626 | if not ignore_invalid_messages: |
637 | 627 | raise e |
638 | 628 | if invalid_messages_log_level: |
639 | 629 | logger.log(level=invalid_messages_log_level, msg=e) |
640 | | - |
641 | 630 | return PostsResponse( |
642 | 631 | posts=posts, |
643 | 632 | pagination_page=response_json["pagination_page"], |
@@ -903,7 +892,7 @@ async def watch_messages( |
903 | 892 | break |
904 | 893 |
|
905 | 894 |
|
906 | | -class AuthenticatedAlephClient(AlephClient, AuthenticatedAlephClientBase): |
| 895 | +class AuthenticatedAlephClient(AlephClient, BaseAuthenticatedAlephClient): |
907 | 896 | account: Account |
908 | 897 |
|
909 | 898 | BROADCAST_MESSAGE_FIELDS = { |
|
0 commit comments