From 8d571b10a97b316e63f9eb658bba0d0daffb7a04 Mon Sep 17 00:00:00 2001
From: Duncan Macleod <duncan.macleod@ligo.org>
Date: Thu, 2 May 2019 07:30:28 +0100
Subject: [PATCH] gracedb.events: updated Event.datadir for python3

we need to dance between str (unicode) and bytes to talk to hashlib and StringIO at the same time
---
 gracedb/events/models.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/gracedb/events/models.py b/gracedb/events/models.py
index 2e3ed5b11..65e4af1c3 100644
--- a/gracedb/events/models.py
+++ b/gracedb/events/models.py
@@ -33,10 +33,7 @@ from django.conf import settings
 import pytz
 import calendar
 
-try:
-    from io import StringIO
-except ImportError:  # python < 3
-    from cStringIO import StringIO
+from io import StringIO
 
 from hashlib import sha1
 import shutil
@@ -246,7 +243,11 @@ class Event(models.Model):
     @property
     def datadir(self):
         # Create a file-like object which is the SHA-1 hexdigest of the Event's primary key
-        hdf = StringIO(sha1(str(self.id)).hexdigest())
+        hid = sha1(str(self.id).encode("utf-8")).hexdigest()
+        try:
+            hdf = StringIO(hid.decode("utf-8"))
+        except AttributeError:  # python < 3
+            hdf = StringIO(hid)
 
         # Build up the nodes of the directory structure
         nodes = [hdf.read(i) for i in settings.GRACEDB_DIR_DIGITS]
-- 
GitLab