Ejemplo n.º 1
0
    def run(self):
        while not self.quiting:
            try:
                data = self.sock.recv(8192)
            except socket.timeout:
                self.handle_timeouts()

                continue
            self.log("NetIO < %s" % repr(data))
            try:
                for i in range(2):
                    try:
                        tmp = data
                        resp = None
                        if tmp[:2] == '\x00\x00':
                            tmp = zlib.decompressobj().decompress(tmp[2:])
                            self.log("UnZip | %s" % repr(tmp))
                        resp = ResponseResolver(tmp)
                    except:
                        sys.excepthook(*sys.exc_info())
                        self.crypt = None
                        self.session = None
                    else:
                        break
                if not resp:
                    raise AniDBPacketCorruptedError, "Either decrypting, decompressing or parsing the packet failed"
                cmd = self.cmd_dequeue(resp)
                resp = resp.resolve(cmd)
                resp.parse()
                if resp.rescode in ('200', '201'):
                    self.session = resp.attrs['sesskey']
                if resp.rescode in ('209', ):
                    print "sorry encryption is not supported"
                    raise
                    #self.crypt=aes(md5(resp.req.apipassword+resp.attrs['salt']).digest())
                if resp.rescode in ('203', '403', '500', '501', '503', '506'):
                    self.session = None
                    self.crypt = None
                if resp.rescode in ('504', '555'):
                    self.banned = True
                    print "AniDB API informs that user or client is banned:", resp.resstr
                resp.handle()
                if not cmd or not cmd.mode:
                    self.resp_queue(resp)
                else:
                    self.tags.remove(resp.restag)
            except:
                sys.excepthook(*sys.exc_info())
                print "Avoiding flood by paranoidly panicing: Aborting link thread, killing connection, releasing waiters and quiting"
                self.sock.close()
                try:
                    cmd.waiter.release()
                except:
                    pass
                for tag, cmd in self.cmd_queue.iteritems():
                    try:
                        cmd.waiter.release()
                    except:
                        pass
                sys.exit()
Ejemplo n.º 2
0
    def run(self):
        while not self._quiting:
            try:
                data = self.sock.recv(8192)
            except socket.timeout:
                self._handle_timeouts()

                continue
            self.log("NetIO < %s" % repr(data))
            try:
                for i in range(2):
                    try:
                        tmp = data
                        resp = None
                        if tmp[:2] == '\x00\x00':
                            tmp = zlib.decompressobj().decompress(tmp[2:])
                            self.log("UnZip | %s" % repr(tmp))
                        resp = ResponseResolver(tmp)
                    except:
                        sys.excepthook(*sys.exc_info())
                        self.crypt = None
                        self.session = None
                    else:
                        break
                if not resp:
                    raise AniDBPacketCorruptedError, "Either decrypting, decompressing or parsing the packet failed"
                cmd = self._cmd_dequeue(resp)
                resp = resp.resolve(cmd)
                resp.parse()
                if resp.rescode in ('200', '201'):
                    self.session = resp.attrs['sesskey']
                if resp.rescode in ('209',):
                    print "sorry encryption is not supported"
                    raise
                    #self.crypt=aes(md5(resp.req.apipassword+resp.attrs['salt']).digest())
                if resp.rescode in ('203', '403', '500', '501', '503', '506'):
                    self.session = None
                    self.crypt = None
                if resp.rescode in ('504', '555'):
                    self.banned = True
                    print "AniDB API informs that user or client is banned:", resp.resstr
                resp.handle()
                if not cmd or not cmd.mode:
                    self._resp_queue(resp)
                else:
                    self.tags.remove(resp.restag)
            except:
                sys.excepthook(*sys.exc_info())
                print "Avoiding flood by paranoidly panicing: Aborting link thread, killing connection, releasing waiters and quiting"
                self.sock.close()
                try:cmd.waiter.release()
                except:pass
                for tag, cmd in self.cmd_queue.iteritems():
                    try:cmd.waiter.release()
                    except:pass
                sys.exit()
