eww.ioproxy

We replace sys.std[in, out, err] with instances of IOProxy. IOProxy provides a thread-local proxy to whatever we want to use for IO.

It is worth mentioning that this is not a perfect proxy. Specifically, it doesn’t proxy any magic methods. There are lots of ways to fix that, but so far it hasn’t been needed.

If you want to make modification to sys.std[in, out, err], any changes you make prior to calling embed will be respected and handled correctly. If you change the IO files after calling embed, everything will break. Ooof.

Fortunately, that’s a rare use case. In the event you want to though, you can use the register() and unregister() public APIs. Check out the Troubleshooting page for more information.

class eww.ioproxy.IOProxy(original_file)[source]

Bases: object

IOProxy provides a proxy object meant to replace sys.std[in, out, err]. It does not proxy magic methods. It is used by calling the object’s register and unregister methods.

__getattr__(name)[source]

All other methods and attributes lookups go to the original file.

__init__(original_file)[source]

Creates the thread local and registers the original file.

Parameters:original_file (file) – Since IOProxy is used to replace an existing file, original_file should be the file you’re replacing.
__weakref__

list of weak references to the object (if defined)

register(io_file)[source]

Used to register a file for use in a particular thread.

Parameters:io_file (file) – io_file will override the existing file, but only in the thread register is called in.
Returns:None
unregister()[source]

Used to unregister a file for use in a particular thread.

Returns:None
write(data, *args, **kwargs)[source]

Modify the write method to force a flush after each write so our sockets work correctly.

Parameters:data (str) – A string to be written to the file being proxied.
Returns:None