D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
thread-self
/
root
/
usr
/
share
/
doc
/
python3-pycurl
/
examples
/
tests
/
Filename :
test_build_config.py
back
Copy
#! /usr/bin/env python # -*- coding: utf-8 -*- # vi:ts=4:et import pycurl import zlib try: from io import BytesIO except ImportError: try: from cStringIO import StringIO as BytesIO except ImportError: from StringIO import StringIO as BytesIO c = pycurl.Curl() c.setopt(c.URL, 'http://pycurl.io') #c.setopt(c.ENCODING, 'deflate') c.setopt(c.HTTPHEADER, ['Accept-Encoding: deflate']) body = BytesIO() c.setopt(c.WRITEFUNCTION, body.write) encoding_found = False def header_function(header): global encoding_found if header.decode('iso-8859-1').lower().startswith('content-encoding: deflate'): encoding_found = True c.setopt(c.HEADERFUNCTION, header_function) c.perform() assert encoding_found print('Server supports deflate encoding') encoded = body.getvalue() # should not raise exceptions zlib.decompress(encoded, -zlib.MAX_WBITS) print('Server served deflated body') c.reset() c.setopt(c.URL, 'http://pycurl.io') c.setopt(c.ENCODING, 'deflate') body = BytesIO() c.setopt(c.WRITEFUNCTION, body.write) encoding_found = False def header_function(header): global encoding_found if header.decode('iso-8859-1').lower().startswith('content-encoding: deflate'): encoding_found = True c.setopt(c.HEADERFUNCTION, header_function) c.perform() assert encoding_found print('Server claimed deflate encoding as expected') # body should be decoded encoded = body.getvalue() if '<html' in encoded.decode('iso-8859-1').lower(): print('Curl inflated served body') else: fail = False try: zlib.decompress(encoded, -zlib.MAX_WBITS) print('Curl did not inflate served body') fail = True except: print('Weird') fail = True if fail: assert False c.close()
Name
Size
Last Modified
Owner
Permissions
Actions
test_build_config.py
1.724
KB
December 03 2017 7:03:13
root
0644
test_gtk.py
2.598
KB
December 03 2017 7:03:17
root
0644
test_xmlrpc.py
0.731
KB
August 30 2017 1:46:03
root
0644
2017 © D7net | D704T team