From 80d5624164fd1a4fd05bc4e669e316f07c1036b8 Mon Sep 17 00:00:00 2001 From: Bohdan Marukhnenko Date: Thu, 23 Nov 2023 11:40:01 +0200 Subject: [PATCH] Fixed need for python 3.10+ caused by typing --- tempmail/providers.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tempmail/providers.py b/tempmail/providers.py index b7efbb6..755b055 100644 --- a/tempmail/providers.py +++ b/tempmail/providers.py @@ -2,6 +2,7 @@ import random from datetime import datetime from dataclasses import dataclass +from typing import Optional, List, Tuple, Dict import requests @@ -16,7 +17,7 @@ class OneSecMail: inbox_update_interval = 0.5 """How often to update the inbox in seconds""" - def __init__(self, address: str | None = None, username: str | None = None, domain: str | None = None) -> None: + def __init__(self, address: Optional[str] = None, username: Optional[str] = None, domain: Optional[str] = None) -> None: """Create a new 1secmail.com email address :param address: The full email address (username@domain) @@ -36,7 +37,7 @@ def __init__(self, address: str | None = None, username: str | None = None, doma self.domain = domain or random.choice(self.get_domains()) """The domain of the email address (after the @)""" - def get_inbox(self) -> list['OneSecMail.MessageInfo']: + def get_inbox(self) -> List['OneSecMail.MessageInfo']: """Get the inbox of the email address""" resp = self._session.get(f'https://www.1secmail.com/api/v1/?action=getMessages&login={self.username}&domain={self.domain}') resp.raise_for_status() @@ -56,7 +57,7 @@ def download_attachment(self, id: int, file: str) -> bytes: resp.raise_for_status() return resp.content - def wait_for_message(self, timeout: int | None = 60, filter: callable = lambda _: True) -> 'OneSecMail.Message': + def wait_for_message(self, timeout: Optional[int] = 60, filter: callable = lambda _: True) -> 'OneSecMail.Message': """Wait for a message to arrive in the inbox :param timeout: How long to wait for a message to arrive, in seconds @@ -76,7 +77,7 @@ def wait_for_message(self, timeout: int | None = 60, filter: callable = lambda _ @staticmethod @utils.cache - def get_domains() -> tuple[str, ...]: + def get_domains() -> Tuple[str, ...]: """List of allowed email domains""" resp = requests.get('https://www.1secmail.com/api/v1/?action=getDomainList') resp.raise_for_status() @@ -118,7 +119,7 @@ def message(self) -> 'OneSecMail.Message': return self._mail_instance.get_message(self.id) @classmethod - def from_dict(cls, mail_instance: 'OneSecMail', msg_info: dict[str, any]) -> 'OneSecMail.MessageInfo': + def from_dict(cls, mail_instance: 'OneSecMail', msg_info: Dict[str, any]) -> 'OneSecMail.MessageInfo': """Create a MessageInfo from a raw api response""" return cls( _mail_instance=mail_instance, @@ -155,12 +156,12 @@ def date(self) -> datetime: return datetime.fromisoformat(self.date_str) @property - def attachments(self) -> list['OneSecMail.Attachment']: + def attachments(self) -> List['OneSecMail.Attachment']: """List of attachments in the message (files)""" return [OneSecMail.Attachment.from_dict(self._mail_instance, self.id, attachment) for attachment in self._attachments] @classmethod - def from_dict(cls, mail_instance: 'OneSecMail', msg: dict[str, any]) -> 'OneSecMail.Message': + def from_dict(cls, mail_instance: 'OneSecMail', msg: Dict[str, any]) -> 'OneSecMail.Message': """Create a Message from a raw api response""" return cls( _mail_instance=mail_instance, @@ -192,7 +193,7 @@ def download(self) -> bytes: return self._mail_instance.download_attachment(self._message_id, self.filename) @classmethod - def from_dict(cls, mail_instance: 'OneSecMail', message_id: int, attachment: dict[str, any]) -> 'OneSecMail.Attachment': + def from_dict(cls, mail_instance: 'OneSecMail', message_id: int, attachment: Dict[str, any]) -> 'OneSecMail.Attachment': """Create an Attachment from a raw api response""" return cls( _mail_instance=mail_instance,