Skip to content

Commit

Permalink
Compatibility fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vulnersCom committed Sep 18, 2018
1 parent 4364aef commit 24a25ab
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion vulners/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-

__version__ = "1.3.5"
__version__ = "1.3.6"

from vulners.api import Vulners
11 changes: 7 additions & 4 deletions vulners/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from six import string_types

from .common.ratelimit import rate_limited
from .common.attributeList import AttributeList
from . import __version__ as api_version


Expand Down Expand Up @@ -310,7 +311,7 @@ def search(self, query, limit=100, offset=0, fields=("id", "title", "description
total = max(results.get('total'), total)
for element in results.get('search'):
dataDocs.append(element.get('_source'))
return dataDocs, total
return AttributeList(dataDocs, total = total)

def searchPage(self, query, pageSize = 20, offset=0, fields=("id", "title", "description", "type", "bulletinFamily", "cvss", "published", "modified", "href")):
"""
Expand All @@ -326,7 +327,7 @@ def searchPage(self, query, pageSize = 20, offset=0, fields=("id", "title", "des
results = self.__search(query, offset, min(pageSize, self.__search_size), fields or [])
total = results.get('total')
dataDocs = [element.get('_source') for element in results.get('search')]
return dataDocs, total
return AttributeList(dataDocs, total = total)

def searchExploit(self, query, lookup_fields=None, limit=500, offset=0, fields=("id", "title", "description", "cvss", "href", "sourceData")):
"""
Expand Down Expand Up @@ -356,7 +357,8 @@ def searchExploit(self, query, lookup_fields=None, limit=500, offset=0, fields=(
total = max(results.get('total'), total)
for element in results.get('search'):
dataDocs.append(element.get('_source'))
return dataDocs, total
return AttributeList(dataDocs, total = total)


def searchExploitPage(self, query, lookup_fields=None, pageSize=20, offset=0, fields=("id", "title", "description", "cvss", "href", "sourceData")):
"""
Expand All @@ -380,7 +382,8 @@ def searchExploitPage(self, query, lookup_fields=None, pageSize=20, offset=0, fi
results = self.__search(searchQuery, offset, min(pageSize, self.__search_size), fields or [])
total = results.get('total')
dataDocs = [element.get('_source') for element in results.get('search')]
return dataDocs, total
return AttributeList(dataDocs, total = total)


def softwareVulnerabilities(self, name, version, maxVulnerabilities = 50):
"""
Expand Down
39 changes: 39 additions & 0 deletions vulners/common/attributeList.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class AttributeList(list):
"""
A subclass of list that can accept additional attributes.
Should be able to be used just like a regular list.
The problem:
a = [1, 2, 4, 8]
a.x = "Hey!" # AttributeError: 'list' object has no attribute 'x'
The solution:
a = L(1, 2, 4, 8)
a.x = "Hey!"
print a # [1, 2, 4, 8]
print a.x # "Hey!"
print len(a) # 4
You can also do these:
a = L( 1, 2, 4, 8 , x="Hey!" ) # [1, 2, 4, 8]
a = L( 1, 2, 4, 8 )( x="Hey!" ) # [1, 2, 4, 8]
a = L( [1, 2, 4, 8] , x="Hey!" ) # [1, 2, 4, 8]
a = L( {1, 2, 4, 8} , x="Hey!" ) # [1, 2, 4, 8]
a = L( [2 ** b for b in range(4)] , x="Hey!" ) # [1, 2, 4, 8]
a = L( (2 ** b for b in range(4)) , x="Hey!" ) # [1, 2, 4, 8]
a = L( 2 ** b for b in range(4) )( x="Hey!" ) # [1, 2, 4, 8]
a = L( 2 ) # [2]
"""
def __new__(self, *args, **kwargs):
return list.__new__(self, args, kwargs)

def __init__(self, *args, **kwargs):
if len(args) == 1 and hasattr(args[0], '__iter__'):
list.__init__(self, args[0])
else:
list.__init__(self, args)
self.__dict__.update(kwargs)

def __call__(self, **kwargs):
self.__dict__.update(kwargs)
return self

0 comments on commit 24a25ab

Please sign in to comment.