Skip to content

Commit

Permalink
fixed bug with sqlite on py3
Browse files Browse the repository at this point in the history
  • Loading branch information
savon-noir committed Jun 28, 2014
1 parent 4de764e commit bd60f1f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion libnmap/plugins/backendpluginFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ def create(cls, plugin_name="mongodb", **kwargs):
try:
backendplugin = classobj(**kwargs)
except Exception as error:
print("Cannot create Backend: {0}".format(error))
raise Exception("Cannot create Backend: {0}".format(error))
return backendplugin
3 changes: 1 addition & 2 deletions libnmap/plugins/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def insert(self, report):
try:
oid = self.collection.insert(json.loads(j))
except:
print("MONGODB cannot insert")
raise
raise Exception("Failed to insert nmap object in MongoDB")
return str(oid)

def get(self, str_report_id=None):
Expand Down
5 changes: 2 additions & 3 deletions libnmap/plugins/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ def insert(self, report):
strjsonnmapreport = json.dumps(report, cls=ReportEncoder)
mykey.set_contents_from_string(strjsonnmapreport)
except:
print("Bucket cannot insert")
raise
raise Exception("Failed to add nmap object in s3 bucket")
return str(oid)

def get(self, str_report_id=None):
Expand All @@ -108,7 +107,7 @@ def get(self, str_report_id=None):
nmapreportjson = json.loads(mykey.get_contents_as_string())
nmapreport = NmapParser.parse_fromdict(nmapreportjson)
except S3ResponseError:
print("Not Found")
pass
return nmapreport

def getall(self, dict_filter=None):
Expand Down
12 changes: 7 additions & 5 deletions libnmap/plugins/sql.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
from sqlalchemy import create_engine
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, DateTime, Text
from sqlalchemy.types import Integer, DateTime, LargeBinary
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

Expand Down Expand Up @@ -53,15 +53,17 @@ class Reports(Base):

id = Column('report_id', Integer, primary_key=True)
inserted = Column('inserted', DateTime(), default='now')
report_json = Column('report_json', Text(convert_unicode=True))
report_json = Column('report_json', LargeBinary())

def __init__(self, obj_NmapReport):
self.inserted = datetime.fromtimestamp(obj_NmapReport.endtime)
self.report_json = json.dumps(obj_NmapReport,
cls=ReportEncoder)
dumped_json = json.dumps(obj_NmapReport,
cls=ReportEncoder)
self.report_json = bytes(dumped_json.encode('UTF-8'))

def decode(self):
nmap_report_obj = json.loads(self.report_json,
json_decoded = self.report_json.decode('utf-8')
nmap_report_obj = json.loads(json_decoded,
cls=ReportDecoder)
return nmap_report_obj

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27,py34
envlist = py27,py32
[testenv]
deps=nose
pymongo
Expand Down

0 comments on commit bd60f1f

Please sign in to comment.