fix AESZipFile and code review
Showing
2 changed files
with
6 additions
and
32 deletions
... | @@ -81,33 +81,6 @@ class ECM: | ... | @@ -81,33 +81,6 @@ class ECM: |
81 | def get_headers(self): | 81 | def get_headers(self): |
82 | return {'Authorization': '{0} {1}'.format(self.token_type, self.get_oauth_token())} | 82 | return {'Authorization': '{0} {1}'.format(self.token_type, self.get_oauth_token())} |
83 | 83 | ||
84 | def search(self, application_id, business_type, prefix): | ||
85 | sql = "select * from {0} where b_application_no='{1}' and object_name like '{2}%'".format( | ||
86 | self.settlement_type, application_id, prefix) | ||
87 | search_args = { | ||
88 | "userName": self.username, | ||
89 | "password": self.pwd, | ||
90 | "docbase": self.doc_base_map.get(business_type), | ||
91 | "documentType": self.settlement_type, | ||
92 | "dql": sql | ||
93 | } | ||
94 | response = requests.post(self.search_url, headers=self.get_headers(), json=search_args, verify=False) | ||
95 | if response.status_code != 200: | ||
96 | raise ECMException('ECM search failed with code: {0} , with headers: {1}'.format( | ||
97 | response.status_code, response.headers)) | ||
98 | result = [] | ||
99 | for object_dict in response.json().get('Envelope', {}).get('Body', {}).get('executeResponse', {}).get( | ||
100 | 'return', {}).get('dataPackage', {}).get('DataObjects', []): | ||
101 | object_id = object_dict.get('Identity', {}).get('ObjectId', {}).get('@id', '') | ||
102 | object_name = '' | ||
103 | for attr_dict in object_dict.get('Properties', {}).get('Properties', []): | ||
104 | if attr_dict.get('@name', '') == 'object_name': | ||
105 | object_name = attr_dict.get('Value', '') | ||
106 | break | ||
107 | if len(object_id) > 0 and len(object_name) > 0: | ||
108 | result.append((object_name, object_id)) | ||
109 | return result | ||
110 | |||
111 | def download(self, save_path, object_id, document_scheme, business_type): | 84 | def download(self, save_path, object_id, document_scheme, business_type): |
112 | doc_type, _, _ = self.doc_type_map.get(document_scheme) | 85 | doc_type, _, _ = self.doc_type_map.get(document_scheme) |
113 | download_json = { | 86 | download_json = { | ... | ... |
1 | import os | 1 | import os |
2 | import re | 2 | import re |
3 | import zipfile | 3 | import zipfiles |
4 | 4 | ||
5 | import rarfile | 5 | import rarfile |
6 | from zipfile import ZipFile | 6 | # from zipfile import ZipFile |
7 | from pyzipper import AESZipFile | ||
7 | 8 | ||
8 | 9 | ||
9 | def file_write(file, file_path): | 10 | def file_write(file, file_path): |
... | @@ -15,7 +16,7 @@ def file_write(file, file_path): | ... | @@ -15,7 +16,7 @@ def file_write(file, file_path): |
15 | def write_zip_file(dir_name, zipfile_path): | 16 | def write_zip_file(dir_name, zipfile_path): |
16 | if not os.path.isdir(dir_name): | 17 | if not os.path.isdir(dir_name): |
17 | return | 18 | return |
18 | with ZipFile(zipfile_path, 'w') as z: | 19 | with zipfiles.ZipFile(zipfile_path, 'w') as z: |
19 | for root, dirs, files in os.walk(dir_name): | 20 | for root, dirs, files in os.walk(dir_name): |
20 | root_target_path = root.replace(dir_name, '') | 21 | root_target_path = root.replace(dir_name, '') |
21 | for single_file in files: | 22 | for single_file in files: |
... | @@ -37,7 +38,7 @@ def extract_zip_or_rar(file_path, extract_path, pwd_list=[]): | ... | @@ -37,7 +38,7 @@ def extract_zip_or_rar(file_path, extract_path, pwd_list=[]): |
37 | if len(pwd_list) > 0: | 38 | if len(pwd_list) > 0: |
38 | for password in pwd_list: | 39 | for password in pwd_list: |
39 | try: | 40 | try: |
40 | with zipfile.ZipFile(file_path) as zf: | 41 | with AESZipFile(file_path) as zf: |
41 | zf.extractall(extract_path, pwd=bytes(password, 'utf-8')) | 42 | zf.extractall(extract_path, pwd=bytes(password, 'utf-8')) |
42 | except Exception as e: | 43 | except Exception as e: |
43 | continue | 44 | continue |
... | @@ -47,7 +48,7 @@ def extract_zip_or_rar(file_path, extract_path, pwd_list=[]): | ... | @@ -47,7 +48,7 @@ def extract_zip_or_rar(file_path, extract_path, pwd_list=[]): |
47 | return False | 48 | return False |
48 | else: | 49 | else: |
49 | try: | 50 | try: |
50 | with zipfile.ZipFile(file_path) as zf: | 51 | with zipfiles.ZipFile(file_path) as zf: |
51 | zf.extractall(extract_path) | 52 | zf.extractall(extract_path) |
52 | except Exception as e: | 53 | except Exception as e: |
53 | return False | 54 | return False | ... | ... |
-
Please register or sign in to post a comment