コード例 #1
0
 def post(self, resource):
     self.__assert_unfinished()
     rs = resource.post({"statements": self.statements})
     location = rs.location
     if location:
         self.__execute = Resource(location)
     j = rs.content
     rs.close()
     self.statements = []
     if "commit" in j:
         self.__commit = Resource(j["commit"])
     if "errors" in j:
         errors = j["errors"]
         if len(errors) >= 1:
             error = errors[0]
             raise self.error_class.hydrate(error)
     out = []
     for result in j["results"]:
         producer = RecordProducer(result["columns"])
         out.append([
             producer.produce(
                 self.__begin.service_root.graph.hydrate(r["rest"]))
             for r in result["data"]
         ])
     return out
コード例 #2
0
 def __init__(self, uri):
     self.statements = []
     self.__begin = Resource(uri)
     self.__begin_commit = Resource(uri + "/commit")
     self.__execute = None
     self.__commit = None
     self.__finished = False
コード例 #3
0
def test_implicit_authentication_through_resource_constructor():
    from py2neo.core import _headers, Resource
    _headers.clear()
    _headers.update({None: [("X-Stream", "true")]})
    resource = Resource("http://*****:*****@localhost:7474/")
    headers = _get_headers("localhost:7474")
    assert headers['Authorization'] == 'Basic YXJ0aHVyOmV4Y2FsaWJ1cg=='
    assert resource.headers['Authorization'] == 'Basic YXJ0aHVyOmV4Y2FsaWJ1cg=='
コード例 #4
0
ファイル: __init__.py プロジェクト: zrg1993/py2neo
 def __init__(self, uri=None):
     if uri is None:
         service_root = ServiceRoot()
         manager = Resource(service_root.resource.metadata["management"])
         monitor = Monitor(manager.metadata["services"]["monitor"])
         uri = monitor.resource.uri
     Service.__init__(self)
     self.bind(uri)
コード例 #5
0
    def _index_manager(self, content_type):
        """ Fetch the index management resource for the given `content_type`.

        :param content_type:
        :return:
        """
        if content_type is Node:
            uri = self.resource.metadata["node_index"]
        elif content_type is Relationship:
            uri = self.resource.metadata["relationship_index"]
        else:
            raise TypeError("Indexes can manage either Nodes or Relationships")
        return Resource(uri)
コード例 #6
0
 def __init__(self, content_type, uri, name=None):
     Service.__init__(self)
     self._content_type = content_type
     key_value_pos = uri.find("/{key}/{value}")
     if key_value_pos >= 0:
         self._searcher = ResourceTemplate(uri)
         self.bind(uri[:key_value_pos])
     else:
         self.bind(uri)
         self._searcher = ResourceTemplate(uri.string + "/{key}/{value}")
     uri = self.resource.uri
     if self.graph.neo4j_version >= (1, 9):
         self._create_or_fail = Resource(
             uri.resolve("?uniqueness=create_or_fail"))
         self._get_or_create = Resource(
             uri.resolve("?uniqueness=get_or_create"))
     else:
         self._create_or_fail = None
         self._get_or_create = Resource(uri.resolve("?unique"))
     self._query_template = ResourceTemplate(uri.string + "{?query,order}")
     self._name = name or uri.path.segments[-1]
     self.__searcher_stem_cache = {}
コード例 #7
0
ファイル: __init__.py プロジェクト: zrg1993/py2neo
 def fetch_latest_stats(self):
     """ Fetch the latest server statistics as a list of 2-tuples, each
     holding a `datetime` object and a named tuple of node, relationship and
     property counts.
     """
     counts = namedtuple(
         "Stats", ("node_count", "relationship_count", "property_count"))
     uri = self.resource.metadata["resources"]["latest_data"]
     latest_data = Resource(uri).get().content
     timestamps = latest_data["timestamps"]
     data = latest_data["data"]
     data = zip(
         (datetime.fromtimestamp(t) for t in timestamps),
         (counts(*x) for x in zip(
             (numberise(n) for n in data["node_count"]),
             (numberise(n) for n in data["relationship_count"]),
             (numberise(n) for n in data["property_count"]),
         )),
     )
     return data
コード例 #8
0
ファイル: loader.py プロジェクト: LiuYuQ/beifen
 def __init__(self, graph, path=DEFAULT_PATH):
     UnmanagedExtension.__init__(self, graph, path)
     self.geoff_loader = Resource(self.resource.metadata["geoff_loader"])