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
|
import logging
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from .exceptions import PyMISPInvalidFormat
|
from .exceptions import PyMISPInvalidFormat, PyMISPError
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('pymisp')
|
logger = logging.getLogger('pymisp')
|
||||||
|
@ -284,7 +284,7 @@ class AbstractMISP(MutableMapping, MISPFileCache):
|
||||||
|
|
||||||
def _to_feed(self):
|
def _to_feed(self):
|
||||||
if not hasattr(self, '_fields_for_feed'):
|
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 = {}
|
to_return = {}
|
||||||
for field in self._fields_for_feed:
|
for field in self._fields_for_feed:
|
||||||
if getattr(self, field, None) is not None:
|
if getattr(self, field, None) is not None:
|
||||||
|
@ -343,7 +343,7 @@ class AbstractMISP(MutableMapping, MISPFileCache):
|
||||||
if isinstance(val, bool):
|
if isinstance(val, bool):
|
||||||
self.__edited = val
|
self.__edited = val
|
||||||
else:
|
else:
|
||||||
raise Exception('edited can only be True or False')
|
raise PyMISPError('edited can only be True or False')
|
||||||
|
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
if name[0] != '_' and not self.__edited and name in self.keys():
|
if name[0] != '_' and not self.__edited and name in self.keys():
|
||||||
|
|
|
@ -1895,7 +1895,7 @@ class ExpandedPyMISP(PyMISP):
|
||||||
if adhereToWarninglists in wl_params:
|
if adhereToWarninglists in wl_params:
|
||||||
query['adhereToWarninglists'] = adhereToWarninglists
|
query['adhereToWarninglists'] = adhereToWarninglists
|
||||||
else:
|
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:
|
if distribution is not None:
|
||||||
query['distribution'] = distribution
|
query['distribution'] = distribution
|
||||||
if returnMetaAttributes:
|
if returnMetaAttributes:
|
||||||
|
|
|
@ -99,7 +99,7 @@ def make_bool(value):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
raise Exception('Unable to convert {} to a boolean.'.format(value))
|
raise PyMISPError('Unable to convert {} to a boolean.'.format(value))
|
||||||
|
|
||||||
|
|
||||||
class MISPAttribute(AbstractMISP):
|
class MISPAttribute(AbstractMISP):
|
||||||
|
@ -378,7 +378,7 @@ class MISPAttribute(AbstractMISP):
|
||||||
try:
|
try:
|
||||||
with ZipFile(self.data) as f:
|
with ZipFile(self.data) as f:
|
||||||
if not self.__is_misp_encrypted_file(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():
|
for name in f.namelist():
|
||||||
if name.endswith('.filename.txt'):
|
if name.endswith('.filename.txt'):
|
||||||
with f.open(name, pwd=b'infected') as unpacked:
|
with f.open(name, pwd=b'infected') as unpacked:
|
||||||
|
@ -798,7 +798,7 @@ class MISPEvent(AbstractMISP):
|
||||||
attributes.append(a)
|
attributes.append(a)
|
||||||
|
|
||||||
if not attributes:
|
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
|
self.edited = True
|
||||||
return attributes
|
return attributes
|
||||||
|
|
||||||
|
@ -820,7 +820,7 @@ class MISPEvent(AbstractMISP):
|
||||||
found = True
|
found = True
|
||||||
break
|
break
|
||||||
if not found:
|
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):
|
def add_attribute(self, type, value, **kwargs):
|
||||||
"""Add an attribute. type and value are required but you can pass all
|
"""Add an attribute. type and value are required but you can pass all
|
||||||
|
|
Loading…
Reference in New Issue