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