From 2ba7b0838dc1fd99f919860f3efd75416a0dfe35 Mon Sep 17 00:00:00 2001 From: Bohdan Marukhnenko Date: Sat, 6 Jan 2024 18:08:54 +0200 Subject: [PATCH] Added python 3.7+ support --- README.md | 3 +++ setup.py | 7 +++++-- tempmail/providers.py | 21 +++++++++++++++------ tempmail/utils.py | 2 +- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2890aa5..2587fde 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # Python Temp Email Library + +[![Python 3.7+](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/downloads) + **tempmail-python** is a Python library for generating and managing temporary email addresses using the 1secmail service. It provides functions for creating email addresses, checking for new messages, and retrieving message contents. ## Installation diff --git a/setup.py b/setup.py index da5e65d..33c1969 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,11 @@ from setuptools import setup, find_packages + def read(path: str) -> str: with open(path, 'r', encoding='utf-8') as f: return f.read() + setup( name='tempmail-python', version='2.3.2', @@ -13,15 +15,16 @@ def read(path: str) -> str: author='cubicbyte', author_email='bmaruhnenko@gmail.com', url='https://github.com/cubicbyte/tempmail-python', - packages = find_packages(), + packages=find_packages(), license='MIT', keywords='disposable-email temporary-email temp-email temp-mail email mail email-generator mail-generator', install_requires=[ 'requests>=2.19.0', ], + python_requires='>=3.7', classifiers=[ 'Development Status :: 5 - Production/Stable', 'Programming Language :: Python :: 3', 'License :: OSI Approved :: MIT License', ], -) \ No newline at end of file +) diff --git a/tempmail/providers.py b/tempmail/providers.py index 755b055..3a6fdc0 100644 --- a/tempmail/providers.py +++ b/tempmail/providers.py @@ -1,14 +1,16 @@ import time import random +from typing import Dict, Optional, Tuple, List, Callable from datetime import datetime from dataclasses import dataclass -from typing import Optional, List, Tuple, Dict import requests from . import utils -__all__ = ('OneSecMail',) +__all__ = ( + 'OneSecMail', +) class OneSecMail: @@ -17,7 +19,12 @@ class OneSecMail: inbox_update_interval = 0.5 """How often to update the inbox in seconds""" - def __init__(self, address: Optional[str] = None, username: Optional[str] = None, domain: Optional[str] = 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) @@ -57,7 +64,8 @@ def download_attachment(self, id: int, file: str) -> bytes: resp.raise_for_status() return resp.content - def wait_for_message(self, timeout: Optional[int] = 60, filter: callable = lambda _: True) -> 'OneSecMail.Message': + def wait_for_message(self, timeout: Optional[int] = 60, + filter: Callable[['OneSecMail.Message'], bool] = 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 @@ -148,7 +156,7 @@ class Message: html_body: str "Message body (html format)" _mail_instance: 'OneSecMail' - _attachments: list[dict[str, any]] + _attachments: List[Dict[str, any]] @property def date(self) -> datetime: @@ -158,7 +166,8 @@ def date(self) -> datetime: @property 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] + 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': diff --git a/tempmail/utils.py b/tempmail/utils.py index 6dc265c..bf9ef81 100644 --- a/tempmail/utils.py +++ b/tempmail/utils.py @@ -11,7 +11,7 @@ def random_string(length: int): def cache(func): """Cache the result of a function with saved type hints""" - @functools.lru_cache + @functools.lru_cache(maxsize=128) @functools.wraps(func) def wrapper(*args, **kwargs): return func(*args, **kwargs)