formatting

Former-commit-id: b78188d885230fd4ad617ee7288e840aa6dea321
This commit is contained in:
Abubakar Abid 2022-03-14 09:37:30 -05:00
parent a415e5abc8
commit 2a7757ee7e
3 changed files with 11 additions and 10 deletions

View File

@ -207,10 +207,12 @@ class CSVLogger(FlaggingCallback):
writer.writerow(headers)
writer.writerow(csv_data)
with open(log_fp, "wb") as csvfile:
csvfile.write(utils.santize_for_csv(
encryptor.encrypt(
interface.encryption_key, output.getvalue().encode()
))
csvfile.write(
utils.santize_for_csv(
encryptor.encrypt(
interface.encryption_key, output.getvalue().encode()
)
)
)
else:
if flag_index is None:

View File

@ -290,12 +290,13 @@ def get_default_args(func: Callable) -> Dict[str, Any]:
def santize_for_csv(data: str | List[str] | List[List[str]]):
""" Sanitizes data so that it can be safely written to a CSV file. """
"""Sanitizes data so that it can be safely written to a CSV file."""
def sanitize(item):
return "'" + item
unsafe_prefixes = ("+", "=", "-", "@")
if isinstance(data, str):
if data.startswith(unsafe_prefixes):
warnings.warn("Sanitizing flagged data by escaping cell contents")
@ -318,4 +319,3 @@ def santize_for_csv(data: str | List[str] | List[List[str]]):
return sanitized_data
else:
raise ValueError("Unsupported data type: " + str(type(data)))

View File

@ -15,8 +15,8 @@ from gradio.utils import (
json,
launch_analytics,
readme_to_html,
version_check,
santize_for_csv,
version_check,
)
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
@ -135,6 +135,5 @@ class TestSanitizeForCSV(unittest.TestCase):
self.assertEquals(safe_data, [["abc", "'=abc"]])
if __name__ == "__main__":
unittest.main()