Beispiel #1
0
 def __init__(
     self,
     type: Union[int, Opcode],
     from_client: bool,
     content: bytes,
     timestamp: Optional[float] = None,
     killed: bool = False,
 ) -> None:
     self.from_client = from_client
     self.type = Opcode(type)
     self.content = content
     self.timestamp: float = timestamp or time.time()
     self.killed = killed
Beispiel #2
0
 def __init__(
     self, type: int, from_client: bool, content: Union[bytes, str], timestamp: Optional[float]=None, killed: bool=False
 ) -> None:
     self.type = Opcode(type)  # type: ignore
     """indicates either TEXT or BINARY (from wsproto.frame_protocol.Opcode)."""
     self.from_client = from_client
     """True if this messages was sent by the client."""
     self.content = content
     """A byte-string representing the content of this message."""
     self.timestamp: float = timestamp or time.time()
     """Timestamp of when this message was received or created."""
     self.killed = killed
     """True if this messages was killed and should not be sent to the other endpoint."""
 def __repr__(self):
     vals = [
         "ws frame:",
         Opcode(self.opcode).name.lower()
     ]
     flags = []
     for i in ["fin", "rsv1", "rsv2", "rsv3", "mask"]:
         if getattr(self, i):
             flags.append(i)
     if flags:
         vals.extend([":", "|".join(flags)])
     if self.masking_key:
         vals.append(":key=%s" % repr(self.masking_key))
     if self.payload_length:
         vals.append(" %s" % human.pretty_size(self.payload_length))
     return "".join(vals)
Beispiel #4
0
 def set_state(self, state: WebSocketMessageState) -> None:
     typ, self.from_client, self.content, self.timestamp, self.killed = state
     self.type = Opcode(typ)
Beispiel #5
0
 def set_state(self, state):
     self.type, self.from_client, self.content, self.timestamp, self.killed = state
     self.type = Opcode(self.type)  # replace enum with bare int