当前位置: 首页>>代码示例>>Python>>正文


Python proxy.ProxyClient类代码示例

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


在下文中一共展示了ProxyClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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,代码来源:


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