Browse Source

add a bunch of doc strings.. still more to come, but discovered a

test coverage bug..
main
John-Mark Gurney 4 years ago
parent
commit
77f71985d4
1 changed files with 63 additions and 1 deletions
  1. +63
    -1
      wsfwd/__init__.py

+ 63
- 1
wsfwd/__init__.py View File

@@ -40,7 +40,20 @@ class TestTimeout(unittest.IsolatedAsyncioTestCase):
await somefun() await somefun()


class WFProcess: class WFProcess:
'''
This implements a similar interface to the Process interface
as documented at:
https://docs.python.org/3/library/asyncio-subprocess.html#asyncio.asyncio.subprocess.Process
'''

def __init__(self, client, stdin, stdout): def __init__(self, client, stdin, stdout):
'''
client must be an instance of WSFWDClient.
stdin and stdout are the objects implementing the
StreamWriter and StreamReader interfaces as defined
by the asyncio interface.
'''

self._client = client self._client = client
self._stdin = stdin self._stdin = stdin
self._stdout = stdout self._stdout = stdout
@@ -48,6 +61,14 @@ class WFProcess:
self._retcode_waiters = [] self._retcode_waiters = []


def set_returncode(self, retcode): def set_returncode(self, retcode):
'''
This is to be called by WSFWDClient when it receives
the the exit command.

It will set the returcode property, and wait up any
waiters that are waiting in wait.
'''

if self._returncode is not None: if self._returncode is not None:
raise RuntimeError('return code already set') raise RuntimeError('return code already set')


@@ -64,17 +85,33 @@ class WFProcess:


@property @property
def returncode(self): def returncode(self):
'''
https://docs.python.org/3/library/asyncio-subprocess.html#asyncio.asyncio.subprocess.Process.returncode
'''

return self._returncode return self._returncode


@property @property
def stdin(self): def stdin(self):
'''
https://docs.python.org/3/library/asyncio-subprocess.html#asyncio.asyncio.subprocess.Process.stdin
'''

return self._stdin return self._stdin


@property @property
def stdout(self): def stdout(self):
'''
https://docs.python.org/3/library/asyncio-subprocess.html#asyncio.asyncio.subprocess.Process.stdout
'''

return self._stdout return self._stdout


async def wait(self): async def wait(self):
'''
https://docs.python.org/3/library/asyncio-subprocess.html#asyncio.asyncio.subprocess.Process.wait
'''

if self.returncode is not None: if self.returncode is not None:
return self.returncode return self.returncode


@@ -88,7 +125,8 @@ class WFProcess:
self._retcode_waiters.remove(fut) self._retcode_waiters.remove(fut)


class WFStreamWriter: class WFStreamWriter:
'''This emulates asyncio.StreamWriter.
'''This emulates asyncio.StreamWriter. For more info, see:
https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamWriter


The following methods/properties are not implemented: The following methods/properties are not implemented:
can_write_eof, write_eof, transport, get_extra_info can_write_eof, write_eof, transport, get_extra_info
@@ -100,29 +138,53 @@ class WFStreamWriter:
self._closed = False self._closed = False


def write(self, data): def write(self, data):
'''
https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamWriter.write
'''

return self.writelines([ data ]) return self.writelines([ data ])


def writelines(self, data): def writelines(self, data):
'''
https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamWriter.writelines
'''

if self._closed: if self._closed:
raise RuntimeError('stream is closed') raise RuntimeError('stream is closed')


self._client.sendstream(self._stream, *data) self._client.sendstream(self._stream, *data)


async def drain(self): async def drain(self):
'''
https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamWriter.drain
'''

if self._closed: if self._closed:
raise RuntimeError('stream is closed') raise RuntimeError('stream is closed')


await self._client.drain(self._stream) await self._client.drain(self._stream)


def is_closing(self): def is_closing(self):
'''
https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamWriter.is_closing
'''

return self._closed return self._closed


def close(self): def close(self):
'''
https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamWriter.close
'''

self._closed = True self._closed = True


self._closetask = asyncio.create_task(self._client._sendcmd(dict(cmd='chanclose', chan=self._stream))) self._closetask = asyncio.create_task(self._client._sendcmd(dict(cmd='chanclose', chan=self._stream)))


async def wait_closed(self): async def wait_closed(self):
'''
https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamWriter.wait_closed
'''

pass pass


class WSFWDCommon: class WSFWDCommon:


Loading…
Cancel
Save