Mitch Garnaat

Another run at fixing the Py3 encoding problems.

......@@ -63,7 +63,7 @@ class Context(object):
if os.path.isdir('.kappa'):
cache_file = os.path.join('.kappa', 'cache')
if os.path.isfile(cache_file):
with open(cache_file, 'rb') as fp:
with open(cache_file, 'r') as fp:
self.cache = yaml.load(fp)
def _delete_cache(self):
......@@ -75,14 +75,14 @@ class Context(object):
if not os.path.isdir('.kappa'):
os.mkdir('.kappa')
cache_file = os.path.join('.kappa', 'cache')
with open(cache_file, 'wb') as fp:
with open(cache_file, 'w') as fp:
yaml.dump(self.cache, fp)
def get_cache_value(self, key):
return self.cache.setdefault(self.environment, dict()).get(key)
def set_cache_value(self, key, value):
self.cache.setdefault(self.environment, dict())[key] = value
self.cache.setdefault(self.environment, dict())[key] = value.encode('utf-8')
self._save_cache()
@property
......
......@@ -137,7 +137,7 @@ class Function(object):
m = hashlib.md5()
with open(self.zipfile_name, 'rb') as fp:
m.update(fp.read())
zip_md5 = m.hexdigest().encode('utf-8')
zip_md5 = m.hexdigest()
cached_md5 = self._context.get_cache_value('zip_md5')
LOG.debug('zip_md5: %s', zip_md5)
LOG.debug('cached md5: %s', cached_md5)
......@@ -153,12 +153,12 @@ class Function(object):
# If the MD5 does not match the cached MD5, the configuration has
# changed and needs to be updated so return True.
m = hashlib.md5()
m.update(self.description)
m.update(self.handler)
m.update(str(self.memory_size))
m.update(self._context.exec_role_arn)
m.update(str(self.timeout))
config_md5 = m.hexdigest().encode('utf-8')
m.update(self.description.encode('utf-8'))
m.update(self.handler.encode('utf-8'))
m.update(str(self.memory_size).encode('utf-8'))
m.update(self._context.exec_role_arn.encode('utf-8'))
m.update(str(self.timeout).encode('utf-8'))
config_md5 = m.hexdigest()
cached_md5 = self._context.get_cache_value('config_md5')
LOG.debug('config_md5: %s', config_md5)
LOG.debug('cached_md5: %s', cached_md5)
......
......@@ -125,7 +125,7 @@ class Policy(object):
def _check_md5(self, document):
m = hashlib.md5()
m.update(document.encode('utf-8'))
policy_md5 = m.hexdigest().encode('utf-8')
policy_md5 = m.hexdigest()
cached_md5 = self._context.get_cache_value('policy_md5')
LOG.debug('policy_md5: %s', policy_md5)
LOG.debug('cached md5: %s', cached_md5)
......