Merge ~spitap/dkimpy:FixSilentFailNonAsync into dkimpy:master

Proposed by Adrien
Status: Needs review
Proposed branch: ~spitap/dkimpy:FixSilentFailNonAsync
Merge into: dkimpy:master
Diff against target: 31 lines (+6/-0)
1 file modified
dkim/__init__.py (+6/-0)
Reviewer Review Type Date Requested Status
dkimpy developers Pending
Review via email: mp+427829@code.launchpad.net

Commit message

Raise an exception when calling an async function where it shouldn't.

Description of the change

To post a comment you must log in.

Unmerged commits

8f008c0... by Adrien

Raise exception when calling async function where it shouldn't

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/dkim/__init__.py b/dkim/__init__.py
2index acdad51..4c4ba09 100644
3--- a/dkim/__init__.py
4+++ b/dkim/__init__.py
5@@ -39,6 +39,7 @@ import re
6 import sys
7 import time
8 import binascii
9+import inspect
10
11 # only needed for arc
12 try:
13@@ -187,6 +188,9 @@ class NaClNotFoundError(DKIMException):
14 class UnknownKeyTypeError(DKIMException):
15 """ Key type (k tag) is not known (rsa/ed25519) """
16
17+class AsyncFunctionCalledFromNonAsync(DKIMException):
18+ """ Tried to call async function not properly"""
19+
20
21 def select_headers(headers, include_headers):
22 """Select message header fields to be signed/verified.
23@@ -946,6 +950,8 @@ class DKIM(DomainSigner):
24 #: @return: True if signature verifies or False otherwise
25 #: @raise DKIMException: when the message, signature, or key are badly formed
26 def verify(self,idx=0,dnsfunc=get_txt):
27+ if inspect.iscoroutinefunction(dnsfunc):
28+ raise AsyncFunctionCalledFromNonAsync()
29 prep = self.verify_headerprep(idx)
30 if prep:
31 sig, include_headers, sigheaders = prep

Subscribers

People subscribed via source and target branches

to all changes: