HEX
Server: Apache
System: Linux msm5694.mjhst.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: camjab_ssh (1000)
PHP: 5.3.29
Disabled: NONE
Upload Files
File: //lib/python2.7/site-packages/lsm/_transport.pyo
ó
-ÎP`c@sãddlZddlZddlZddlZddlZddlZddlmZmZddlm	Z
ddlmZ
ddlmZdefd„ƒYZd„Zd	ejfd
„ƒYZedkrßejƒndS(iÿÿÿÿN(tLsmErrortErrorNumber(t	SocketEOF(tDataDecoder(tDataEncodert	TransPortcBsŒeZdZdZd„Zd„Zd„Zd„Zed„ƒZ	d„Z
d„Zd	„Zd
„Z
dd„Zdd
„Zd„ZRS(s®
    Provides wire serialization by using json.  Loosely conforms to json-rpc,
    however a length header was added so that we would have the ability to use
    non sax like json parsers, which are more abundant.

    <Zero padded 10 digit number [1..2**32] for the length followed by
    valid json.

    Notes:
    id field (json-rpc) is present but currently not being used.
    This is available to be expanded on later.
    i
cCs‚|dkrtdƒ‚ntƒ}xNt|ƒ|krt|jj|t|ƒƒ}|sgtƒ‚n||7}q'W|jdƒS(sš
        Reads l number of bytes before returning.  Will raise a SocketEOF
        if socket returns zero bytes (i.e. socket no longer connected)
        is Trying to read less than 1 byte!sutf-8(t
ValueErrort	bytearraytlentstrecvt
_SocketEOFtdecode(tselftltdatatr((s2/usr/lib/python2.7/site-packages/lsm/_transport.pyt	_read_all-s	cCsu|dkst|ƒdkr-tdƒ‚ntjtt|ƒƒ|jƒ|}|jjt|j	dƒƒƒdS(s]
        Sends the json formatted message by pre-appending the length
        first.
        isMsg argument emptysutf-8N(
tNoneRRtstrtzfilltHDR_LENR	tsendalltbytestencode(R
tmsgR	((s2/usr/lib/python2.7/site-packages/lsm/_transport.pyt	_send_msg?s%cCscy+|j|jƒ}|jt|ƒƒ}Wn1tjk
r^}ttjdt|ƒƒ‚nX|S(sk
        Reads header first to get the length and then the remaining
        bytes of the message.
        s.Error while reading a message from the plug-in(	RRtinttsocketterrorRRtTRANSPORT_COMMUNICATIONR(R
RRte((s2/usr/lib/python2.7/site-packages/lsm/_transport.pyt	_recv_msgMs	cCs
||_dS(N(R	(R
tsocket_descriptor((s2/usr/lib/python2.7/site-packages/lsm/_transport.pyt__init__\scCs®ytjtjtjƒ}tjj|ƒrntj|tjtjBƒrY|j	|ƒq€t
tjdƒ‚nt
tj
dƒ‚Wn&tjk
r©t
tjdƒ‚nX|S(sE
        Returns a connected socket from the passed in path.
        s-Permissions are incorrect for IPC socket filesPlug-in appears to not exists*Unable to connect to lsmd, daemon started?(RtAF_UNIXtSOCK_STREAMtostpathtexiststaccesstR_OKtW_OKtconnectRRtPLUGIN_SOCKET_PERMISSIONtPLUGIN_NOT_EXISTRtPLUGIN_IPC_FAIL(R&R	((s2/usr/lib/python2.7/site-packages/lsm/_transport.pyt
get_socket_s		
	
cCs|jjƒdS(s@
        Closes the transport and the underlying socket
        N(R	tclose(R
((s2/usr/lib/python2.7/site-packages/lsm/_transport.pyR0wscCsyyAi|d6dd6|d6}tj|dtƒ}|j|ƒWn1tjk
rt}ttjdt	|ƒƒ‚nXdS(s 
        Sends a request given a method and arguments.
        Note: arguments must be in the form that can be automatically
        serialized to json
        tmethodidtidtparamstclss,Error while sending a message to the plug-inN(
tjsontdumpst_DataEncoderRRRRRRR(R
R1targsRRtse((s2/usr/lib/python2.7/site-packages/lsm/_transport.pytsend_req}s	cCs/|jƒ}t|ƒr+tj|dtƒSdS(sG
        Reads a message and returns the parsed version of it.
        R4N(R RR5tloadst_DataDecoder(R
R((s2/usr/lib/python2.7/site-packages/lsm/_transport.pytread_reqŒscCs&|j||ƒ|jƒ\}}|S(s;
        Sends a request and waits for a response.
        (R:t	read_resp(R
R1R8treplytmsg_id((s2/usr/lib/python2.7/site-packages/lsm/_transport.pytrpc•scCsIi|d6i|d6|d6|d6d6}|jtj|dtƒƒdS(s,
        Used to transmit an error.
        R2tcodetmessageRRR4N(RR5R6R7(R
R@t
error_codeRRR((s2/usr/lib/python2.7/site-packages/lsm/_transport.pyt
send_erroržsidcCs4i|d6|d6}|jtj|dtƒƒdS(s-
        Used to transmit a response
        R2tresultR4N(RR5R6R7(R
RFR@R((s2/usr/lib/python2.7/site-packages/lsm/_transport.pyt	send_resp¦scCsY|jƒ}tj|dtƒ}d|kr?|d|dfS|d}t|‚dS(NR4RFR2R(R R5R;R<R(R
RtrespR((s2/usr/lib/python2.7/site-packages/lsm/_transport.pyR>­s
N(t__name__t
__module__t__doc__RRRR R"tstaticmethodR/R0R:R=RARRERGR>(((s2/usr/lib/python2.7/site-packages/lsm/_transport.pyRs										cCs­t|ƒ}|jƒ}zƒxk|ddkrˆ|ddkrh|j|d|dd|ddƒn|j|dƒ|jƒ}qW|j|dƒWd|jƒXdS(	s)
    Test echo server for test case.
    R1tdoneRR2R3t	errorcodeterrormsgN(RR=RERGR0(R	tsrvR((s2/usr/lib/python2.7/site-packages/lsm/_transport.pyt_server¸st_TestTransportcBs5eZd„Zd„Zd„Zd„Zd„ZRS(cCshtjtjtjƒ\|_|_t|jƒ|_tj	dt
d|jfƒ|_|jjƒdS(NttargetR8(
Rt
socketpairR#R$tcR	Rtclientt	threadingtThreadRQtservertstart(R
((s2/usr/lib/python2.7/site-packages/lsm/_transport.pytsetUpÑs
!cCs{ddddddg}x\|D]T}|jjd|ƒ|jjƒ\}}|j|dkƒ|j||kƒqWdS(	Nt0t s   s{}:""sSome text messagetDEADBEEFttestid(RVR:R>t
assertTrue(R
ttcttR?R@((s2/usr/lib/python2.7/site-packages/lsm/_transport.pyttest_simpleÚs
cCs»d}d}|jjdi|d6|d6ƒ|jt|jjƒy2|jjdi|d6|d6ƒ|jjƒWn?tk
r¶}|j|j|kƒ|j|j|kƒnXdS(NsTest error messageidRRNRO(RVR:tassertRaisesRR>R`RBR(R
te_msgte_codeR((s2/usr/lib/python2.7/site-packages/lsm/_transport.pyttest_exceptionsãs!c	CsÜxÕtdddƒD]Á}d|}idd6dd6|d	6}tj|d
tƒ}tjt|ƒtjƒ|}|j	t|ƒdkƒx|D]}|j
j|ƒq’W|jj
ƒ\}}|j	||kƒqWdS(Niii
txtdripR1idR2R3R4(trangeR5R6R7tstringRRRRR`RUtsendRVR>(	R
RtpayloadRRtwiretiR?R@((s2/usr/lib/python2.7/site-packages/lsm/_transport.pyt	test_slowós

cCsL|jjddƒ|jjƒ\}}|j|dkƒ|jjƒdS(NRM(RVR:RR>R`RYtjoin(R
RHR@((s2/usr/lib/python2.7/site-packages/lsm/_transport.pyttearDowns(RIRJR[RcRgRpRr(((s2/usr/lib/python2.7/site-packages/lsm/_transport.pyRRÐs
						t__main__(R5RRkR%tunittestRWtlsm._commonRRRRt	lsm._dataRR<RR7tobjectRRQtTestCaseRRRItmain(((s2/usr/lib/python2.7/site-packages/lsm/_transport.pyt<module>s›	>