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


Python Headers.hasHeader方法代码示例

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


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

示例1: test_hasHeaderTrue

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import hasHeader [as 别名]
 def test_hasHeaderTrue(self):
     """
     Check that L{Headers.hasHeader} returns C{True} when the given header
     is found.
     """
     h = Headers()
     h.setRawHeaders(u"test\u00E1", [u"lemur"])
     self.assertTrue(h.hasHeader(u"test\u00E1"))
     self.assertTrue(h.hasHeader(u"Test\u00E1"))
     self.assertTrue(h.hasHeader(b"test\xe1"))
     self.assertTrue(h.hasHeader(b"Test\xe1"))
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:13,代码来源:test_http_headers.py

示例2: test_nameNotEncodable

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import hasHeader [as 别名]
    def test_nameNotEncodable(self):
        """
        Passing L{unicode} to any function that takes a header name will encode
        said header name as ISO-8859-1, and if it cannot be encoded, it will
        raise a L{UnicodeDecodeError}.
        """
        h = Headers()

        # Only these two functions take names
        with self.assertRaises(UnicodeEncodeError):
            h.setRawHeaders(u"\u2603", [u"val"])

        with self.assertRaises(UnicodeEncodeError):
            h.hasHeader(u"\u2603")
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:16,代码来源:test_http_headers.py

示例3: test_setRawHeaders

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import hasHeader [as 别名]
 def test_setRawHeaders(self):
     """
     L{Headers.setRawHeaders} sets the header values for the given
     header name to the sequence of strings, encoded.
     """
     rawValue = [u"value1", u"value2"]
     rawEncodedValue = [b"value1", b"value2"]
     h = Headers()
     h.setRawHeaders("test", rawValue)
     self.assertTrue(h.hasHeader(b"test"))
     self.assertTrue(h.hasHeader(b"Test"))
     self.assertTrue(h.hasHeader("test"))
     self.assertTrue(h.hasHeader("Test"))
     self.assertEqual(h.getRawHeaders("test"), rawValue)
     self.assertEqual(h.getRawHeaders(b"test"), rawEncodedValue)
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:17,代码来源:test_http_headers.py

示例4: test_removeHeader

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import hasHeader [as 别名]
    def test_removeHeader(self):
        """
        Check that L{Headers.removeHeader} removes the given header.
        """
        h = Headers()

        h.setRawHeaders("foo", ["lemur"])
        self.assertTrue(h.hasHeader("foo"))
        h.removeHeader("foo")
        self.assertFalse(h.hasHeader("foo"))

        h.setRawHeaders("bar", ["panda"])
        self.assertTrue(h.hasHeader("bar"))
        h.removeHeader("Bar")
        self.assertFalse(h.hasHeader("bar"))
开发者ID:AndyPanda95,项目名称:python-for-android,代码行数:17,代码来源:test_http_headers.py

示例5: request

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import hasHeader [as 别名]
    def request(self, method, uri, headers=None, bodyProducer=None):
        """
        Issue a new request via the configured proxy.
        """

        if version >= Version('twisted', 13, 1, 0):
            parsed_uri = _URI.getFromBytes(uri)
            scheme = parsed_uri.scheme
            host = parsed_uri.host
            port = parsed_uri.port
        else:
            scheme, host, port, path = _parse(uri)
        request_path = uri

        d = self._connect(scheme, host, port)

        if headers is None:
            headers = Headers()
        if not headers.hasHeader('host'):
            # This is a lot of copying.  It might be nice if there were a bit
            # less.
            headers = Headers(dict(headers.getAllRawHeaders()))
            headers.addRawHeader(
                'host', self._computeHostValue(scheme, host, port))

        def cbConnected(proto):
            # NOTE: For the proxy case the path should be the full URI.
            return proto.request(
                Request(method, request_path, headers, bodyProducer))

        d.addCallback(cbConnected)
        return d
开发者ID:lazy404,项目名称:txsuds,代码行数:34,代码来源:twisted_transport.py

