Exemplo n.º 1
0
    def pull(self, n, qid, records):
        """ Enqueue a PULL message.

        :param n: number of records to pull (-1 means all)
        :param qid: the query for which to pull records (-1 means the query
                    immediately preceding)
        :param records: list-like container into which records may be appended
        :return: :class:`.QueryResponse` object
        """
        v = self.bolt_version
        if v >= 4:
            args = {"n": n}
            if qid >= 0:
                args["qid"] = qid
            log.debug("C: PULL %r", args)
            self.requests.append(Structure(CLIENT[v]["PULL"], args))
        elif n >= 0 or qid >= 0:
            raise ProtocolError("Reactive PULL is not available in "
                                "Bolt v%d" % v)
        else:
            log.debug("C: PULL_ALL")
            self.requests.append(Structure(CLIENT[v]["PULL_ALL"]))
        response = QueryResponse(self, records)
        self.responses.append(response)
        return response
Exemplo n.º 2
0
 def run(self, cypher, parameters=None, metadata=None):
     parameters = parameters or {}
     metadata = metadata or {}
     if self.bolt_version >= 3:
         log.debug("C: RUN %r %r %r", cypher, parameters, metadata)
         run = Structure(CLIENT[self.bolt_version]["RUN"], cypher,
                         parameters, metadata)
     elif metadata:
         raise ProtocolError("RUN metadata is not available in Bolt v%d" %
                             self.bolt_version)
     else:
         log.debug("C: RUN %r %r", cypher, parameters)
         run = Structure(CLIENT[self.bolt_version]["RUN"], cypher,
                         parameters)
     self.requests.append(run)
     response = QueryResponse(self)
     self.responses.append(response)
     return response
Exemplo n.º 3
0
 def rollback(self):
     if self.bolt_version >= 3:
         log.debug("C: ROLLBACK")
         self.requests.append(
             Structure(CLIENT[self.bolt_version]["ROLLBACK"]))
     else:
         raise ProtocolError("ROLLBACK is not available in Bolt v%d" %
                             self.bolt_version)
     response = QueryResponse(self)
     self.responses.append(response)
     return response
Exemplo n.º 4
0
 def commit(self):
     if self.bolt_version >= 3:
         log.debug("C: COMMIT")
         self.requests.append(Structure(
             CLIENT[self.bolt_version]["COMMIT"]))
     else:
         raise ProtocolError("COMMIT is not available in Bolt v%d" %
                             self.bolt_version)
     response = QueryResponse(self)
     self.responses.append(response)
     return response
Exemplo n.º 5
0
 def begin(self, metadata=None):
     metadata = metadata or {}
     if self.bolt_version >= 3:
         log.debug("C: BEGIN %r", metadata)
         self.requests.append(
             Structure(CLIENT[self.bolt_version]["BEGIN"], metadata))
     else:
         raise ProtocolError("BEGIN is not available in Bolt v%d" %
                             self.bolt_version)
     response = QueryResponse(self)
     self.responses.append(response)
     return response
Exemplo n.º 6
0
 def __init__(self, s, bolt_version, auth, user_agent=None):
     self.socket = s
     self.address = AddressList([self.socket.getpeername()])
     self.bolt_version = bolt_version
     log.debug("Opened connection to «%s» using Bolt v%d", self.address,
               self.bolt_version)
     self.requests = []
     self.responses = []
     try:
         user, password = auth
     except (TypeError, ValueError):
         user, password = "******", ""
     if user_agent is None:
         user_agent = self.default_user_agent()
     if bolt_version >= 3:
         args = {
             "scheme": "basic",
             "principal": user,
             "credentials": password,
             "user_agent": user_agent,
         }
         log.debug("C: HELLO %r" % dict(args, credentials="..."))
         request = Structure(CLIENT[self.bolt_version]["HELLO"], args)
     else:
         auth_token = {
             "scheme": "basic",
             "principal": user,
             "credentials": password,
         }
         log.debug("C: INIT %r %r", user_agent,
                   dict(auth_token, credentials="..."))
         request = Structure(CLIENT[self.bolt_version]["INIT"], user_agent,
                             auth_token)
     self.requests.append(request)
     response = Response(self)
     self.responses.append(response)
     self.send_all()
     self.fetch_all()
     self.server_agent = response.metadata["server"]
Exemplo n.º 7
0
    def discard(self, n, qid):
        """ Enqueue a DISCARD message.

        :param n: number of records to discard (-1 means all)
        :param qid: the query for which to discard records (-1 means the query
                    immediately preceding)
        :return: :class:`.QueryResponse` object
        """
        v = self.bolt_version
        if v >= 4:
            args = {"n": n}
            if qid >= 0:
                args["qid"] = qid
            log.debug("C: DISCARD %r", args)
            self.requests.append(Structure(CLIENT[v]["DISCARD"], args))
        elif n >= 0 or qid >= 0:
            raise ProtocolError("Reactive DISCARD is not available in "
                                "Bolt v%d" % v)
        else:
            log.debug("C: DISCARD_ALL")
            self.requests.append(Structure(CLIENT[v]["DISCARD_ALL"]))
        response = QueryResponse(self)
        self.responses.append(response)
        return response
Exemplo n.º 8
0
 def reset(self):
     log.debug("C: RESET")
     self.requests.append(Structure(CLIENT[self.bolt_version]["RESET"]))
     self.send_all()
     response = Response(self)
     self.responses.append(response)