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


Python proxy.ProxyClient方法代码示例

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


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

示例1: makeProxyClient

# 需要导入模块: from twisted.web import proxy [as 别名]
# 或者: from twisted.web.proxy import ProxyClient [as 别名]
def makeProxyClient(self, request, method=b"GET", headers=None,
                        requestBody=b""):
        """
        Make a L{ProxyClient} object used for testing.

        @param request: The request to use.
        @param method: The HTTP method to use, GET by default.
        @param headers: The HTTP headers to use expressed as a dict. If not
            provided, defaults to {'accept': 'text/html'}.
        @param requestBody: The body of the request. Defaults to the empty
            string.
        @return: A L{ProxyClient}
        """
        if headers is None:
            headers = {b"accept": b"text/html"}
        path = b'/' + request.postpath
        return ProxyClient(
            method, path, b'HTTP/1.0', headers, requestBody, request) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_proxy.py

示例2: assertForwardsHeaders

# 需要导入模块: from twisted.web import proxy [as 别名]
# 或者: from twisted.web.proxy import ProxyClient [as 别名]
def assertForwardsHeaders(self, proxyClient, requestLine, headers):
        """
        Assert that C{proxyClient} sends C{headers} when it connects.

        @param proxyClient: A L{ProxyClient}.
        @param requestLine: The request line we expect to be sent.
        @param headers: A dict of headers we expect to be sent.
        @return: If the assertion is successful, return the request body as
            bytes.
        """
        self.connectProxy(proxyClient)
        requestContent = proxyClient.transport.value()
        receivedLine, receivedHeaders, body = self._parseOutHeaders(
            requestContent)
        self.assertEqual(receivedLine, requestLine)
        self.assertEqual(receivedHeaders, headers)
        return body 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_proxy.py

示例3: makeProxyClient

# 需要导入模块: from twisted.web import proxy [as 别名]
# 或者: from twisted.web.proxy import ProxyClient [as 别名]
def makeProxyClient(self, request, method="GET", headers=None,
                        requestBody=""):
        """
        Make a L{ProxyClient} object used for testing.

        @param request: The request to use.
        @param method: The HTTP method to use, GET by default.
        @param headers: The HTTP headers to use expressed as a dict. If not
            provided, defaults to {'accept': 'text/html'}.
        @param requestBody: The body of the request. Defaults to the empty
            string.
        @return: A L{ProxyClient}
        """
        if headers is None:
            headers = {"accept": "text/html"}
        path = '/' + request.postpath
        return ProxyClient(
            method, path, 'HTTP/1.0', headers, requestBody, request) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:20,代码来源:test_proxy.py

示例4: assertForwardsHeaders

# 需要导入模块: from twisted.web import proxy [as 别名]
# 或者: from twisted.web.proxy import ProxyClient [as 别名]
def assertForwardsHeaders(self, proxyClient, requestLine, headers):
        """
        Assert that C{proxyClient} sends C{headers} when it connects.

        @param proxyClient: A L{ProxyClient}.
        @param requestLine: The request line we expect to be sent.
        @param headers: A dict of headers we expect to be sent.
        @return: If the assertion is successful, return the request body as
            bytes.
        """
        self.connectProxy(proxyClient)
        requestContent = proxyClient.transport.value()
        receivedLine, receivedHeaders, body = self._parseOutHeaders(
            requestContent)
        self.assertEquals(receivedLine, requestLine)
        self.assertEquals(receivedHeaders, headers)
        return body 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:19,代码来源:test_proxy.py

示例5: connectProxy

# 需要导入模块: from twisted.web import proxy [as 别名]
# 或者: from twisted.web.proxy import ProxyClient [as 别名]
def connectProxy(self, proxyClient):
        """
        Connect a proxy client to a L{StringTransportWithDisconnection}.

        @param proxyClient: A L{ProxyClient}.
        @return: The L{StringTransportWithDisconnection}.
        """
        clientTransport = StringTransportWithDisconnection()
        clientTransport.protocol = proxyClient
        proxyClient.makeConnection(clientTransport)
        return clientTransport 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:test_proxy.py

示例6: test_forward

# 需要导入模块: from twisted.web import proxy [as 别名]
# 或者: from twisted.web.proxy import ProxyClient [as 别名]
def test_forward(self):
        """
        When connected to the server, L{ProxyClient} should send the saved
        request, with modifications of the headers, and then forward the result
        to the parent request.
        """
        return self._testDataForward(
            200, b"OK", [(b"Foo", [b"bar", b"baz"])], b"Some data\r\n") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_proxy.py

示例7: test_headersCleanups

# 需要导入模块: from twisted.web import proxy [as 别名]
# 或者: from twisted.web.proxy import ProxyClient [as 别名]
def test_headersCleanups(self):
        """
        The headers given at initialization should be modified:
        B{proxy-connection} should be removed if present, and B{connection}
        should be added.
        """
        client = ProxyClient(b'GET', b'/foo', b'HTTP/1.0',
            {b"accept": b"text/html", b"proxy-connection": b"foo"}, b'', None)
        self.assertEqual(client.headers,
            {b"accept": b"text/html", b"connection": b"close"}) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_proxy.py

示例8: test_buildProtocol

# 需要导入模块: from twisted.web import proxy [as 别名]
# 或者: from twisted.web.proxy import ProxyClient [as 别名]
def test_buildProtocol(self):
        """
        L{ProxyClientFactory.buildProtocol} should produce a L{ProxyClient}
        with the same values of attributes (with updates on the headers).
        """
        factory = ProxyClientFactory(b'GET', b'/foo', b'HTTP/1.0',
                                     {b"accept": b"text/html"}, b'Some data',
                                     None)
        proto = factory.buildProtocol(None)
        self.assertIsInstance(proto, ProxyClient)
        self.assertEqual(proto.command, b'GET')
        self.assertEqual(proto.rest, b'/foo')
        self.assertEqual(proto.data, b'Some data')
        self.assertEqual(proto.headers,
                          {b"accept": b"text/html", b"connection": b"close"}) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:test_proxy.py

示例9: __init__

# 需要导入模块: from twisted.web import proxy [as 别名]
# 或者: from twisted.web.proxy import ProxyClient [as 别名]
def __init__(self, *args, **kwargs):
			self.intercept = {'song': b'/eapi/v3/song/detail/', 'search': b'/eapi/cloudsearch/pc', 'url': b'/eapi/song/enhance/player/url', 'album': b'/eapi/v1/album', 'artist': b'/eapi/v1/artist', 'playlist': b'/eapi/v3/playlist/detail', 'discovery': b'/eapi/v1/discovery/new/songs', 'linux': b'/api/linux/forward'}
			self.interval = {self.intercept['song']: 10, self.intercept['search']: 100, 'default': 10}
			self.temp_buffer = {self.intercept['song']: None, self.intercept['search']: None}
			self.timestamp = {self.intercept['song']: time.time(), self.intercept['search']: time.time()}
			proxy.ProxyClient.__init__(self, *args, **kwargs) 
开发者ID:yi-ji,项目名称:NeteaseMusicAbroad,代码行数:8,代码来源:NeteaseMusicProxy.py

示例10: handleResponsePart

# 需要导入模块: from twisted.web import proxy [as 别名]
# 或者: from twisted.web.proxy import ProxyClient [as 别名]
def handleResponsePart(self, buffer):
			if self.rest in [self.intercept['song'], self.intercept['search'], self.intercept['playlist'], self.intercept['discovery'], self.intercept['linux']] or self.intercept['album'] in self.rest or self.intercept['artist'] in self.rest:
				print(self.headers)
				if self.headers[b'content-length'] != mainland_proxy.url_request_length:
					print('response intercepted: ', self.rest)
					if self.rest not in self.timestamp:
						self.timestamp[self.rest] = time.time()
						self.temp_buffer[self.rest] = None
					if time.time() - self.timestamp[self.rest] > self.interval.get(self.rest, self.interval['default']):
						self.temp_buffer[self.rest] = 0
						self.timestamp[self.rest] = time.time()
					if self.temp_buffer[self.rest] != None:
						buffer = self.temp_buffer[self.rest] + buffer
					buffer_str = sh_gzip_decompress(buffer)
					if buffer_str == None or b'unexpected end of file' in buffer_str:
						self.temp_buffer[self.rest] = buffer
						self.timestamp[self.rest] = time.time()
						return
					else:
						del self.temp_buffer[self.rest]
						del self.timestamp[self.rest]
					buffer_str = modify_response(buffer_str)
					#print buffer_str
					buffer = sh_gzip_compress(buffer_str)
			if self.rest == self.intercept['url']:
				self.check_buffer(buffer)
			proxy.ProxyClient.handleResponsePart(self, buffer) 
