Make _rpc private

This commit is contained in:
link2xt
2022-12-04 14:03:43 +00:00
parent bad5a1de55
commit ee19789cac
4 changed files with 44 additions and 44 deletions

View File

@@ -7,7 +7,7 @@ from .message import Message
class Account: class Account:
def __init__(self, rpc, account_id) -> None: def __init__(self, rpc, account_id) -> None:
self.rpc = rpc self._rpc = rpc
self.account_id = account_id self.account_id = account_id
def __repr__(self) -> str: def __repr__(self) -> str:
@@ -15,53 +15,53 @@ class Account:
async def wait_for_event(self) -> dict: async def wait_for_event(self) -> dict:
"""Wait until the next event and return it.""" """Wait until the next event and return it."""
return await self.rpc.wait_for_event(self.account_id) return await self._rpc.wait_for_event(self.account_id)
async def remove(self) -> None: async def remove(self) -> None:
"""Remove the account.""" """Remove the account."""
await self.rpc.remove_account(self.account_id) await self._rpc.remove_account(self.account_id)
async def start_io(self) -> None: async def start_io(self) -> None:
"""Start the account I/O.""" """Start the account I/O."""
await self.rpc.start_io(self.account_id) await self._rpc.start_io(self.account_id)
async def stop_io(self) -> None: async def stop_io(self) -> None:
"""Stop the account I/O.""" """Stop the account I/O."""
await self.rpc.stop_io(self.account_id) await self._rpc.stop_io(self.account_id)
async def get_info(self) -> dict: async def get_info(self) -> dict:
return await self.rpc.get_info(self.account_id) return await self._rpc.get_info(self.account_id)
async def get_file_size(self) -> int: async def get_file_size(self) -> int:
return await self.rpc.get_account_file_size(self.account_id) return await self._rpc.get_account_file_size(self.account_id)
async def is_configured(self) -> bool: async def is_configured(self) -> bool:
"""Return True for configured accounts.""" """Return True for configured accounts."""
return await self.rpc.is_configured(self.account_id) return await self._rpc.is_configured(self.account_id)
async def set_config(self, key: str, value: Optional[str] = None) -> None: async def set_config(self, key: str, value: Optional[str] = None) -> None:
"""Set the configuration value key pair.""" """Set the configuration value key pair."""
await self.rpc.set_config(self.account_id, key, value) await self._rpc.set_config(self.account_id, key, value)
async def get_config(self, key: str) -> Optional[str]: async def get_config(self, key: str) -> Optional[str]:
"""Get the configuration value.""" """Get the configuration value."""
return await self.rpc.get_config(self.account_id, key) return await self._rpc.get_config(self.account_id, key)
async def configure(self) -> None: async def configure(self) -> None:
"""Configure an account.""" """Configure an account."""
await self.rpc.configure(self.account_id) await self._rpc.configure(self.account_id)
async def create_contact(self, address: str, name: Optional[str] = None) -> Contact: async def create_contact(self, address: str, name: Optional[str] = None) -> Contact:
"""Create a contact with the given address and, optionally, a name.""" """Create a contact with the given address and, optionally, a name."""
return Contact( return Contact(
self.rpc, self._rpc,
self.account_id, self.account_id,
await self.rpc.create_contact(self.account_id, address, name), await self._rpc.create_contact(self.account_id, address, name),
) )
async def secure_join(self, qrdata: str) -> Chat: async def secure_join(self, qrdata: str) -> Chat:
chat_id = await self.rpc.secure_join(self.account_id, qrdata) chat_id = await self._rpc.secure_join(self.account_id, qrdata)
return Chat(self.rpc, self.account_id, chat_id) return Chat(self._rpc, self.account_id, chat_id)
async def get_fresh_messages(self) -> List[Message]: async def get_fresh_messages(self) -> List[Message]:
"""Return the list of fresh messages, newest messages first. """Return the list of fresh messages, newest messages first.
@@ -70,10 +70,10 @@ class Account:
If you are writing a bot, use get_fresh_messages_in_arrival_order instead, If you are writing a bot, use get_fresh_messages_in_arrival_order instead,
to process oldest messages first. to process oldest messages first.
""" """
fresh_msg_ids = await self.rpc.get_fresh_msgs(self.account_id) fresh_msg_ids = await self._rpc.get_fresh_msgs(self.account_id)
return [Message(self.rpc, self.account_id, msg_id) for msg_id in fresh_msg_ids] return [Message(self._rpc, self.account_id, msg_id) for msg_id in fresh_msg_ids]
async def get_fresh_messages_in_arrival_order(self) -> List[Message]: async def get_fresh_messages_in_arrival_order(self) -> List[Message]:
"""Return fresh messages list sorted in the order of their arrival, with ascending IDs.""" """Return fresh messages list sorted in the order of their arrival, with ascending IDs."""
fresh_msg_ids = sorted(await self.rpc.get_fresh_msgs(self.account_id)) fresh_msg_ids = sorted(await self._rpc.get_fresh_msgs(self.account_id))
return [Message(self.rpc, self.account_id, msg_id) for msg_id in fresh_msg_ids] return [Message(self._rpc, self.account_id, msg_id) for msg_id in fresh_msg_ids]

