Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/landscape/broker/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/landscape/broker/exchangestore.pyc


Tc@sdZddlZyddlZWn!ek
rEddlmZnXddlmZdefdYZ	defdYZ
d	ZdS(
sEProvide access to the persistent data used by the L{MessageExchange}.iN(tdbapi2(twith_cursortMessageContextcBs&eZdZdZedZRS(srStores a context for incoming messages that require a response.

    The context consists of

      - the "operation-id" value
      - the secure ID that was in effect when the message was received
      - the message type
      - the time when the message was received

    This data will be used to detect secure ID changes between the time at
    which the request message came in and the completion of the request.
    If the secure ID did change the result message is obolete and will not be
    sent to the server.

    @param db: the sqlite database handle.
    @param id: the database key value for this instance.
    cCs1||_||_||_||_||_dS(N(t_dbtoperation_idt	secure_idtmessage_typet	timestamp(tselftdbRRRR((sB/usr/lib/python2.7/dist-packages/landscape/broker/exchangestore.pyt__init__s
				cCs|jd|jfdS(Ns0DELETE FROM message_context WHERE operation_id=?(texecuteR(Rtcursor((sB/usr/lib/python2.7/dist-packages/landscape/broker/exchangestore.pytremove&s(t__name__t
__module__t__doc__R
RR
(((sB/usr/lib/python2.7/dist-packages/landscape/broker/exchangestore.pyRs	t
ExchangeStorecBsSeZdZdZdZdZedZedZ	edZ
RS(s/Message meta data required by the L{MessageExchange}.

    The implementation uses a SQLite database as backend, with a single table
    called "message_context", whose schema is defined in
    L{ensure_exchange_schema}.

    @param filename: The name of the file that contains the sqlite database.
    cCs
||_dS(N(t	_filename(Rtfilename((sB/usr/lib/python2.7/dist-packages/landscape/broker/exchangestore.pyR
8scCst|jdS(N(tensure_exchange_schemaR(R((sB/usr/lib/python2.7/dist-packages/landscape/broker/exchangestore.pyt_ensure_schema;scCs8|||tjf}|jd|t|j|S(s,Add a L{MessageContext} with the given data.seINSERT INTO message_context    (operation_id, secure_id, message_type, timestamp)    VALUES (?,?,?,?)(ttimeRRR(RRRRRtparams((sB/usr/lib/python2.7/dist-packages/landscape/broker/exchangestore.pytadd_message_context>s
cCs=|jd|f|j}|r5t|j|SdSdS(s?The L{MessageContext} for the given C{operation_id} or C{None}.saSELECT operation_id, secure_id, message_type, timestamp FROM message_context WHERE operation_id=?N(RtfetchoneRRtNone(RRRtrow((sB/usr/lib/python2.7/dist-packages/landscape/broker/exchangestore.pytget_message_contextIs
cCs4|jd|j}g|D]}|d^q S(s@Return all operation IDs currently stored in C{message_context}.s(SELECT operation_id FROM message_contexti(Rtfetchall(RRtresultR((sB/usr/lib/python2.7/dist-packages/landscape/broker/exchangestore.pytall_operation_idsUs
N(RRRRRR
RRRRR(((sB/usr/lib/python2.7/dist-packages/landscape/broker/exchangestore.pyR-s		cCsv|j}y|jd|jdWn1tjtjfk
r]|j|jnX|j|jdS(sgCreate all tables needed by a L{ExchangeStore}.

    @param db: A connection to a SQLite database.
    sCREATE TABLE message_context (id INTEGER PRIMARY KEY, timestamp TIMESTAMP,   secure_id TEXT NOT NULL, operation_id INTEGER NOT NULL,   message_type text NOT NULL)sKCREATE UNIQUE INDEX msgctx_operationid_idx ON message_context(operation_id)N(RRtsqlite3tOperationalErrort
DatabaseErrortclosetrollbacktcommit(R	R((sB/usr/lib/python2.7/dist-packages/landscape/broker/exchangestore.pyR]s

(RRR tImportErrort	pysqlite2Rtlandscape.lib.storeRtobjectRRR(((sB/usr/lib/python2.7/dist-packages/landscape/broker/exchangestore.pyt<module>s
!0