Implemented response/stream/lines to read line by line. raw views to expose raw values.
This commit is contained in:
@@ -116,7 +116,15 @@ def get_manager(resource, context):
|
|||||||
|
|
||||||
@contextlib.asynccontextmanager
|
@contextlib.asynccontextmanager
|
||||||
async def manager():
|
async def manager():
|
||||||
if view == 'value':
|
if view == 'raw':
|
||||||
|
if not is_readable(path):
|
||||||
|
raise ValueError(f'Non-readable path "{path}".')
|
||||||
|
else:
|
||||||
|
value = await get_value(context, path)
|
||||||
|
yield ResourceManager(
|
||||||
|
shell_repr=value.decode('utf-8'),
|
||||||
|
coro=asyncio.sleep(0))
|
||||||
|
elif view == 'value':
|
||||||
if not is_readable(path):
|
if not is_readable(path):
|
||||||
raise ValueError(f'Non-readable path "{path}".')
|
raise ValueError(f'Non-readable path "{path}".')
|
||||||
else:
|
else:
|
||||||
@@ -130,12 +138,15 @@ def get_manager(resource, context):
|
|||||||
filename = tempfile.mktemp()
|
filename = tempfile.mktemp()
|
||||||
os.mkfifo(filename)
|
os.mkfifo(filename)
|
||||||
|
|
||||||
if path == 'response/stream':
|
if path.startswith('response/stream'):
|
||||||
async def manage_fifo():
|
async def manage_fifo():
|
||||||
initialized = False
|
initialized = False
|
||||||
try:
|
try:
|
||||||
async with aiofiles.open(filename, 'rb') as fifo:
|
async with aiofiles.open(filename, 'rb') as fifo:
|
||||||
while True:
|
while True:
|
||||||
|
if path.endswith('/lines'):
|
||||||
|
chunk = await fifo.readline()
|
||||||
|
else:
|
||||||
chunk = await fifo.read(128)
|
chunk = await fifo.read(128)
|
||||||
if chunk:
|
if chunk:
|
||||||
if not initialized:
|
if not initialized:
|
||||||
|
|||||||
Reference in New Issue
Block a user