|
5 | 5 | # old deprecated settings
|
6 | 6 |
|
7 | 7 | MJML_BACKEND_MODE = getattr(settings, "MJML_BACKEND_MODE", None)
|
8 |
| -if MJML_BACKEND_MODE is not None: |
9 |
| - assert MJML_BACKEND_MODE in {"cmd", "tcpserver", "httpserver"} |
| 8 | +if MJML_BACKEND_MODE is not None and MJML_BACKEND_MODE not in {"cmd", "tcpserver", "httpserver"}: |
| 9 | + err_msg = f"Invalid value of MJML_BACKEND_MODE: {MJML_BACKEND_MODE}; allowed values: cmd, tcpserver, httpserver" |
| 10 | + raise ValueError(err_msg) |
10 | 11 |
|
11 | 12 | # cmd backend mode configs
|
12 | 13 | MJML_EXEC_CMD = getattr(settings, "MJML_EXEC_CMD", None)
|
|
15 | 16 | # tcpserver backend mode configs
|
16 | 17 | MJML_TCPSERVERS = getattr(settings, "MJML_TCPSERVERS", None)
|
17 | 18 | if MJML_TCPSERVERS is not None:
|
18 |
| - assert isinstance(MJML_TCPSERVERS, (list, tuple)) |
| 19 | + if not isinstance(MJML_TCPSERVERS, (list, tuple)): |
| 20 | + err_msg = f"Invalid type of MJML_TCPSERVERS: {type(MJML_TCPSERVERS)}; allowed types: list, tuple" |
| 21 | + raise ValueError(err_msg) |
| 22 | + |
19 | 23 | for t in MJML_TCPSERVERS:
|
20 |
| - assert isinstance(t, (list, tuple)) and len(t) == 2 and isinstance(t[0], str) and isinstance(t[1], int) |
| 24 | + if not (isinstance(t, (list, tuple)) and len(t) == 2 and isinstance(t[0], str) and isinstance(t[1], int)): |
| 25 | + err_msg = "Invalid value of MJML_TCPSERVERS" |
| 26 | + raise ValueError(err_msg) |
21 | 27 |
|
22 | 28 | # httpserver backend mode configs
|
23 | 29 | MJML_HTTPSERVERS = getattr(settings, "MJML_HTTPSERVERS", None)
|
24 | 30 | if MJML_HTTPSERVERS is not None:
|
25 |
| - assert isinstance(MJML_HTTPSERVERS, (list, tuple)) |
| 31 | + if not isinstance(MJML_HTTPSERVERS, (list, tuple)): |
| 32 | + err_msg = f"Invalid type of MJML_HTTPSERVERS: {type(MJML_HTTPSERVERS)}; allowed types: list, tuple" |
| 33 | + raise ValueError(err_msg) |
| 34 | + |
26 | 35 | for t in MJML_HTTPSERVERS:
|
27 |
| - assert isinstance(t, dict) |
28 |
| - assert "URL" in t and isinstance(t["URL"], str) |
| 36 | + if not (isinstance(t, dict) and "URL" in t and isinstance(t["URL"], str)): |
| 37 | + err_msg = "Invalid value of MJML_HTTPSERVERS" |
| 38 | + raise ValueError(err_msg) |
| 39 | + |
29 | 40 | if "HTTP_AUTH" in t:
|
30 | 41 | http_auth = t["HTTP_AUTH"]
|
31 |
| - assert isinstance(http_auth, (type(None), list, tuple)) |
32 |
| - if http_auth is not None: |
33 |
| - assert len(http_auth) == 2 and isinstance(http_auth[0], str) and isinstance(http_auth[1], str) |
| 42 | + if not isinstance(http_auth, (type(None), list, tuple)): |
| 43 | + err_msg = "Invalid value of HTTP_AUTH in MJML_HTTPSERVERS" |
| 44 | + raise ValueError(err_msg) |
| 45 | + if http_auth is not None and not ( |
| 46 | + len(http_auth) == 2 and isinstance(http_auth[0], str) and isinstance(http_auth[1], str) |
| 47 | + ): |
| 48 | + err_msg = "Invalid value of HTTP_AUTH in MJML_HTTPSERVERS" |
| 49 | + raise ValueError(err_msg) |
0 commit comments