mirror of https://github.com/MISP/PyMISP
fix: Raise PyMISPError instead of Exception
parent
4fed55a09d
commit
446649992f
|
@ -24,7 +24,7 @@ except ImportError:
|
|||
import logging
|
||||
from enum import Enum
|
||||
|
||||
from .exceptions import PyMISPInvalidFormat
|
||||
from .exceptions import PyMISPInvalidFormat, PyMISPError
|
||||
|
||||
|
||||
logger = logging.getLogger('pymisp')
|
||||
|
@ -284,7 +284,7 @@ class AbstractMISP(MutableMapping, MISPFileCache):
|
|||
|
||||
def _to_feed(self):
|
||||
if not hasattr(self, '_fields_for_feed'):
|
||||
raise Exception('Unable to export in the feed format, _fields_for_feed is missing.')
|
||||
raise PyMISPError('Unable to export in the feed format, _fields_for_feed is missing.')
|
||||
to_return = {}
|
||||
for field in self._fields_for_feed:
|
||||
if getattr(self, field, None) is not None:
|
||||
|
@ -343,7 +343,7 @@ class AbstractMISP(MutableMapping, MISPFileCache):
|
|||
if isinstance(val, bool):
|
||||
self.__edited = val
|
||||
else:
|
||||
raise Exception('edited can only be True or False')
|
||||
raise PyMISPError('edited can only be True or False')
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name[0] != '_' and not self.__edited and name in self.keys():
|
||||
|
|
|
@ -1895,7 +1895,7 @@ class ExpandedPyMISP(PyMISP):
|
|||
if adhereToWarninglists in wl_params:
|
||||
query['adhereToWarninglists'] = adhereToWarninglists
|
||||
else:
|
||||
raise Exception('Invalid parameter, adhereToWarninglists Can only be {}'.format(', '.join(wl_params)))
|
||||
raise PyMISPError('Invalid parameter, adhereToWarninglists Can only be {}'.format(', '.join(wl_params)))
|
||||
if distribution is not None:
|
||||
query['distribution'] = distribution
|
||||
if returnMetaAttributes:
|
||||
|
|
|
@ -99,7 +99,7 @@ def make_bool(value):
|
|||
return False
|
||||
return True
|
||||
else:
|
||||
raise Exception('Unable to convert {} to a boolean.'.format(value))
|
||||
raise PyMISPError('Unable to convert {} to a boolean.'.format(value))
|
||||
|
||||
|
||||
class MISPAttribute(AbstractMISP):
|
||||
|
@ -378,7 +378,7 @@ class MISPAttribute(AbstractMISP):
|
|||
try:
|
||||
with ZipFile(self.data) as f:
|
||||
if not self.__is_misp_encrypted_file(f):
|
||||
raise Exception('Not an existing malware sample')
|
||||
raise PyMISPError('Not an existing malware sample')
|
||||
for name in f.namelist():
|
||||
if name.endswith('.filename.txt'):
|
||||
with f.open(name, pwd=b'infected') as unpacked:
|
||||
|
@ -798,7 +798,7 @@ class MISPEvent(AbstractMISP):
|
|||
attributes.append(a)
|
||||
|
||||
if not attributes:
|
||||
raise Exception('No attribute with identifier {} found.'.format(attribute_identifier))
|
||||
raise PyMISPError('No attribute with identifier {} found.'.format(attribute_identifier))
|
||||
self.edited = True
|
||||
return attributes
|
||||
|
||||
|
@ -820,7 +820,7 @@ class MISPEvent(AbstractMISP):
|
|||
found = True
|
||||
break
|
||||
if not found:
|
||||
raise Exception('No attribute with UUID/ID {} found.'.format(attribute_id))
|
||||
raise PyMISPError('No attribute with UUID/ID {} found.'.format(attribute_id))
|
||||
|
||||
def add_attribute(self, type, value, **kwargs):
|
||||
"""Add an attribute. type and value are required but you can pass all
|
||||
|
|
Loading…
Reference in New Issue