When asking the `dot` helper function to process a graph from inline input to a
binary output format, the `universal_newlines=True` parameter would not be
passed to the underlying `subprocess.check_output` call, resulting in failure to
encode the input. That is, something like the following:
dot("png:gd", source="digraph { a -> b; }")
would result in:
self = <subprocess.Popen object at 0x7fbb862ae390>
def _communicate(self, input, endtime, orig_timeout):
…
> input_view = memoryview(self._input)
E TypeError: memoryview: a bytes-like object is required, not 'str'
/usr/lib64/python3.6/subprocess.py:1519: TypeError
Note that this problem was latent, as no usage fitting the above scenario
currently exists. Something like this will be introduced in a future commit.
Gitlab: related to #1786
"one of `source_file` or `source` needs to be provided"
# is the output format a textual format?
+ output_is_text = T in ("cmapx", "json", "pic", "svg", "xdot")
+
kwargs = {}
- if T in ("cmapx", "json", "pic", "svg", "xdot"):
+ if output_is_text:
kwargs["universal_newlines"] = True
args = ["dot", f"-T{T}"]
if source_file is not None:
args += [source_file]
+ elif not output_is_text:
+ kwargs["input"] = source.encode("utf-8")
else:
kwargs["input"] = source