How to use the circuits.net.events.write function in circuits

To help you get started, we’ve selected a few circuits examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github circuits / circuits / circuits / web / http.py View on Github external
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
github circuits / circuits / examples / chatserver.py View on Github external
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))
github circuits / circuits / circuits / web / http.py View on Github external
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
github circuits / circuits / circuits / protocols / websocket.py View on Github external
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)
github circuits / circuits / examples / web / terminal / terminal.py View on Github external
def input(self, data):
        if self._stdin is not None:
            self.fire(write(data), self._stdin)
github circuits / circuits / circuits / protocols / websocket.py View on Github external
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)
github circuits / circuits / examples / proxy.py View on Github external
def read(self, sock, data):
        client = self.clients[sock]
        self.fire(write(data), client.channel)
github AmeyKamat / MEERA / meera / api / websockets.py View on Github external
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)))
github circuits / circuits / circuits / protocols / websocket.py View on Github external
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)