當前位置: 首頁>>代碼示例>>Python>>正文


Python ProxyClient.handleResponsePart方法代碼示例

本文整理匯總了Python中twisted.web.proxy.ProxyClient.handleResponsePart方法的典型用法代碼示例。如果您正苦於以下問題:Python ProxyClient.handleResponsePart方法的具體用法?Python ProxyClient.handleResponsePart怎麽用?Python ProxyClient.handleResponsePart使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.web.proxy.ProxyClient的用法示例。


在下文中一共展示了ProxyClient.handleResponsePart方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: handleResponseEnd

# 需要導入模塊: from twisted.web.proxy import ProxyClient [as 別名]
# 或者: from twisted.web.proxy.ProxyClient import handleResponsePart [as 別名]
 def handleResponseEnd(self):
     self._buffer = ''.join(self._buffer)
     if self.replace: #if content replace is needed
         if self.encoding == 'gzip':
             try:
                 buffer1 = StringIO.StringIO(self._buffer)
                 gzipper = gzip.GzipFile(fileobj=buffer1)
                 html = gzipper.read()
             except Exception, what:
                 print self.factory.realhost,what
                 html = self._buffer
         elif self.encoding == 'deflate':
             try:
                 html = zlib.decompress(self._buffer)
             except zlib.error:
                 html = zlib.decompress(self._buffer, -zlib.MAX_WBITS)
         else:
             html = self._buffer
         self._buffer = self.factory.rp.process(self.factory.host,self.ctype,html)
         if self.reencode and ("flash" not in self.ctype):
             newbuffer = StringIO.StringIO()
             gzipper = gzip.GzipFile(fileobj=newbuffer,mode='wb')
             gzipper.write(self._buffer)
             gzipper.close()
             self._buffer = newbuffer.getvalue()
             self.headers_to_cache["Content-Encoding"]="gzip"
             ProxyClient.handleHeader(self,"Content-Encoding","gzip")
         self.headers_to_cache["Content-Length"]=len(self._buffer)
         ProxyClient.handleHeader(self, "Content-Length", len(self._buffer))
         ProxyClient.handleResponsePart(self,self._buffer)
開發者ID:habedi,項目名稱:rproxy,代碼行數:32,代碼來源:rproxy.py

示例2: handleResponsePart

# 需要導入模塊: from twisted.web.proxy import ProxyClient [as 別名]
# 或者: from twisted.web.proxy.ProxyClient import handleResponsePart [as 別名]
 def handleResponsePart(self, buffer):
     if self.replacing is not None:
         pass
     elif self.rewriting is not None:
         self._buf += buffer
     else:
         ProxyClient.handleResponsePart(self, buffer)
開發者ID:thouis,項目名稱:works-in-progress,代碼行數:9,代碼來源:prox2.py

示例3: handleResponseEnd

# 需要導入模塊: from twisted.web.proxy import ProxyClient [as 別名]
# 或者: from twisted.web.proxy.ProxyClient import handleResponsePart [as 別名]
 def handleResponseEnd(self):
     if self.image_parser:
         print "imageparsing ", compress_rate
         try:
           image = self.image_parser.close()
         except IOError as (error):
           print "I/O error: ", error
           print self.image_parser
           
         
         try:
             # do the compression
             format = image.format
             newsize = int(image.size[0] * compress_rate) , int(image.size[1] * compress_rate)
             image.thumbnail(newsize) # likely, image sizing like this does not work
             s = StringIO()
             image.save(s, format)
             buffer = s.getvalue()
         except NameError as (error):
             print "in exception: ", error
             # send Original C-length if just queryed for header
             buffer = " " *(int(self.clength))
         print "Header:  Content-Lengths ", len(buffer)
         ProxyClient.handleHeader(self, "Content-Length", len(buffer))
         
         # all headers received and processed
         ProxyClient.handleEndHeaders(self)
         ProxyClient.handleResponsePart(self, buffer)
     
     ProxyClient.handleResponseEnd(self)
開發者ID:Eeko,項目名稱:resizer_proxy,代碼行數:32,代碼來源:compressproxy.py

示例4: handleResponseEnd

# 需要導入模塊: from twisted.web.proxy import ProxyClient [as 別名]
# 或者: from twisted.web.proxy.ProxyClient import handleResponsePart [as 別名]
 def handleResponseEnd(self):
     log.msg("handleResponseEnd")
     if self.rewrite:
         banner2 = banner % dict(
             height = self.config['height'],
             bannerurl = self.config['bannerurl'],
             )
         buffer = self.buffer.replace("</head>", banner2)
         ProxyClient.handleHeader(self, "Content-Length", str(len(buffer)))
         ProxyClient.handleEndHeaders(self)
         ProxyClient.handleResponsePart(self, buffer)
         self.rewrite = False
     ProxyClient.handleResponseEnd(self)
開發者ID:isotoma,項目名稱:badgerproxy,代碼行數:15,代碼來源:proxyclient.py

示例5: handleResponseEnd

# 需要導入模塊: from twisted.web.proxy import ProxyClient [as 別名]
# 或者: from twisted.web.proxy.ProxyClient import handleResponsePart [as 別名]
 def handleResponseEnd(self):
     if self.image_parser:
         image = self.image_parser.close()
         try:
             format = image.format
             image = image.rotate(180)
             s = StringIO()
             image.save(s, format)
             buffer = s.getvalue()
         except:
             buffer = ""
         ProxyClient.handleHeader(self, "Content-Length", len(buffer))
         ProxyClient.handleEndHeaders(self)
         ProxyClient.handleResponsePart(self, buffer)
     ProxyClient.handleResponseEnd(self)
開發者ID:tobiashochguertel,項目名稱:postman-proxy_server.py,代碼行數:17,代碼來源:twisted-proxy.py

示例6: handleResponseEnd

# 需要導入模塊: from twisted.web.proxy import ProxyClient [as 別名]
# 或者: from twisted.web.proxy.ProxyClient import handleResponsePart [as 別名]
 def handleResponseEnd(self):
     if self.replacing is not None:
         try:
             buffer = open(self.replacing).read()
         except:
             buffer = ""
         ProxyClient.handleHeader(self, "Content-Length", len(buffer))
         ProxyClient.handleEndHeaders(self)
         ProxyClient.handleResponsePart(self, buffer)
     elif self.rewriting:
         buffer = self._buf.replace('"id": "BIRD_RED"', '"id": "BIRD_BLACK"')
         ProxyClient.handleHeader(self, "Content-Length", len(buffer))
         ProxyClient.handleEndHeaders(self)
         ProxyClient.handleResponsePart(self, buffer)
     ProxyClient.handleResponseEnd(self)
開發者ID:thouis,項目名稱:works-in-progress,代碼行數:17,代碼來源:prox2.py

示例7: _forward_response

# 需要導入模塊: from twisted.web.proxy import ProxyClient [as 別名]
# 或者: from twisted.web.proxy.ProxyClient import handleResponsePart [as 別名]
 def _forward_response(self, response):
     content = self.father.response_content
     if not response.drop_connection and not response.reset_connection:
         # fix this... odd that it must exist
         if not self._finished:
             ProxyClient.handleResponsePart(self, content)
             ProxyClient.handleResponseEnd(self)
         log.msg("Response forwarded: " + str(response))
     else:
         if response.drop_connection:
             ProxyClient.handleResponsePart(self, content)
             ProxyClient.handleResponseEnd(self)
             response.transport.loseConnection()
             log.msg("Connection dropped")
         else:
             response.transport.abortConnection()
             log.msg("Connection reset")
開發者ID:KorayAgaya,項目名稱:HeliosBurn,代碼行數:19,代碼來源:http.py

示例8: handleResponseEnd

# 需要導入模塊: from twisted.web.proxy import ProxyClient [as 別名]
# 或者: from twisted.web.proxy.ProxyClient import handleResponsePart [as 別名]
    def handleResponseEnd(self):
        if self.needsRewrite():
            log.msg("Rewriting " + self.father.uri)

            # We might have increased or decreased the page size. Since we have not written
            # to the client yet, we can still modify the headers.
            self.rewriteResponse()
            self.header_buffer["content-length"] = len(self.buffer)
            for key in self.header_buffer.keys():
                ProxyClient.handleHeader(self, key, self.header_buffer[key])
            ProxyClient.handleEndHeaders(self)
            ProxyClient.handleResponsePart(self, self.buffer) 
            
            self.buffer = ""
            self.header_buffer = {}
        
        ProxyClient.handleResponseEnd(self)
開發者ID:koto,項目名稱:iplex_adblock,代碼行數:19,代碼來源:BufferingProxyClient.py

示例9: handleResponseEnd

# 需要導入模塊: from twisted.web.proxy import ProxyClient [as 別名]
# 或者: from twisted.web.proxy.ProxyClient import handleResponsePart [as 別名]
 def handleResponseEnd(self):
     url = self.father.uri
     if self.gziped == True:
         temp = StringIO.StringIO(self.buf)
         s = gzip.GzipFile(fileobj=temp)
         content = s.read()
     else:
         content = self.buf
     if needModifyDetailApi(url):
         content = modifyDetailApi(content)
     elif needModifyPlayerApi(url):
         content = modifyPlayerApi(content)
     elif needModifyDownloadApi(url):
         content = modifyDownloadApi(content)
     if self.buf != "":
         if self.gziped == True:
             ProxyClient.handleResponsePart(self, compress(content))
         else:
             ProxyClient.handleResponsePart(self, content)
     ProxyClient.handleResponseEnd(self)
開發者ID:yknx4,項目名稱:UnlockNeteaseMusicProxy,代碼行數:22,代碼來源:netease_music_proxy.py

示例10: handleResponsePart

# 需要導入模塊: from twisted.web.proxy import ProxyClient [as 別名]
# 或者: from twisted.web.proxy.ProxyClient import handleResponsePart [as 別名]
 def handleResponsePart(self, buffer):
     url = self.father.uri
     if needModifyPlayerApi(url) or needModifyDetailApi(url) or needModifyDownloadApi(url):
         self.buf += buffer
     else:
         ProxyClient.handleResponsePart(self, buffer)
開發者ID:yknx4,項目名稱:UnlockNeteaseMusicProxy,代碼行數:8,代碼來源:netease_music_proxy.py

示例11: handleResponsePart

# 需要導入模塊: from twisted.web.proxy import ProxyClient [as 別名]
# 或者: from twisted.web.proxy.ProxyClient import handleResponsePart [as 別名]
 def handleResponsePart(self, buffer):
     if self.rewrite:
         self.buffer += buffer
     else:
         ProxyClient.handleResponsePart(self, buffer)
開發者ID:isotoma,項目名稱:badgerproxy,代碼行數:7,代碼來源:proxyclient.py

示例12: handleResponsePart

# 需要導入模塊: from twisted.web.proxy import ProxyClient [as 別名]
# 或者: from twisted.web.proxy.ProxyClient import handleResponsePart [as 別名]
 def handleResponsePart(self, buffer):
     if self.image_parser:
         self.image_parser.feed(buffer)
     else:
         ProxyClient.handleResponsePart(self, buffer)
開發者ID:tobiashochguertel,項目名稱:postman-proxy_server.py,代碼行數:7,代碼來源:twisted-proxy.py

示例13: handleResponsePart

# 需要導入模塊: from twisted.web.proxy import ProxyClient [as 別名]
# 或者: from twisted.web.proxy.ProxyClient import handleResponsePart [as 別名]
 def handleResponsePart(self, buffer):
     #self._buffer += buffer
     self._buffer.append(buffer)
     if not self.replace:
         ProxyClient.handleResponsePart(self,buffer)
開發者ID:habedi,項目名稱:rproxy,代碼行數:7,代碼來源:rproxy.py

示例14: handleResponsePart

# 需要導入模塊: from twisted.web.proxy import ProxyClient [as 別名]
# 或者: from twisted.web.proxy.ProxyClient import handleResponsePart [as 別名]
 def handleResponsePart(self, buffer):
     
     if self.needsRewrite():
         self.buffer = self.buffer + buffer
     else:
         ProxyClient.handleResponsePart(self, buffer)
開發者ID:koto,項目名稱:iplex_adblock,代碼行數:8,代碼來源:BufferingProxyClient.py


注:本文中的twisted.web.proxy.ProxyClient.handleResponsePart方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。