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


Python Headers.copy方法代码示例

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


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

示例1: request

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import copy [as 别名]
    def request(self, method, uri, headers=None, bodyProducer=None):
        """
        Issue a new request to the wrapped L{Agent}.

        Send a I{Cookie} header if a cookie for C{uri} is stored in
        L{CookieAgent.cookieJar}. Cookies are automatically extracted and
        stored from requests.

        If a C{'cookie'} header appears in C{headers} it will override the
        automatic cookie header obtained from the cookie jar.

        @see: L{Agent.request}
        """
        if headers is None:
            headers = Headers()
        lastRequest = _FakeUrllib2Request(uri)
        # Setting a cookie header explicitly will disable automatic request
        # cookies.
        if not headers.hasHeader('cookie'):
            self.cookieJar.add_cookie_header(lastRequest)
            cookieHeader = lastRequest.get_header('Cookie', None)
            if cookieHeader is not None:
                headers = headers.copy()
                headers.addRawHeader('cookie', cookieHeader)

        d = self._agent.request(method, uri, headers, bodyProducer)
        d.addCallback(self._extractCookies, lastRequest)
        return d
开发者ID:GunioRobot,项目名称:twisted,代码行数:30,代码来源:client.py

示例2: test_copy

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import copy [as 别名]
    def test_copy(self):
        """
        L{Headers.copy} creates a new independent copy of an existing
        L{Headers} instance, allowing future modifications without impacts
        between the copies.
        """
        h = Headers()
        h.setRawHeaders(u'test\u00E1', [u'foo\u2603'])
        i = h.copy()

        # The copy contains the same value as the original
        self.assertEqual(i.getRawHeaders(u'test\u00E1'), [u'foo\u2603'])
        self.assertEqual(i.getRawHeaders(b'test\xe1'), [b'foo\xe2\x98\x83'])

        # Add a header to the original
        h.addRawHeader(u'test\u00E1', u'bar')

        # Verify that the copy has not changed
        self.assertEqual(i.getRawHeaders(u'test\u00E1'), [u'foo\u2603'])
        self.assertEqual(i.getRawHeaders(b'test\xe1'), [b'foo\xe2\x98\x83'])

        # Add a header to the copy
        i.addRawHeader(u'test\u00E1', b'baz')

        # Verify that the orignal does not have it
        self.assertEqual(
            h.getRawHeaders(u'test\u00E1'), [u'foo\u2603', u'bar'])
        self.assertEqual(
            h.getRawHeaders(b'test\xe1'), [b'foo\xe2\x98\x83', b'bar'])
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:31,代码来源:test_http_headers.py

示例3: request

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import copy [as 别名]
    def request(self, method, uri, headers=None, bodyProducer=None):
        parsedURI = client._parse(uri)
        
        host_addr = address.IPv4Address('TCP', parsedURI.host, parsedURI.port)
        
        
        # ripped from _AgentBase._requestWithEndpoint
        if headers is None:
            headers = Headers()
        if not headers.hasHeader('host'):
            headers = headers.copy()
            headers.addRawHeader(
                'host', self._computeHostValue(parsedURI.scheme, parsedURI.host,
                                               parsedURI.port))
        request = client.Request(method, parsedURI.path, headers, bodyProducer,
                                 persistent=False)

        c = ClientProtocol(request)
        
        # ouch
        self.root.putChild('', self.root)
        
        server = Site(self.root).buildProtocol(self.addr)
        loopbackAsync(server, c, host_addr, self.addr)
        return c.response.addBoth(self._done, c)
开发者ID:tomprince,项目名称:agentforhire,代码行数:27,代码来源:badhack.py

示例4: request

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import copy [as 别名]
 def request(self, method, uri, headers=None, bodyProducer=None):
     if headers is None:
         headers = Headers()
     else:
         headers = headers.copy()
     for name, value in self._header_list:
         headers.addRawHeader(name, value)
     return self._agent.request(method, uri, headers, bodyProducer)
开发者ID:seraphlnWu,项目名称:creditor,代码行数:10,代码来源:http.py

示例5: request

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import copy [as 别名]
 def request(self, method, uri, headers=None, bodyProducer=None):
     if headers is None:
         headers = Headers()
     else:
         headers = headers.copy()
     if not headers.hasHeader('user-agent'):
         headers.addRawHeader('user-agent', self.user_agent)
     return self.agent.request(method, uri, headers, bodyProducer)
开发者ID:kxz,项目名称:omnipresence,代码行数:10,代码来源:http.py

示例6: test_copy

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import copy [as 别名]
 def test_copy(self):
     """
     L{Headers.copy} creates a new independant copy of an existing
     L{Headers} instance, allowing future modifications without impacts
     between the copies.
     """
     h = Headers()
     h.setRawHeaders('test', ['foo'])
     i = h.copy()
     self.assertEquals(i.getRawHeaders('test'), ['foo'])
     h.addRawHeader('test', 'bar')
     self.assertEquals(i.getRawHeaders('test'), ['foo'])
     i.addRawHeader('test', 'baz')
     self.assertEquals(h.getRawHeaders('test'), ['foo', 'bar'])
