mirror of https://github.com/MISP/PyMISP
Restore python3 support
parent
f50f4acfc0
commit
249407c32f
|
@ -9,12 +9,24 @@ import time
|
||||||
import requests
|
import requests
|
||||||
import os
|
import os
|
||||||
import base64
|
import base64
|
||||||
from urlparse import urljoin
|
try:
|
||||||
import StringIO
|
from urllib.parse import urljoin
|
||||||
|
except ImportError:
|
||||||
|
from urlparse import urljoin
|
||||||
|
try:
|
||||||
|
from io import StringIO
|
||||||
|
except ImportError:
|
||||||
|
from StringIO import StringIO
|
||||||
import zipfile
|
import zipfile
|
||||||
import warnings
|
import warnings
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
|
# Least dirty way to support python 2 and 3
|
||||||
|
try:
|
||||||
|
basestring
|
||||||
|
except NameError:
|
||||||
|
basestring = str
|
||||||
|
|
||||||
|
|
||||||
class PyMISPError(Exception):
|
class PyMISPError(Exception):
|
||||||
def __init__(self, message):
|
def __init__(self, message):
|
||||||
|
@ -40,8 +52,8 @@ def deprecated(func):
|
||||||
warnings.warn_explicit(
|
warnings.warn_explicit(
|
||||||
"Call to deprecated function {}.".format(func.__name__),
|
"Call to deprecated function {}.".format(func.__name__),
|
||||||
category=DeprecationWarning,
|
category=DeprecationWarning,
|
||||||
filename=func.func_code.co_filename,
|
filename=func.__code__.co_filename,
|
||||||
lineno=func.func_code.co_firstlineno + 1
|
lineno=func.__code__.co_firstlineno + 1
|
||||||
)
|
)
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
return new_func
|
return new_func
|
||||||
|
@ -537,14 +549,14 @@ class PyMISP(object):
|
||||||
return False, result.get('message')
|
return False, result.get('message')
|
||||||
details = []
|
details = []
|
||||||
for f in result['result']:
|
for f in result['result']:
|
||||||
zipped = StringIO.StringIO(base64.b64decode(f['base64']))
|
zipped = StringIO(base64.b64decode(f['base64']))
|
||||||
archive = zipfile.ZipFile(zipped)
|
archive = zipfile.ZipFile(zipped)
|
||||||
try:
|
try:
|
||||||
# New format
|
# New format
|
||||||
unzipped = StringIO.StringIO(archive.open(f['md5'], pwd='infected').read())
|
unzipped = StringIO(archive.open(f['md5'], pwd='infected').read())
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# Old format
|
# Old format
|
||||||
unzipped = StringIO.StringIO(archive.open(f['filename'], pwd='infected').read())
|
unzipped = StringIO(archive.open(f['filename'], pwd='infected').read())
|
||||||
details.append([f['event_id'], f['filename'], unzipped])
|
details.append([f['event_id'], f['filename'], unzipped])
|
||||||
return True, details
|
return True, details
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue