Skip to content

Commit

Permalink
Added compatibility with Python version older than 2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
davidetortoioli committed Feb 10, 2016
1 parent b72746c commit aad980c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 31 deletions.
36 changes: 20 additions & 16 deletions deepviz/intel.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import inspect
import requests
import simplejson

from deepviz.result import *

try:
import json
except:
import simplejson as json


URL_INTEL_SEARCH = "https://api.deepviz.com/intel/search"
URL_INTEL_IP = "https://api.deepviz.com/intel/network/ip"
URL_INTEL_DOMAIN = "https://api.deepviz.com/intel/network/domain"
Expand Down Expand Up @@ -33,7 +37,7 @@ def ip_info(self, api_key=None, ip=None, time_delta=None, history=False):
msg = "You must provide one or more IPs in a list"
return Result(status=INPUT_ERROR, msg=msg)

body = simplejson.dumps(
body = json.dumps(
{
"history": _history,
"api_key": api_key,
Expand All @@ -42,7 +46,7 @@ def ip_info(self, api_key=None, ip=None, time_delta=None, history=False):
)

if time_delta:
body = simplejson.dumps(
body = json.dumps(
{
"time_delta": time_delta,
"history": _history,
Expand All @@ -55,12 +59,12 @@ def ip_info(self, api_key=None, ip=None, time_delta=None, history=False):
except Exception as e:
return Result(status=NETWORK_ERROR, msg="Error while connecting to Deepviz: %s" % e)

data = simplejson.loads(r.content)
data = json.loads(r.content)

if r.status_code == 200:
return Result(status=SUCCESS, msg=data['data'])
else:
data = simplejson.loads(r.content)
data = json.loads(r.content)
if r.status_code >= 500:
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
else:
Expand Down Expand Up @@ -91,7 +95,7 @@ def domain_info(self, api_key=None, domain=None, time_delta=None, history=False,
return Result(status=INPUT_ERROR, msg=msg)

if filters:
body = simplejson.dumps(
body = json.dumps(
{
"output_filters": filters,
"history": _history,
Expand All @@ -100,7 +104,7 @@ def domain_info(self, api_key=None, domain=None, time_delta=None, history=False,
}
)
else:
body = simplejson.dumps(
body = json.dumps(
{
"history": _history,
"api_key": api_key,
Expand All @@ -110,7 +114,7 @@ def domain_info(self, api_key=None, domain=None, time_delta=None, history=False,

elif time_delta:
if filters:
body = simplejson.dumps(
body = json.dumps(
{
"output_filters": filters,
"time_delta": time_delta,
Expand All @@ -119,7 +123,7 @@ def domain_info(self, api_key=None, domain=None, time_delta=None, history=False,
}
)
else:
body = simplejson.dumps(
body = json.dumps(
{
"time_delta": time_delta,
"history": _history,
Expand All @@ -133,7 +137,7 @@ def domain_info(self, api_key=None, domain=None, time_delta=None, history=False,
msg = "Error while connecting to Deepviz: %s" % e
return Result(status=NETWORK_ERROR, msg=msg)

data = simplejson.loads(r.content)
data = json.loads(r.content)

if r.status_code == 200:
return Result(status=SUCCESS, msg=data['data'])
Expand All @@ -153,15 +157,15 @@ def search(self, api_key=None, search_string=None, start_offset=None, elements=N

if start_offset is not None and elements is not None:
result_set = ["start=%d" % start_offset, "rows=%d" % elements]
body = simplejson.dumps(
body = json.dumps(
{
"result_set": result_set,
"string": search_string,
"api_key": api_key,
}
)
else:
body = simplejson.dumps(
body = json.dumps(
{
"string": search_string,
"api_key": api_key,
Expand All @@ -173,7 +177,7 @@ def search(self, api_key=None, search_string=None, start_offset=None, elements=N
except Exception as e:
return Result(status=NETWORK_ERROR, msg="Error while connecting to Deepviz: %s" % e)

data = simplejson.loads(r.content)
data = json.loads(r.content)

if r.status_code == 200:
return Result(status=SUCCESS, msg=data['data'])
Expand Down Expand Up @@ -213,14 +217,14 @@ def advanced_search(self, api_key=None, sim_hash=None, created_files=None, imp_h
msg = "Value '%s' must be in a string form" % i
return Result(status=INPUT_ERROR, msg=msg)

final_body = simplejson.dumps(body)
final_body = json.dumps(body)

try:
r = requests.post(URL_INTEL_SEARCH_ADVANCED, data=final_body)
except Exception as e:
return Result(status=NETWORK_ERROR, msg="Error while connecting to Deepviz: %s" % e)

data = simplejson.loads(r.content)
data = json.loads(r.content)

if r.status_code == 200:
msg = data['data']
Expand Down
32 changes: 18 additions & 14 deletions deepviz/sandbox.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import os
import requests
import simplejson
from deepviz.result import *

try:
import json
except:
import simplejson as json

URL_UPLOAD_SAMPLE = "https://api.deepviz.com/sandbox/submit"
URL_DOWNLOAD_REPORT = "https://api.deepviz.com/general/report"
URL_DOWNLOAD_SAMPLE = "https://api.deepviz.com/sandbox/sample"
Expand Down Expand Up @@ -52,11 +56,11 @@ def upload_sample(self, path=None, api_key=None):
return Result(status=NETWORK_ERROR, msg=msg)

if r.status_code == 200:
data = simplejson.loads(r.content)
data = json.loads(r.content)
msg = data['data']
return Result(status=SUCCESS, msg=msg)
else:
data = simplejson.loads(r.content)
data = json.loads(r.content)
if r.status_code >= 500:
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
else:
Expand Down Expand Up @@ -114,7 +118,7 @@ def download_sample(self, md5=None, path=None, api_key=None):
msg = "Cannot create file '%s'" % finalpath
return Result(status=INTERNAL_ERROR, msg=msg)

body = simplejson.dumps(
body = json.dumps(
{
"api_key": api_key,
"md5": md5
Expand All @@ -129,7 +133,7 @@ def download_sample(self, md5=None, path=None, api_key=None):
_file.close()
return Result(status=SUCCESS, msg="Sample downloaded to '%s'" % finalpath)
else:
data = simplejson.loads(r.content)
data = json.loads(r.content)
if r.status_code >= 500:
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
else:
Expand All @@ -143,7 +147,7 @@ def sample_result(self, md5=None, api_key=None):
if not md5:
return Result(status=INPUT_ERROR, msg="MD5 cannot be null or empty String")

body = simplejson.dumps(
body = json.dumps(
{
"api_key": api_key,
"md5": md5,
Expand All @@ -155,7 +159,7 @@ def sample_result(self, md5=None, api_key=None):
except Exception as e:
return Result(status=NETWORK_ERROR, msg="Error while connecting to Deepviz: %s" % e)

data = simplejson.loads(r.content)
data = json.loads(r.content)

if r.status_code == 200:
return Result(status=SUCCESS, msg=data['data'])
Expand All @@ -174,14 +178,14 @@ def sample_report(self, md5=None, api_key=None, filters=None):
return Result(status=INPUT_ERROR, msg="MD5 cannot be null or empty String")

if not filters:
body = simplejson.dumps(
body = json.dumps(
{
"api_key": api_key,
"md5": md5
}
)
else:
body = simplejson.dumps(
body = json.dumps(
{
"md5": md5,
"api_key": api_key,
Expand All @@ -194,7 +198,7 @@ def sample_report(self, md5=None, api_key=None, filters=None):
except Exception as e:
return Result(status=NETWORK_ERROR, msg="Error while connecting to Deepviz: %s" % e)

data = simplejson.loads(r.content)
data = json.loads(r.content)

if r.status_code == 200:
return Result(status=SUCCESS, msg=data['data'])
Expand All @@ -212,7 +216,7 @@ def bulk_download_request(self, md5_list=None, api_key=None):
if not md5_list:
return Result(status=INPUT_ERROR, msg="MD5 list empty or invalid")

body = simplejson.dumps(
body = json.dumps(
{
"api_key": api_key,
"hashes": md5_list
Expand All @@ -223,7 +227,7 @@ def bulk_download_request(self, md5_list=None, api_key=None):
msg = "Error while connecting to Deepviz. [%s]" % e
return Result(status=NETWORK_ERROR, msg=msg)

data = simplejson.loads(r.content)
data = json.loads(r.content)

if r.status_code == 200:
return Result(status=SUCCESS, msg=data['data'])
Expand Down Expand Up @@ -256,7 +260,7 @@ def bulk_download_retrieve(self, id_request=None, path=None, api_key=None):
except Exception as _:
return Result(status=INTERNAL_ERROR, msg="Cannot create file '%s'" % finalpath)

body = simplejson.dumps(
body = json.dumps(
{
"api_key": api_key,
"id_request": str(id_request)
Expand All @@ -271,7 +275,7 @@ def bulk_download_retrieve(self, id_request=None, path=None, api_key=None):
_file.close()
return Result(status=SUCCESS, msg="File downloaded to '%s'" % finalpath)
else:
data = simplejson.loads(r.content)
data = json.loads(r.content)
if r.status_code >= 500:
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
else:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name='python-deepviz',
version='1.1.0',
version='1.1.1',
author='Saferbytes',
author_email='[email protected]',
url="https://github.com/saferbytes/python-deepviz",
Expand Down

0 comments on commit aad980c

Please sign in to comment.