diff options
Diffstat (limited to 'wsgitools/digest.py')
-rw-r--r-- | wsgitools/digest.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/wsgitools/digest.py b/wsgitools/digest.py index 532b371..6395d02 100644 --- a/wsgitools/digest.py +++ b/wsgitools/digest.py @@ -19,7 +19,7 @@ import hashlib import time import os -from wsgitools.internal import bytes2str, str2bytes +from wsgitools.internal import bytes2str, str2bytes, textopen from wsgitools.authentication import AuthenticationRequired, \ ProtocolViolation, AuthenticationMiddleware @@ -239,18 +239,19 @@ class HtdigestTokenGenerator(AbstractTokenGenerator): """ assert isinstance(htdigestfile, str) self.users = {} - for line in file(htdigestfile): - parts = line.rstrip("\n").split(":") - if len(parts) != 3: - if ignoreparseerrors: + with textopen(htdigestfile, "r") as htdigest: + for line in htdigest: + parts = line.rstrip("\n").split(":") + if len(parts) != 3: + if ignoreparseerrors: + continue + raise ValueError("invalid number of colons in htdigest file") + user, realm, token = parts + if realm != self.realm: continue - raise ValueError("invalid number of colons in htdigest file") - user, realm, token = parts - if realm != self.realm: - continue - if user in self.users and not ignoreparseerrors: - raise ValueError("duplicate user in htdigest file") - self.users[user] = token + if user in self.users and not ignoreparseerrors: + raise ValueError("duplicate user in htdigest file") + self.users[user] = token def __call__(self, user, algo="md5"): assert algo.lower() in ["md5", "md5-sess"] |