# -*- coding: utf-8 -*-1# This program is free software; you can redistribute it and/or modify2# it under the terms of the GNU General Public License as published by3# the Free Software Foundation; either version 2 of the License, or4# (at your option) any later version.5#6# This program is distributed in the hope that it will be useful,7# but WITHOUT ANY WARRANTY; without even the implied warranty of8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9# GNU General Public License for more details.10#11# You should have received a copy of the GNU General Public License12# along with this program; if not, write to the Free Software13# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,14# MA 02110-1301, USA.15#16# Author: Mauro Soria1718import json1920from lib.core.decorators import locked21from lib.core.settings import COMMAND, START_TIME22from lib.report.factory import BaseReport, FileReportMixin232425class JSONReport(FileReportMixin, BaseReport):26__format__ = "json"27__extension__ = "json"2829def new(self):30return {31"info": {"args": COMMAND, "time": START_TIME},32"results": [],33}3435def parse(self, file):36with open(file) as fh:37return json.load(fh)3839@locked40def save(self, file, result):41data = self.parse(file)42data["results"].append({43"url": result.url,44"status": result.status,45"contentLength": result.length,46"contentType": result.type,47"redirect": result.redirect,48})49self.write(file, data)5051def write(self, file, data):52with open(file, "w") as fh:53json.dump(data, fh, sort_keys=True, indent=4)545556