View File

@@ -8,34 +8,34 @@ if TYPE_CHECKING:
class Chat: class Chat:
def __init__(self, rpc: Rpc, account_id: int, chat_id: int) -> None: def __init__(self, rpc: Rpc, account_id: int, chat_id: int) -> None:
self.rpc = rpc self._rpc = rpc
self.account_id = account_id self.account_id = account_id
self.chat_id = chat_id self.chat_id = chat_id
async def block(self) -> None: async def block(self) -> None:
"""Block the chat.""" """Block the chat."""
await self.rpc.block_chat(self.account_id, self.chat_id) await self._rpc.block_chat(self.account_id, self.chat_id)
async def accept(self) -> None: async def accept(self) -> None:
"""Accept the contact request.""" """Accept the contact request."""
await self.rpc.accept_chat(self.account_id, self.chat_id) await self._rpc.accept_chat(self.account_id, self.chat_id)
async def delete(self) -> None: async def delete(self) -> None:
await self.rpc.delete_chat(self.account_id, self.chat_id) await self._rpc.delete_chat(self.account_id, self.chat_id)
async def get_encryption_info(self) -> str: async def get_encryption_info(self) -> str:
return await self.rpc.get_chat_encryption_info(self.account_id, self.chat_id) return await self._rpc.get_chat_encryption_info(self.account_id, self.chat_id)
async def send_text(self, text: str) -> "Message": async def send_text(self, text: str) -> "Message":
from .message import Message from .message import Message
msg_id = await self.rpc.misc_send_text_message( msg_id = await self._rpc.misc_send_text_message(
self.account_id, self.chat_id, text self.account_id, self.chat_id, text
) )
return Message(self.rpc, self.account_id, msg_id) return Message(self._rpc, self.account_id, msg_id)
async def leave(self) -> None: async def leave(self) -> None:
await self.rpc.leave_group(self.account_id, self.chat_id) await self._rpc.leave_group(self.account_id, self.chat_id)
async def get_fresh_message_count(self) -> int: async def get_fresh_message_count(self) -> int:
return await self.rpc.get_fresh_msg_cnt(self.account_id, self.chat_id) return await self._rpc.get_fresh_msg_cnt(self.account_id, self.chat_id)

View File

