def _internal_action(self, action, path, member=None, headers=None, query=None, wait=None): """ Executes an action method. """ # Populate the headers: headers = headers or {} # Send the request and wait for the response: request = http.Request( method='POST', path='%s/%s' % (self._path, path), query=query, headers=headers, ) request.body = writer.Writer.write(action, indent=True) context = self._connection.send(request) def callback(response): if response.code in [200, 201, 202]: result = self._check_action(response) if member: return getattr(result, member) else: self._check_fault(response) future = Future(self._connection, context, callback) return future.wait() if wait else future
def _internal_remove(self, headers=None, query=None, wait=None): """ Executes an `remove` method. """ # Populate the headers: headers = headers or {} # Send the request and wait for the response: request = http.Request(method='DELETE', path=self._path, query=query, headers=headers) context = self._connection.send(request) def callback(response): if response.code not in [200]: self._check_fault(response) future = Future(self._connection, context, callback) return future.wait() if wait else future
def _internal_get(self, headers=None, query=None, wait=None): """ Executes an `get` method. """ # Populate the headers: headers = headers or {} # Send the request: request = http.Request(method='GET', path=self._path, query=query, headers=headers) context = self._connection.send(request) def callback(response): if response.code in [200]: return self._internal_read_body(response) else: self._check_fault(response) future = Future(self._connection, context, callback) return future.wait() if wait else future
def _internal_update(self, object, headers=None, query=None, wait=None): """ Executes an `update` method. """ # Populate the headers: headers = headers or {} # Send the request and wait for the response: request = http.Request(method='PUT', path=self._path, query=query, headers=headers) request.body = writer.Writer.write(object, indent=True) context = self._connection.send(request) def callback(response): if response.code in [200]: return self._internal_read_body(response) else: self._check_fault(response) future = Future(self._connection, context, callback) return future.wait() if wait else future