diff --git a/emails/__init__.pyi b/emails/__init__.pyi new file mode 100644 index 0000000..0ba0e6a --- /dev/null +++ b/emails/__init__.pyi @@ -0,0 +1,10 @@ +from typing import Any, Optional, Union, Tuple, List, Dict, Callable +from .message import Message as Message, html as html +from .utils import MessageID as MessageID + +__title__: str +__version__: str +__author__: str +__license__: str +__copyright__: str +USER_AGENT: str diff --git a/emails/backend/__init__.pyi b/emails/backend/__init__.pyi new file mode 100644 index 0000000..150ec9c --- /dev/null +++ b/emails/backend/__init__.pyi @@ -0,0 +1,2 @@ +from .factory import ObjectFactory as ObjectFactory +from .smtp import SMTPBackend as SMTPBackend diff --git a/emails/backend/factory.pyi b/emails/backend/factory.pyi new file mode 100644 index 0000000..2c96345 --- /dev/null +++ b/emails/backend/factory.pyi @@ -0,0 +1,12 @@ +from typing import Any, Dict, Type, TypeVar + +T = TypeVar('T') + +def simple_dict2str(d: Dict[str, Any]) -> str: ... + +class ObjectFactory: + cls: Type[Any] + pool: Dict[str, Any] + def __init__(self, cls: Type[Any]) -> None: ... + def __getitem__(self, k: Dict[str, Any]) -> Any: ... + def invalidate(self, k: Dict[str, Any]) -> Any: ... diff --git a/emails/backend/response.pyi b/emails/backend/response.pyi new file mode 100644 index 0000000..ce70313 --- /dev/null +++ b/emails/backend/response.pyi @@ -0,0 +1,27 @@ +from typing import Any, Optional, List, Dict, Tuple + +class Response: + backend: Any + _exc: Optional[Exception] + from_addr: Optional[str] + to_addrs: Optional[List[str]] + _finished: bool + def __init__(self, exception: Optional[Exception] = ..., backend: Any = ...) -> None: ... + def set_exception(self, exc: Exception) -> None: ... + def raise_if_needed(self) -> None: ... + @property + def error(self) -> Optional[Exception]: ... + @property + def success(self) -> bool: ... + +class SMTPResponse(Response): + responses: List[Any] + esmtp_opts: Optional[List[str]] + rcpt_options: Optional[List[str]] + status_code: Optional[int] + status_text: Optional[str] + last_command: Optional[str] + refused_recipient: Dict[str, Any] + refused_recipients: Dict[str, Any] + def __init__(self, exception: Optional[Exception] = ..., backend: Any = ...) -> None: ... + def set_status(self, command: str, code: int, text: str, **kwargs: Any) -> None: ... diff --git a/emails/backend/smtp/__init__.pyi b/emails/backend/smtp/__init__.pyi new file mode 100644 index 0000000..4c293bc --- /dev/null +++ b/emails/backend/smtp/__init__.pyi @@ -0,0 +1 @@ +from .backend import SMTPBackend as SMTPBackend diff --git a/emails/backend/smtp/backend.pyi b/emails/backend/smtp/backend.pyi new file mode 100644 index 0000000..c388eab --- /dev/null +++ b/emails/backend/smtp/backend.pyi @@ -0,0 +1,25 @@ +from typing import Any, Optional, Dict, List, Type, Callable +from ..response import SMTPResponse +from .client import SMTPClientWithResponse, SMTPClientWithResponse_SSL + +class SMTPBackend: + DEFAULT_SOCKET_TIMEOUT: int + connection_cls: Type[SMTPClientWithResponse] + connection_ssl_cls: Type[SMTPClientWithResponse_SSL] + response_cls: Type[SMTPResponse] + smtp_cls: Type[Any] + ssl: bool + tls: Optional[bool] + smtp_cls_kwargs: Dict[str, Any] + host: Optional[str] + port: Optional[int] + fail_silently: bool + mail_options: List[str] + _client: Optional[Any] + + def __init__(self, ssl: bool = ..., fail_silently: bool = ..., mail_options: Optional[List[str]] = ..., **kwargs: Any) -> None: ... + def get_client(self) -> Any: ... + def close(self) -> None: ... + def make_response(self, exception: Optional[Exception] = ...) -> SMTPResponse: ... + def retry_on_disconnect(self, func: Callable[..., Any]) -> Callable[..., Any]: ... + def _send(self, **kwargs: Any) -> Any: ... diff --git a/emails/backend/smtp/client.pyi b/emails/backend/smtp/client.pyi new file mode 100644 index 0000000..7cb813e --- /dev/null +++ b/emails/backend/smtp/client.pyi @@ -0,0 +1,34 @@ +from typing import Any, Union, Sequence +from smtplib import SMTP, SMTP_SSL + +class SMTPClientWithResponse(SMTP): + parent: Any + make_response: Any + tls: bool + ssl: bool + debug: int + # user: str + # password: str + _initialized: bool + initialized: bool + def __init__(self, parent: Any, **kwargs: Any) -> None: ... + def initialize(self) -> None: ... + def quit(self) -> Any: ... + def _rset(self) -> None: ... + def sendmail(self, from_addr: str, to_addrs: Union[str, Sequence[str]], msg: Any, mail_options: Sequence[str] = ..., rcpt_options: Sequence[str] = ...) -> Any: ... + +class SMTPClientWithResponse_SSL(SMTP_SSL): + parent: Any + make_response: Any + tls: bool + ssl: bool + debug: int + # user: str + # password: str + _initialized: bool + initialized: bool + def __init__(self, parent: Any, **kwargs: Any) -> None: ... + def initialize(self) -> None: ... + def quit(self) -> Any: ... + def _rset(self) -> None: ... + def sendmail(self, from_addr: str, to_addrs: Union[str, Sequence[str]], msg: Any, mail_options: Sequence[str] = ..., rcpt_options: Sequence[str] = ...) -> Any: ... diff --git a/emails/django/__init__.pyi b/emails/django/__init__.pyi new file mode 100644 index 0000000..0db7d23 --- /dev/null +++ b/emails/django/__init__.pyi @@ -0,0 +1,17 @@ +from typing import Any, Optional, List, Union, Dict +from ..message import MessageTransformerMixin, MessageSignMixin, MessageBuildMixin, BaseMessage + +class DjangoMessageMixin: + _recipients: Optional[List[str]] + _from_email: Optional[str] + @property + def encoding(self) -> str: ... + def recipients(self) -> List[str]: ... + @property + def from_email(self) -> str: ... + def _set_emails(self, mail_to: Optional[Union[str, List[str]]] = ..., set_mail_to: bool = ..., mail_from: Optional[str] = ..., set_mail_from: bool = ..., to: Optional[Union[str, List[str]]] = ...) -> None: ... + def send(self, mail_to: Optional[Union[str, List[str]]] = ..., set_mail_to: bool = ..., mail_from: Optional[str] = ..., set_mail_from: bool = ..., context: Optional[Dict[str, Any]] = ..., connection: Optional[Any] = ..., to: Optional[Union[str, List[str]]] = ...) -> Any: ... + +class DjangoMessage(DjangoMessageMixin, MessageTransformerMixin, MessageSignMixin, MessageBuildMixin, BaseMessage): ... + +Message = DjangoMessage diff --git a/emails/django_.pyi b/emails/django_.pyi new file mode 100644 index 0000000..3c4dd9a --- /dev/null +++ b/emails/django_.pyi @@ -0,0 +1 @@ +from .django import * diff --git a/emails/exc.pyi b/emails/exc.pyi new file mode 100644 index 0000000..efc666f --- /dev/null +++ b/emails/exc.pyi @@ -0,0 +1,5 @@ +from .packages.dkim import DKIMException as DKIMException + +class HTTPLoaderError(Exception): ... +class BadHeaderError(ValueError): ... +class IncompleteMessage(ValueError): ... diff --git a/emails/loader/__init__.pyi b/emails/loader/__init__.pyi new file mode 100644 index 0000000..2704a05 --- /dev/null +++ b/emails/loader/__init__.pyi @@ -0,0 +1,9 @@ +from typing import Any, Optional, Dict, Type, List +from .local_store import FileSystemLoader as FileSystemLoader, ZipLoader as ZipLoader, MsgLoader as MsgLoader, FileNotFound as FileNotFound +from .helpers import guess_charset as guess_charset + +class LoadError(Exception): ... +class IndexFileNotFound(LoadError): ... +class InvalidHtmlFile(LoadError): ... + +def from_html(html: str, text: Optional[str] = ..., base_url: Optional[str] = ..., message_params: Optional[Dict[str, Any]] = ..., local_loader: Optional[Any] = ..., template_cls: Optional[Type[Any]] = ..., message_cls: Optional[Type[Any]] = ..., source_filename: Optional[str] = ..., requests_params: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> Any: ... diff --git a/emails/loader/helpers.pyi b/emails/loader/helpers.pyi new file mode 100644 index 0000000..40b3452 --- /dev/null +++ b/emails/loader/helpers.pyi @@ -0,0 +1,24 @@ +from typing import Any, Optional, List, Tuple, Union, Pattern + +class ReRules: + re_meta: Pattern[Any] + re_is_http_equiv: Pattern[Any] + re_parse_http_equiv: Pattern[Any] + re_charset: Pattern[Any] + def __init__(self, conv: Optional[Any] = ...) -> None: ... + +RULES_U: ReRules +RULES_B: ReRules + +def guess_text_charset(text: Union[str, bytes], is_html: bool = ...) -> Optional[str]: ... +def guess_html_charset(html: Union[str, bytes]) -> Optional[str]: ... +def guess_charset(headers: Any, html: Union[str, bytes]) -> Optional[str]: ... + +COMMON_CHARSETS: Tuple[str, ...] + +def decode_text(text: Union[str, bytes], + is_html: bool = ..., + guess_charset: bool = ..., + try_common_charsets: bool = ..., + charsets: Optional[List[str]] = ..., + fallback_charset: str = ...) -> Tuple[str, Optional[str]]: ... diff --git a/emails/loader/local_store.pyi b/emails/loader/local_store.pyi new file mode 100644 index 0000000..8337043 --- /dev/null +++ b/emails/loader/local_store.pyi @@ -0,0 +1,51 @@ +from typing import Any, Optional, List, Tuple, Union, Iterator +# from .helpers import decode_text + +class FileNotFound(Exception): ... + +def split_template_path(template: str) -> List[str]: ... +def open_if_exists(filename: str, mode: str = ...) -> Optional[Any]: ... + +class BaseLoader: + def __getitem__(self, filename: str) -> Optional[bytes]: ... + def get_file(self, name: str) -> Tuple[Optional[bytes], Optional[float]]: ... + def list_files(self) -> Iterator[str]: ... + def content(self, filename: str, is_html: bool = ..., decode: bool = ..., guess_charset: bool = ..., charset: str = ...) -> Union[str, bytes, None]: ... + def find_index_file(self, filename: Optional[str] = ..., extensions: Tuple[str, ...] = ..., stop_names: Tuple[str, ...] = ..., raise_if_not_found: bool = ...) -> Optional[str]: ... + +class FileSystemLoader(BaseLoader): + searchpath: List[str] + encoding: str + base_path: Optional[str] + def __init__(self, searchpath: Union[str, List[str]], encoding: str = ..., base_path: Optional[str] = ...) -> None: ... + def get_file(self, name: str) -> Tuple[Optional[bytes], Optional[float]]: ... + def list_files(self) -> Iterator[str]: ... + +class ZipLoader(BaseLoader): + zipfile: Any + encoding: str + base_path: Optional[str] + _decoded_filenames: Optional[Any] + _original_filenames: Optional[Any] + def __init__(self, file: Any, encoding: str = ..., base_path: Optional[str] = ...) -> None: ... + def get_file(self, name: str) -> Tuple[Optional[bytes], Optional[float]]: ... + def list_files(self) -> Iterator[str]: ... + +class MsgLoader(BaseLoader): + msg: Any + base_path: Optional[str] + _html_parts: List[Any] + _text_parts: List[Any] + _files: Any + _content_ids: Any + _parsed: bool + headers: Any + def __init__(self, msg: Any, base_path: Optional[str] = ...) -> None: ... + def get_file(self, name: str) -> Tuple[Optional[bytes], Optional[float]]: ... + def list_files(self) -> Iterator[str]: ... + @property + def attachments(self) -> Any: ... + @property + def html(self) -> Any: ... + @property + def text(self) -> Any: ... diff --git a/emails/message.pyi b/emails/message.pyi new file mode 100644 index 0000000..de1a6a2 --- /dev/null +++ b/emails/message.pyi @@ -0,0 +1,160 @@ +from typing import Any, Optional, Union, Tuple, List, Dict, Callable, Set, Type +from .store import BaseFile, MemoryFileStore +from .signers import DKIMSigner +from .backend import ObjectFactory, SMTPBackend +from .transformer import MessageTransformer + +class BaseMessage: + attachment_cls: Type[BaseFile] + filestore_cls: Type[MemoryFileStore] + policy: Any + _attachments: Optional[MemoryFileStore] + charset: str + headers_encoding: str + _message_id: Union[str, Callable[[], str], None] + render_data: Dict[str, Any] + _mail_from: Optional[Tuple[str, str]] + _mail_to: List[Tuple[str, str]] + _cc: List[Tuple[str, str]] + _bcc: List[Tuple[str, str]] + _headers: Dict[str, Any] + _html: Any + _html_url: Optional[str] + _text: Any + _text_url: Optional[str] + _subject: Optional[str] + _date: Union[str, Callable[[], str], bool, None] + + def __init__(self, + charset: str = ..., + message_id: Union[str, Callable[[], str], None] = ..., + date: Union[str, Callable[[], str], bool, None] = ..., + subject: Optional[str] = ..., + mail_from: Union[str, Tuple[str, str], None] = ..., + mail_to: Union[str, List[str], Tuple[str, str], List[Tuple[str, str]], None] = ..., + headers: Optional[Dict[str, Any]] = ..., + html: Any = ..., + text: Any = ..., + attachments: Optional[List[Any]] = ..., + cc: Union[str, List[str], Tuple[str, str], List[Tuple[str, str]], None] = ..., + bcc: Union[str, List[str], Tuple[str, str], List[Tuple[str, str]], None] = ..., + headers_encoding: Optional[str] = ...) -> None: ... + + def set_mail_from(self, mail_from: Union[str, Tuple[str, str], None]) -> None: ... + def get_mail_from(self) -> Optional[Tuple[str, str]]: ... + mail_from: Optional[Tuple[str, str]] + + def set_mail_to(self, mail_to: Union[str, List[str], Tuple[str, str], List[Tuple[str, str]], None]) -> None: ... + def get_mail_to(self) -> List[Tuple[str, str]]: ... + mail_to: List[Tuple[str, str]] + + def set_cc(self, addr: Union[str, List[str], Tuple[str, str], List[Tuple[str, str]], None]) -> None: ... + def get_cc(self) -> List[Tuple[str, str]]: ... + cc: List[Tuple[str, str]] + + def set_bcc(self, addr: Union[str, List[str], Tuple[str, str], List[Tuple[str, str]], None]) -> None: ... + def get_bcc(self) -> List[Tuple[str, str]]: ... + bcc: List[Tuple[str, str]] + + def get_recipients_emails(self) -> List[str]: ... + def set_headers(self, headers: Optional[Dict[str, Any]]) -> None: ... + + def set_html(self, html: Any, url: Optional[str] = ...) -> None: ... + def get_html(self) -> Any: ... + html: Any + + def set_text(self, text: Any, url: Optional[str] = ...) -> None: ... + def get_text(self) -> Any: ... + text: Any + + @property + def html_body(self) -> Any: ... + @property + def text_body(self) -> Any: ... + + def set_subject(self, value: Optional[str]) -> None: ... + def get_subject(self) -> Optional[str]: ... + subject: Optional[str] + + def render(self, **kwargs: Any) -> None: ... + + def set_date(self, value: Union[str, Callable[[], str], bool, None]) -> None: ... + def get_date(self) -> Optional[str]: ... + date: Optional[str] + message_date: Optional[str] + + @property + def message_id(self) -> Optional[str]: ... + @message_id.setter + def message_id(self, value: Union[str, Callable[[], str], None]) -> None: ... + + @property + def attachments(self) -> MemoryFileStore: ... + def attach(self, **kwargs: Any) -> None: ... + +class MessageBuildMixin: + ROOT_PREAMBLE: str + ADDRESS_HEADERS: Set[str] + before_build: Optional[Callable[[Any], None]] + after_build: Optional[Callable[[Any, Any], None]] + + def encode_header(self, value: Any) -> Any: ... + def encode_address_header(self, pair: Optional[Tuple[str, str]]) -> Optional[str]: ... + encode_name_header: Callable[[Optional[Tuple[str, str]]], Optional[str]] + def set_header(self, msg: Any, key: str, value: Any, encode: bool = ...) -> None: ... + def _build_root_message(self, message_cls: Optional[Type[Any]] = ..., **kw: Any) -> Any: ... + def _build_html_part(self) -> Any: ... + def _build_text_part(self) -> Any: ... + def build_message(self, message_cls: Optional[Type[Any]] = ...) -> Any: ... + _build_message: Callable[[Optional[Type[Any]]], Any] + def as_message(self, message_cls: Optional[Type[Any]] = ...) -> Any: ... + message: Callable[[Optional[Type[Any]]], Any] + def as_string(self, message_cls: Optional[Type[Any]] = ...) -> str: ... + def as_bytes(self, message_cls: Optional[Type[Any]] = ...) -> bytes: ... + +class MessageSendMixin: + smtp_pool_factory: Type[ObjectFactory] + smtp_cls: Type[SMTPBackend] + @property + def smtp_pool(self) -> ObjectFactory: ... + def send(self, + to: Union[str, List[str], Tuple[str, str], List[Tuple[str, str]], None] = ..., + set_mail_to: bool = ..., + mail_from: Union[str, Tuple[str, str], None] = ..., + set_mail_from: bool = ..., + render: Optional[Dict[str, Any]] = ..., + smtp_mail_options: Optional[Any] = ..., + smtp_rcpt_options: Optional[Any] = ..., + smtp: Union[Dict[str, Any], Any, None] = ...) -> Any: ... + +class MessageTransformerMixin: + transformer_cls: Optional[Type[MessageTransformer]] + _transformer: Optional[MessageTransformer] + def create_transformer(self, transformer_cls: Optional[Type[MessageTransformer]] = ..., **kw: Any) -> MessageTransformer: ... + def destroy_transformer(self) -> None: ... + @property + def transformer(self) -> MessageTransformer: ... + def transform(self, **kwargs: Any) -> None: ... + +class MessageSignMixin: + signer_cls: Type[DKIMSigner] + _signer: Optional[DKIMSigner] + def sign(self, **kwargs: Any) -> Any: ... + dkim: Callable[..., Any] + def sign_message(self, msg: Any) -> Any: ... + def sign_string(self, message_string: str) -> str: ... + def sign_bytes(self, message_bytes: bytes) -> bytes: ... + +class Message(MessageSendMixin, MessageTransformerMixin, MessageSignMixin, MessageBuildMixin, BaseMessage): ... + +def html(**kwargs: Any) -> Message: ... + +class DjangoMessageProxy: + _message: Message + _recipients: Optional[List[str]] + _context: Dict[str, Any] + from_email: str + encoding: str + def __init__(self, message: Message, recipients: Optional[List[str]] = ..., context: Optional[Dict[str, Any]] = ...) -> None: ... + def recipients(self) -> List[str]: ... + def message(self) -> Any: ... diff --git a/emails/packages/dkim/__init__.pyi b/emails/packages/dkim/__init__.pyi new file mode 100644 index 0000000..cd78823 --- /dev/null +++ b/emails/packages/dkim/__init__.pyi @@ -0,0 +1,6 @@ +from typing import Any, Optional, Tuple, List, Union + +class DKIMException(Exception): ... +class UnparsableKeyError(DKIMException): ... + +def sign(message: Union[str, bytes], selector: bytes, domain: bytes, privkey: bytes, identity: Optional[bytes] = ..., canonicalize: Tuple[bytes, bytes] = ..., signature_algorithm: bytes = ..., include_headers: Optional[List[str]] = ..., length: bool = ..., logger: Optional[Any] = ...) -> bytes: ... diff --git a/emails/signers.pyi b/emails/signers.pyi new file mode 100644 index 0000000..8bf677a --- /dev/null +++ b/emails/signers.pyi @@ -0,0 +1,14 @@ +from typing import Any, Optional, Union, Tuple, Dict +from email.message import Message + +class DKIMSigner: + ignore_sign_errors: bool + _sign_params: Dict[str, Any] + + def __init__(self, selector: str, domain: str, key: Union[str, bytes, Any] = ..., ignore_sign_errors: bool = ..., **kwargs: Any) -> None: ... + def get_sign_string(self, message: Union[str, bytes]) -> Optional[bytes]: ... + def get_sign_bytes(self, message: Union[str, bytes]) -> Optional[bytes]: ... + def get_sign_header(self, message: Union[str, bytes]) -> Optional[Tuple[str, str]]: ... + def sign_message(self, msg: Message) -> Message: ... + def sign_message_string(self, message_string: str) -> str: ... + def sign_message_bytes(self, message_bytes: bytes) -> bytes: ... diff --git a/emails/store/__init__.pyi b/emails/store/__init__.pyi new file mode 100644 index 0000000..019a060 --- /dev/null +++ b/emails/store/__init__.pyi @@ -0,0 +1,2 @@ +from .file import BaseFile as BaseFile, LazyHTTPFile as LazyHTTPFile +from .store import MemoryFileStore as MemoryFileStore diff --git a/emails/store/file.pyi b/emails/store/file.pyi new file mode 100644 index 0000000..9413f1a --- /dev/null +++ b/emails/store/file.pyi @@ -0,0 +1,49 @@ +from typing import Any, Optional, Dict, Union, List, Tuple +from email.mime.base import MIMEBase + +MIMETYPE_UNKNOWN: str + +def fix_content_type(content_type: Optional[str], t: str = ...) -> str: ... + +class BaseFile: + uri: Optional[str] + absolute_url: Optional[str] + filename: Optional[str] + data: Any + _mime_type: Optional[str] + _headers: Dict[str, Any] + _content_id: Optional[str] + _content_disposition: str + subtype: Optional[str] + local_loader: Any + _data: Any + _uri: Optional[str] + _filename: Optional[str] + + def __init__(self, **kwargs: Any) -> None: ... + def as_dict(self, fields: Optional[Union[List[str], Tuple[str, ...]]] = ...) -> Dict[str, Any]: ... + def get_data(self) -> Any: ... + def set_data(self, value: Any) -> None: ... + def get_uri(self) -> Optional[str]: ... + def set_uri(self, value: Optional[str]) -> None: ... + def get_filename(self) -> Optional[str]: ... + def set_filename(self, value: Optional[str]) -> None: ... + def get_mime_type(self) -> str: ... + @property + def mime_type(self) -> str: ... + @property + def content_disposition(self) -> str: ... + @property + def content_id(self) -> Optional[str]: ... + @property + def mime(self) -> Optional[MIMEBase]: ... + @property + def is_inline(self) -> bool: ... + +class LazyHTTPFile(BaseFile): + requests_args: Optional[Dict[str, Any]] + _fetched: bool + def __init__(self, requests_args: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def fetch(self) -> None: ... + @property + def headers(self) -> Dict[str, Any]: ... diff --git a/emails/store/store.pyi b/emails/store/store.pyi new file mode 100644 index 0000000..cdcf17f --- /dev/null +++ b/emails/store/store.pyi @@ -0,0 +1,22 @@ +from typing import Any, Optional, Dict, Union, List, Iterator, Type +from .file import BaseFile + +class FileStore: ... + +class MemoryFileStore(FileStore): + file_cls: Type[BaseFile] + _files: Dict[str, BaseFile] + _filenames: Dict[str, str] + + def __init__(self, file_cls: Optional[Type[BaseFile]] = ...) -> None: ... + def __contains__(self, k: Any) -> bool: ... + def keys(self) -> List[str]: ... + def __len__(self) -> int: ... + def as_dict(self) -> Iterator[Dict[str, Any]]: ... + def remove(self, uri: Union[str, BaseFile]) -> None: ... + def unique_filename(self, filename: str, uri: Optional[str] = ...) -> str: ... + def add(self, value: Union[BaseFile, Dict[str, Any]], replace: bool = ...) -> BaseFile: ... + def by_uri(self, uri: str) -> Optional[BaseFile]: ... + def by_filename(self, filename: str) -> Optional[BaseFile]: ... + def __getitem__(self, uri: str) -> Optional[BaseFile]: ... + def __iter__(self) -> Iterator[BaseFile]: ... diff --git a/emails/template/__init__.pyi b/emails/template/__init__.pyi new file mode 100644 index 0000000..f8c7c5a --- /dev/null +++ b/emails/template/__init__.pyi @@ -0,0 +1,3 @@ +from .jinja_template import JinjaTemplate as JinjaTemplate +from .base import StringTemplate as StringTemplate +from .mako_template import MakoTemplate as MakoTemplate diff --git a/emails/template/base.pyi b/emails/template/base.pyi new file mode 100644 index 0000000..fd29bca --- /dev/null +++ b/emails/template/base.pyi @@ -0,0 +1,16 @@ +from typing import Any, Dict, Callable + +class BaseTemplate: + template_text: str + kwargs: Dict[str, Any] + _template: Any + def __init__(self, template_text: str, **kwargs: Any) -> None: ... + def set_template_text(self, template_text: str) -> None: ... + def render(self, **kwargs: Any) -> str: ... + def compile_template(self) -> Any: ... + @property + def template(self) -> Any: ... + +class StringTemplate(BaseTemplate): + def compile_template(self) -> Callable[..., str]: ... + def render(self, **kwargs: Any) -> str: ... diff --git a/emails/template/jinja_template.pyi b/emails/template/jinja_template.pyi new file mode 100644 index 0000000..8a1b33c --- /dev/null +++ b/emails/template/jinja_template.pyi @@ -0,0 +1,9 @@ +from typing import Any, Optional, Dict +from .base import BaseTemplate + +class JinjaTemplate(BaseTemplate): + DEFAULT_JINJA_ENVIRONMENT: Dict[str, Any] + environment: Any + def __init__(self, template_text: str, environment: Optional[Any] = ...) -> None: ... + def compile_template(self) -> Any: ... + def render(self, **kwargs: Any) -> str: ... diff --git a/emails/template/mako_template.pyi b/emails/template/mako_template.pyi new file mode 100644 index 0000000..50ef9a6 --- /dev/null +++ b/emails/template/mako_template.pyi @@ -0,0 +1,6 @@ +from typing import Any +from .base import BaseTemplate + +class MakoTemplate(BaseTemplate): + def compile_template(self) -> Any: ... + def render(self, **kwargs: Any) -> str: ... diff --git a/emails/transformer.pyi b/emails/transformer.pyi new file mode 100644 index 0000000..98f6e01 --- /dev/null +++ b/emails/transformer.pyi @@ -0,0 +1,62 @@ +from typing import Any, Optional, Union, List, Dict, Callable, Type +# from premailer import Premailer +# from lxml import etree +from .store import MemoryFileStore, LazyHTTPFile +from .message import Message + +class LocalPremailer(Any): + local_loader: Any + attribute_name: Optional[str] + def __init__(self, html: Any, local_loader: Optional[Any] = ..., attribute_name: Optional[str] = ..., **kw: Any) -> None: ... + def _load_external(self, url: str) -> Optional[str]: ... + +class HTMLParser: + _cdata_regex: Any + _xml_title_regex: Any + default_parser_method: str + default_output_method: str + _method: str + _output_method: str + _html: str + _tree: Optional[Any] + def __init__(self, html: str, method: Optional[str] = ..., output_method: Optional[str] = ...) -> None: ... + @property + def html(self) -> str: ... + @property + def tree(self) -> Any: ... + def to_string(self, encoding: str = ..., **kwargs: Any) -> str: ... + def apply_to_images(self, func: Callable[..., Any], images: bool = ..., backgrounds: bool = ..., styles_uri: bool = ...) -> None: ... + def apply_to_links(self, func: Callable[..., Any]) -> None: ... + def add_content_type_meta(self, content_type: str = ..., charset: str = ..., element_cls: Type[Any] = ...) -> Optional[Any]: ... + def save(self, **kwargs: Any) -> None: ... + +class BaseTransformer(HTMLParser): + UNSAFE_TAGS: List[str] + attachment_store_cls: Type[MemoryFileStore] + attachment_file_cls: Type[LazyHTTPFile] + html_attribute_name: str + attachment_store: MemoryFileStore + local_loader: Any + base_url: Optional[str] + requests_params: Optional[Dict[str, Any]] + _premailer: Optional[LocalPremailer] + def __init__(self, html: str, local_loader: Optional[Any] = ..., attachment_store: Optional[MemoryFileStore] = ..., requests_params: Optional[Dict[str, Any]] = ..., method: Optional[str] = ..., base_url: Optional[str] = ...) -> None: ... + def get_absolute_url(self, url: str) -> str: ... + def attribute_value(self, el: Any) -> Optional[str]: ... + _attribute_value: Callable[[Any], Optional[str]] + def _default_attachment_check(self, el: Any, hints: Dict[str, Any]) -> bool: ... + def _load_attachment_func(self, uri: str, element: Optional[Any] = ..., callback: Optional[Callable[..., bool]] = ..., **kw: Any) -> str: ... + def get_premailer(self, **kw: Any) -> LocalPremailer: ... + @property + def premailer(self) -> LocalPremailer: ... + def remove_unsafe_tags(self) -> BaseTransformer: ... + def load_and_transform(self, css_inline: bool = ..., remove_unsafe_tags: bool = ..., make_links_absolute: bool = ..., set_content_type_meta: bool = ..., update_stylesheet: bool = ..., load_images: Union[bool, Callable[..., bool]] = ..., images_inline: bool = ..., **kw: Any) -> BaseTransformer: ... + def make_all_images_inline(self) -> BaseTransformer: ... + def synchronize_inline_images(self, inline_names: Optional[Dict[str, str]] = ..., non_inline_names: Optional[Dict[str, str]] = ...) -> BaseTransformer: ... + +class Transformer(BaseTransformer): ... + +class MessageTransformer(BaseTransformer): + message: Message + def __init__(self, message: Message, **kw: Any) -> None: ... + def save(self, **kwargs: Any) -> None: ... diff --git a/emails/utils.pyi b/emails/utils.pyi new file mode 100644 index 0000000..6a3adc5 --- /dev/null +++ b/emails/utils.pyi @@ -0,0 +1,28 @@ +from typing import Any, Optional, Union, Tuple, List, Dict, Callable, TypeVar +import email.charset + +_charsets_loaded: bool +CHARSETS_FIX: List[List[str]] + +def load_email_charsets() -> None: ... + +T = TypeVar('T') + +class cached_property: + func: Callable[[Any], T] + def __init__(self, func: Callable[[Any], T]) -> None: ... + def __get__(self, obj: Any, cls: Any) -> T: ... + +class CachedDnsName: + def __str__(self) -> str: ... + def get_fqdn(self) -> str: ... + +DNS_NAME: CachedDnsName + +def decode_header(value: Union[str, bytes], default: str = ..., errors: str = ...) -> str: ... + +class MessageID: + domain: str + idstring: str + def __init__(self, domain: Optional[str] = ..., idstring: Optional[str] = ...) -> None: ... + def __str__(self) -> str: ...