fix: Allow inkex to be imported when stdout is closed or atypical
Prior to this commit, if sys.stdout had been closed or had been
bound to an atypical output stream, even just an import inkex
would throw an exception.
To resolve the situation, this commit moves all use of sys.stdout
to the time that run()
is called, avoids using it if any
alternate output has been specified, and attempts to handle
various possible cases for what sys.stdout may have been bound to.
(As far as I can tell, it's not possible to uniformly handle
all cases, as there does not seem to be a uniform way to obtain
the "binary equivalent" of a text-io stream.)
Resolves #412 (closed)