• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python proxy.ProxyClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中twisted.web.proxy.ProxyClient的典型用法代码示例。如果您正苦于以下问题:Python ProxyClient类的具体用法?Python ProxyClient怎么用?Python ProxyClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ProxyClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, *args, **kwargs):
        ProxyClient.__init__(self, *args, **kwargs)
        self.overrides = []
        self.restricted_headers = [
            'accept-charset',
            'accept-encoding',
            'access-control-request-headers',
            'access-control-request-method',
            'connection',
            'content-length',
            'cookie',
            'cookie2',
            'content-transfer-encoding',
            'date',
            'expect',
            'host',
            'keep-alive',
            'origin',
            'referer',
            'te',
            'trailer',
            'transfer-encoding',
            'upgrade',
            'user-agent',
            'via'
            ]

        self.all_headers = []
        self.unsent_restricted_headers = []
开发者ID:tobiashochguertel,项目名称:postman-proxy_server.py,代码行数:29,代码来源:proxy_server.py


示例2: handleHeader

 def handleHeader(self, key, value):
     if key == "Content-Type" and value in ["image/jpeg", "image/gif", "image/png"]:
         self.image_parser = Parser()
     if key == "Content-Length" and self.image_parser:
         pass
     else:
         ProxyClient.handleHeader(self, key, value)
开发者ID:tobiashochguertel,项目名称:postman-proxy_server.py,代码行数:7,代码来源:twisted-proxy.py


示例3: _testDataForward

    def _testDataForward(self, data, method="GET", body=""):
        """
        Build a fake proxy connection, and send C{data} over it, checking that
        it's forwarded to the originating request.
        """
        # Connect everything
        clientTransport = StringTransportWithDisconnection()
        serverTransport = StringTransportWithDisconnection()
        channel = DummyChannel(serverTransport)
        parent = DummyParent(channel)
        serverTransport.protocol = channel

        client = ProxyClient(method, '/foo', 'HTTP/1.0',
                             {"accept": "text/html"}, body, parent)
        clientTransport.protocol = client
        client.makeConnection(clientTransport)

        # Check data sent
        self.assertEquals(clientTransport.value(),
            "%s /foo HTTP/1.0\r\n"
            "connection: close\r\n"
            "accept: text/html\r\n\r\n%s" % (method, body))

        # Fake an answer
        client.dataReceived(data)

        # Check that the data has been forwarded
        self.assertEquals(serverTransport.value(), data)

        clientTransport.loseConnection()
        self.assertIsInstance(channel.lostReason, ConnectionDone)
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:31,代码来源:test_proxy.py


示例4: handleResponsePart

 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,代码行数:7,代码来源:prox2.py


示例5: __init__

 def __init__(self, *args, **kwargs):
     self._buffer = []
     self.encoding = ''
     self.ctype = ''
     self.reencode = True
     self.replace = False
     self.headers_to_cache = {}
     ProxyClient.__init__(self,*args,**kwargs)
开发者ID:habedi,项目名称:rproxy,代码行数:8,代码来源:rproxy.py


示例6: handleHeader

    def handleHeader(self, key, value):
        # change response header here
        print("Header: %s: %s" % (key, value))
        l = key.lower()
        if l == "location":
            key = "Postman-Location"

        ProxyClient.handleHeader(self, key, value)
开发者ID:tobiashochguertel,项目名称:postman-proxy_server.py,代码行数:8,代码来源:proxy_server.py


示例7: handleHeader

 def handleHeader(self, key, value):
     log.msg("<<< %s: %s" % (key, value))
     if key.lower() == "content-type":
         if value.startswith("text/html"):
             self.rewrite = True
         ProxyClient.handleHeader(self, key, value)
     elif key.lower() == "content-length":
         self.length = value
     else:
         ProxyClient.handleHeader(self, key, value)
开发者ID:isotoma,项目名称:badgerproxy,代码行数:10,代码来源:proxyclient.py


示例8: connectionMade

 def connectionMade(self):
     ProxyClient.connectionMade(self)
     log.msg("message sent")
     # interrupt now before server can reply?
     if self.father.mode == MyProxyRequest.INTERRUPT_AFTER_SEND:
         log.msg("interrupt after sending")
         # finish writing, but never read
         self.transport.loseConnection()
         # Be nice and report a real error back to the proxy client.
         self.father.setResponseCode(501, "Gateway error")
         self.father.responseHeaders.addRawHeader("Content-Type", "text/plain")
         self.father.write("connection intentionally interrupted after sending and before receiving")
