hio.core.wiring
hio.help.wiring module
Module Contents
- hio.core.wiring.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
- Parameters:
instance (cls is Class instance of subclass)
wirelogs (name is str name of wirelog instance for filename so can have multiple) – at different paths thar each use different file name
Boolean (temp is) – Otherwise open in persistent directory, do not clear on close
directory (True means open in temporary) – Otherwise open in persistent directory, do not clear on close
close (clear on) – 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)
- class hio.core.wiring.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
- rxed
True means log rx
- Type:
bool
- txed
True means log tx
- Type:
bool
- samed
True means log both rx and tx to same file or buffer
- Type:
bool
- filed
True means log to file; False means log to memory buffer
- Type:
bool
- fmt
io write bytes printf style format string Default is:
b"\n%(dx)b %(who)b:\n%(data)b\n"
Placeholder semantics:
whois src or dst for rx/tx,dxis the io direction (b’tx’ or b’rx’), anddatais the actual io payload bytes. To write data without direction, who, or line feeds, usefmt=b'%(data)b'.- Type:
bytes
- name
used in file name
- Type:
str
- temp
True means use /tmp directory
- Type:
bool
- prefix
used as part of path prefix and formatting
- Type:
str
- headDirPath
used as head of path
- Type:
str
- tailDirPath
used as tail of path
- Type:
str
- altTailDirPath
alternate tail of path
- Type:
str
- dirPath
full directory path
- Type:
str
- rxl
rx log file or memory buffer
- Type:
io.IOBase | io.BytesIO | None
- txl
tx log file or memory buffer
- Type:
io.IOBase | io.BytesIO | None
- opened
True means file/buffer is opened; False otherwise
- Type:
bool
- 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
- Parameters:
ignore. (fmt is optional bytes printf format If None or unchanged then) – Otherwise when creating io use .rxed if not provided
ignore. – Otherwise when creating io use .txed if not provided
ignore. – Otherwise when creating io use .same if not provided
ignore. – Otherwise when creating io use .filed if not provided
ignore. – Otherwise when creating io use .fmt if not provided
name (name is optional) –
- if None or unchanged then ignore otherwise recreate path
When recreating path, If not provided use .name
boolean (temp is optional) –
- If None ignore Otherwise
Assign to .temp If True then open in temporary directory and clear on close, If False then open persistent directory
database (headDirPath is optional str head directory pathname of main) –
- if None or unchanged then ignore otherwise recreate path
When recreating path, If not provided use default .HeadDirpath
closing (clear is Boolean True means clear .path when)
- 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.
- 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:
- clearDirPath()
Remove logfile directory at .dirPath
- readRx()
Returns rx string buffer value if .buffify else None
- readTx()
Returns tx string buffer value if .buffify else None
- writeRx(data, who=b'')
Write bytes data received from source host port address tuple,
- writeTx(data, who=b'')
Write bytes data transmitted to destination address da,
- class hio.core.wiring.WireLogDoer(wl, **kwa)
Bases:
hio.base.doing.DoerBasic 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.
- enter(*, temp=None)
Do ‘enter’ context actions. Override in subclass. Not a generator method. Set up resources. Comparable to context manager enter.
- Parameters:
temp (bool | None) – True means use temporary file resources if any None means ignore parameter value. Use self.temp
Inject temp or self.temp into file resources here if any
Doist or DoDoer winds its doers on enter
- 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.