#NEWLINE# @ staticmethod #NEWLINE# def buildMessage( buf , mask = True ) : #NEWLINE# #INDENT# c_buf = buf #NEWLINE# msg = '' #NEWLINE# if mask : #NEWLINE# #INDENT# key = '' . join ( [ str ( chr ( random . randrange ( 1 , 255 ) ) ) for i in xrange ( 4 ) ] ) #NEWLINE# #UNINDENT# o = ( ( 1 << 7 ) + 1 ) #NEWLINE# msg += str ( chr ( o ) ) #NEWLINE# buf_len = len ( buf ) #NEWLINE# if ( buf_len < 126 ) : #NEWLINE# #INDENT# o = buf_len #NEWLINE# if mask : #NEWLINE# #INDENT# msg += str ( chr ( ( o + ( 1 << 7 ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# msg += str ( chr ( o ) ) #NEWLINE# #UNINDENT# if mask : #NEWLINE# #INDENT# msg += key #NEWLINE# msg += Frame . encodeMessage ( buf , key ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# msg += buf #NEWLINE# #UNINDENT# return msg #NEWLINE# #UNINDENT# if ( buf_len <= ( ( 1 << 16 ) - 1 ) ) : #NEWLINE# #INDENT# if mask : #NEWLINE# #INDENT# msg += str ( chr ( ( 126 + ( 1 << 7 ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# msg += str ( chr ( 126 ) ) #NEWLINE# #UNINDENT# for i in range ( 1 , 3 ) : #NEWLINE# #INDENT# o = ( ( buf_len >> ( 16 - ( 8 * i ) ) ) & ( ( 2 ** 8 ) - 1 ) ) #NEWLINE# msg += str ( chr ( o ) ) #NEWLINE# #UNINDENT# if mask : #NEWLINE# #INDENT# msg += key #NEWLINE# msg += Frame . encodeMessage ( buf , key ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# msg += buf #NEWLINE# #UNINDENT# return o #NEWLINE# #UNINDENT# if ( buf_len <= ( ( 1 << 64 ) - 1 ) ) : #NEWLINE# #INDENT# if mask : #NEWLINE# #INDENT# msg += str ( chr ( ( 127 + ( 1 << 7 ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# msg += str ( chr ( 127 ) ) #NEWLINE# #UNINDENT# for i in range ( 1 , 9 ) : #NEWLINE# #INDENT# o = ( ( buf_len >> ( 64 - ( 8 * i ) ) ) & ( ( 2 ** 8 ) - 1 ) ) #NEWLINE# msg += str ( chr ( o ) ) #NEWLINE# #UNINDENT# if mask : #NEWLINE# #INDENT# msg += key #NEWLINE# msg += Frame . encodeMessage ( buf , key ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# msg += buf #NEWLINE# #UNINDENT# return msg