Somewhat fancy voice command recognition software
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

hasher.py 997B

12345678910111213141516171819202122232425262728293031323334353637
  1. # This is part of Kaylee
  2. # -- this code is licensed GPLv3
  3. # Copyright 2015-2016 Clayton G. Hobbs
  4. # Portions Copyright 2013 Jezra
  5. import json
  6. import hashlib
  7. class Hasher:
  8. """Keep track of hashes for Kaylee"""
  9. def __init__(self, config):
  10. self.config = config
  11. try:
  12. with open(self.config.hash_file, 'r') as f:
  13. self.hashes = json.load(f)
  14. except IOError:
  15. # No stored hash
  16. self.hashes = {}
  17. def __getitem__(self, hashname):
  18. try:
  19. return self.hashes[hashname]
  20. except (KeyError, TypeError):
  21. return None
  22. def __setitem__(self, hashname, value):
  23. self.hashes[hashname] = value
  24. def get_hash_object(self):
  25. """Returns an object to compute a new hash"""
  26. return hashlib.sha256()
  27. def store(self):
  28. """Store the current hashes into a the hash file"""
  29. with open(self.config.hash_file, 'w') as f:
  30. json.dump(self.hashes, f)