From f9bea6bba09454bf829f2eefbab213a08b889772 Mon Sep 17 00:00:00 2001 From: Zanie Date: Fri, 12 Jan 2024 17:55:14 -0600 Subject: [PATCH] Defer import of JSON; generate a UUID manually --- scripts/hookd/hookd.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/hookd/hookd.py b/scripts/hookd/hookd.py index c978f3bec..00378161c 100755 --- a/scripts/hookd/hookd.py +++ b/scripts/hookd/hookd.py @@ -9,11 +9,9 @@ from __future__ import annotations import enum import importlib import io -import json import errno import os import sys -import uuid import time import traceback from contextlib import ExitStack, contextmanager @@ -297,6 +295,10 @@ def parse_config_settings(buffer: TextIO) -> StringDict | None: if not data: return None + # We defer the import of `json` until someone actually passes us a `config_settings` + # object since it's not necessarily common + import json + try: # TODO(zanieb): Consider using something faster than JSON here since we _should_ # be restricted to strings @@ -540,7 +542,8 @@ def tmpfile(): candidate_tempdirs = None for attempt in range(_max_tmpfile_attempts): - name = uuid.uuid4().hex + # Generate a random hex string, similar to a UUID without version and variant information + name = "%032x" % int.from_bytes(os.urandom(16)) # Every one hundred attempts, switch to another candidate directory if not _default_tmpdir and attempt % 100 == 0: