def _makeFrame(buf, opcode, fin, mask=None):
 bufferLength = len(buf)
 if (mask is not None):
  lengthMask = 128
 else:
  lengthMask = 0
 if (bufferLength > 65535):
  length = ('%s%s' % (chr((lengthMask | 127)), pack('>Q', bufferLength)))
 elif (bufferLength > 125):
  length = ('%s%s' % (chr((lengthMask | 126)), pack('>H', bufferLength)))
 else:
  length = chr((lengthMask | bufferLength))
 if fin:
  header = 128
 else:
  header = 1
 header = chr((header | opcode.value))
 if (mask is not None):
  buf = ('%s%s' % (mask, _mask(buf, mask)))
 frame = ('%s%s%s' % (header, length, buf))
 return frame

def _makeFrame ( buf , opcode , fin , mask = None ) : bufferLength = len ( buf ) if ( mask is not None ) : lengthMask = 128 else : lengthMask = 0 if ( bufferLength > 65535 ) : length = ( '%s%s' % ( chr ( ( lengthMask | 127 ) ) , pack ( '>Q' , bufferLength ) ) ) elif ( bufferLength > 125 ) : length = ( '%s%s' % ( chr ( ( lengthMask | 126 ) ) , pack ( '>H' , bufferLength ) ) ) else : length = chr ( ( lengthMask | bufferLength ) ) if fin : header = 128 else : header = 1 header = chr ( ( header | opcode . value ) ) if ( mask is not None ) : buf = ( '%s%s' % ( mask , _mask ( buf , mask ) ) ) frame = ( '%s%s%s' % ( header , length , buf ) ) return frame
make a frame .