开发者ID:freedesktop-unofficial-mirror,项目名称:SyncEvolution__syncevolution,代码行数:12,代码来源:proxy.py


示例9: handleResponseEnd

 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,代码行数:30,代码来源:compressproxy.py


示例10: __init__

 def __init__(self, *args, **kwargs):
     ProxyClient.__init__(self, *args, **kwargs)
     self.replacing = None
     self.rewriting = None
     self._buf = None
     cache_path = cache_file(self.father.uri)
     replace_path = replace_file(self.father.uri)
     if cache_path and not os.path.exists(cache_path):
         t = threading.Thread(target=lambda:urllib.urlretrieve(self.father.uri, cache_path))
         t.start()
     if replace_path:
         self.replacing = replace_path
     elif 'json/Level' in self.father.uri and self.father.uri.endswith('.json'):
         self.rewriting = True
         self._buf = ''
开发者ID:thouis,项目名称:works-in-progress,代码行数:15,代码来源:prox2.py


示例11: __init__

 def __init__(self, command, rest, version, headers, data, father, resource):
    father.notifyFinish().addErrback(self._clientfinished, father, resource)
    if "proxy-connection" in headers:
       del headers["proxy-connection"]
    headers["connection"] = "close"
    headers.pop('keep-alive', None)
    self.headers = headers
    log.debug("Proxy Client SEND headers: "+str(headers))
    ProxyClient.__init__(self,
                        command=command,
                        rest=rest,
                        version=version,
                        headers=headers,
                        data=data,
                        father=father)
开发者ID:,项目名称:,代码行数:15,代码来源:


示例12: handleHeader

 def handleHeader(self, key, value):
     value = self.factory.rp.get_aliasheader(self.factory.host,value) 
     if DEBUG:
         pass
         #print key,value
     if key == "Content-Type" and (value.startswith("text") or \
             ("java" in value) or ("flash" in value)):
         self.replace = True
         self.ctype = value
     if key == "Content-Encoding":
         self.encoding = value
         return
     if key == "Content-Length":
         return
     else:
         self.headers_to_cache[key] = value
         ProxyClient.handleHeader(self, key, value)
开发者ID:habedi,项目名称:rproxy,代码行数:17,代码来源:rproxy.py


示例13: __init__

    def __init__(self, command, rest, version, headers, data, request):
        """
        Override ProxyClient.__init__ to:
            1. Set client HBModuleRegistry
            2. Set an intercept buffer
            3. Set an intercept header
            4. Set transaction_id

        """

        ProxyClient.__init__(self, command, rest, version, headers, data,
                             request)
        self.module_registry = request.module_registry
        self.buffer = ""
        self.header = {}
        now = datetime.datetime.now()
        self.father.response_createdAt = now.strftime('%Y-%m-%d %H:%M:%S')
开发者ID:KorayAgaya,项目名称:HeliosBurn,代码行数:17,代码来源:http.py


示例14: _testDataForward

    def _testDataForward(self, code, message, headers, body, method="GET",
                         requestBody="", loseConnection=True):
        """
        Build a fake proxy connection, and send C{data} over it, checking that
        it's forwarded to the originating request.
        """
        request = DummyRequest(['foo'])

        # Connect a proxy client to a fake transport.
        clientTransport = StringTransportWithDisconnection()
        client = ProxyClient(method, '/foo', 'HTTP/1.0',
                             {"accept": "text/html"}, requestBody, request)
        clientTransport.protocol = client
        client.makeConnection(clientTransport)

        # Check data sent
        self.assertEquals(clientTransport.value(),
            "%s /foo HTTP/1.0\r\n"
            "connection: close\r\n"
            "accept: text/html\r\n\r\n%s" % (method, requestBody))

        # Fake an answer
        client.dataReceived("HTTP/1.0 %d %s\r\n" % (code, message))
        for (header, values) in headers:
            for value in values:
                client.dataReceived("%s: %s\r\n" % (header, value))
        client.dataReceived("\r\n" + body)

        # Check that the response data has been forwarded back to the original
        # requester.
        self.assertEquals(request.responseCode, code)
        self.assertEquals(request.responseMessage, message)
        receivedHeaders = list(request.responseHeaders.getAllRawHeaders())
        receivedHeaders.sort()
        expectedHeaders = headers[:]
        expectedHeaders.sort()
        self.assertEquals(receivedHeaders, expectedHeaders)
        self.assertEquals(''.join(request.written), body)

        # Check that when the response is done, the request is finished.
        if loseConnection:
            clientTransport.loseConnection()

        # Even if we didn't call loseConnection, the transport should be
        # disconnected.  This lets us not rely on the server to close our
        # sockets for us.
        self.assertFalse(clientTransport.connected)
        self.assertEquals(request.finished, 1)
开发者ID:Almad,项目名称:twisted,代码行数:48,代码来源:test_proxy.py


示例15: handleHeader

 def handleHeader(self, key, value):
    if key.lower() == 'location':
       log.debug("Manage location header")
       uri=urlparse(value)
       value=uri.path
       if len(uri.query) > 0:
          value=value+"?"+uri.query
    #    value = self.proxymap.absoluteURLOf(value, self.host_header())
    log.debug("HANDLE HEADER: "+str(key)+" "+str(value))
    return ProxyClient.handleHeader(self, key, value)
开发者ID:,项目名称:,代码行数:10,代码来源:


示例16: handleResponseEnd

 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,代码行数:13,代码来源:proxyclient.py


示例17: sendHeader

    def sendHeader(self, name, value):
        if "postman-" in name:
            new_header = name[8:]
            print "Header %s, %s, %s" % (name, value, new_header)
            name = new_header
            header = {
                "name": name,
                "value": value
                }

            self.all_headers.append(name)
            ProxyClient.sendHeader(self, name, value)
        elif name in self.restricted_headers:
            header = {
                "name": name,
                "value": value
                }
            print "Restricted header %s" % name
            self.unsent_restricted_headers.append(header)
        else:
            ProxyClient.sendHeader(self, name, value)
开发者ID:tobiashochguertel,项目名称:postman-proxy_server.py,代码行数:21,代码来源:proxy_server.py


示例18: handleResponseEnd

 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,代码行数:30,代码来源:rproxy.py


示例19: handleHeader

 def handleHeader(self, key, value):
     if key.lower() == "content-type": 
         if value in ["image/jpeg", "image/gif", "image/png"]:
             self.image_parser = Parser()
         
         self.ctype_received = True         # content-type must be known before handling header
         if self.clength != 0 and not self.image_parser:
             # processes a content-length, if that was a prior header
             print "Header:  Content-Length  ", self.clength
             ProxyClient.handleHeader(self, "Content-Length", self.clength)
             
     if key.lower() == "content-length": 
         print "Handling content-length"
         if self.image_parser: # don't set content-length yet if an image-file.
             print "CHeader1: ", key, " ", value
             # LEAVES CONTENT-LENGTH UNSET!
         elif self.ctype_received:
             # a bit ugly. Just pass the header forward, if not an image c-length
             print "CHeader2: ", key, " ", value
             ProxyClient.handleHeader(self, key, value)
         else:
             # if content-type has not been processed yet
             print "old-clength ", value
             self.clength = value
             
             
             
     else:
         print "Header: ", key, " ", value
         ProxyClient.handleHeader(self, key, value)
开发者ID:Eeko,项目名称:resizer_proxy,代码行数:30,代码来源:compressproxy.py


示例20: handleStatus

 def handleStatus(self, version, code, message):
    log.debug("HANDLE STATUS: "+str(version)+" "+str(code)+" "+str(message))
    """
    if int(code)==304:
       log.debug("304 detected")
       self.father.transport.write(str(code)+" "+str(message)+" "+str(version))
       self.handleResponseEnd()
       self.father.transport.loseConnection()
       return
    else:
       return ProxyClient.handleStatus(self, version, code, message)
    """
    return ProxyClient.handleStatus(self, version, code, message)
开发者ID:,项目名称:,代码行数:13,代码来源:



注:本文中的twisted.web.proxy.ProxyClient类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python resource.getChildForRequest函数代码示例发布时间:2022-05-27
下一篇:
Python microdom.parseString函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap