Browse Source

httpclient: make sure we error out quickly if nested calls are made

Curl will give an error if we call .setopt() while a .perform() is
in progress, for example if we try to do a stream_insert() while
in the middle of a stream_extract().  Move the setopt() to the
beginning of the get/put functions to ensure that we hit this
error before we mess with the URLs or anything else.
tags/nilmdb-0.2
Jim Paris 11 years ago
parent
commit
e7af863017
1 changed files with 2 additions and 2 deletions
  1. +2
    -2
      nilmdb/httpclient.py

+ 2
- 2
nilmdb/httpclient.py View File

@@ -195,9 +195,9 @@ class HTTPClient(object):

def put(self, url, postdata, params = None, retjson = True):
"""Simple PUT"""
self.curl.setopt(pycurl.UPLOAD, 1)
self._setup_url(url, params)
data = cStringIO.StringIO(postdata)
self.curl.setopt(pycurl.UPLOAD, 1)
self.curl.setopt(pycurl.READFUNCTION, data.read)
return self._doreq(url, params, retjson)

@@ -223,8 +223,8 @@ class HTTPClient(object):

def put_gen(self, url, postdata, params = None, retjson = True):
"""Simple PUT, returning a generator"""
self.curl.setopt(pycurl.UPLOAD, 1)
self._setup_url(url, params)
data = cStringIO.StringIO(postdata)
self.curl.setopt(pycurl.UPLOAD, 1)
self.curl.setopt(pycurl.READFUNCTION, data.read)
return self._doreq_gen(url, params, retjson)

Loading…
Cancel
Save