# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from io import BytesIO
-
+from urllib.request import urlopen
from django import forms
from django.conf import settings
from django.utils.translation import gettext_lazy as _, gettext
from django.utils.safestring import mark_safe
from PIL import Image as PILImage
-from cover.utils import get_import_data, FlickrError, URLOpener
+from cover.utils import get_import_data, FlickrError
class ImageAddForm(forms.ModelForm):
if not download_url and not uploaded_file:
raise forms.ValidationError(gettext('No image specified'))
if download_url:
- image_data = URLOpener().open(download_url).read()
+ with urlopen(download_url) as f:
+ image_data = f.read()
width, height = PILImage.open(BytesIO(image_data)).size
else:
width, height = PILImage.open(uploaded_file.file).size