def _hydrated(data): if isinstance(data, dict): if 'self' in data: obj_type = neo4j.URI(data['self']).path.segments[-2] if obj_type == 'node': return Node(data) elif obj_type == 'relationship': return Rel(data) raise NotImplemented("Don't know how to inflate: " + repr(data)) elif neo4j.is_collection(data): return type(data)([_hydrated(datum) for datum in data]) else: return data
import warnings import sys from threading import local from py2neo import neo4j from py2neo.exceptions import ClientError from py2neo.packages.httpstream import SocketError from py2neo import cypher as py2neo_cypher from .exception import CypherException, UniqueProperty, TransactionError if sys.version_info >= (3, 0): from urllib.parse import urlparse else: from urlparse import urlparse # noqa logger = logging.getLogger(__name__) path_to_id = lambda val: int(neo4j.URI(val).path.segments[-1]) class PatchedTransaction(py2neo_cypher.Transaction): def __init__(self, uri): super(PatchedTransaction, self).__init__(uri) def _post(self, resource): self._assert_unfinished() rs = resource._post({"statements": self._statements}) location = dict(rs.headers).get("location") if location: self._execute = py2neo_cypher.Resource(location) j = rs.json rs.close() self._clear()