How to use gzip_uncompress method in avocado

Best Python code snippet using avocado_python

downTXT.py

Source:downTXT.py Github

copy

Full Screen

...15import log1617logger = log.Log(config.log_dir, config.log_name)1819def gzip_uncompress(c_data):20 buf = StringIO(c_data)21 f = gzip.GzipFile(mode = 'rb', fileobj = buf)22 try:23 r_data = f.read()24 finally:25 f.close()26 return r_data2728class DownTXT(object):29 getDocInfo = 'https://wenku.baidu.com/api/doc/getdocinfo?callback=cb'30 downDocUrl = 'https://wkretype.bdimg.com/retype/text/'3132 def __init__(self, fileDir, url, info):33 self.fileDir = './' + fileDir + '/'34 self.URL = url35 self.WkInfo = info36 if not os.path.exists(self.fileDir):37 os.mkdir(self.fileDir)3839 def down(self):40 docID = self.URL[self.URL.rfind('/') + 1 : self.URL.find('.html')]41 reqHeader = config.reqHeaderBDWK42 reqHeader['Referer'] = self.URL43 reqHeader['HOST'] = 'wenku.baidu.com'44 # 获取文档信息45 # url: https://wenku.baidu.com/api/doc/getdocinfo?callback=cb&doc_id=60108d36336c1eb91a375dd2&t=1524896355038&_=152489635426446 ms = int(time.time() * 1000)47 reqUrl = DownTXT.getDocInfo + '&doc_id=' + docID + '&t=' + str(ms+2000) + '&_=' + str(ms)48 logger.info(reqUrl)49 req = urllib2.Request(reqUrl, headers=reqHeader)50 response = urllib2.urlopen(req)51 res = response.read()52 logger.info('响应头信息:' + str(response.headers))53 #if response.headers['Transfer-Encoding'] == 'chunked':54 # res = decode_chunked(res)55 if response.headers['Content-Encoding'] == 'gzip':56 res = gzip_uncompress(res)57 logger.info('getDocInfo 响应信息: ' + res)58 docInfo = res[res.find('(')+1 : res.rfind(')')]59 docInfo = json.loads(docInfo)60 # 获取文档内容61 reqUrl = DownTXT.downDocUrl + docID + '?type=txt&callback=cb&pn=1&rn=' + str(self.WkInfo['totalPageNum']) +\62 '&rsign=' + docInfo['rsign'] + '&_=' + str(ms) + docInfo['md5sum']63 reqHeader['HOST'] = 'wkretype.bdimg.com'64 req = urllib2.Request(reqUrl, headers=reqHeader)65 response = urllib2.urlopen(req)66 res = response.read()67 if response.headers['Content-Encoding'] == 'gzip':68 res = gzip_uncompress(res)69 docContent = res[res.find('(')+1 : res.rfind(')')]70 docContent = json.loads(docContent)71 # 保存内容到txt文件72 txtFileName = self.fileDir + self.WkInfo['title'] + '.' + self.WkInfo['docType']73 fp = open(txtFileName, 'w')74 for dc in docContent:75 fp.write(dc['parags'][0]['c'])76 fp.close() ...

Full Screen

Full Screen

decode_gzip_base64.py

Source:decode_gzip_base64.py Github

copy

Full Screen

...1112# 有人问密文是什么加密,有人注意到是 gzip + base64 , 貌似是python2的1314def de_ciper():15 print(gzip_uncompress(base64.b64decode(16 "H4sIAAmhtGAA/2NgZGBg+A8EIBoEWEAMvuDK4pLUXD2n/Pyc1MQ8kBB7bnxZYk5pKgMjIzcAmxcDozUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==")))171819def gzip_uncompress(c_data):20 try:21 buf = BytesIO(c_data)22 print(gzip.GzipFile(mode='rb', fileobj=buf).read())23 except Exception as e:24 print("uncompress wrong" + e)252627# de_ciper()2829if __name__ == '__main__':3031 txt = de_ciper() ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful