def clean_file(self): file = self.cleaned_data.get('file', '') #check a file in form for viruses if file: from tempfile import mkstemp import pyclamav import os tmpfile = mkstemp()[1] f = open(tmpfile, 'wb') f.write(file.content) f.close() isvirus, name = pyclamav.scanfile(tmpfile) os.unlink(tmpfile) if isvirus: raise forms.ValidationError( \ "WARNING! Virus \"%s\" was detected in this file. \ Check your system." % name) return file