speckenv 6.2__tar.gz → 6.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,25 @@
1
+ Metadata-Version: 2.5
2
+ Name: speckenv
3
+ Version: 6.3.0
4
+ Project-URL: Homepage, https://github.com/matthiask/speckenv/
5
+ Author-email: Matthias Kestenholz <mk@feinheit.ch>
6
+ License: BSD-3-Clause
7
+ License-File: LICENSE
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: License :: OSI Approved :: BSD License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Programming Language :: Python :: 3.15
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/x-rst
22
+
1
23
  ========
2
24
  speckenv
3
25
  ========
@@ -162,12 +184,42 @@ pass the return value to ``globals().update()``.
162
184
  from speckenv import env
163
185
  from speckenv_django import django_email_url
164
186
 
165
- # DATABASE_URL=smtp://
187
+ # EMAIL_URL=smtp://
166
188
  if DEBUG:
167
189
  globals().update(django_email_url(env("EMAIL_URL", default="console://")))
168
190
  else:
169
191
  globals().update(django_email_url(env("EMAIL_URL", default="smtp://")))
170
192
 
193
+ Django 6.1 deprecated the individual ``EMAIL_*`` settings in favor of the
194
+ ``MAILERS`` dictionary; use ``django_mailer_url`` below instead when you're
195
+ using Django 6.1 or better.
196
+
197
+
198
+ ``django_mailer_url``
199
+ ~~~~~~~~~~~~~~~~~~~~~
200
+
201
+ Returns an entry for the ``MAILERS`` dictionary introduced in Django 6.1.
202
+ Supports the same URLs as ``django_email_url``, and additionally accepts
203
+ ``?ssl_keyfile=...`` and ``?ssl_certfile=...``. ``SERVER_EMAIL`` isn't a part
204
+ of a mailer's configuration, so ``_server_email`` raises a ``ValueError``.
205
+ ``_default_from_email`` is passed on as a ``default_from_email`` option; Django's
206
+ own backends reject it, but custom backends may support it. Use the ``backend``
207
+ keyword argument to select such a backend, e.g.
208
+ ``django_mailer_url(url, backend="email_hosts.backends.EmailHostsBackend")``.
209
+
210
+ .. code-block:: python
211
+
212
+ from speckenv import env
213
+ from speckenv_django import django_mailer_url
214
+
215
+ # MAILER_URL=submission://user:password@smtp.example.com
216
+ MAILERS = {
217
+ "default": django_mailer_url(
218
+ env("MAILER_URL", default="console://" if DEBUG else "smtp://")
219
+ )
220
+ }
221
+ DEFAULT_FROM_EMAIL = env("DEFAULT_FROM_EMAIL", default="webmaster@localhost")
222
+
171
223
 
172
224
  Automatically substituting other Django 12factor libraries
173
225
  ==========================================================
@@ -1,22 +1,3 @@
1
- Metadata-Version: 2.1
2
- Name: speckenv
3
- Version: 6.2
4
- Project-URL: Homepage, https://github.com/matthiask/speckenv/
5
- Author-email: Matthias Kestenholz <mk@feinheit.ch>
6
- License: BSD-3-Clause
7
- License-File: LICENSE
8
- Classifier: Intended Audience :: Developers
9
- Classifier: License :: OSI Approved :: BSD License
10
- Classifier: Operating System :: OS Independent
11
- Classifier: Programming Language :: Python
12
- Classifier: Programming Language :: Python :: 3 :: Only
13
- Classifier: Programming Language :: Python :: 3.9
14
- Classifier: Programming Language :: Python :: 3.10
15
- Classifier: Programming Language :: Python :: 3.11
16
- Classifier: Programming Language :: Python :: 3.12
17
- Requires-Python: >=3.9
18
- Description-Content-Type: text/x-rst
19
-
20
1
  ========
21
2
  speckenv
22
3
  ========
@@ -181,12 +162,42 @@ pass the return value to ``globals().update()``.
181
162
  from speckenv import env
182
163
  from speckenv_django import django_email_url
183
164
 
184
- # DATABASE_URL=smtp://
165
+ # EMAIL_URL=smtp://
185
166
  if DEBUG:
186
167
  globals().update(django_email_url(env("EMAIL_URL", default="console://")))
187
168
  else:
188
169
  globals().update(django_email_url(env("EMAIL_URL", default="smtp://")))
189
170
 
