aboutsummaryrefslogtreecommitdiff
path: root/.venv/lib/python3.12/site-packages/aiofiles/threadpool/utils.py
diff options
context:
space:
mode:
authorS. Solomon Darnell2025-03-28 21:52:21 -0500
committerS. Solomon Darnell2025-03-28 21:52:21 -0500
commit4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch)
treeee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/aiofiles/threadpool/utils.py
parentcc961e04ba734dd72309fb548a2f97d67d578813 (diff)
downloadgn-ai-master.tar.gz
two version of R2R are hereHEADmaster
Diffstat (limited to '.venv/lib/python3.12/site-packages/aiofiles/threadpool/utils.py')
-rw-r--r--.venv/lib/python3.12/site-packages/aiofiles/threadpool/utils.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/aiofiles/threadpool/utils.py b/.venv/lib/python3.12/site-packages/aiofiles/threadpool/utils.py
new file mode 100644
index 00000000..5fd3bb99
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/aiofiles/threadpool/utils.py
@@ -0,0 +1,72 @@
+import functools
+
+
+def delegate_to_executor(*attrs):
+ def cls_builder(cls):
+ for attr_name in attrs:
+ setattr(cls, attr_name, _make_delegate_method(attr_name))
+ return cls
+
+ return cls_builder
+
+
+def proxy_method_directly(*attrs):
+ def cls_builder(cls):
+ for attr_name in attrs:
+ setattr(cls, attr_name, _make_proxy_method(attr_name))
+ return cls
+
+ return cls_builder
+
+
+def proxy_property_directly(*attrs):
+ def cls_builder(cls):
+ for attr_name in attrs:
+ setattr(cls, attr_name, _make_proxy_property(attr_name))
+ return cls
+
+ return cls_builder
+
+
+def cond_delegate_to_executor(*attrs):
+ def cls_builder(cls):
+ for attr_name in attrs:
+ setattr(cls, attr_name, _make_cond_delegate_method(attr_name))
+ return cls
+
+ return cls_builder
+
+
+def _make_delegate_method(attr_name):
+ async def method(self, *args, **kwargs):
+ cb = functools.partial(getattr(self._file, attr_name), *args, **kwargs)
+ return await self._loop.run_in_executor(self._executor, cb)
+
+ return method
+
+
+def _make_proxy_method(attr_name):
+ def method(self, *args, **kwargs):
+ return getattr(self._file, attr_name)(*args, **kwargs)
+
+ return method
+
+
+def _make_proxy_property(attr_name):
+ def proxy_property(self):
+ return getattr(self._file, attr_name)
+
+ return property(proxy_property)
+
+
+def _make_cond_delegate_method(attr_name):
+ """For spooled temp files, delegate only if rolled to file object"""
+
+ async def method(self, *args, **kwargs):
+ if self._file._rolled:
+ cb = functools.partial(getattr(self._file, attr_name), *args, **kwargs)
+ return await self._loop.run_in_executor(self._executor, cb)
+ else:
+ return getattr(self._file, attr_name)(*args, **kwargs)
+
+ return method