commit ecc8a0411157e3733a48feb9b44cf24085b6cd9a
parent 303a9736cfa8958e69f3c0231ded02b2ebb90805
Author: nolash <dev@holbrook.no>
Date: Mon, 29 Jun 2020 22:44:22 +0200
Add array of hashers to entry, fix faulty config file parser
Diffstat:
4 files changed, 32 insertions(+), 15 deletions(-)
diff --git a/feedwarrior/common.py b/feedwarrior/common.py
@@ -2,7 +2,7 @@
import uuid
import hashlib
-defaulthasher = hashlib.sha256
+defaulthashers = [hashlib.sha256, hashlib.sha1]
def parse_uuid(uu):
if type(uu).__name__ == 'str':
diff --git a/feedwarrior/config.py b/feedwarrior/config.py
@@ -2,10 +2,13 @@
import os
import configparser
import hashlib
+import logging
# third party imports
from xdg import BaseDirectory
+logg = logging.getLogger()
+
class config:
@@ -15,18 +18,23 @@ class config:
config_paths = [filename]
config_loaded = False
+
if filename == None:
config_paths = BaseDirectory.load_config_paths('feedwarrior')
+ if filename != None:
for p in config_paths:
try:
cp.read(filename)
+ logg.info('successfully read config {}'.format(p))
+ config_loaded = True
break
except FileNotFoundError:
+ logg.debug('config file {} not found'.format(p))
pass
- if cp.has_section('FEEDWARRIOR'):
- self.data_dir = cp['FEEDWARRIOR'].get(['datadir'])
+ if cp.has_option('FEEDWARRIOR', 'datadir'):
+ self.data_dir = cp['FEEDWARRIOR']['datadir']
self.feeds_dir = os.path.join(self.data_dir, 'feeds')
self.alias_dir = os.path.join(self.feeds_dir, 'names')
diff --git a/feedwarrior/entry.py b/feedwarrior/entry.py
@@ -7,7 +7,7 @@ import enum
import time
# local imports
-from .common import defaulthasher
+from .common import defaulthashers
logg = logging.getLogger()
@@ -61,7 +61,7 @@ class entry:
-def from_multipart_file(filename, hasher=defaulthasher):
+def from_multipart_file(filename, hashers=defaulthashers):
#def process_as_multipart_file(config, feed, filename):
f = open(filename, 'r')
m = email.message_from_file(f)
@@ -72,7 +72,12 @@ def from_multipart_file(filename, hasher=defaulthasher):
# the hasher calculates a uuid from the canonical order of the message contents
# TODO: currently the canonical order is the order of items in the message. this should
# rather be the lexiographical order of the hash integer values of the items.
- htop = hasher()
+ htops = []
+ hparts = {}
+ for h in hashers:
+ hasher = h()
+ htops.append(h())
+ hparts[hasher.name] = hasher
# TODO: this is a naïve parser. If presumes that the message stucture will
# always be a multipart container on top. Therefore it will always discard the top item
@@ -86,17 +91,21 @@ def from_multipart_file(filename, hasher=defaulthasher):
if p.get_content_maintype() == 'multipart':
logg.warn('recursive multipart is not implemented, skipping part {}'.format(i))
- hpart = hasher()
- hpart.update(p.get_payload(decode=True))
- psum = hpart.digest()
- htop.update(psum)
+ for htop in htops:
+ hpart = hparts[htop.name]
+ hpart.update(p.get_payload(decode=True))
+ psum = hpart.digest()
+ htop.update(psum)
i += 1
- msum = htop.digest()
- uu = uuid.UUID(bytes=msum[:16])
- m.add_header('X-FEEDWARRIOR-HASH', htop.name)
- m.add_header('X-FEEDWARRIOR-DIGEST', base64.encodebytes(msum).decode('ascii'))
+ for h in htops:
+ hasher = hparts[h.name]
+ msum = hasher.digest()
+ uu = uuid.UUID(bytes=msum[:16])
+ #m.add_header('X-FEEDWARRIOR-HASH', htop.name)
+ header_key = 'X-FEEDWARRIOR-{}'.format(h.name.upper())
+ m.add_header(header_key, base64.encodebytes(msum).decode('ascii'))
if subject == None:
subject = str(uu)
diff --git a/scripts/feedwarrior b/scripts/feedwarrior
@@ -41,7 +41,7 @@ args = argparser.parse_args(sys.argv[1:])
if args.v:
logging.getLogger().setLevel(logging.DEBUG)
-logg.debug('loading config {}'.format(args.c))
+logg.debug('attempting to load config {}'.format(args.c))
config = feedwarrior.load_config(args.c)