Browse Source

Make httpclient.put take a content-type instead of picking one

No reason to push the content-type decision into httpclient
tags/nilmdb-2.0.0
Jim Paris 2 years ago
parent
commit
5d9fc5500c
3 changed files with 6 additions and 9 deletions
  1. +1
    -1
      nilmdb/client/client.py
  2. +3
    -5
      nilmdb/client/httpclient.py
  3. +2
    -3
      tests/test_client.py

+ 1
- 1
nilmdb/client/client.py View File

@@ -181,7 +181,7 @@ class Client(object):
}
if binary:
params["binary"] = 1
return self.http.put("stream/insert", data, params, binary)
return self.http.put("stream/insert", data, params)

def stream_intervals(self, path, start = None, end = None, diffpath = None):
"""


+ 3
- 5
nilmdb/client/httpclient.py View File

@@ -122,12 +122,10 @@ class HTTPClient(object):
else:
return self._req("POST", url, None, params)

def put(self, url, data, params = None, binary = False):
def put(self, url, data, params = None,
content_type = "application/octet-stream"):
"""Simple PUT (parameters in URL, data in body)"""
if binary:
h = { 'Content-type': 'application/octet-stream' }
else:
h = { 'Content-type': 'text/plain; charset=utf-8' }
h = { 'Content-type': content_type }
return self._req("PUT", url, query = params, body = data, headers = h)

# Generator versions that return data one line at a time.


+ 2
- 3
tests/test_client.py View File

@@ -259,8 +259,7 @@ class TestClient(object):
with assert_raises(ClientError) as e:
client.http.put("stream/insert", b"",
{ "path": "xxxx", "start": 0, "end": 1,
"binary": 1 },
binary = True)
"binary": 1 })
in_("No such stream", str(e.exception))

# Bad content type
@@ -268,7 +267,7 @@ class TestClient(object):
client.http.put("stream/insert", b"",
{ "path": "xxxx", "start": 0, "end": 1,
"binary": 1 },
binary = False)
content_type="text/plain; charset=utf-8")
in_("Content type must be application/octet-stream", str(e.exception))

# Specify start/end (starts too late)


Loading…
Cancel
Save