def hydrate(cls, data, batch): graph = getattr(batch, "graph", None) job_id = data["id"] uri = data["from"] status_code = data.get("status") location = data.get("location") if graph is None or batch[job_id].raw_result: body = data.get("body") else: body = None try: body = graph._hydrate(data.get("body")) except GraphError as error: message = "Batch job %s failed with %s\n%s" % ( job_id, error.__class__.__name__, ustr(error)) raise_from(BatchError(message, batch, job_id, status_code, uri, location), error) else: # If Cypher results, reduce to single row or single value if possible if isinstance(body, Cursor): if body.forward(): record = body.current() width = len(record) if width == 1: body = record[0] else: body = record else: body = None return cls(batch, job_id, uri, status_code, location, body)
def hydrate(cls, data, batch): graph = getattr(batch, "graph", None) job_id = data["id"] uri = data["from"] status_code = data.get("status") location = data.get("location") if graph is None or batch[job_id].raw_result: body = data.get("body") else: body = None try: body = graph.hydrate(data.get("body")) except GraphError as error: message = "Batch job %s failed with %s\n%s" % ( job_id, error.__class__.__name__, ustr(error)) raise_from( BatchError(message, batch, job_id, status_code, uri, location), error) else: # If Cypher results, reduce to single row or single value if possible if isinstance(body, RecordList): num_rows = len(body) if num_rows == 0: body = None elif num_rows == 1: body = body[0] num_columns = len(body) if num_columns == 1: body = body[0] return cls(batch, job_id, uri, status_code, location, body)
def hydrate(cls, data, batch): graph = getattr(batch, "graph", None) job_id = data["id"] uri = data["from"] status_code = data.get("status") location = data.get("location") if graph is None or batch[job_id].raw_result: body = data.get("body") else: body = None try: body = graph.hydrate(data.get("body")) except GraphError as error: message = "Batch job %s failed with %s\n%s" % ( job_id, error.__class__.__name__, ustr(error)) raise_from(BatchError(message, batch, job_id, status_code, uri, location), error) else: # If Cypher results, reduce to single row or single value if possible if isinstance(body, RecordList): num_rows = len(body) if num_rows == 0: body = None elif num_rows == 1: body = body[0] num_columns = len(body) if num_columns == 1: body = body[0] return cls(batch, job_id, uri, status_code, location, body)
def delete(self, headers=None, **kwargs): """ Perform an HTTP DELETE to this resource. :arg headers: Extra headers to pass in the request. :arg kwargs: Other arguments to pass to the underlying `httpstream` method. :rtype: :class:`httpstream.Response` :raises: :class:`py2neo.GraphError` """ headers = dict(self.headers, **(headers or {})) try: response = self.__base.delete(headers, **kwargs) except (ClientError, ServerError) as error: if error.status_code == UNAUTHORIZED: raise Unauthorized(self.uri.string) if isinstance(error, JSONResponse): content = dict(error.content, request=error.request, response=error) else: content = {} message = content.pop( "message", "HTTP DELETE returned response %s" % error.status_code) raise_from(GraphError(message, **content), error) else: return response
def get(self, headers=None, redirect_limit=5, **kwargs): """ Perform an HTTP GET to this resource. :arg headers: Extra headers to pass in the request. :arg redirect_limit: Maximum number of times to follow redirects. :arg kwargs: Other arguments to pass to the underlying `httpstream` method. :rtype: :class:`httpstream.Response` :raises: :class:`py2neo.GraphError` """ headers = dict(self.headers, **(headers or {})) kwargs.update(cache=True) try: response = self.__base.get(headers=headers, redirect_limit=redirect_limit, **kwargs) except (ClientError, ServerError) as error: if error.status_code == UNAUTHORIZED: raise Unauthorized(self.uri.string) if isinstance(error, JSONResponse): content = dict(error.content, request=error.request, response=error) else: content = {} message = content.pop( "message", "HTTP GET returned response %s" % error.status_code) raise_from(GraphError(message, **content), error) else: self.__last_get_response = response return response
def get(self, headers=None, redirect_limit=5, **kwargs): """ Perform an HTTP GET to this resource. :arg headers: Extra headers to pass in the request. :arg redirect_limit: Maximum number of times to follow redirects. :arg kwargs: Other arguments to pass to the underlying `httpstream` method. :rtype: :class:`httpstream.Response` :raises: :class:`py2neo.GraphError` """ headers = dict(self.headers, **(headers or {})) kwargs.update(cache=True) try: response = self.__base.get(headers=headers, redirect_limit=redirect_limit, **kwargs) except (ClientError, ServerError) as error: if error.status_code == UNAUTHORIZED: raise Unauthorized(self.uri.string) if isinstance(error, JSONResponse): content = dict(error.content, request=error.request, response=error) else: content = {} message = content.pop("message", "HTTP GET returned response %s" % error.status_code) raise_from(GraphError(message, **content), error) else: self.__last_get_response = response return response
def delete(self, headers=None, **kwargs): """ Perform an HTTP DELETE to this resource. :arg headers: Extra headers to pass in the request. :arg kwargs: Other arguments to pass to the underlying `httpstream` method. :rtype: :class:`httpstream.Response` :raises: :class:`py2neo.GraphError` """ headers = dict(self.headers, **(headers or {})) try: response = self.__base.delete(headers, **kwargs) except (ClientError, ServerError) as error: if error.status_code == UNAUTHORIZED: raise Unauthorized(self.uri.string) if isinstance(error, JSONResponse): content = dict(error.content, request=error.request, response=error) else: content = {} message = content.pop("message", "HTTP DELETE returned response %s" % error.status_code) raise_from(GraphError(message, **content), error) else: return response