hio.core.wiring =============== .. py:module:: hio.core.wiring .. autoapi-nested-parse:: hio.help.wiring module Module Contents --------------- .. py:function:: openWL(cls=None, name='test', temp=True, **kwa) Context manager wrapper WireLog instances. Defaults to temporary wire logs. Context 'with' statements call .close on exit of 'with' block :param cls is Class instance of subclass instance: :param name is str name of wirelog instance for filename so can have multiple wirelogs: at different paths thar each use different file name :param temp is Boolean: Otherwise open in persistent directory, do not clear on close :param True means open in temporary directory: Otherwise open in persistent directory, do not clear on close :param clear on close: Otherwise open in persistent directory, do not clear on close Usage:: with openWL(name="bob") as wl: wl.writeRx .... with openWL(name="eve", cls=SubclassedWireLog) .. py:class:: WireLog(rxed=True, txed=True, samed=False, filed=False, fmt=None, name='main', temp=False, prefix=None, headDirPath=None, reopen=False, clear=False) For debugging of non-blocking transports, provides log files or in memory buffers for logging 'over the wire' network tx and rx packets as bytes .. attribute:: rxed True means log rx :type: bool .. attribute:: txed True means log tx :type: bool .. attribute:: samed True means log both rx and tx to same file or buffer :type: bool .. attribute:: filed True means log to file; False means log to memory buffer :type: bool .. attribute:: fmt io write bytes printf style format string Default is:: b"\n%(dx)b %(who)b:\n%(data)b\n" Placeholder semantics: ``who`` is src or dst for rx/tx, ``dx`` is the io direction (b'tx' or b'rx'), and ``data`` is the actual io payload bytes. To write data without direction, who, or line feeds, use ``fmt=b'%(data)b'``. :type: bytes .. attribute:: name used in file name :type: str .. attribute:: temp True means use /tmp directory :type: bool .. attribute:: prefix used as part of path prefix and formatting :type: str .. attribute:: headDirPath used as head of path :type: str .. attribute:: tailDirPath used as tail of path :type: str .. attribute:: altTailDirPath alternate tail of path :type: str .. attribute:: dirPath full directory path :type: str .. attribute:: rxl rx log file or memory buffer :type: io.IOBase | io.BytesIO | None .. attribute:: txl tx log file or memory buffer :type: io.IOBase | io.BytesIO | None .. attribute:: opened True means file/buffer is opened; False otherwise :type: bool .. py:method:: reopen(rxed=None, txed=None, samed=None, filed=None, fmt=None, name=None, temp=None, headDirPath=None, clear=False) Use or Create if not preexistent, directory path for file .path First closes .path if already opened. If clear is True then also clears .path before reopening :param rxed is optional Boolean If None or unchanged then ignore.: Otherwise when creating io use .rxed if not provided :param txed is optional Boolean If None or unchanged then ignore.: Otherwise when creating io use .txed if not provided :param samed is optional Boolean If None or unchanged then ignore.: Otherwise when creating io use .same if not provided :param filed is optional Boolean If None or unchanged then ignore.: Otherwise when creating io use .filed if not provided :param fmt is optional bytes printf format If None or unchanged then ignore.: Otherwise when creating io use .fmt if not provided :param name is optional name: if None or unchanged then ignore otherwise recreate path When recreating path, If not provided use .name :param temp is optional boolean: If None ignore Otherwise Assign to .temp If True then open in temporary directory and clear on close, If False then open persistent directory :param headDirPath is optional str head directory pathname of main database: if None or unchanged then ignore otherwise recreate path When recreating path, If not provided use default .HeadDirpath :param clear is Boolean True means clear .path when closing: .. py:method:: flush() flush files if any and opened. A file flush only moves from program buffer to operating system buffer. A file fsync moves from operating system buffer to disk. .. py:method:: close(clear=False) Close io logs. If clear or self.temp then remove directory at .dirPath :param clear is boolean: :param True means clear directory at .dirPath if any: .. py:method:: clearDirPath() Remove logfile directory at .dirPath .. py:method:: readRx() Returns rx string buffer value if .buffify else None .. py:method:: readTx() Returns tx string buffer value if .buffify else None .. py:method:: writeRx(data, who=b'') Write bytes data received from source host port address tuple, .. py:method:: writeTx(data, who=b'') Write bytes data transmitted to destination address da, .. py:class:: WireLogDoer(wl, **kwa) Bases: :py:obj:`hio.base.doing.Doer` Basic WireLog Doer Inherited attributes: .done is Boolean completion state. True means completed. Otherwise incomplete. Incompletion maybe due to close or abort. Attributes: .wl is WireLog subclass. Inherited properties: .tyme is float ._tymist.tyme, relative cycle or artificial time. .tock is float, desired time in seconds between runs or until next run, non negative, zero means run asap. Methods include `.wind`, `.__call__`, `.do`, `.enter`, `.recur`, `.exit`, `.close`, and `.abort`. Hidden attributes: `._tymist` and `._tock`. .. py:method:: enter(*, temp=None) Do 'enter' context actions. Override in subclass. Not a generator method. Set up resources. Comparable to context manager enter. :param temp: True means use temporary file resources if any None means ignore parameter value. Use self.temp :type temp: bool | None Inject temp or self.temp into file resources here if any Doist or DoDoer winds its doers on enter .. py:method:: exit() Do 'exit' context actions. Override in subclass. Not a generator method. Clean up resources. Comparable to context manager exit. Called by finally after normal return, close, or abort. After .exit() do returns resulting in StopIteration.