Ejemplo n.º 1
0
    def getEdges(self, vertex, inEdges=True, outEdges=True, rawResults=False):
        """returns in, out, or both edges liked to a given document. vertex can be either a Document object or a string for an _id.
		If rawResults a arango results will be return as fetched, if false, will return a liste of Edge objects"""
        if vertex.__class__ is Document:
            vId = vertex._id
        elif (type(vertex) is types.UnicodeType) or (type(vertex) is
                                                     types.StringType):
            vId = vertex
        else:
            raise ValueError("Vertex is neither a Document nor a String")

        params = {"vertex": vId}
        if inEdges and outEdges:
            pass
        elif inEdges:
            params["direction"] = "in"
        elif outEdges:
            params["direction"] = "out"
        else:
            raise ValueError(
                "inEdges, outEdges or both must have a boolean value")

        r = self.connection.session.get(self.edgesURL, params=params)
        data = r.json()
        if r.status_code == 200:
            if not rawResults:
                ret = []
                for e in data["edges"]:
                    ret.append(Edge(self, e))
                return ret
            else:
                return data["edges"]
        else:
            raise CreationError("Unable to return edges for vertex: %s" % vId,
                                data)
Ejemplo n.º 2
0
	def _developDoc(self, i) :
		"""private function that transforms a json returned by ArangoDB into a pyArango Document or Edge"""
		docJson = self.result[i]
		try :
			collection = self.database[docJson["_id"].split("/")[0]]
		except KeyError :
			raise CreationError("result %d is not a valid Document. Try setting rawResults to True" % i)

		if collection.type == COL.COLLECTION_EDGE_TYPE :
			self.result[i] = Edge(collection, docJson)
 		else :
 			self.result[i] = Document(collection, docJson)
Ejemplo n.º 3
0
 def _developDoc(self, i):
     docJson = self.result[i]
     if self.collection.type == COL.COLLECTION_EDGE_TYPE:
         self.result[i] = Edge(self.collection, docJson)
     else:
         self.result[i] = Document(self.collection, docJson)