e1915d08 by 周伟奇

fix AESZipFile and code review

1 parent 6966f069
......@@ -81,33 +81,6 @@ class ECM:
def get_headers(self):
return {'Authorization': '{0} {1}'.format(self.token_type, self.get_oauth_token())}
def search(self, application_id, business_type, prefix):
sql = "select * from {0} where b_application_no='{1}' and object_name like '{2}%'".format(
self.settlement_type, application_id, prefix)
search_args = {
"userName": self.username,
"password": self.pwd,
"docbase": self.doc_base_map.get(business_type),
"documentType": self.settlement_type,
"dql": sql
}
response = requests.post(self.search_url, headers=self.get_headers(), json=search_args, verify=False)
if response.status_code != 200:
raise ECMException('ECM search failed with code: {0} , with headers: {1}'.format(
response.status_code, response.headers))
result = []
for object_dict in response.json().get('Envelope', {}).get('Body', {}).get('executeResponse', {}).get(
'return', {}).get('dataPackage', {}).get('DataObjects', []):
object_id = object_dict.get('Identity', {}).get('ObjectId', {}).get('@id', '')
object_name = ''
for attr_dict in object_dict.get('Properties', {}).get('Properties', []):
if attr_dict.get('@name', '') == 'object_name':
object_name = attr_dict.get('Value', '')
break
if len(object_id) > 0 and len(object_name) > 0:
result.append((object_name, object_id))
return result
def download(self, save_path, object_id, document_scheme, business_type):
doc_type, _, _ = self.doc_type_map.get(document_scheme)
download_json = {
......
import os
import re
import zipfile
import zipfiles
import rarfile
from zipfile import ZipFile
# from zipfile import ZipFile
from pyzipper import AESZipFile
def file_write(file, file_path):
......@@ -15,7 +16,7 @@ def file_write(file, file_path):
def write_zip_file(dir_name, zipfile_path):
if not os.path.isdir(dir_name):
return
with ZipFile(zipfile_path, 'w') as z:
with zipfiles.ZipFile(zipfile_path, 'w') as z:
for root, dirs, files in os.walk(dir_name):
root_target_path = root.replace(dir_name, '')
for single_file in files:
......@@ -37,7 +38,7 @@ def extract_zip_or_rar(file_path, extract_path, pwd_list=[]):
if len(pwd_list) > 0:
for password in pwd_list:
try:
with zipfile.ZipFile(file_path) as zf:
with AESZipFile(file_path) as zf:
zf.extractall(extract_path, pwd=bytes(password, 'utf-8'))
except Exception as e:
continue
......@@ -47,7 +48,7 @@ def extract_zip_or_rar(file_path, extract_path, pwd_list=[]):
return False
else:
try:
with zipfile.ZipFile(file_path) as zf:
with zipfiles.ZipFile(file_path) as zf:
zf.extractall(extract_path)
except Exception as e:
return False
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!