Skip to content

Commit

Permalink
Merge 7b4e229 into 1188b8c
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiot committed Jul 15, 2019
2 parents 1188b8c + 7b4e229 commit e86dde0
Show file tree
Hide file tree
Showing 10 changed files with 1,600 additions and 402 deletions.
6 changes: 0 additions & 6 deletions Pipfile
Expand Up @@ -3,11 +3,6 @@ name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[[source]]
name = "lief_index"
url = "https://lief-project.github.io/packages/"
verify_ssl = true

[dev-packages]
nose = "*"
coveralls = "*"
Expand All @@ -17,7 +12,6 @@ requests-mock = "*"
[packages]
pymisp = {editable = true,extras = ["fileobjects", "neo", "openioc", "virustotal", "pdfexport"],path = "."}
pymispwarninglists = {editable = true,git = "https://github.com/MISP/PyMISPWarningLists.git"}
lief = {version = ">=0.10.0.dev0",index = "lief_index",markers = "python_version >= '3.5'"}

[requires]
python_version = "3"
Expand Down
82 changes: 44 additions & 38 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion examples/generate_file_objects.py
Expand Up @@ -5,7 +5,7 @@
import json

try:
from pymisp import MISPEncode
from pymisp import MISPEncode, AbstractMISP
from pymisp.tools import make_binary_objects
except ImportError:
pass
Expand Down Expand Up @@ -59,6 +59,7 @@ def make_objects(path):
group.add_argument("-p", "--path", help="Path to process.")
group.add_argument("-c", "--check", action='store_true', help="Check the dependencies.")
args = parser.parse_args()
a = AbstractMISP()

if args.check:
print(check())
Expand Down
32 changes: 14 additions & 18 deletions pymisp/__init__.py
@@ -1,6 +1,5 @@
__version__ = '2.4.111'
import logging
import functools
import warnings
import sys

Expand All @@ -14,28 +13,26 @@
logger.setLevel(logging.WARNING)


def deprecated(func):
'''This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emitted
when the function is used.'''
def warning_2020():

@functools.wraps(func)
def new_func(*args, **kwargs):
warnings.showwarning(
"Call to deprecated function {}.".format(func.__name__),
category=DeprecationWarning,
filename=func.__code__.co_filename,
lineno=func.__code__.co_firstlineno + 1
)
return func(*args, **kwargs)
return new_func
if sys.version_info < (3, 6):
warnings.warn("""
Python 2.7 is officially end of life the 2020-01-01. For this occasion,
we decided to review which versions of Python we support and our conclusion
is to only support python 3.6+ starting the 2020-01-01.
Every version of pymisp released after the 2020-01-01 will fail if the
python interpreter is prior to python 3.6.
**Please update your codebase.**""", DeprecationWarning, stacklevel=3)


try:
warning_2020()
from .exceptions import PyMISPError, NewEventError, NewAttributeError, MissingDependency, NoURL, NoKey, InvalidMISPObject, UnknownMISPObjectTemplate, PyMISPInvalidFormat, MISPServerError, PyMISPNotImplementedYet, PyMISPUnexpectedResponse, PyMISPEmptyResponse # noqa
from .api import PyMISP # noqa
from .abstract import AbstractMISP, MISPEncode, MISPTag, Distribution, ThreatLevel, Analysis # noqa
from .mispevent import MISPEvent, MISPAttribute, MISPObjectReference, MISPObjectAttribute, MISPObject, MISPUser, MISPOrganisation, MISPSighting, MISPLog, MISPShadowAttribute # noqa
from .mispevent import MISPEvent, MISPAttribute, MISPObjectReference, MISPObjectAttribute, MISPObject, MISPUser, MISPOrganisation, MISPSighting, MISPLog, MISPShadowAttribute, MISPWarninglist, MISPTaxonomy, MISPNoticelist, MISPObjectTemplate # noqa
from .tools import AbstractMISPObjectGenerator # noqa
from .tools import Neo4j # noqa
from .tools import stix # noqa
Expand All @@ -44,6 +41,7 @@ def new_func(*args, **kwargs):
from .tools import ext_lookups # noqa

if sys.version_info >= (3, 6):
from .aping import ExpandedPyMISP # noqa
# Let's not bother with old python
try:
from .tools import reportlab_generator # noqa
Expand All @@ -53,8 +51,6 @@ def new_func(*args, **kwargs):
except NameError:
# FIXME: The import should not raise an exception if reportlab isn't installed
pass
if sys.version_info >= (3, 6):
from .aping import ExpandedPyMISP # noqa
logger.debug('pymisp loaded properly')
except ImportError as e:
logger.warning('Unable to load pymisp properly: {}'.format(e))
20 changes: 10 additions & 10 deletions pymisp/abstract.py
Expand Up @@ -13,14 +13,13 @@
# Try to import MutableMapping the python 3.3+ way
try:
from collections.abc import MutableMapping
except:
except Exception:
pass


logger = logging.getLogger('pymisp')

if sys.version_info < (3, 0):
logger.warning("You're using python 2, it is strongly recommended to use python >=3.6")
from collections import MutableMapping

# This is required because Python 2 is a pain.
Expand Down Expand Up @@ -74,7 +73,7 @@ class MISPEncode(JSONEncoder):
def default(self, obj):
if isinstance(obj, AbstractMISP):
return obj.jsonable()
elif isinstance(obj, datetime.datetime):
elif isinstance(obj, (datetime.datetime, datetime.date)):
return obj.isoformat()
elif isinstance(obj, Enum):
return obj.value
Expand Down Expand Up @@ -270,16 +269,17 @@ def __eq__(self, other):
else:
return False

def __repr__(self):
if hasattr(self, 'name'):
return '<{self.__class__.__name__}(name={self.name})'.format(self=self)
return '<{self.__class__.__name__}(NotInitialized)'.format(self=self)


class MISPTag(AbstractMISP):
def __init__(self):
super(MISPTag, self).__init__()

def from_dict(self, name, **kwargs):
self.name = name
def from_dict(self, **kwargs):
if kwargs.get('Tag'):
kwargs = kwargs.get('Tag')
super(MISPTag, self).from_dict(**kwargs)

def __repr__(self):
if hasattr(self, 'name'):
return '<{self.__class__.__name__}(name={self.name})'.format(self=self)
return '<{self.__class__.__name__}(NotInitialized)'.format(self=self)

0 comments on commit e86dde0

Please sign in to comment.