def coerce_parameters(x): if x is None: return None elif isinstance(x, bool): return x elif isinstance(x, integer): if INT64_MIN <= x <= INT64_MAX: return x raise ValueError( "Integer out of bounds (64-bit signed integer values only)") elif isinstance(x, float): return x elif isinstance(x, string): return ustr(x) elif isinstance( x, (bytes, bytearray) ): # the order is important here - bytes must be checked after string return x elif isinstance(x, list): return list(map(coerce_parameters, x)) elif isinstance(x, dict): return { ustr(key): coerce_parameters(value) for key, value in x.items() } else: raise TypeError("Parameters of type {} are not supported".format( type(x).__name__))
def dehydrate_(obj): try: f = self.dehydration_functions[type(obj)] except KeyError: pass else: return f(obj) if obj is None: return None elif isinstance(obj, bool): return obj elif isinstance(obj, integer): if INT64_MIN <= obj <= INT64_MAX: return obj raise ValueError("Integer out of bounds (64-bit signed integer values only)") elif isinstance(obj, float): return obj elif isinstance(obj, string): return ustr(obj) elif isinstance(obj, (bytes, bytearray)): # order is important here - bytes must be checked after string if self.supports_bytes: return obj else: raise TypeError("This PackSteam channel does not support BYTES (consider upgrading to Neo4j 3.2+)") elif isinstance(obj, (list, map_type)): return list(map(dehydrate_, obj)) elif isinstance(obj, dict): return {key: dehydrate_(value) for key, value in obj.items()} else: raise TypeError(obj)
def dehydrate_(obj): try: f = self.dehydration_functions[type(obj)] except KeyError: pass else: return f(obj) if obj is None: return None elif isinstance(obj, bool): return obj elif isinstance(obj, integer): if INT64_MIN <= obj <= INT64_MAX: return obj raise ValueError( "Integer out of bounds (64-bit signed integer values only)" ) elif isinstance(obj, float): return obj elif isinstance(obj, string): return ustr(obj) elif isinstance( obj, (bytes, bytearray) ): # order is important here - bytes must be checked after string return obj elif isinstance(obj, list): return list(map(dehydrate_, obj)) elif isinstance(obj, dict): return {key: dehydrate_(value) for key, value in obj.items()} else: raise TypeError(obj)
def _encode_relationship_detail(self, relationship, template): return u"[" + template.format( id=relationship.id, type=u":" + ustr(type(relationship).__name__), properties=PropertyDictView( relationship, encoding=self.encoding, quote=self.quote), property=PropertySelector(relationship, u""), ).strip() + u"]"
def get(self, key, default=None): try: index = self.__keys.index(ustr(key)) except ValueError: return default if 0 <= index < len(self): return super(Record, self).__getitem__(index) else: return default
def _run(self, statement, parameters): if self.closed(): raise SessionError("Session closed") run_response = Response(self._connection) pull_all_response = Response(self._connection) self._last_result = result = BoltStatementResult(self, run_response, pull_all_response) result.statement = ustr(statement) result.parameters = _fix_parameters(parameters, self._connection.protocol_version, supports_bytes=self._connection.server.supports_bytes()) self._connection.append(RUN, (result.statement, result.parameters), response=run_response) self._connection.append(PULL_ALL, response=pull_all_response) return result
def _run(self, statement, parameters): if self.closed(): raise SessionError("Session closed") run_response = Response(self._connection) pull_all_response = Response(self._connection) self._last_result = result = BoltStatementResult(self, run_response, pull_all_response) result.statement = ustr(statement) result.parameters = _fix_parameters(parameters, self._connection.protocol_version) try: self._connection.append(RUN, (result.statement, result.parameters), response=run_response) self._connection.append(PULL_ALL, response=pull_all_response) except AttributeError: pass return result