cleanup style

pull/1/head
Raphaël Vinot 2014-04-14 10:55:20 +02:00
parent ac482e8f00
commit 93ddd4cf50
1 changed files with 22 additions and 22 deletions

View File

@ -1,12 +1,14 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Python API for MISP """
import requests
class PyMISP(object):
""" Python API for MISP, you will need the URL
of the instnce you want to query, and the auth key of your user."""
def __init__(self, url, key, out_type='json'):
self.url = url + '/events'
@ -14,7 +16,6 @@ class PyMISP(object):
self.out_type = out_type
self.rest = self.url + '/{}'
def __prepare_session(self, force_out=None):
"""
Prepare the headers of the session
@ -24,12 +25,12 @@ class PyMISP(object):
else:
out = self.out_type
session = requests.Session()
session.headers.update({'Authorization': self.key,
session.headers.update(
{'Authorization': self.key,
'Accept': 'application/' + out,
'content-type': 'text/' + out})
return session
# ############### REST API ################
def get_index(self):
@ -78,7 +79,7 @@ class PyMISP(object):
"""
to_return = ''
if values is not None:
if type(values) != type([]):
if not isinstance(values, list):
to_return += values
else:
to_return += '&&'.join(values)
@ -87,7 +88,7 @@ class PyMISP(object):
to_return += '&&!'
else:
to_return += '!'
if type(values) != type([]):
if not isinstance(values, list):
to_return += not_values
else:
to_return += '&&!'.join(not_values)
@ -124,7 +125,6 @@ class PyMISP(object):
session = self.__prepare_session()
return session.get(attach.format(event_id), verify=False)
# ############## Export ###############
def download_all(self):
@ -141,10 +141,10 @@ class PyMISP(object):
"""
template = self.url + '/events/xml/download/{}/{}'
if with_attachement:
a = 'true'
attach = 'true'
else:
a = 'false'
attach = 'false'
session = self.__prepare_session('xml')
return session.get(template.format(event_id, a), verify=False)
return session.get(template.format(event_id, attach), verify=False)
##########################################