Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ckanext-odsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open-Data
ckanext-odsh
Commits
1707e93a
Commit
1707e93a
authored
5 years ago
by
anonymous
Browse files
Options
Downloads
Patches
Plain Diff
Revert Changes
parent
9ff0190c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ckanext/odsh/lib/odsh_icap_client.py
+13
-13
13 additions, 13 deletions
ckanext/odsh/lib/odsh_icap_client.py
with
13 additions
and
13 deletions
ckanext/odsh/lib/odsh_icap_client.py
+
13
−
13
View file @
1707e93a
...
@@ -4,7 +4,7 @@ import time
...
@@ -4,7 +4,7 @@ import time
from
ckan.common
import
config
from
ckan.common
import
config
import
logging
import
logging
log
=
logging
.
getLogger
(
__name__
)
#
log = logging.getLogger(__name__)
class
ODSHICAPRequest
(
object
):
class
ODSHICAPRequest
(
object
):
...
@@ -18,19 +18,19 @@ class ODSHICAPRequest(object):
...
@@ -18,19 +18,19 @@ class ODSHICAPRequest(object):
self
.
FILEBUFF
=
FILEBUFF
self
.
FILEBUFF
=
FILEBUFF
def
send
(
self
):
def
send
(
self
):
log
.
info
(
"
----- Starting ICAP-Request via RESPMOD -----
"
)
#
log.info("----- Starting ICAP-Request via RESPMOD -----")
# socket connect
# socket connect
try
:
try
:
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
except
socket
.
error
as
msg
:
except
socket
.
error
as
msg
:
log
.
error
(
msg
[
1
])
#
log.error(msg[1])
sys
.
exit
(
1
)
sys
.
exit
(
1
)
try
:
try
:
sock
.
connect
((
self
.
HOST
,
self
.
PORT
))
sock
.
connect
((
self
.
HOST
,
self
.
PORT
))
except
socket
.
error
as
msg
:
except
socket
.
error
as
msg
:
log
.
error
(
msg
[
1
])
#
log.error(msg[1])
sys
.
exit
(
2
)
sys
.
exit
(
2
)
# create and send header
# create and send header
...
@@ -45,7 +45,7 @@ class ODSHICAPRequest(object):
...
@@ -45,7 +45,7 @@ class ODSHICAPRequest(object):
data_response
=
self
.
_recvall
(
sock
)
data_response
=
self
.
_recvall
(
sock
)
response_object
=
self
.
_parse_response
(
data_response
)
response_object
=
self
.
_parse_response
(
data_response
)
log
.
info
(
"
----- Finished ICAP-Request via RESPMOD -----
"
)
#
log.info("----- Finished ICAP-Request via RESPMOD -----")
return
response_object
return
response_object
...
@@ -73,12 +73,12 @@ class ODSHICAPRequest(object):
...
@@ -73,12 +73,12 @@ class ODSHICAPRequest(object):
return
icapRequest
return
icapRequest
def
_sendfile
(
self
,
fileBuffer
,
sock
):
def
_sendfile
(
self
,
fileBuffer
,
sock
):
log
.
info
(
'
Start sending file.
'
)
#
log.info('Start sending file.')
PACK_SIZE
=
1024
# in bytes
PACK_SIZE
=
1024
# in bytes
l
=
fileBuffer
.
read
(
PACK_SIZE
)
l
=
fileBuffer
.
read
(
PACK_SIZE
)
while
(
l
):
while
(
l
):
log
.
info
(
'
Sending {} bytes of data...
'
.
format
(
len
(
l
)))
#
log.info('Sending {} bytes of data...'.format(len(l)))
sock
.
send
(
'
{:02X}
'
.
format
(
len
(
l
)).
encode
())
sock
.
send
(
'
{:02X}
'
.
format
(
len
(
l
)).
encode
())
sock
.
send
(
"
\r\n
"
.
encode
())
sock
.
send
(
"
\r\n
"
.
encode
())
sock
.
send
(
l
)
sock
.
send
(
l
)
...
@@ -86,22 +86,22 @@ class ODSHICAPRequest(object):
...
@@ -86,22 +86,22 @@ class ODSHICAPRequest(object):
l
=
fileBuffer
.
read
(
PACK_SIZE
)
l
=
fileBuffer
.
read
(
PACK_SIZE
)
def
_sendfile_old
(
self
,
fileName
,
sock
):
def
_sendfile_old
(
self
,
fileName
,
sock
):
log
.
info
(
'
OLD: Start sending file.
'
)
#
log.info('OLD: Start sending file.')
PACK_SIZE
=
1024
# in bytes
PACK_SIZE
=
1024
# in bytes
with
open
(
fileName
)
as
f
:
with
open
(
fileName
)
as
f
:
l
=
f
.
read
(
PACK_SIZE
)
l
=
f
.
read
(
PACK_SIZE
)
while
(
l
):
while
(
l
):
log
.
info
(
'
Sending {} bytes of data...
'
.
format
(
len
(
l
)))
#
log.info('Sending {} bytes of data...'.format(len(l)))
sock
.
send
(
'
{:02X}
'
.
format
(
len
(
l
)).
encode
())
sock
.
send
(
'
{:02X}
'
.
format
(
len
(
l
)).
encode
())
sock
.
send
(
"
\r\n
"
.
encode
())
sock
.
send
(
"
\r\n
"
.
encode
())
sock
.
send
(
l
)
sock
.
send
(
l
)
sock
.
send
(
"
\r\n
"
.
encode
())
sock
.
send
(
"
\r\n
"
.
encode
())
l
=
f
.
read
(
PACK_SIZE
)
l
=
f
.
read
(
PACK_SIZE
)
log
.
info
(
'
Done sending.
'
)
#
log.info('Done sending.')
def
_recvall
(
self
,
sock
):
def
_recvall
(
self
,
sock
):
log
.
info
(
'
Receiving response from icap server...
'
)
#
log.info('Receiving response from icap server...')
BUFF_SIZE
=
4096
# 4 KiB
BUFF_SIZE
=
4096
# 4 KiB
data
=
b
''
data
=
b
''
while
True
:
while
True
:
...
@@ -113,7 +113,7 @@ class ODSHICAPRequest(object):
...
@@ -113,7 +113,7 @@ class ODSHICAPRequest(object):
return
data
return
data
def
_parse_response
(
self
,
data_response
):
def
_parse_response
(
self
,
data_response
):
log
.
info
(
'
Parsing response...
'
)
#
log.info('Parsing response...')
lines
=
data_response
.
split
(
'
\r\n
'
)
lines
=
data_response
.
split
(
'
\r\n
'
)
http_status_code
=
self
.
_parse_response_http_statuscode
(
lines
)
http_status_code
=
self
.
_parse_response_http_statuscode
(
lines
)
http_block
=
self
.
_parse_block
(
lines
,
'
HTTP/1.1
'
)
http_block
=
self
.
_parse_block
(
lines
,
'
HTTP/1.1
'
)
...
@@ -163,7 +163,7 @@ class ODSHParsedICAPResponse(object):
...
@@ -163,7 +163,7 @@ class ODSHParsedICAPResponse(object):
def
virus_found
(
self
):
def
virus_found
(
self
):
if
(
self
.
http_status_code
!=
200
)
and
(
self
.
http_status_code
!=
403
):
if
(
self
.
http_status_code
!=
200
)
and
(
self
.
http_status_code
!=
403
):
msg
=
'
Received an unknown http response code: {}
'
.
format
(
self
.
http_status_code
)
msg
=
'
Received an unknown http response code: {}
'
.
format
(
self
.
http_status_code
)
log
.
warning
(
msg
)
#
log.warning(msg)
raise
UnknownResponseException
(
msg
)
raise
UnknownResponseException
(
msg
)
return
self
.
http_status_code
!=
200
return
self
.
http_status_code
!=
200
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment