Show More
@@ -16,7 +16,8 from copy import deepcopy | |||||
16 | from os.path import splitext |
|
16 | from os.path import splitext | |
17 | from pathlib import Path, PurePath |
|
17 | from pathlib import Path, PurePath | |
18 |
|
18 | |||
19 | from IPython.utils.py3compat import cast_unicode |
|
19 | from typing import Optional | |
|
20 | ||||
20 | from IPython.testing.skipdoctest import skip_doctest |
|
21 | from IPython.testing.skipdoctest import skip_doctest | |
21 | from . import display_functions |
|
22 | from . import display_functions | |
22 |
|
23 | |||
@@ -518,7 +519,7 class SVG(DisplayObject): | |||||
518 | _read_flags = 'rb' |
|
519 | _read_flags = 'rb' | |
519 | # wrap data in a property, which extracts the <svg> tag, discarding |
|
520 | # wrap data in a property, which extracts the <svg> tag, discarding | |
520 | # document headers |
|
521 | # document headers | |
521 | _data = None |
|
522 | _data: Optional[str] = None | |
522 |
|
523 | |||
523 | @property |
|
524 | @property | |
524 | def data(self): |
|
525 | def data(self): | |
@@ -540,7 +541,9 class SVG(DisplayObject): | |||||
540 | # fallback on the input, trust the user |
|
541 | # fallback on the input, trust the user | |
541 | # but this is probably an error. |
|
542 | # but this is probably an error. | |
542 | pass |
|
543 | pass | |
543 | svg = cast_unicode(svg) |
|
544 | if isinstance(svg, bytes): | |
|
545 | self._data = svg.decode(errors="replace") | |||
|
546 | else: | |||
544 | self._data = svg |
|
547 | self._data = svg | |
545 |
|
548 | |||
546 | def _repr_svg_(self): |
|
549 | def _repr_svg_(self): |
@@ -18,7 +18,6 from IPython.utils.process import find_cmd, FindCmdError | |||||
18 | from traitlets.config import get_config |
|
18 | from traitlets.config import get_config | |
19 | from traitlets.config.configurable import SingletonConfigurable |
|
19 | from traitlets.config.configurable import SingletonConfigurable | |
20 | from traitlets import List, Bool, Unicode |
|
20 | from traitlets import List, Bool, Unicode | |
21 | from IPython.utils.py3compat import cast_unicode |
|
|||
22 |
|
21 | |||
23 |
|
22 | |||
24 | class LaTeXTool(SingletonConfigurable): |
|
23 | class LaTeXTool(SingletonConfigurable): | |
@@ -58,8 +57,9 class LaTeXTool(SingletonConfigurable): | |||||
58 | ).tag(config=True) |
|
57 | ).tag(config=True) | |
59 |
|
58 | |||
60 |
|
59 | |||
61 | def latex_to_png(s, encode=False, backend=None, wrap=False, color='Black', |
|
60 | def latex_to_png( | |
62 | scale=1.0): |
|
61 | s: str, encode=False, backend=None, wrap=False, color="Black", scale=1.0 | |
|
62 | ): | |||
63 | """Render a LaTeX string to PNG. |
|
63 | """Render a LaTeX string to PNG. | |
64 |
|
64 | |||
65 | Parameters |
|
65 | Parameters | |
@@ -80,7 +80,7 def latex_to_png(s, encode=False, backend=None, wrap=False, color='Black', | |||||
80 | None is returned when the backend cannot be used. |
|
80 | None is returned when the backend cannot be used. | |
81 |
|
81 | |||
82 | """ |
|
82 | """ | |
83 | s = cast_unicode(s) |
|
83 | assert isinstance(s, str) | |
84 | allowed_backends = LaTeXTool.instance().backends |
|
84 | allowed_backends = LaTeXTool.instance().backends | |
85 | if backend is None: |
|
85 | if backend is None: | |
86 | backend = allowed_backends[0] |
|
86 | backend = allowed_backends[0] |
@@ -170,7 +170,7 try: | |||||
170 | # not really a cl-arg, fallback on _process_common |
|
170 | # not really a cl-arg, fallback on _process_common | |
171 | return py_arg_split(commandline, posix=posix, strict=strict) |
|
171 | return py_arg_split(commandline, posix=posix, strict=strict) | |
172 | argvn = c_int() |
|
172 | argvn = c_int() | |
173 |
result_pointer = CommandLineToArgvW( |
|
173 | result_pointer = CommandLineToArgvW(commandline.lstrip(), ctypes.byref(argvn)) | |
174 | result_array_type = LPCWSTR * argvn.value |
|
174 | result_array_type = LPCWSTR * argvn.value | |
175 | result = [arg for arg in result_array_type.from_address(ctypes.addressof(result_pointer.contents))] |
|
175 | result = [arg for arg in result_array_type.from_address(ctypes.addressof(result_pointer.contents))] | |
176 | retval = LocalFree(result_pointer) |
|
176 | retval = LocalFree(result_pointer) |
General Comments 0
You need to be logged in to leave comments.
Login now