コード例 #1
0
    def test_parseAcceptEncoding(self):
        """
        Test the parsing of a variety of Accept-Encoding field values.
        """
        cases = [('compress, gzip', {
            'compress': 1.0,
            'gzip': 1.0,
            'identity': 0.0001
        }), ('', {
            'identity': 0.0001
        }), ('*', {
            '*': 1
        }),
                 ('compress;q=0.5, gzip;q=1.0', {
                     'compress': 0.5,
                     'gzip': 1.0,
                     'identity': 0.0001
                 }),
                 ('gzip;q=1.0, identity;q=0.5, *;q=0', {
                     'gzip': 1.0,
                     'identity': 0.5,
                     '*': 0
                 })]

        for value, result in cases:
            self.assertEqual(parseAcceptEncoding(value),
                             result,
                             msg='error parsing %r' % value)
コード例 #2
0
 def canCompress(self, req):
     """
     Check whether the client has negotiated a content encoding we support.
     """
     value = req.getHeader('accept-encoding')
     if value is not None:
         encodings = parseAcceptEncoding(value)
         return encodings.get('gzip', 0.0) > 0.0
     return False
コード例 #3
0
ファイル: test_compression.py プロジェクト: StetHD/nevow
    def test_parseAcceptEncoding(self):
        """
        Test the parsing of a variety of Accept-Encoding field values.
        """
        cases = [
            ('compress, gzip',
             {'compress': 1.0, 'gzip': 1.0, 'identity': 0.0001}),
            ('',
             {'identity': 0.0001}),
            ('*',
             {'*': 1}),
            ('compress;q=0.5, gzip;q=1.0',
             {'compress': 0.5, 'gzip': 1.0, 'identity': 0.0001}),
            ('gzip;q=1.0, identity;q=0.5, *;q=0',
             {'gzip': 1.0, 'identity': 0.5, '*': 0})
            ]

        for value, result in cases:
            self.assertEqual(parseAcceptEncoding(value), result, msg='error parsing %r' % value)
コード例 #4
0
 def canCompress(req):
     value = req.getHeader('accept-encoding')
     if value is not None:
         encodings = parseAcceptEncoding(value)
         return encodings.get('gzip', 0.0) > 0.0
     return False