Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Commit

Permalink
Get a oid list and create a generator to return the vts.
Browse files Browse the repository at this point in the history
Using this generartor reduce the amount of memory used for the get_vts response
  • Loading branch information
jjnicola committed Feb 10, 2020
1 parent 9796cac commit 52da0ec
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions ospd/ospd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,8 @@ def get_vt_xml(self, vt_id: str):
return vt_xml

def get_vts_xml(self, vt_id: str = None, filtered_vts: Dict = None):
""" Gets collection of vulnerability test information in XML format.
""" Python Generator for VTS.
Gets collection of vulnerability test information in XML format.
If vt_id is specified, the collection will contain only this vt, if
found.
If no vt_id is specified or filtered_vts is None (default), the
Expand All @@ -1341,34 +1342,32 @@ def get_vts_xml(self, vt_id: str = None, filtered_vts: Dict = None):
Arguments:
vt_id (vt_id, optional): ID of the vt to get.
filtered_vts (dict, optional): Filtered VTs collection.
filtered_vts (list, optional): Filtered VTs collection.
Return:
String of collection of vulnerability test information in
XML format.
"""

vts_xml = Element('vts')

vts_xml = []
if not self.vts:
return vts_xml

# No match for the filter
if filtered_vts is not None and len(filtered_vts) == 0:
return vts_xml

if filtered_vts:
for vt_id in filtered_vts:
vts_xml.append(self.get_vt_xml(vt_id))
vts_list = filtered_vts
elif vt_id:
vts_xml.append(self.get_vt_xml(vt_id))
vts_list = [vt_id]
else:
# Because DictProxy for python3.5 doesn't support
# TODO: Because DictProxy for python3.5 doesn't support
# iterkeys(), itervalues(), or iteritems() either, the iteration
# must be done as follow.
for vt_id in iter(self.vts.keys()):
vts_xml.append(self.get_vt_xml(vt_id))
vts_list = iter(self.vts.keys())

return vts_xml
for vt_id in vts_list:
yield self.get_vt_xml(vt_id)

def handle_get_version_command(self) -> str:
""" Handles <get_version> command.
Expand Down

0 comments on commit 52da0ec

Please sign in to comment.