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)
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
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)
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