mirror of
https://github.com/codex-storage/bittorrent-benchmarks.git
synced 2025-02-23 00:08:11 +00:00
25 lines
651 B
Python
25 lines
651 B
Python
from io import StringIO
|
|
|
|
from benchmarks.logging.sources.sources import OutputManager
|
|
|
|
|
|
class InMemoryOutputManager(OutputManager):
|
|
def __init__(self):
|
|
self.fs = {}
|
|
|
|
def _open(self, relative_path, mode: str, encoding: str):
|
|
root = self.fs
|
|
for element in relative_path.parts[:-1]:
|
|
subtree = root.get(element)
|
|
if subtree is None:
|
|
subtree = {}
|
|
root[element] = subtree
|
|
root = subtree
|
|
|
|
output = StringIO()
|
|
root[relative_path.parts[-1]] = output
|
|
return output
|
|
|
|
def __exit__(self, exc_type, exc_value, traceback, /):
|
|
pass
|