Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
body = b"".join(parts)
if body:
if res.chunked:
buf = [
hex(len(body))[2:].encode(self._encoding),
b"\r\n",
body,
b"\r\n"
]
body = b"".join(buf)
self.fire(write(sock, body))
if res.chunked:
self.fire(write(sock, b"0\r\n\r\n"))
if not res.stream:
if res.close:
self.fire(close(sock))
# Delete the request/response objects if present
if sock in self._clients:
del self._clients[sock]
res.done = True
def read_user_input(self, data):
self.fire(write(data))
def broadcast(self, data, exclude=None):
exclude = exclude or []
targets = (sock for sock in self.clients.keys() if sock not in exclude)
for target in targets:
self.fire(write(target, data))
self.fire(write(sock, data))
if res.body and not res.done:
try:
data = next(res.body)
while not data: # Skip over any null byte sequences
data = next(res.body)
except StopIteration:
data = None
self.fire(stream(res, data))
else:
if res.body:
res.body.close()
if res.chunked:
self.fire(write(sock, b"0\r\n\r\n"))
if res.close:
self.fire(close(sock))
if sock in self._clients:
del self._clients[sock]
res.done = True
def _write(self, data):
if self._sock is not None:
self.fire(write(self._sock, data), self.parent.channel)
else:
self.fire(write(data), self.parent.channel)
def input(self, data):
if self._stdin is not None:
self.fire(write(data), self._stdin)
def _write(self, data):
if self._sock is not None:
self.fire(write(self._sock, data), self.parent.channel)
else:
self.fire(write(data), self.parent.channel)
def read(self, sock, data):
client = self.clients[sock]
self.fire(write(data), client.channel)
def chat(self, context):
clientId = context.clientId
socket = self.clientManager.getSocket(clientId)
messageType = "reply"
body = context.interaction
contextId = context.contextId
self.fire(write(socket, getResponse(messageType, contextId, body)))
def _write(self, data):
if self._sock is not None:
self.fire(write(self._sock, data), self.parent.channel)
else:
self.fire(write(data), self.parent.channel)