Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cairosvg/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import gzip
import os
import re
from urllib.parse import urlunparse
from xml.etree.ElementTree import Element
Expand Down Expand Up @@ -345,6 +346,8 @@ def __init__(self, **kwargs):
bytestring = kwargs.get('bytestring')
file_obj = kwargs.get('file_obj')
url = kwargs.get('url')
if isinstance(url, os.PathLike):
url = os.fspath(url)
unsafe = kwargs.get('unsafe')
parent = kwargs.get('parent')
parent_children = kwargs.get('parent_children')
Expand Down
2 changes: 1 addition & 1 deletion cairosvg/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def convert(cls, bytestring=None, *, file_obj=None, url=None, dpi=96,

:param bytestring: The SVG source as a byte-string.
:param file_obj: A file-like object.
:param url: A filename.
:param url: A filename, given as a string or a path-like object.

Give some options:

Expand Down
3 changes: 3 additions & 0 deletions cairosvg/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def test_api(tmp_path):
assert svg2png(url=str(temp_0)) == expected_content
assert svg2png(url=f'file://{temp_0}') == expected_content

# Read from a pathlib.Path
assert svg2png(url=temp_0) == expected_content

with temp_0.open('rb') as file_object:
# Read from a real file object
assert svg2png(file_obj=file_object) == expected_content
Expand Down
2 changes: 2 additions & 0 deletions cairosvg/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def parse_url(url, base=None):
the "folder" part of it is prepended to the URL.

"""
if isinstance(url, os.PathLike):
url = os.fspath(url)
if url:
match = URL.search(url)
if match:
Expand Down
Loading