Skip to content

Commit

Permalink
strict address backport resistance
Browse files Browse the repository at this point in the history
  • Loading branch information
e3rd committed Feb 19, 2025
1 parent 25b7d5c commit f5bb8fe
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions envelope/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from os import environ
import re
import inspect
import sys
from .utils import assure_list

Expand All @@ -14,21 +15,29 @@

def _getaddresses(*args):
# NOTE Python finally changed the old way of parsing wrong addresses.
# README should reflect that.
#
# We might start using strict=True (default) in the future.
# if sys.version_info < (3, 12, 3):
if sys.version_info <= (3, 11) or sys.version_info[:2] == (3, 12) and sys.version_info < (3, 12, 3):
return getaddresses(*args)
return getaddresses(*args, strict=False)
# The difficult version check is due to #45. Docs show that the parameter was added at 3.13,
# however older docs show it was at 3.12.6. Mine 3.12.3 has it too. And according to tests,
# it seems some 3.11.N have it too. It seems to be backported randomly.
# Remove the check as of Python3.13 being the minimum version.
# if sys.version_info <= (3, 11) or sys.version_info[:2] == (3, 12) and sys.version_info < (3, 12, 3):
signature = inspect.signature(getaddresses)
parameters = signature.parameters

if 'strict' in parameters:
return getaddresses(*args, strict=False)
return getaddresses(*args)


def _parseaddr(*args):
# NOTE Python finally changed the old way of parsing wrong addresses.
# We might start using strict=True (default) in the future.
# README should reflect that.
# if sys.version_info < (3, 12, 3):
if sys.version_info <= (3, 11) or sys.version_info[:2] == (3, 12) and sys.version_info < (3, 12, 3):
return parseaddr(*args)
return parseaddr(*args, strict=False)
# See the comment _getaddresses.
signature = inspect.signature(getaddresses)
parameters = signature.parameters
if 'strict' in parameters:
return parseaddr(*args, strict=False)
return parseaddr(*args)


class Address(str):
Expand Down

0 comments on commit f5bb8fe

Please sign in to comment.