python3 byte vs str compatibility for constructing document data urls
authorDiane Trout <diane@ghic.org>
Mon, 20 Jul 2015 18:37:23 +0000 (11:37 -0700)
committerDiane Trout <diane@ghic.org>
Mon, 20 Jul 2015 18:37:23 +0000 (11:37 -0700)
htsworkflow/submission/encoded.py

index 97f66e9abb36dcd84a0c6747471a4642c3b31b9a..964cdb69a7454aeaf9f02dbe6b5e3bbf3bcd9488 100644 (file)
@@ -498,7 +498,7 @@ class TypedColumnParser(object):
     def parse_sheet_string_type(value):
         """Helper function to parse :string columns in sheet (the default)
         """
-        return unicode(value)
+        return str(value)
 
     def __getitem__(self, name):
         parser = {
@@ -559,7 +559,7 @@ class Document(object):
 
     def get_document(self):
         if os.path.exists(self.url):
-            with open(self.url, 'r') as instream:
+            with open(self.url, 'rb') as instream:
                 assert self.url.endswith('pdf')
                 self.content_type = 'application/pdf'
                 self.document = instream.read()
@@ -577,7 +577,7 @@ class Document(object):
             'attachment': {
               'download': self.filename,
               'type': self.content_type,
-              'href': 'data:'+self.content_type+';base64,' + base64.b64encode(self.document),
+              'href': 'data:'+self.content_type+';base64,' + base64.b64encode(self.document).decode('ascii'),
               'md5sum': self.md5sum.hexdigest()
             },
             'document_type': self.document_type,