def render_json(self, pretty=False): """ Render the report results as JSON. Parameters ---------- pretty : bool, optional Whether to format the resulting JSON in a more legible way ( default False). """ return jsonify(self.result, pretty=pretty)
def process_bind_param(self, value, dialect): """Convert the value to a JSON encoded string before storing it.""" try: with BytesIO() as stream: with GzipFile(fileobj=stream, mode="wb") as file_handle: file_handle.write( jsonify(value, pretty=False).encode("utf-8")) output = stream.getvalue() return output except TypeError as error: log_json_incompatible_types(value) raise_with_traceback(error)
def process_bind_param(self, value, dialect): """Convert the value to a JSON encoded string before storing it.""" try: with BytesIO() as stream: with GzipFile(fileobj=stream, mode="wb") as file_handle: file_handle.write( jsonify(value, pretty=False).encode("utf-8") ) output = stream.getvalue() return output except TypeError as error: log_json_incompatible_types(value) raise_with_traceback(error)
def store(self, result, filename, pretty=True): """ Write a result to the given file. Parameters ---------- result : memote.MemoteResult The dictionary structure of results. filename : str or pathlib.Path Store results directly to the given filename. pretty : bool, optional Whether (default) or not to write JSON in a more legible format. """ LOGGER.info("Storing result in '%s'.", filename) if filename.endswith(".gz"): with gzip.open(filename, "wb") as file_handle: file_handle.write( jsonify(result, pretty=pretty).encode("utf-8")) else: with open(filename, "w", encoding="utf-8") as file_handle: file_handle.write(jsonify(result, pretty=pretty))
def store(self, result, filename, pretty=True): """ Write a result to the given file. Parameters ---------- result : memote.MemoteResult The dictionary structure of results. filename : str or pathlib.Path Store results directly to the given filename. pretty : bool, optional Whether (default) or not to write JSON in a more legible format. """ LOGGER.info("Storing result in '%s'.", filename) if filename.endswith(".gz"): with gzip.open(filename, "wb") as file_handle: file_handle.write( jsonify(result, pretty=pretty).encode("utf-8") ) else: with open(filename, "w", encoding="utf-8") as file_handle: file_handle.write(jsonify(result, pretty=pretty))
def store(self, result, filename, env_info=True, pretty=True): """ Write a result to the given file. Parameters ---------- result : memote.MemoteResult The dictionary structure of results. filename : str or pathlib.Path Store results directly to the given filename. env_info : bool, optional Add Python environment information to the result object. pretty : bool, optional Whether (default) or not to write JSON in a more legible format. """ if env_info: self.add_environment(result.meta) LOGGER.info("Storing result in '%s'.", filename) with open(filename, "w", encoding="utf-8") as file_handle: file_handle.write(jsonify(result, pretty=pretty))
def process_bind_param(self, value, dialect): """Convert the value to a JSON encoded string before storing it.""" return jsonify(value, pretty=False)