171
+ Django 6.1 deprecated the individual ``EMAIL_*`` settings in favor of the
172
+ ``MAILERS`` dictionary; use ``django_mailer_url`` below instead when you're
173
+ using Django 6.1 or better.
174
+
175
+
176
+ ``django_mailer_url``
177
+ ~~~~~~~~~~~~~~~~~~~~~
178
+
179
+ Returns an entry for the ``MAILERS`` dictionary introduced in Django 6.1.
180
+ Supports the same URLs as ``django_email_url``, and additionally accepts
181
+ ``?ssl_keyfile=...`` and ``?ssl_certfile=...``. ``SERVER_EMAIL`` isn't a part
182
+ of a mailer's configuration, so ``_server_email`` raises a ``ValueError``.
183
+ ``_default_from_email`` is passed on as a ``default_from_email`` option; Django's
184
+ own backends reject it, but custom backends may support it. Use the ``backend``
185
+ keyword argument to select such a backend, e.g.
186
+ ``django_mailer_url(url, backend="email_hosts.backends.EmailHostsBackend")``.
187
+
188
+ .. code-block:: python
189
+
190
+ from speckenv import env
191
+ from speckenv_django import django_mailer_url
192
+
193
+ # MAILER_URL=submission://user:password@smtp.example.com
194
+ MAILERS = {
195
+ "default": django_mailer_url(
196
+ env("MAILER_URL", default="console://" if DEBUG else "smtp://")
197
+ )
198
+ }
199
+ DEFAULT_FROM_EMAIL = env("DEFAULT_FROM_EMAIL", default="webmaster@localhost")
200
+
190
201
 
191
202
  Automatically substituting other Django 12factor libraries
192
203
  ==========================================================
