Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
周伟奇
/
bmw-ocr
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
e1915d08
authored
2022-09-08 17:18:12 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix AESZipFile and code review
1 parent
6966f069
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
32 deletions
src/apps/doc/ocr/ecm.py
src/common/tools/file_tools.py
src/apps/doc/ocr/ecm.py
View file @
e1915d0
...
...
@@ -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
=
{
...
...
src/common/tools/file_tools.py
View file @
e1915d0
import
os
import
re
import
zipfile
import
zipfile
s
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
AES
ZipFile
(
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
zipfile
s
.
ZipFile
(
file_path
)
as
zf
:
zf
.
extractall
(
extract_path
)
except
Exception
as
e
:
return
False
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment