Skip to content

Commit

Permalink
try importing blake2b from pyblake2 on ImportErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
ansemjo committed Dec 17, 2019
1 parent b162cd5 commit 34f0a0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ decently fast for example.
Make sure you run a decently modern Python 3 (anything newer than `3.5` _should_ work, development
was done on `3.7`).

**Note:** When running on Python 3.5 (e.g. on Debian 9 "stretch") you need to install
[pyblake2](https://pypi.org/project/pyblake2/) because the `hashlib` does not include `blake2b` in
3.5 yet.

### PIP

Install the package via `pip` by running:
Expand Down
9 changes: 7 additions & 2 deletions imapfetch/imapfetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import imaplib
import mailbox
import logging
import hashlib
import configparser
import time
import binascii
Expand All @@ -15,6 +14,12 @@
import os
import re

# import hashlib from library or pyblake2 package
try:
from hashlib import blake2b
except ImportError:
from pyblake2 import blake2b

# system is windows
nt = os.name == "nt"

Expand All @@ -29,7 +34,7 @@
l = lambda n: log.getChild(n)

# cryptographic hash for indexing purposes
Blake2b = lambda b: hashlib.blake2b(b, digest_size=32).digest()
Blake2b = lambda b: blake2b(b, digest_size=32).digest()

# join path to absolute and expand ~ home
join = lambda p, base=".": os.path.abspath(os.path.join(base, os.path.expanduser(p)))
Expand Down

0 comments on commit 34f0a0c

Please sign in to comment.