memegen.services.image   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 95.24%

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 36
rs 10
c 0
b 0
f 0
ccs 20
cts 21
cp 0.9524
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ImageService.__init__() 0 5 1
A ImageService.create() 0 21 5
1 1
import log
2
3 1
from ._base import Service
4
from ..domain import Image, Font
5 1
6
7
class ImageService(Service):
8 1
9
    def __init__(self, template_store, font_store, image_store, **kwargs):
10
        super().__init__(**kwargs)
11 1
        self.template_store = template_store
12
        self.font_store = font_store
13 1
        self.image_store = image_store
14 1
15 1
    def create(self, template, text, font=None, **options):
16 1
        image = Image(
17 1
            template, text,
18
            font=font or self.font_store.find(Font.DEFAULT),
19 1
            watermark_font=self.font_store.find(Font.WATERMARK),
20 1
            **options,
21
        )
22
23
        try:
24
            self.image_store.create(image)
25
        except OSError as exception:
26
            if "name too long" in str(exception):
27 1
                exception = self.exceptions.FilenameTooLong
28 1
            elif "image file" in str(exception):
29 1
                exception = self.exceptions.InvalidImageLink
30 1
            raise exception  # pylint: disable=raising-bad-type
31 1
        except (ValueError, SystemError) as exception:
32 1
            log.warning(exception)
33 1
            raise self.exceptions.InvalidImageLink
34 1
35
        return image
36