Skip to content

Commit

Permalink
rename stderr_write_bytes, include optional flush
Browse files Browse the repository at this point in the history
  • Loading branch information
xflr6 committed Aug 12, 2018
1 parent 371d81b commit 0e1d3c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 6 additions & 2 deletions graphviz/_compat.py
Expand Up @@ -20,8 +20,10 @@ def makedirs(name, mode=0o777, exist_ok=False):
if not exist_ok or not os.path.isdir(name):
raise

def stderr_write_binary(data):
def stderr_write_bytes(data, flush=False):
sys.stderr.write(data)
if flush:
sys.stderr.flush()


else:
Expand All @@ -34,6 +36,8 @@ def iteritems(d):
def makedirs(name, mode=0o777, exist_ok=False): # allow os.makedirs mocking
return os.makedirs(name, mode, exist_ok=exist_ok)

def stderr_write_binary(data):
def stderr_write_bytes(data, flush=False):
encoding = sys.stderr.encoding or sys.getdefaultencoding()
sys.stderr.write(data.decode(encoding))
if flush:
sys.stderr.flush()
5 changes: 2 additions & 3 deletions graphviz/backend.py
Expand Up @@ -9,7 +9,7 @@
import subprocess
import contextlib

from ._compat import stderr_write_binary
from ._compat import stderr_write_bytes

from . import tools

Expand Down Expand Up @@ -167,8 +167,7 @@ def pipe(engine, format, data, quiet=False):
out, err = proc.communicate(data)
if proc.returncode:
if not quiet:
stderr_write_binary(err)
sys.stderr.flush()
stderr_write_bytes(err, flush=True)
raise subprocess.CalledProcessError(proc.returncode, cmd, output=out)

return out
Expand Down

0 comments on commit 0e1d3c0

Please sign in to comment.