Example #1
0
 def _map_value(self, value):
     ''' Maps a raw deserialized row to proper types '''
     # TODO: Once we've gotten here, we've done the following:
     # -> Recieve the full response, copy it from network buffer it into a ByteBuffer (copy 1)
     # -> Copy all the data into a String (copy 2)
     # -> Deserialize that string (copy 3)
     # -> Map the deserialized JSON to our response format (copy 4, what we are doing in this method)
     # This should not bee needed. Technically, this mapping from transport format to python types should require exactly one copy, 
     # from the network buffer into the python VM.
     if isinstance(value, list):
         out = []
         for c in value:
             out.append(self._map_value( c ))
         return out
     elif isinstance(value, dict) and 'metadata' in value and 'labels' in value['metadata'] and 'self' in value:
         return neo4j.Node(ustr(value['metadata']['id']), value['metadata']['labels'], value['data'])
     elif isinstance(value, dict) and 'metadata' in value and 'type' in value and 'self' in value:
         return neo4j.Relationship(ustr(value['metadata']['id']), value['type'], value['start'].split('/')[-1], value['end'].split('/')[-1], value['data'])
     elif isinstance(value, dict):
         out = {}
         for k,v in value.items():
             out[k] = self._map_value( v )
         return out
     elif isinstance(value, str):
         return ustr(value)
     else:
         return value
Example #2
0
    def _http_req(self, method, path, payload=None, retries=2):
        serialized_payload = json.dumps(
            payload) if payload is not None else None

        try:
            self._http.request(method, path, serialized_payload,
                               self._COMMON_HEADERS)
            http_response = self._http.getresponse()
        except (http.BadStatusLine, http.CannotSendRequest):
            self._http = http.HTTPConnection(self._host)
            if retries > 0:
                return self._http_req(method, path, payload, retries - 1)
            self._handle_error(self, None, Connection.OperationalError,
                               "Connection has expired.")

        if not http_response.status in [200, 201]:
            message = "Server returned unexpected response: " + ustr(
                http_response.status) + ustr(http_response.read())
            self._handle_error(self, None, Connection.OperationalError,
                               message)

        return http_response
Example #3
0
 def _map_value(self, value):
     ''' Maps a raw deserialized row to proper types '''
     # TODO: Once we've gotten here, we've done the following:
     # -> Recieve the full response, copy it from network buffer it into a ByteBuffer (copy 1)
     # -> Copy all the data into a String (copy 2)
     # -> Deserialize that string (copy 3)
     # -> Map the deserialized JSON to our response format (copy 4, what we are doing in this method)
     # This should not bee needed. Technically, this mapping from transport format to python types should require exactly one copy,
     # from the network buffer into the python VM.
     if isinstance(value, list):
         out = []
         for c in value:
             out.append(self._map_value(c))
         return out
     elif isinstance(value,
                     dict) and 'metadata' in value and 'labels' in value[
                         'metadata'] and 'self' in value:
         return neo4j.Node(ustr(value['metadata']['id']),
                           value['metadata']['labels'], value['data'])
     elif isinstance(
             value, dict
     ) and 'metadata' in value and 'type' in value and 'self' in value:
         return neo4j.Relationship(ustr(value['metadata']['id']),
                                   value['type'],
                                   value['start'].split('/')[-1],
                                   value['end'].split('/')[-1],
                                   value['data'])
     elif isinstance(value, dict):
         out = {}
         for k, v in value.items():
             out[k] = self._map_value(v)
         return out
     elif isinstance(value, str):
         return ustr(value)
     else:
         return value
    def _http_req(self, method, path, payload=None, retries=2):
        serialized_payload = json.dumps(payload) if payload is not None else None

        try:
            self._http.request(method, path, serialized_payload, self._COMMON_HEADERS)
            http_response = self._http.getresponse()
        except (http.BadStatusLine, http.CannotSendRequest):
            self._http = http.HTTPConnection(self._host)
            if retries > 0:
                return self._http_req(method, path, payload, retries-1)
            self._handle_error(self, None, Connection.OperationalError, "Connection has expired.")

        if not http_response.status in [200, 201]:
            message = "Server returned unexpected response: " + ustr(http_response.status) + ustr(http_response.read())
            self._handle_error(self, None, Connection.OperationalError, message)

        return http_response
 def _handle_errors(self, response, owner, cursor):
     for error in response['errors']:
         ErrorClass = neo_code_to_error_class(error['code'])
         error_value = ustr(error['code']) + ": " + ustr(error['message'])
         self._handle_error(owner, cursor, ErrorClass, error_value)
 def _handle_errors(self, response, owner, cursor):
     for error in response['errors']:
         ErrorClass = neo_code_to_error_class(error['code'])
         error_value = ustr(error['code']) + ": " + ustr(error['message'])
         self._handle_error(owner, cursor, ErrorClass, error_value)