Skip to content

Commit f543f6a

Browse files
committed
raise ERROR responses from clamd as ResponseErrors
1 parent 2554281 commit f543f6a

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

clamd.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ResponseError(ClamdError):
6060
pass
6161

6262

63-
class BufferTooLongError(ClamdError):
63+
class BufferTooLongError(ResponseError):
6464
"""Class for errors with clamd using INSTREAM with a buffer lenght > StreamMaxLength in /etc/clamav/clamd.conf"""
6565

6666

@@ -156,7 +156,11 @@ def _basic_command(self, command):
156156
self._init_socket()
157157
try:
158158
self._send_command(command)
159-
return self._recv_response()
159+
response = self._recv_response().rsplit("ERROR", 1)
160+
if len(response) > 1:
161+
raise ResponseError(response[0])
162+
else:
163+
return response[0]
160164
finally:
161165
self._close_socket()
162166

@@ -290,7 +294,10 @@ def _parse_response(self, msg):
290294
"""
291295
parses responses for SCAN, CONTSCAN, MULTISCAN and STREAM commands.
292296
"""
293-
return scan_response.match(msg).group("path", "virus", "status")
297+
try:
298+
return scan_response.match(msg).group("path", "virus", "status")
299+
except AttributeError:
300+
raise ResponseError(msg.rsplit("ERROR", 1)[0])
294301

295302

296303
class ClamdUnixSocket(ClamdNetworkSocket):

0 commit comments

Comments
 (0)