...
 
Commits (9)
ligo-gracedb (1.28-1) unstable; urgency=low
* Various fixes for Python 3
-- Tanner Prestegard <tanner.prestegard@ligo.org> Tue, 24 Apr 2018 10:44:43 -0500
ligo-gracedb (1.27-1) unstable; urgency=low
* Changed DEFAULT_SERVICE_URL used by command-line client to match other instances
......
%define name ligo-gracedb
%define version 1.27
%define unmangled_version 1.27
%define version 1.28
%define unmangled_version 1.28
%define release 1
Summary: Gravity Wave Candidate Event Database
......
......@@ -18,7 +18,7 @@
__all__ = ["cli", "rest"]
GIT_TAG = 'gracedb-1.27-1'
GIT_TAG = 'gracedb-1.28-1'
# issue 717. Required for backward compatibility -- make sure "from ligo import gracedb"
# works as it used to.
......
......@@ -26,7 +26,7 @@ DEFAULT_SERVICE_URL = "https://gracedb.ligo.org/api"
DEFAULT_BASIC_URL = "https://gracedb.ligo.org/apibasic/"
GIT_TAG = 'gracedb-1.27-1'
GIT_TAG = 'gracedb-1.28-1'
DEFAULT_COLUMNS = "graceid,labels,group,pipeline,search,far,gpstime,created,dataurl"
......
......@@ -86,10 +86,11 @@ class _GraceDbLogStream(object):
self._queue.task_done()
def write(self, text):
with self._lock:
if self._closed:
raise RuntimeError('Log handler is already closed')
self._queue.put(text)
if text.strip():
with self._lock:
if self._closed:
raise RuntimeError('Log handler is already closed')
self._queue.put(text)
def close(self):
with self._lock:
......
......@@ -754,7 +754,7 @@ class GraceDb(GsiRest):
filecontents = sys.stdin.read()
else:
filecontents = open(filename, "rb").read()
elif isinstance(filecontents, file):
elif hasattr(filecontents, 'read'):
# XXX Does not scale well.
filecontents = filecontents.read()
files = [('upload', os.path.basename(filename), filecontents)]
......@@ -817,7 +817,7 @@ class GraceDb(GsiRest):
filecontents = sys.stdin.read()
else:
filecontents = open(filename, "rb").read()
elif isinstance(filecontents, file):
elif hasattr(filecontents, 'read'):
# XXX Does not scale well.
filecontents = filecontents.read()
files = [('upload', os.path.basename(filename), filecontents)]
......@@ -1243,7 +1243,7 @@ class GraceDbBasic(GraceDb):
# response. Effectively, the 401 response will have special status.
if response.status == 401:
try:
msg = "\nERROR: %s \n\n" % json.loads(response.read())['error']
msg = "\nERROR: %s \n\n" % json.loads(response.read())['detail']
except:
msg = "\nERROR: \n\n"
msg += "Please check the username/password in your .netrc file. \n"
......@@ -1262,28 +1262,36 @@ def encode_multipart_formdata(fields, files):
files is a sequence of (name, filename, value) elements for data to be uploaded as files
Return (content_type, body) ready for httplib.HTTP instance
"""
BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$'
CRLF = '\r\n'
BOUNDARY = b'----------ThIs_Is_tHe_bouNdaRY_$'
CRLF = b'\r\n'
L = []
for (key, value) in fields:
if value is None: continue
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"' % key)
L.append('')
# str(value) in case it is unicode
L.append(str(value))
L.append(b'--' + BOUNDARY)
L.append(b'Content-Disposition: form-data; name="%s"' % key.encode())
L.append(b'')
# encode in case it is unicode
if isinstance(value, six.binary_type):
L.append(value)
elif isinstance(value, six.text_type):
L.append(value.encode())
else:
L.append(str(value).encode())
for (key, filename, value) in files:
if value is None: continue
L.append('--' + BOUNDARY)
L.append(b'--' + BOUNDARY)
# str(filename) in case it is unicode
L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, str(filename)))
L.append('Content-Type: %s' % get_content_type(filename))
L.append('')
L.append(value)
L.append('--' + BOUNDARY + '--')
L.append('')
L.append(b'Content-Disposition: form-data; name="%s"; filename="%s"' % (key.encode(), filename.encode()))
L.append(b'Content-Type: %s' % get_content_type(filename).encode())
L.append(b'')
if isinstance(value, six.text_type):
L.append(value.encode())
else:
L.append(value)
L.append(b'--' + BOUNDARY + b'--')
L.append(b'')
body = CRLF.join(L)
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
content_type = b'multipart/form-data; boundary=%s' % BOUNDARY
return content_type, body
def get_content_type(filename):
......
......@@ -174,10 +174,10 @@ class TestMain(TestGraceDb):
self.assertEqual(r.status, 201) # CREATED
r_content = r.json()
link = r_content['permalink']
self.assertEqual(open(uploadFile, 'r').read(),
self.assertEqual(open(uploadFile, 'rb').read(),
self._gracedb.get(self._gracedb.files(self._eventId).json()
['big.data']).read())
self.assertEqual(open(uploadFile, 'r').read(),
self.assertEqual(open(uploadFile, 'rb').read(),
self._gracedb.get(link).read())
def test_upload_file(self):
......@@ -189,11 +189,11 @@ class TestMain(TestGraceDb):
r_content = r.json()
link = r_content['permalink']
self.assertEqual(open(uploadFile, 'r').read(),
self.assertEqual(open(uploadFile, 'rb').read(),
self._gracedb.get(self._gracedb.files(self._eventId).json()
['upload.data']).read())
self.assertEqual(open(uploadFile, 'r').read(),
self.assertEqual(open(uploadFile, 'rb').read(),
self._gracedb.get(link).read())
# Re-upload slightly different file.
......@@ -204,11 +204,11 @@ class TestMain(TestGraceDb):
r_content = r.json()
link2 = r_content['permalink']
self.assertEqual(open(uploadFile2, 'r').read(),
self.assertEqual(open(uploadFile2, 'rb').read(),
self._gracedb.get(self._gracedb.files(self._eventId).json()
['upload.data']).read())
self.assertEqual(open(uploadFile2, 'r').read(),
self.assertEqual(open(uploadFile2, 'rb').read(),
self._gracedb.get(link2).read())
self.assertNotEqual(link, link2)
......@@ -356,7 +356,7 @@ class TestMain(TestGraceDb):
handler.close()
event_logs = self._gracedb.logs(graceid).read()
self.assertTrue(message in event_logs)
self.assertTrue(message.encode() in event_logs)
def test_issue717(self):
# non-backwards-compatibility of cli.Client import.
......@@ -370,7 +370,7 @@ class TestMain(TestGraceDb):
def test_gittag(self):
# try to make sure GIT_TAG is set properly.
import errno
version = "1.27"
version = "1.28"
try:
# If we are in the source dir (setup.py is available)
# make sure the version above agrees.
......
......@@ -19,7 +19,7 @@
import os
from setuptools import setup, find_packages
version = "1.27"
version = "1.28"
setup(
name = "ligo-gracedb",
......