Module bjsonrpc.request

class bjsonrpc.request.Request(conn, request_data)

Represents a request to the other end which may be not be completed yet. This class is automatically created by method Proxy.

Parameters:

conn
Connection instance which this Request belongs to. (internally stored as Request.conn)
request_data
Dictionary object to serialize as JSON to send to the other end. (internally stored as Request.data)

Attributes:

response
JSON Object of the response, as a dictionary. If no response has been received, this is None.
event_response
A threading.Event object, which is set to true when a response has been received. Useful to wake up threads or to wait exactly until the response is received.
callbacks
List array where the developer can append functions to call when the response is received. The function will get the Request object as a first argument.
request_id
Number of ID that identifies the call. For notifications this is None. Be careful because it may be not an integer. Strings and other objects may be valid for other implementations.
hasresponse()

Method thet checks if there’s a response or not. Returns True if there it is or False if it haven’t arrived yet.

setresponse(value)

Method used by Connection instance to tell Request that a Response is available to this request.

Parameters:

value
Value (JSON decoded) received from socket.
value

Property to get value response. If the response is not available, it waits to it (see wait method). If the response contains an Error, this method raises exceptions.ServerError with the error text inside.

From version 0.2.0 you can also call the class itself to get the value:

req_stime = rpcconn.method.getServerTime()
print req_stime.value  
print req_stime()     # equivalent to the prior line.
wait()

Block until there is a response. Will manage the socket and dispatch messages until the response is found.

Previous topic

Module bjsonrpc.connection

Next topic

Module bjsonrpc.handlers

This Page