@@ -6,11 +6,11 @@ requires = [
6
6
 
7
7
  [project]
8
8
  name = "speckenv"
9
- version = "6.2"
9
+ version = "6.3.0"
10
10
  readme = "README.rst"
11
- license = {text= "BSD-3-Clause"}
11
+ license = { text = "BSD-3-Clause" }
12
12
  authors = [
13
- { name = "Matthias Kestenholz", email = "mk@feinheit.ch" },
13
+ { name = "Matthias Kestenholz", email = "mk@feinheit.ch" },
14
14
  ]
15
15
  requires-python = ">=3.9"
16
16
  classifiers = [
@@ -23,21 +23,34 @@ classifiers = [
23
23
  "Programming Language :: Python :: 3.10",
24
24
  "Programming Language :: Python :: 3.11",
25
25
  "Programming Language :: Python :: 3.12",
26
+ "Programming Language :: Python :: 3.13",
27
+ "Programming Language :: Python :: 3.14",
28
+ "Programming Language :: Python :: 3.15",
26
29
  ]
27
- [project.urls]
28
- Homepage = "https://github.com/matthiask/speckenv/"
30
+ urls.Homepage = "https://github.com/matthiask/speckenv/"
29
31
 
30
- [tool.hatch.build]
31
- include = [
32
+ [tool.hatch]
33
+ build.include = [
32
34
  "speckenv.py",
33
35
  "speckenv_django.py",
34
36
  "speckenv_django_patch.py",
35
37
  ]
36
38
 
37
39
  [tool.ruff]
40
+ target-version = "py39"
41
+ fix = true
42
+ show-fixes = true
43
+ extend-ignore = [
44
+ # Allow zip() without strict=
45
+ "B905",
46
+ # No line length errors
47
+ "E501",
48
+ ]
38
49
  extend-select = [
39
50
  # pyflakes, pycodestyle
40
- "F", "E", "W",
51
+ "F",
52
+ "E",
53
+ "W",
41
54
  # mmcabe
42
55
  "C90",
43
56
  # isort
@@ -67,29 +80,16 @@ extend-select = [
67
80
  # pygrep-hooks
68
81
  "PGH",
69
82
  # pylint
70
- "PLC", "PLE", "PLW",
83
+ "PLC",
84
+ "PLE",
85
+ "PLW",
71
86
  # unused noqa
72
87
  "RUF100",
73
88
  ]
74
- extend-ignore = [
75
- # Allow zip() without strict=
76
- "B905",
77
- # No line length errors
78
- "E501",
79
- ]
80
- fix = true
81
- show-fixes = true
82
- target-version = "py39"
83
-
84
- [tool.ruff.isort]
85
- combine-as-imports = true
86
- lines-after-imports = 2
87
-
88
- [tool.ruff.mccabe]
89
- max-complexity = 15
90
-
91
- [tool.ruff.per-file-ignores]
92
- "*/migrat*/*" = [
89
+ isort.combine-as-imports = true
90
+ isort.lines-after-imports = 2
91
+ mccabe.max-complexity = 15
92
+ per-file-ignores."*/migrat*/*" = [
93
93
  # Allow using PascalCase model names in migrations
94
94
  "N806",
95
95
  # Ignore the fact that migration files are invalid module names
@@ -7,6 +7,7 @@ __all__ = [
7
7
  "django_cache_url",
8
8
  "django_database_url",
9
9
  "django_email_url",
10
+ "django_mailer_url",
10
11
  "django_storage_url",
11
12
  ]
12
13
 
@@ -91,35 +92,50 @@ INTERESTING_MAIL_BACKENDS = {
91
92
  }
92
93
 
93
94
 
95
+ def _smtp_options(url, qs):
96
+ options = {
97
+ "host": url.hostname,
98
+ "port": url.port,
99
+ "username": _unquote(url.username or ""),
100
+ "password": _unquote(url.password or ""),
101
+ "use_tls": False,
102
+ "use_ssl": False,
103
+ "timeout": None,
104
+ }
105
+
106
+ if url.scheme == "smtp":
107
+ options["host"] = url.hostname or "localhost"
108
+ options["port"] = url.port or 25
109
+ if url.scheme == "submission":
110
+ options["use_tls"] = True
111
+ options["port"] = url.port or 587
112
+ if "ssl" in qs:
113
+ options["use_ssl"] = True
114
+ options["use_tls"] = False
115
+ if "tls" in qs:
116
+ options["use_ssl"] = False
117
+ options["use_tls"] = True
118
+ if timeout := qs.get("timeout"):
119
+ options["timeout"] = int(timeout)
120
+ return options
121
+
122
+
94
123
  def django_email_url(s, /):
95
124
  url = parse.urlparse(s)
96
125
  qs = dict(parse.parse_qsl(url.query))
126
+ options = _smtp_options(url, qs)
97
127
 
98
128
  config = {
99
129
  "EMAIL_BACKEND": INTERESTING_MAIL_BACKENDS[url.scheme],
100
- "EMAIL_HOST_USER": _unquote(url.username or ""),
101
- "EMAIL_HOST_PASSWORD": _unquote(url.password or ""),
102
- "EMAIL_HOST": url.hostname,
103
- "EMAIL_PORT": url.port,
104
- "EMAIL_TIMEOUT": None,
105
- "EMAIL_USE_SSL": False,
106
- "EMAIL_USE_TLS": False,
130
+ "EMAIL_HOST_USER": options["username"],
131
+ "EMAIL_HOST_PASSWORD": options["password"],
132
+ "EMAIL_HOST": options["host"],
133
+ "EMAIL_PORT": options["port"],
134
+ "EMAIL_TIMEOUT": options["timeout"],
135
+ "EMAIL_USE_SSL": options["use_ssl"],
136
+ "EMAIL_USE_TLS": options["use_tls"],
107
137
  }
108
138
 
109
- if url.scheme == "smtp":
110
- config["EMAIL_HOST"] = url.hostname or "localhost"
111
- config["EMAIL_PORT"] = url.port or 25
112
- if url.scheme == "submission":
113
- config["EMAIL_USE_TLS"] = True
114
- config["EMAIL_PORT"] = url.port or 587
115
- if "ssl" in qs:
116
- config["EMAIL_USE_SSL"] = True
117
- config["EMAIL_USE_TLS"] = False
118
- if "tls" in qs:
119
- config["EMAIL_USE_SSL"] = False
120
- config["EMAIL_USE_TLS"] = True
121
- if timeout := qs.get("timeout"):
122
- config["EMAIL_TIMEOUT"] = int(timeout)
123
139
  if email := qs.get("_default_from_email"):
124
140
  config["DEFAULT_FROM_EMAIL"] = email
125
141
  if email := qs.get("_server_email"):
@@ -127,6 +143,49 @@ def django_email_url(s, /):
127
143
  return config
128
144
 
129
145
 
146
+ def _smtp_mailer_url(url, qs):
147
+ options = _smtp_options(url, qs)
148
+ for key in ("ssl_keyfile", "ssl_certfile"):
149
+ if value := qs.get(key):
150
+ options[key] = value
151
+ return {
152
+ "BACKEND": "django.core.mail.backends.smtp.EmailBackend",
153
+ "OPTIONS": options,
154
+ }
155
+
156
+
157
+ def _optionless_mailer_url(backend):
158
+ return lambda url, qs: {"BACKEND": backend, "OPTIONS": {}}
159
+
160
+
161
+ INTERESTING_MAILER_BACKENDS = {
162
+ "smtp": _smtp_mailer_url,
163
+ "submission": _smtp_mailer_url,
164
+ "locmem": _optionless_mailer_url("django.core.mail.backends.locmem.EmailBackend"),
165
+ "console": _optionless_mailer_url("django.core.mail.backends.console.EmailBackend"),
166
+ "dummy": _optionless_mailer_url("django.core.mail.backends.dummy.EmailBackend"),
167
+ }
168
+
169
+
170
+ def django_mailer_url(s, /, *, backend=None):
171
+ url = parse.urlparse(s)
172
+ qs = dict(parse.parse_qsl(url.query))
173
+
174
+ if "_server_email" in qs:
175
+ raise ValueError(
176
+ "_server_email cannot be part of a MAILERS entry,"
177
+ " set SERVER_EMAIL separately."
178
+ )
179
+
180
+ config = INTERESTING_MAILER_BACKENDS[url.scheme](url, qs)
181
+ # Only supported by custom backends, Django rejects it otherwise
182
+ if email := qs.get("_default_from_email"):
183
+ config["OPTIONS"]["default_from_email"] = email
184
+ if backend:
185
+ config["BACKEND"] = backend
186
+ return config
187
+
188
+
130
189
  def _file_storage_url(url, qs, *, base_dir):
131
190
  return {
132
191
  "BACKEND": "django.core.files.storage.FileSystemStorage",
File without changes
File without changes
File without changes