Exemple #1
0
class WebWriter:
    def __init__(self, web):
        self.s = BytesIO()
        self.web = web

    def write(self, txt):
        if isinstance(txt, str):
            txt = txt.encode()

        s = self.s
        wdt = self.web.wdt
        wdt.feed()
        s.write(txt)
        wdt.feed()

        if s.tell() > 1200:
            wdt.feed()
            self.web.write(s.getvalue())
            wdt.feed()
            self.s = BytesIO()

    def flush(self):
        if self.s.tell() > 0:
            wdt = self.web.wdt
            wdt.feed()
            self.web.write(self.s.getvalue())
            wdt.feed()
            self.s = BytesIO()
    def sendto(self, bytes, *args, **kwargs):
        if self.type != socket.SOCK_DGRAM:
            return _BaseSocket.sendto(self, bytes, *args, **kwargs)
        if not self._proxyconn:
            self.bind(("", 0))

        address = args[-1]
        flags = args[:-1]

        header = BytesIO()
        RSV = b"\x00\x00"
        header.write(RSV)
        STANDALONE = b"\x00"
        header.write(STANDALONE)
        self._write_SOCKS5_address(address, header)

        sent = _BaseSocket.send(self,
                                header.getvalue() + bytes, *flags, **kwargs)
        return sent - header.tell()