mirror of
https://github.com/rbreu/beeref.git
synced 2026-03-11 08:54:28 +00:00
Fix pasting images from Web when URL contanis non-ASCII chars (#87)
This commit is contained in:
parent
c6a68116e6
commit
327126b649
2 changed files with 16 additions and 2 deletions
|
|
@ -84,9 +84,10 @@ def load_image(path):
|
|||
path = os.path.normpath(path.toLocalFile())
|
||||
return (exif_rotated_image(path), path)
|
||||
|
||||
url = bytes(path.toEncoded()).decode()
|
||||
img = exif_rotated_image()
|
||||
try:
|
||||
imgdata = request.urlopen(path.url()).read()
|
||||
imgdata = request.urlopen(url).read()
|
||||
except URLError as e:
|
||||
logger.debug(f'Downloading image failed: {e.reason}')
|
||||
else:
|
||||
|
|
@ -96,4 +97,4 @@ def load_image(path):
|
|||
f.write(imgdata)
|
||||
logger.debug(f'Temporarily saved in: {fname}')
|
||||
img = exif_rotated_image(fname)
|
||||
return (img, path.url())
|
||||
return (img, url)
|
||||
|
|
|
|||
|
|
@ -91,6 +91,19 @@ def test_load_image_loads_from_existing_web_url(view, imgdata3x3):
|
|||
assert filename == url
|
||||
|
||||
|
||||
@httpretty.activate
|
||||
def test_load_image_loads_from_existing_web_url_non_ascii(view, imgdata3x3):
|
||||
url = 'http://example.com/föö.png'
|
||||
httpretty.register_uri(
|
||||
httpretty.GET,
|
||||
url,
|
||||
body=imgdata3x3,
|
||||
)
|
||||
img, filename = load_image(QtCore.QUrl(url))
|
||||
assert img.isNull() is False
|
||||
assert filename == 'http://example.com/f%C3%B6%C3%B6.png'
|
||||
|
||||
|
||||
@httpretty.activate
|
||||
def test_load_image_loads_from_web_url_errors(view, imgfilename3x3):
|
||||
url = 'http://example.com/foo.png'
|
||||
|
|
|
|||
Loading…
Reference in a new issue