Ejemplo n.º 3
0
    def run(self):
        while not self.quiting:
            try:
                data = self.sock.recv(8192)
            except socket.timeout:
                self.handle_timeouts()

                continue
            self.log("NetIO < %s" % repr(data))
            try:
                for i in range(2):
                    try:
                        tmp = data
                        resp = None
                        if tmp[:2] == "\x00\x00":
                            tmp = zlib.decompressobj().decompress(tmp[2:])
                            self.log("UnZip | %s" % repr(tmp))
                        resp = ResponseResolver(tmp)
                    except:
                        sys.excepthook(*sys.exc_info())
                        self.crypt = None
                        self.session = None
                    else:
                        break
                if not resp:
                    raise err.AniDBPacketCorruptedError(
                        "Either decrypting, decompressing or parsing the " "packet failed"
                    )
                cmd = self.cmd_dequeue(resp)
                resp = resp.resolve(cmd)
                resp.parse()
                if resp.rescode in ("200", "201"):
                    self.session = resp.attrs["sesskey"]
                if resp.rescode in ("209",):
                    # TODO: Check if this is worth implementing/possible to
                    # implement in a sane way
                    print "sorry encryption is not supported"
                    raise
                    # self.crypt = aes(
                    #   md5(resp.req.apipassword+resp.attrs['salt']).digest())
                if resp.rescode in ("203", "403", "500", "501", "503", "506"):
                    self.session = None
                    self.crypt = None
                elif resp.rescode in ("504", "555"):
                    self.banned = True
                    self.banmsg = resp
                    Log("AniDB API informs that user or client is banned:", resp)
                elif resp.rescode == "505":
                    Log(
                        "Got illegal input or access denied. Either you're "
                        "underprivileged or there's a bug somewhere."
                    )
                else:
                    Log("Got unhandled status code %s, proceeding as usual." % resp.rescode.__repr__())
                resp.handle()
                if not cmd or not cmd.mode:
                    self.resp_queue(resp)
                else:
                    self.tags.remove(resp.restag)
            except:
                sys.excepthook(*sys.exc_info())
                Log(
                    "Avoiding flood by paranoidly panicing: Aborting link "
                    "thread, killing connection, releasing waiters and "
                    "quiting"
                )
                self.sock.close()

                try:
                    cmd.waiter.release()
                except:
                    pass

                for tag, cmd in self.cmd_queue.iteritems():
                    try:
                        cmd.waiter.release()
                    except:
                        pass
                sys.exit()
Ejemplo n.º 4
0
    def run(self):
        while not self.quiting:
            try:
                data = self.sock.recv(8192)
            except socket.timeout:
                self.handle_timeouts()

                continue
            self.log("NetIO < %s" % repr(data))
            try:
                for i in range(2):
                    try:
                        tmp = data
                        resp = None
                        if tmp[:2] == '\x00\x00':
                            tmp = zlib.decompressobj().decompress(tmp[2:])
                            self.log("UnZip | %s" % repr(tmp))
                        resp = ResponseResolver(tmp)
                    except:
                        sys.excepthook(*sys.exc_info())
                        self.crypt = None
                        self.session = None
                    else:
                        break
                if not resp:
                    raise err.AniDBPacketCorruptedError(
                        "Either decrypting, decompressing or parsing the "
                        "packet failed")
                cmd = self.cmd_dequeue(resp)
                resp = resp.resolve(cmd)
                resp.parse()
                if resp.rescode in ('200', '201'):
                    self.session = resp.attrs['sesskey']
                if resp.rescode in ('209', ):
                    # TODO: Check if this is worth implementing/possible to
                    # implement in a sane way
                    print "sorry encryption is not supported"
                    raise
                    # self.crypt = aes(
                    #   md5(resp.req.apipassword+resp.attrs['salt']).digest())
                if resp.rescode in ('203', '403', '500', '501', '503', '506'):
                    self.session = None
                    self.crypt = None
                elif resp.rescode in ('504', '555'):
                    self.banned = True
                    self.banmsg = resp
                    Log("AniDB API informs that user or client is banned:",
                        resp)
                elif resp.rescode == "505":
                    Log("Got illegal input or access denied. Either you're "
                        "underprivileged or there's a bug somewhere.")
                else:
                    Log("Got unhandled status code %s, proceeding as usual." %
                        resp.rescode.__repr__())
                resp.handle()
                if not cmd or not cmd.mode:
                    self.resp_queue(resp)
                else:
                    self.tags.remove(resp.restag)
            except:
                sys.excepthook(*sys.exc_info())
                Log("Avoiding flood by paranoidly panicing: Aborting link "
                    "thread, killing connection, releasing waiters and "
                    "quiting")
                self.sock.close()

                try:
                    cmd.waiter.release()
                except:
                    pass

                for tag, cmd in self.cmd_queue.iteritems():
                    try:
                        cmd.waiter.release()
                    except:
                        pass
                sys.exit()