parameters: (self, s)
docstring: Encode and send a WebSocket message
docstring_summary: Encode and send a WebSocket message
docstring_tokens: Encode and send a WebSocket message
function: def send(self, s):
          """
          Encode and send a WebSocket message
          """
  
          message = ""
          # always send an entire message as one frame (fin)
          b1 = 0x80
  
          # in Python 2, strs are bytes and unicodes are strings
          if type(s) == unicode:
              b1 |= SocketConnection.TEXT
              payload = s.encode("UTF8")
          elif type(s) == str:
              b1 |= SocketConnection.BINARY
              payload = s
  
          message += chr(b1)
  
          # never mask frames from the server to the client
          b2 = 0
          length = len(payload)
          if length < 126:
              b2 |= length
              message += chr(b2)
          elif length < (2 ** 16) - 1:
              b2 |= 126
              message += chr(b2)
              l = struct.pack(">H", length)
              message += l
          else:
              l = struct.pack(">Q", length)
              b2 |= 127
              message += chr(b2)
              message += l
  
          message += payload
  
          if self.readystate == "open":
              self.send_bytes(message)
function_tokens: def send ( self , s ) : message = "" # always send an entire message as one frame (fin) b1 = 0x80 # in Python 2, strs are bytes and unicodes are strings if type ( s ) == unicode : b1 |= SocketConnection . TEXT payload = s . encode ( "UTF8" ) elif type ( s ) == str : b1 |= SocketConnection . BINARY payload = s message += chr ( b1 ) # never mask frames from the server to the client b2 = 0 length = len ( payload ) if length < 126 : b2 |= length message += chr ( b2 ) elif length < ( 2 ** 16 ) - 1 : b2 |= 126 message += chr ( b2 ) l = struct . pack ( ">H" , length ) message += l else : l = struct . pack ( ">Q" , length ) b2 |= 127 message += chr ( b2 ) message += l message += payload if self . readystate == "open" : self . send_bytes ( message )