Skip to content
Snippets Groups Projects
Commit 8d571b10 authored by Duncan Macleod's avatar Duncan Macleod Committed by GraceDB
Browse files

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
parent 05c02f83
No related branches found
No related tags found
No related merge requests found
...@@ -33,10 +33,7 @@ from django.conf import settings ...@@ -33,10 +33,7 @@ from django.conf import settings
import pytz import pytz
import calendar import calendar
try: from io import StringIO
from io import StringIO
except ImportError: # python < 3
from cStringIO import StringIO
from hashlib import sha1 from hashlib import sha1
import shutil import shutil
...@@ -246,7 +243,11 @@ class Event(models.Model): ...@@ -246,7 +243,11 @@ class Event(models.Model):
@property @property
def datadir(self): def datadir(self):
# Create a file-like object which is the SHA-1 hexdigest of the Event's primary key # 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 # Build up the nodes of the directory structure
nodes = [hdf.read(i) for i in settings.GRACEDB_DIR_DIGITS] nodes = [hdf.read(i) for i in settings.GRACEDB_DIR_DIGITS]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment