def receive_message(operation, request_id):
            # Discard the actual server response.
            SocketInfo.receive_message(sock_info, operation, request_id)

            # responseFlags bit 1 is QueryFailure.
            msg = struct.pack('<iiiii', 1 << 1, 0, 0, 0, 0)
            msg += BSON.encode({'$err': 'mock err', 'code': 0})
            return msg
Example #2
0
        def receive_message(operation, request_id):
            # Discard the actual server response.
            SocketInfo.receive_message(sock_info, operation, request_id)

            # responseFlags bit 1 is QueryFailure.
            msg = struct.pack('<iiiii', 1 << 1, 0, 0, 0, 0)
            msg += BSON.encode({'$err': 'mock err', 'code': 0})
            return msg
Example #3
0
    def connect(self):
        """Connect to Mongo and return a new SocketInfo.

        Can raise ConnectionFailure or CertificateError.

        Note that the pool does not keep a reference to the socket -- you
        must call return_socket() when you're done with it.
        """
        return SocketInfo(FakeSocket(self._db), self, None, self.address)
Example #4
0
 def _create_connection(self, pair=None):
     '''Default method for connecting to remote datastore.
     '''
     protocol_factory = self.store.create_protocol
     host, port = pair or self.store._host
     _, protocol = yield self._loop.create_connection(
         protocol_factory, host, port)
     socket_info = SocketInfo(protocol, self.pool_id)
     coroutine_return(socket_info)
Example #5
0
    def get_socket(self, all_credentials, checkout=False):
        """Get a socket from the pool. Use with a "with" statement.

        Returns a :class:`SocketInfo` object wrapping a connected
        :class:`socket.socket`.

        This method should always be used in a with-statement::

            with pool.get_socket(credentials, checkout) as socket_info:
                socket_info.send_message(msg)
                data = socket_info.receive_message(op_code, request_id)

        The socket is logged in or out as needed to match ``all_credentials``
        using the correct authentication mechanism for the server's wire
        protocol version.

        Can raise ConnectionFailure or OperationFailure.

        :Parameters:
          - `all_credentials`: dict, maps auth source to MongoCredential.
          - `checkout` (optional): keep socket checked out.
        """
        self.active_sockets += 1
        yield SocketInfo(FakeSocket(self._db), self, None, self.address)