开发者ID:svpcom,项目名称:twisted-cdeferred,代码行数:16,代码来源:test_http_headers.py

示例7: test_copy

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import copy [as 别名]
 def test_copy(self):
     """
     L{Headers.copy} creates a new independant copy of an existing
     L{Headers} instance, allowing future modifications without impacts
     between the copies.
     """
     h = Headers()
     h.setRawHeaders(b"test", [b"foo"])
     i = h.copy()
     self.assertEqual(i.getRawHeaders(b"test"), [b"foo"])
     h.addRawHeader(b"test", b"bar")
     self.assertEqual(i.getRawHeaders(b"test"), [b"foo"])
     i.addRawHeader(b"test", b"baz")
     self.assertEqual(h.getRawHeaders(b"test"), [b"foo", b"bar"])
开发者ID:pelluch,项目名称:VTK,代码行数:16,代码来源:test_http_headers.py

示例8: CheckupURL

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import copy [as 别名]
def CheckupURL():
    HTTPHeader0 = Headers({'User-Agent': ['PSO2Proxy']}) #We need to send a User-Agent
    if eqalert_config.key_exists('api'):
        eq_URL = eqalert_config.get_key('api')
    else:
        eq_URL = None
    if eq_URL:
        HTTPHeaderX = HTTPHeader0.copy()
        if ETag_Header:
            HTTPHeaderX.addRawHeader('If-None-Match', ETag_Header)
        if Modified_Header:
            HTTPHeaderX.addRawHeader('If-Modified-Since', Modified_Header)
        EQ0 = agent.request('GET', eq_URL, HTTPHeaderX)
        EQ0.addCallback(EQResponse)
        EQ0.addErrback(log.err)
开发者ID:seilexta,项目名称:PSO2Proxy,代码行数:17,代码来源:EQ_Alert.py

示例9: CheckupURL

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import copy [as 别名]
def CheckupURL():
    HTTPHeader0 = Headers({'User-Agent': ['PSO2Proxy']})
    load_eqJP_names()  # Reload file
    for shipNum in config.globalConfig.get_key('enabledShips'):
        if eqnotice_config.key_exists(str(shipNum)):
            eq_URL = eqnotice_config.get_key(str(shipNum))
        else:
            eq_URL = None
        if eq_URL:
            HTTPHeaderX = HTTPHeader0.copy()
            if ETag_Headers[shipNum]:
                HTTPHeaderX.addRawHeader('If-None-Match', ETag_Headers[shipNum])
            if Modified_Headers[shipNum]:
                HTTPHeaderX.addRawHeader('If-Modified-Since', Modified_Headers[shipNum])
            EQ0 = agent.request('GET', eq_URL, HTTPHeaderX)
            EQ0.addCallback(EQResponse, shipNum)
            EQ0.addErrback(log.err)
开发者ID:Kyle873,项目名称:PSO2Proxy,代码行数:19,代码来源:EQ_Notice.py

示例10: _requestWithEndpoint

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import copy [as 别名]
    def _requestWithEndpoint(self, key, endpoint, method, parsedURI,
                             headers, bodyProducer, requestPath):
        if headers is None:
            headers = Headers()

        if not headers.hasHeader('host'):
            headers = headers.copy()
            headers.addRawHeader(
                'host', self._computeHostValue(parsedURI.scheme,
                                               parsedURI.host, parsedURI.port))

        d = self._pool.getConnection(key, endpoint)

        def cbConnected(proto):
            return proto.request(
                SigningRequest._construct(self._signData.makeSigner(),
                                          method, requestPath, headers,
                                          bodyProducer,
                                          persistent=self._pool.persistent,
                                          parsedURI=parsedURI))
        d.addCallback(cbConnected)
        return d
开发者ID:GaretJax,项目名称:txs3,代码行数:24,代码来源:signing.py

示例11: _requestWithEndpoint

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import copy [as 别名]
    def _requestWithEndpoint(self, key, endpoint, method, parsedURI,
                             headers, bodyProducer, requestPath):
        """
        Issue a new request, given the endpoint and the path sent as part of
        the request.
        """
        # Create minimal headers, if necessary:
        if headers is None:
            headers = Headers()
        if not headers.hasHeader('host'):
            headers = headers.copy()  # not supported in twisted <= 11.1, and it doesn't affects us
            headers.addRawHeader(
                'host', self._computeHostValue(parsedURI.scheme, parsedURI.host,
                                               parsedURI.port))

        d = self._pool.getConnection(key, endpoint)
        def cbConnected(proto):
            return proto.request(
                Request(method, requestPath, headers, bodyProducer,
                        persistent=self._pool.persistent))
        d.addCallback(cbConnected)
        return d
开发者ID:schleichdi2,项目名称:OpenNfr_E2_Gui-5.3,代码行数:24,代码来源:client.py

示例12: _connectAndRequest

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import copy [as 别名]
    def _connectAndRequest(self, method, uri, headers, bodyProducer,
                           requestPath=None):
        """
        Internal helper to make the request.

        @param requestPath: If specified, the path to use for the request
            instead of the path extracted from C{uri}.
        """
        scheme, host, port, path = _parse(uri)
        if requestPath is None:
            requestPath = path
        d = self._connect(scheme, host, port)
        if headers is None:
            headers = Headers()
        if not headers.hasHeader('host'):
            headers = headers.copy()
            headers.addRawHeader(
                'host', self._computeHostValue(scheme, host, port))
        def cbConnected(proto):
            return proto.request(
                Request(method, requestPath, headers, bodyProducer))
        d.addCallback(cbConnected)
        return d
开发者ID:GunioRobot,项目名称:twisted,代码行数:25,代码来源:client.py

示例13: request

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import copy [as 别名]
    def request(self, method, uri, headers, bodyProducer):

        if headers is None:
            headers = Headers()
        else:
            headers = headers.copy()

        contentType = headers.getRawHeaders('content-type', [""])[0]
        date = headers.getRawHeaders('date', [""])[0] or self._generateRequestDate(uri)
        headers.setRawHeaders('date', [date])

        uri_origin_form = URI.fromBytes(uri).originForm
        contentMD5 = headers.getRawHeaders('content-md5', [""])[0]

        if not contentMD5 and bodyProducer is not None:

            r = getattr(self.agent, '_reactor') or reactor
            bodyConsumer = StringConsumer(callLater=r.callLater)

            yield bodyProducer.startProducing(bodyConsumer)
            body = bodyConsumer.value()
            bodyProducer = StringBodyProducer(body)

            if body:
                contentMD5 = binascii.b2a_base64(hashlib.md5(body).digest()).strip()
                headers.addRawHeader('content-md5', contentMD5)

        sts = "\n".join([method, contentType or "", contentMD5, date or "", uri_origin_form])
        mac = hmac.new(self.secretKey, sts, digestmod=hashlib.sha1).digest()
        encodedMAC = binascii.b2a_base64(mac).strip()

        auth_header = "AuthHMAC {0}:{1}".format(self.accessKey, encodedMAC)
        headers.addRawHeader('authorization', auth_header)

        d = yield self.agent.request(method, uri, headers, bodyProducer)
        self._handleResponseDate(uri, d)
        defer.returnValue(d)
开发者ID:wgnet,项目名称:twoost,代码行数:39,代码来源:authhmac.py

示例14: request

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import copy [as 别名]
 def request(self, method, uri, headers=None, bodyProducer=None):
     headers = Headers() if headers is None else headers.copy()
     headers.addRawHeader(b'authorization', self._auth_header)
     return self._agent.request(method, uri, headers, bodyProducer)
开发者ID:anjensan,项目名称:twoost,代码行数:6,代码来源:httprpc.py

示例15: request

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import copy [as 别名]
    def request(self, method, uri, headers=None, bodyProducer=None):
        """
        :param method: HTTP method (GET/POST/etc).
        :type method: bytes

        :param uri: Absolute URI to be retrieved.
        :type uri: bytes

        :param headers: HTTP headers to send with the request, or None to
            send no extra headers.
        :type headers: twisted.web.http_headers.Headers, None

        :param bodyProducer: An object which can generate bytes to make up the
            body of this request (for example, the properly encoded contents of
            a file for a file upload).  Or None if the request is to have
            no body.
        :type bodyProducer: twisted.web.iweb.IBodyProducer, None

        :returns a deferred that fires when the header of the response has
            been received (regardless of the response status code). Fails if
            there is any problem which prevents that response from being received
            (including problems that prevent the request from being sent).
        :rtype: Deferred[twisted.web.iweb.IResponse]
        """
        parsed_uri = URI.fromBytes(uri, defaultPort=-1)
        res = yield self._route_matrix_uri(parsed_uri)

        # set up the TLS connection params
        #
        # XXX disabling TLS is really only supported here for the benefit of the
        # unit tests. We should make the UTs cope with TLS rather than having to make
        # the code support the unit tests.
        if self._tls_client_options_factory is None:
            tls_options = None
        else:
            tls_options = self._tls_client_options_factory.get_options(
                res.tls_server_name.decode("ascii")
            )

        # make sure that the Host header is set correctly
        if headers is None:
            headers = Headers()
        else:
            headers = headers.copy()

        if not headers.hasHeader(b'host'):
            headers.addRawHeader(b'host', res.host_header)

        class EndpointFactory(object):
            @staticmethod
            def endpointForURI(_uri):
                ep = LoggingHostnameEndpoint(
                    self._reactor, res.target_host, res.target_port,
                )
                if tls_options is not None:
                    ep = wrapClientTLS(tls_options, ep)
                return ep

        agent = Agent.usingEndpointFactory(self._reactor, EndpointFactory(), self._pool)
        res = yield agent.request(method, uri, headers, bodyProducer)
        defer.returnValue(res)
开发者ID:matrix-org,项目名称:sydent,代码行数:63,代码来源:matrixfederationagent.py


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