@@ -14,39 +14,39 @@ class Contact:
""" """
def __init__(self, rpc: Rpc, account_id: int, contact_id: int) -> None: def __init__(self, rpc: Rpc, account_id: int, contact_id: int) -> None:
self.rpc = rpc self._rpc = rpc
self.account_id = account_id self.account_id = account_id
self.contact_id = contact_id self.contact_id = contact_id
async def block(self) -> None: async def block(self) -> None:
"""Block contact.""" """Block contact."""
await self.rpc.block_contact(self.account_id, self.contact_id) await self._rpc.block_contact(self.account_id, self.contact_id)
async def unblock(self) -> None: async def unblock(self) -> None:
"""Unblock contact.""" """Unblock contact."""
await self.rpc.unblock_contact(self.account_id, self.contact_id) await self._rpc.unblock_contact(self.account_id, self.contact_id)
async def delete(self) -> None: async def delete(self) -> None:
"""Delete contact.""" """Delete contact."""
await self.rpc.delete_contact(self.account_id, self.contact_id) await self._rpc.delete_contact(self.account_id, self.contact_id)
async def change_name(self, name: str) -> None: async def change_name(self, name: str) -> None:
await self.rpc.change_contact_name(self.account_id, self.contact_id, name) await self._rpc.change_contact_name(self.account_id, self.contact_id, name)
async def get_encryption_info(self) -> str: async def get_encryption_info(self) -> str:
return await self.rpc.get_contact_encryption_info( return await self._rpc.get_contact_encryption_info(
self.account_id, self.contact_id self.account_id, self.contact_id
) )
async def get_dictionary(self) -> dict: async def get_dictionary(self) -> dict:
"""Return a dictionary with a snapshot of all contact properties.""" """Return a dictionary with a snapshot of all contact properties."""
return await self.rpc.get_contact(self.account_id, self.contact_id) return await self._rpc.get_contact(self.account_id, self.contact_id)
async def create_chat(self) -> "Chat": async def create_chat(self) -> "Chat":
from .chat import Chat from .chat import Chat
return Chat( return Chat(
self.rpc, self._rpc,
self.account_id, self.account_id,
await self.rpc.create_chat_by_contact_id(self.account_id, self.contact_id), await self._rpc.create_chat_by_contact_id(self.account_id, self.contact_id),
) )

View File

@@ -8,20 +8,20 @@ from .rpc import Rpc
class Message: class Message:
def __init__(self, rpc: Rpc, account_id: int, msg_id: int) -> None: def __init__(self, rpc: Rpc, account_id: int, msg_id: int) -> None:
self.rpc = rpc self._rpc = rpc
self.account_id = account_id self.account_id = account_id
self.msg_id = msg_id self.msg_id = msg_id
async def send_reaction(self, reactions: str) -> "Message": async def send_reaction(self, reactions: str) -> "Message":
msg_id = await self.rpc.send_reaction(self.account_id, self.msg_id, reactions) msg_id = await self._rpc.send_reaction(self.account_id, self.msg_id, reactions)
return Message(self.rpc, self.account_id, msg_id) return Message(self._rpc, self.account_id, msg_id)
async def get_snapshot(self) -> "MessageSnapshot": async def get_snapshot(self) -> "MessageSnapshot":
message_object = await self.rpc.get_message(self.account_id, self.msg_id) message_object = await self._rpc.get_message(self.account_id, self.msg_id)
return MessageSnapshot( return MessageSnapshot(
message=self, message=self,
chat=Chat(self.rpc, self.account_id, message_object["chatId"]), chat=Chat(self._rpc, self.account_id, message_object["chatId"]),
sender=Contact(self.rpc, self.account_id, message_object["fromId"]), sender=Contact(self._rpc, self.account_id, message_object["fromId"]),
text=message_object["text"], text=message_object["text"],
error=message_object.get("error"), error=message_object.get("error"),
is_info=message_object["isInfo"], is_info=message_object["isInfo"],
@@ -29,7 +29,7 @@ class Message:
async def mark_seen(self) -> None: async def mark_seen(self) -> None:
"""Mark the message as seen.""" """Mark the message as seen."""
await self.rpc.markseen_msgs(self.account_id, [self.msg_id]) await self._rpc.markseen_msgs(self.account_id, [self.msg_id])
@dataclass @dataclass