File tree Expand file tree Collapse file tree 1 file changed +27
-16
lines changed Expand file tree Collapse file tree 1 file changed +27
-16
lines changed Original file line number Diff line number Diff line change 1- #!/usr/bin/env python
2- # -*- coding: utf-8 -*-
3- from __future__ import unicode_literals
4-
51try :
6- __version__ = __import__ ('pkg_resources' ).get_distribution ('clamd' ).version
7- except :
8- __version__ = ''
9-
10- # $Source$
2+ import importlib
113
4+ __version__ = importlib .metadata .distribution ("clamd" ).version
5+ except ImportError :
6+ __version__ = ""
127
13- import socket
14- import sys
15- import struct
8+ import base64
169import contextlib
1710import re
18- import base64
11+ import socket
12+ import struct
13+ import sys
14+ from multiprocessing .reduction import sendfds
1915
20- scan_response = re .compile (r"^(?P<path>.*): ((?P<virus>.+) )?(?P<status>(FOUND|OK|ERROR))$" )
16+ scan_response = re .compile (
17+ r"^(?P<path>.*): ((?P<virus>.+) )?(?P<status>(FOUND|OK|ERROR))$"
18+ )
2119EICAR = base64 .b64decode (
22- b' WDVPIVAlQEFQWzRcUFpYNTQoUF4pN0NDKTd9JEVJQ0FSLVNUQU5E'
23- b' QVJELUFOVElWSVJVUy1URVNU\n LUZJTEUhJEgrSCo=\n '
20+ b" WDVPIVAlQEFQWzRcUFpYNTQoUF4pN0NDKTd9JEVJQ0FSLVNUQU5E"
21+ b" QVJELUFOVElWSVJVUy1URVNU\n LUZJTEUhJEgrSCo=\n "
2422)
2523
2624
@@ -313,3 +311,16 @@ def _error_message(self, exception):
313311 path = self .unix_socket ,
314312 msg = exception .args [1 ]
315313 )
314+
315+ def fdscan (self , file ):
316+ """Scan a file referenced by a file descriptor."""
317+ try :
318+ self ._init_socket ()
319+ with open (file , mode = "rb" ) as fp :
320+ self ._send_command ("FILDES" )
321+ sendfds (self .clamd_socket , [fp .fileno ()])
322+ result = self ._recv_response ()
323+ _ , reason , status = self ._parse_response (result )
324+ return {file : (status , reason )}
325+ finally :
326+ self ._close_socket ()
You can’t perform that action at this time.
0 commit comments