开发者ID:yi-ji,项目名称:NeteaseMusicAbroad,代码行数:29,代码来源:NeteaseMusicProxy.py

示例11: handleResponsePart

# 需要导入模块: from twisted.web import proxy [as 别名]
# 或者: from twisted.web.proxy import ProxyClient [as 别名]
def handleResponsePart(self, buffer):
        #Buffer the output if we intend to modify it
        if self.father.has_response_modifiers():
            self.father.response_buffer.write(buffer)
        else:
            proxy.ProxyClient.handleResponsePart(self, buffer) 
开发者ID:pdjstone,项目名称:wsuspect-proxy,代码行数:8,代码来源:intercepting_proxy.py

示例12: handleResponseEnd

# 需要导入模块: from twisted.web import proxy [as 别名]
# 或者: from twisted.web.proxy import ProxyClient [as 别名]
def handleResponseEnd(self):
        #Process the buffered output if we are modifying it
        if self.father.has_response_modifiers():
            if not self._finished:
                #Replace the StringIO with a string for the modifiers
                data = self.father.response_buffer.getvalue()
                self.father.response_buffer.close()
                self.father.response_buffer = data

                #Do editing of response headers / content here
                self.father.run_response_modifiers()
                self.father.responseHeaders.setRawHeaders('content-length', [len(self.father.response_buffer)])
                self.father.write(self.father.response_buffer)
        proxy.ProxyClient.handleResponseEnd(self) 
开发者ID:pdjstone,项目名称:wsuspect-proxy,代码行数:16,代码来源:intercepting_proxy.py

示例13: handleHeader

# 需要导入模块: from twisted.web import proxy [as 别名]
# 或者: from twisted.web.proxy import ProxyClient [as 别名]
def handleHeader(self, key, value):
        proxy.ProxyClient.handleHeader(self, key, value)
        if key.lower() == b'content-type':
            if value.decode().split(';')[0] == 'text/html':
                self.parser = WordParser() 
开发者ID:ScrappyZhang,项目名称:python_web_Crawler_DA_ML_DL,代码行数:7,代码来源:t48_http_proxy_wordcount.py

示例14: handleResponsePart

# 需要导入模块: from twisted.web import proxy [as 别名]
# 或者: from twisted.web.proxy import ProxyClient [as 别名]
def handleResponsePart(self, buffer):
        proxy.ProxyClient.handleResponsePart(self, buffer)
        if hasattr(self, 'parser'):
            self.parser.feed(buffer.decode())
            self.father.wordCounter.addWords(self.parser.getWords())
            del self.parser 
开发者ID:ScrappyZhang,项目名称:python_web_Crawler_DA_ML_DL,代码行数:8,代码来源:t48_http_proxy_wordcount.py

示例15: handleHeader

# 需要导入模块: from twisted.web import proxy [as 别名]
# 或者: from twisted.web.proxy import ProxyClient [as 别名]
def handleHeader(self, key, value):
        if (key.lower() == "content-type" and
                value == "application/vnd.docker.raw-stream"):
            self._handleRawStream()
        return proxy.ProxyClient.handleHeader(self, key, value) 
开发者ID:ClusterHQ,项目名称:powerstrip,代码行数:7,代码来源:powerstrip.py


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