Sfoglia il codice sorgente

permalinks&filetime_from_git:Py3 compat.Fixes #1011

The interface for hashlib.update changed to require input
supporting
[the buffer API](https://docs.python.org/3/c-api/buffer.html).

Also `.next` no longer exists in python 3.
Chris Scutcher 6 anni fa
parent
commit
3ac3ed6492

+ 12 - 3
filetime_from_git/actions.py

@@ -79,6 +79,14 @@ def git_sha_metadata(content, git_content):
     content.metadata['gitsha_oldest'] = str(git_content.get_oldest_commit())
     content.metadata['gitsha_oldest'] = str(git_content.get_oldest_commit())
 
 
 
 
+def update_hash_from_str(hsh, str_input):
+    """
+    Convert a str to object supporting buffer API and update a hash with it.
+    """
+    byte_input = str(str_input).encode("UTF-8")
+    hsh.update(byte_input)
+
+
 @content_git_object_init.connect
 @content_git_object_init.connect
 def git_permalink(content, git_content):
 def git_permalink(content, git_content):
     '''
     '''
@@ -95,9 +103,10 @@ def git_permalink(content, git_content):
         return
         return
 
 
     permalink_hash = hashlib.sha1()
     permalink_hash = hashlib.sha1()
-    permalink_hash.update(str(git_content.get_oldest_commit()))
-    permalink_hash.update(str(git_content.get_oldest_filename()))
-    git_permalink_id = base64.urlsafe_b64encode(permalink_hash.digest())
+    update_hash_from_str(permalink_hash, git_content.get_oldest_commit())
+    update_hash_from_str(permalink_hash, git_content.get_oldest_filename())
+    git_permalink_id_raw = base64.urlsafe_b64encode(permalink_hash.digest())
+    git_permalink_id = git_permalink_id_raw.decode("UTF-8")
     permalink_id_metadata_key = content.settings['PERMALINK_ID_METADATA_KEY']
     permalink_id_metadata_key = content.settings['PERMALINK_ID_METADATA_KEY']
 
 
     if permalink_id_metadata_key in content.metadata:
     if permalink_id_metadata_key in content.metadata:

+ 1 - 1
filetime_from_git/content_adapter.py

@@ -75,7 +75,7 @@ class GitContentAdapter(object):
         '''
         '''
         commit_and_name_iter = self.git.get_commits_and_names_iter(
         commit_and_name_iter = self.git.get_commits_and_names_iter(
             self.content.source_path)
             self.content.source_path)
-        _commit, name = commit_and_name_iter.next()
+        _commit, name = next(commit_and_name_iter)
         return name
         return name
 
 
     @memoized
     @memoized

+ 3 - 3
permalinks/permalinks.py

@@ -82,9 +82,9 @@ def get_permalink_ids_iter(self):
     Method to get permalink ids from content. To be bound to the class last thing
     Method to get permalink ids from content. To be bound to the class last thing
     '''
     '''
     permalink_id_key = self.settings['PERMALINK_ID_METADATA_KEY']
     permalink_id_key = self.settings['PERMALINK_ID_METADATA_KEY']
-    permalink_ids_raw = self.metadata.get(permalink_id_key, '')
+    permalink_ids = self.metadata.get(permalink_id_key, '')
 
 
-    for permalink_id in permalink_ids_raw.split(','):
+    for permalink_id in permalink_ids.split(','):
         if permalink_id:
         if permalink_id:
             yield permalink_id.strip()
             yield permalink_id.strip()
 
 
@@ -98,7 +98,7 @@ def get_permalink_ids(self):
 def get_permalink_path(self):
 def get_permalink_path(self):
     """Get just path component of permalink."""
     """Get just path component of permalink."""
     try:
     try:
-        first_permalink_id = self.get_permalink_ids_iter().next()
+        first_permalink_id = next(self.get_permalink_ids_iter())
     except StopIteration:
     except StopIteration:
         return None
         return None