示例6: request

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import hasHeader [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

示例7: request

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import hasHeader [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

示例8: test_nameEncoding

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import hasHeader [as 别名]
    def test_nameEncoding(self):
        """
        Passing L{unicode} to any function that takes a header name will encode
        said header name as ISO-8859-1.
        """
        h = Headers()

        # We set it using a Unicode string.
        h.setRawHeaders(u"\u00E1", [b"foo"])

        # It's encoded to the ISO-8859-1 value, which we can use to access it
        self.assertTrue(h.hasHeader(b"\xe1"))
        self.assertEqual(h.getRawHeaders(b"\xe1"), [b'foo'])

        # We can still access it using the Unicode string..
        self.assertTrue(h.hasHeader(u"\u00E1"))
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:18,代码来源:test_http_headers.py

示例9: request

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import hasHeader [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

示例10: test_rawHeadersValueEncoding

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import hasHeader [as 别名]
 def test_rawHeadersValueEncoding(self):
     """
     Passing L{unicode} to L{Headers.setRawHeaders} will encode the name as
     ISO-8859-1 and values as UTF-8.
     """
     h = Headers()
     h.setRawHeaders(u"\u00E1", [u"\u2603", b"foo"])
     self.assertTrue(h.hasHeader(b"\xe1"))
     self.assertEqual(h.getRawHeaders(b"\xe1"), [b'\xe2\x98\x83', b'foo'])
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:11,代码来源:test_http_headers.py

示例11: _FakeUrllib2Request

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import hasHeader [as 别名]
class _FakeUrllib2Request(object):
    """
    A fake C{urllib2.Request} object for C{cookielib} to work with.

    @see: U{http://docs.python.org/library/urllib2.html#request-objects}

    @type uri: C{str}
    @ivar uri: Request URI.

    @type headers: L{twisted.web.http_headers.Headers}
    @ivar headers: Request headers.

    @type type: C{str}
    @ivar type: The scheme of the URI.

    @type host: C{str}
    @ivar host: The host[:port] of the URI.

    @since: 11.1
    """
    def __init__(self, uri):
        self.uri = uri
        self.headers = Headers()
        self.type, rest = splittype(self.uri)
        self.host, rest = splithost(rest)


    def has_header(self, header):
        return self.headers.hasHeader(header)


    def add_unredirected_header(self, name, value):
        self.headers.addRawHeader(name, value)


    def get_full_url(self):
        return self.uri


    def get_header(self, name, default=None):
        headers = self.headers.getRawHeaders(name, default)
        if headers is not None:
            return headers[0]
        return None


    def get_host(self):
        return self.host


    def get_type(self):
        return self.type


    def is_unverifiable(self):
        # In theory this shouldn't be hardcoded.
        return False
开发者ID:GunioRobot,项目名称:twisted,代码行数:59,代码来源:client.py

示例12: test_hasHeaderTrue

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import hasHeader [as 别名]
 def test_hasHeaderTrue(self):
     """
     Check that L{Headers.hasHeader} returns C{True} when the given header
     is found.
     """
     h = Headers()
     h.setRawHeaders("test", ["lemur"])
     self.assertTrue(h.hasHeader("test"))
     self.assertTrue(h.hasHeader("Test"))
开发者ID:AndyPanda95,项目名称:python-for-android,代码行数:11,代码来源:test_http_headers.py

示例13: request

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import hasHeader [as 别名]
    def request(self, method, uri, headers=None, bodyProducer=None):
        """
        Issue a new request.
        @param method: The request method to send.
        @type method: C{str}
        @param uri: The request URI send.
        @type uri: C{str}
        @param scheme: A string like C{'http'} or C{'https'} (the only two
            supported values) to use to determine how to establish the
            connection.
 
        @param host: A C{str} giving the hostname which will be connected to in
            order to issue a request.

        @param port: An C{int} giving the port number the connection will be on.

        @param path: A C{str} giving the path portion of the request URL.
        @param headers: The request headers to send.  If no I{Host} header is
            included, one will be added based on the request URI.
        @type headers: L{Headers}
        @param bodyProducer: An object which will produce the request body or,
            if the request body is to be empty, L{None}.
        @type bodyProducer: L{IBodyProducer} provider
        @return: A L{Deferred} which fires with the result of the request (a
            L{Response} instance), or fails if there is a problem setting up a
            connection over which to issue the request.  It may also fail with
            L{SchemeNotSupported} if the scheme of the given URI is not
            supported.
        @rtype: L{Deferred}
        """
        scheme, host, port, path = _parse(uri)
        if headers is None:
            headers = Headers()
        if not headers.hasHeader('host'):
            # This is a lot of copying.  It might be nice if there were a bit
            # less.
            headers = Headers(dict(headers.getAllRawHeaders()))
            headers.addRawHeader(
                'host', self._computeHostValue(scheme, host, port))
        if self.persistent:
            sem = self._semaphores.get((scheme, host, port))
            if sem is None:
                sem = DeferredSemaphore(self.maxConnectionsPerHostName)
                self._semaphores[scheme, host, port] = sem
            return sem.run(self._request, method, scheme, host, port, path,
                           headers, bodyProducer)
        else:
            return self._request(
                method, scheme, host, port, path, headers, bodyProducer)
开发者ID:Hexadite-Omri,项目名称:txwinrm,代码行数:51,代码来源:_zenclient.py

示例14: request

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

        @param method: The request method to send.
        @type method: C{str}

        @param uri: The request URI send.
        @type uri: C{str}

        @param headers: The request headers to send.  If no I{Host} header is
            included, one will be added based on the request URI.
        @type headers: L{Headers}

        @param bodyProducer: An object which will produce the request body or,
            if the request body is to be empty, L{None}.
        @type bodyProducer: L{IBodyProducer} provider

        @return: A L{Deferred} which fires with the result of the request (a
            L{Response} instance), or fails if there is a problem setting up a
            connection over which to issue the request.  It may also fail with
            L{SchemeNotSupported} if the scheme of the given URI is not
            supported.
        @rtype: L{Deferred}
        """
        scheme, host, port, path = _parse(uri)
        if scheme != 'http':
            return defer.fail(SchemeNotSupported(
                    "Unsupported scheme: %r" % (scheme,)))
        cc = ClientCreator(self._reactor, self._protocol)
        d = cc.connectTCP(host, port)
        if headers is None:
            headers = Headers()
        if not headers.hasHeader('host'):
            # This is a lot of copying.  It might be nice if there were a bit
            # less.
            headers = Headers(dict(headers.getAllRawHeaders()))
            headers.addRawHeader(
                'host', self._computeHostValue(scheme, host, port))
        def cbConnected(proto):
            return proto.request(Request(method, path, headers, bodyProducer))
        d.addCallback(cbConnected)
        return d
开发者ID:NicolaeNMV,项目名称:Tsunami,代码行数:45,代码来源:client.py

示例15: _requestWithEndpoint

# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import hasHeader [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:0xfab,项目名称:scrapy,代码行数:21,代码来源:client.py


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