17
17
import shutil
18
18
import subprocess
19
19
import sys
20
+ from urllib .parse import unquote , urlparse
21
+ from urllib .request import pathname2url , url2pathname
20
22
21
23
from PIL import Image , ImageFilter , UnidentifiedImageError
22
24
from bs4 import BeautifulSoup
23
- import six
24
- from six .moves .urllib_parse import unquote , urlparse
25
- from six .moves .urllib_request import pathname2url , url2pathname
26
25
27
26
from pelican import __version__ as pelican_version
28
27
from pelican import signals
@@ -144,7 +143,7 @@ def convert_box(image, top, left, right, bottom):
144
143
else :
145
144
bottom = float (bottom )
146
145
147
- return ( top , left , right , bottom )
146
+ return top , left , right , bottom
148
147
149
148
150
149
def crop (i , left , top , right , bottom ):
@@ -342,7 +341,7 @@ def harvest_images_in_fragment(fragment, settings):
342
341
elif not isinstance (d , dict ):
343
342
raise RuntimeError (
344
343
"Derivative %s definition not handled"
345
- "(must be list or dict)" % ( derivative )
344
+ "(must be list or dict)" % derivative
346
345
)
347
346
348
347
elif "type" not in d :
@@ -419,7 +418,7 @@ def compute_paths(img, settings, derivative):
419
418
def process_img_tag (img , settings , derivative ):
420
419
path = compute_paths (img , settings , derivative )
421
420
if not is_img_identifiable (path .source ):
422
- logger .warn (
421
+ logger .warning (
423
422
"%s Skipping image %s that could not be identified by Pillow" ,
424
423
LOG_PREFIX ,
425
424
path .source ,
@@ -447,7 +446,7 @@ def is_img_identifiable(img_filepath):
447
446
def build_srcset (img , settings , derivative ):
448
447
path = compute_paths (img , settings , derivative )
449
448
if not is_img_identifiable (path .source ):
450
- logger .warn (
449
+ logger .warning (
451
450
"%s Skipping image %s that could not be identified by Pillow" ,
452
451
LOG_PREFIX ,
453
452
path .source ,
@@ -456,7 +455,8 @@ def build_srcset(img, settings, derivative):
456
455
process = settings ["IMAGE_PROCESS" ][derivative ]
457
456
458
457
default = process ["default" ]
459
- if isinstance (default , six .string_types ):
458
+ default_name = ""
459
+ if isinstance (default , str ):
460
460
breakpoints = {i for i , _ in process ["srcset" ]}
461
461
if default not in breakpoints :
462
462
logger .error (
@@ -530,24 +530,30 @@ def convert_div_to_picture_tag(soup, img, group, settings, derivative):
530
530
(default_source_name ,),
531
531
)
532
532
533
- if isinstance (default [1 ], six . string_types ):
533
+ if isinstance (default [1 ], str ):
534
534
default_item_name = default [1 ]
535
535
536
536
elif isinstance (default [1 ], list ):
537
537
default_item_name = "default"
538
538
539
539
source = os .path .join (settings ["PATH" ], default_source ["url" ][1 :])
540
540
destination = os .path .join (
541
- s ["base_path" ],
541
+ default_source ["base_path" ],
542
542
default_source_name ,
543
543
default_item_name ,
544
544
default_source ["filename" ],
545
545
)
546
546
process_image ((source , destination , default [1 ]), settings )
547
+ else :
548
+ raise RuntimeError (
549
+ "Unexpected type for the second value of tuple "
550
+ 'IMAGE_PROCESS["%s"]["default"]; expected string or list.' ,
551
+ (derivative ,),
552
+ )
547
553
548
554
# Change img src to url of default processed image.
549
555
img ["src" ] = os .path .join (
550
- s ["base_url" ],
556
+ default_source ["base_url" ],
551
557
default_source_name ,
552
558
default_item_name ,
553
559
default_source ["filename" ],
@@ -643,24 +649,31 @@ def process_picture(soup, img, group, settings, derivative):
643
649
(default_source_name ,),
644
650
)
645
651
646
- if isinstance (default [1 ], six . string_types ):
652
+ if isinstance (default [1 ], str ):
647
653
default_item_name = default [1 ]
648
654
649
655
elif isinstance (default [1 ], list ):
650
656
default_item_name = "default"
651
657
source = os .path .join (settings ["PATH" ], default_source ["url" ][1 :])
652
658
destination = os .path .join (
653
- s ["base_path" ],
659
+ default_source ["base_path" ],
654
660
default_source_name ,
655
661
default_item_name ,
656
662
default_source ["filename" ],
657
663
)
658
664
659
665
process_image ((source , destination , default [1 ]), settings )
660
666
667
+ else :
668
+ raise RuntimeError (
669
+ "Unexpected type for the second value of tuple "
670
+ 'IMAGE_PROCESS["%s"]["default"]; expected string or list.' ,
671
+ (derivative ,),
672
+ )
673
+
661
674
# Change img src to url of default processed image.
662
675
img ["src" ] = posixpath .join (
663
- s ["base_url" ],
676
+ default_source ["base_url" ],
664
677
default_source_name ,
665
678
default_item_name ,
666
679
default_source ["filename" ],
0 commit comments