Skip to content

Commit

Permalink
started working with V-0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
marktennyson committed Sep 19, 2023
1 parent 627c1ac commit cae6921
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@
- `Updated` Readme file.
- `Fixed` version number issue.
- `Added` the compatibility for Python 3.11.

## 0.2.3
- `Added` compatibility for Pydantic V2.
- `Fixed` several bugs.
4 changes: 2 additions & 2 deletions flask_mailing/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flask.globals import current_app
from jinja2 import Environment, FileSystemLoader
from pydantic_settings import BaseSettings as Settings
from pydantic import DirectoryPath, EmailStr, conint, validator
from pydantic import DirectoryPath, EmailStr, conint, field_validator

from .errors import TemplateFolderDoesNotExist

Expand All @@ -25,7 +25,7 @@ class ConnectionConfig(Settings):
USE_CREDENTIALS: bool = True
VALIDATE_CERTS: bool = True

@validator("MAIL_TEMPLATE_FOLDER")
@field_validator("MAIL_TEMPLATE_FOLDER")
def template_folder_validator(cls, v):
"""Validate the template folder directory."""
if not v:
Expand Down
2 changes: 1 addition & 1 deletion flask_mailing/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, settings: ConnectionConfig):
"""
)

self.settings = settings.dict()
self.settings = settings.model_dump()

async def __aenter__(self): # setting up a connection
await self._configure_connection()
Expand Down
4 changes: 2 additions & 2 deletions flask_mailing/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
if t.TYPE_CHECKING:
from flask import Flask

version_info = (0, 2, 2)
version_info = (0, 2, 3)


class _MailMixin:
Expand Down Expand Up @@ -113,7 +113,7 @@ async def __prepare_message(self, message: Message, template=None):
else:
template_data = self.make_dict(template_body)
message.template_body = template.render(**template_data)
msg = MailMsg(**message.dict())
msg = MailMsg(**message.model_dump())
if self.config.MAIL_FROM_NAME is not None:
sender = f"{self.config.MAIL_FROM_NAME} <{self.config.MAIL_FROM}>"
else:
Expand Down
26 changes: 13 additions & 13 deletions flask_mailing/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
else:
from typing_extensions import Literal

from pydantic import BaseModel, EmailStr, validator
from pydantic import BaseModel, EmailStr, field_validator
from werkzeug.datastructures import FileStorage

from .errors import WrongFile
Expand Down Expand Up @@ -48,13 +48,20 @@ class Message(BaseModel):
subtype: Optional[str] = None
multipart_subtype: MultipartSubtypeEnum = MultipartSubtypeEnum.mixed

@validator("template_params", pre=True, always=True)
def validate_template_params(cls, value, values):
if values.get("template_body", None) is None:
values["template_body"] = value
@field_validator("template_params")
def validate_template_params(cls, value, info):
if info.data.get("template_body", None) is None:
info.data["template_body"] = value
return value

@field_validator("subtype")
def validate_subtype(cls, value, info):
"""Validate subtype field."""
if info.data.get("template_body", None):
return "html"
return value

@validator("attachments")
@field_validator("attachments")
def validate_file(cls, v):
temp = []
mime = MimeTypes()
Expand Down Expand Up @@ -128,13 +135,6 @@ def attach(
self.attachments.append(fsob)
return True

@validator("subtype", pre=True, always=True)
def validate_subtype(cls, value, values):
"""Validate subtype field."""
if values.get("template_body"):
return "html"
return value

class Config:
arbitrary_types_allowed = True

Expand Down
4 changes: 2 additions & 2 deletions flask_mailing/utils/email_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async def init_redis(self):

def validate_email(self, email: str) -> bool:
"""Validate email address"""
EmailStr.validate(email)
EmailStr._validate(email, {})
return True

async def fetch_temp_email_domains(self):
Expand Down Expand Up @@ -359,7 +359,7 @@ async def fetch_info(self):

def validate_email(self, email: str):
"""Validate email address"""
if EmailStr.validate(email):
if EmailStr._validate(email, {}):
return True

def catch_all_check(self):
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ email-validator>=1.1.3
httpx>=0.21.3
pydantic>=1.8.2
typing-extensions>=3.10.0.0
Flask>=2.0.0
Flask>=2.0.0
pydantic-settings>=2.0.3
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
find_packages
)

VERSION = (0, 2, 2)
VERSION = (0, 2, 3)
AUTHOR = "Aniket Sarkar"
AUTHOR_EMAIL = "[email protected]"

Expand Down Expand Up @@ -43,6 +43,7 @@
"asgiref>=3.4.1",
"blinker>=1.4",
"pydantic>=1.8.2",
"pydantic-settings>=2.0.3",
"email-validator>=1.1.3",
"typing-extensions>=3.10.0.0",
"httpx>=0.21.3",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_flask_mailing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


def test_configuration(mail_config):
conf = ConnectionConfig.parse_obj(mail_config)
conf = ConnectionConfig.model_validate(mail_config)
assert conf.MAIL_USERNAME == "[email protected]"
assert conf.MAIL_PORT == 25
4 changes: 2 additions & 2 deletions tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async def test_msgid_header():
subtype="plain",
)

msg = MailMsg(**message.dict())
msg = MailMsg(**message.model_dump())
msg_object = await msg._message("[email protected]")
assert msg_object["Message-ID"] is not None

Expand All @@ -180,7 +180,7 @@ async def test_message_charset():
subtype="plain",
)

msg = MailMsg(**message.dict())
msg = MailMsg(**message.model_dump())
msg_object = await msg._message("[email protected]")
assert msg_object._charset is not None
assert msg_object._charset == "utf-8"

0 comments on commit cae6921

Please sign in to comment.