Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding redux #49

Merged
merged 1 commit into from Feb 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions image_occlusion_enhanced/utils.py
Expand Up @@ -20,10 +20,18 @@
import urllib.parse, urllib.request, urllib.parse, urllib.error
from .imagesize import imagesize

# Anki 2.1 support
from anki import version as anki_version
anki21 = anki_version.startswith("2.1.")

def path2url(path):
"""URL-encode local path"""
return urllib.parse.urljoin(
'file:', urllib.request.pathname2url(path.encode('utf-8')))
if anki21:
return urllib.parse.urljoin(
'file:', urllib.request.pathname2url(path))
else:
return urllib.parse.urljoin(
'file:', urllib.request.pathname2url(path.encode('utf-8')))

def fname2img(path):
"""Return HTML img element for given path"""
Expand Down Expand Up @@ -87,4 +95,4 @@ def _svg_convert_size(size):
if size[-2:] in conversion_table:
return round(float(size[:-2]) * conversion_table[size[-2:]])

return round(float(size))
return round(float(size))