Server IP : 66.29.132.122 / Your IP : 3.144.121.184 Web Server : LiteSpeed System : Linux business142.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : admazpex ( 531) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/self/root/proc/self/root/proc/thread-self/root/proc/thread-self/root/proc/self/root/proc/thread-self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/opt/cloudlinux/venv/lib64/python3.11/site-packages/virtualenv/create/ |
Upload File : |
import logging from collections import OrderedDict class PyEnvCfg: def __init__(self, content, path): self.content = content self.path = path @classmethod def from_folder(cls, folder): return cls.from_file(folder / "pyvenv.cfg") @classmethod def from_file(cls, path): content = cls._read_values(path) if path.exists() else OrderedDict() return PyEnvCfg(content, path) @staticmethod def _read_values(path): content = OrderedDict() for line in path.read_text(encoding="utf-8").splitlines(): equals_at = line.index("=") key = line[:equals_at].strip() value = line[equals_at + 1 :].strip() content[key] = value return content def write(self): logging.debug("write %s", self.path) text = "" for key, value in self.content.items(): line = f"{key} = {value}" logging.debug("\t%s", line) text += line text += "\n" self.path.write_text(text, encoding="utf-8") def refresh(self): self.content = self._read_values(self.path) return self.content def __setitem__(self, key, value): self.content[key] = value def __getitem__(self, key): return self.content[key] def __contains__(self, item): return item in self.content def update(self, other): self.content.update(other) return self def __repr__(self): return f"{self.__class__.__name__}(path={self.path})" __all__ = [ "PyEnvCfg", ]