Total Complexity | 6 |
Total Lines | 29 |
Duplicated Lines | 0 % |
Coverage | 85% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | 1 | import logging |
|
11 | 1 | class ImageService(Service): |
|
12 | |||
13 | 1 | def __init__(self, template_store, font_store, image_store, **kwargs): |
|
14 | 1 | super().__init__(**kwargs) |
|
15 | 1 | self.template_store = template_store |
|
16 | 1 | self.font_store = font_store |
|
17 | 1 | self.image_store = image_store |
|
18 | |||
19 | 1 | def create(self, template, text, font=None, **options): |
|
20 | 1 | image = Image( |
|
21 | template, text, |
||
22 | font=font or self.font_store.find(Font.DEFAULT), |
||
23 | watermark_font=self.font_store.find(Font.DEFAULT), |
||
24 | **options, |
||
|
|||
25 | ) |
||
26 | |||
27 | 1 | try: |
|
28 | 1 | self.image_store.create(image) |
|
29 | 1 | except OSError as exception: |
|
30 | 1 | if "name too long" in str(exception): |
|
31 | 1 | exception = self.exceptions.FilenameTooLong |
|
32 | 1 | elif "image file" in str(exception): |
|
33 | 1 | exception = self.exceptions.InvalidImageLink |
|
34 | 1 | raise exception from None # pylint: disable=raising-bad-type |
|
35 | except SystemError as exception: |
||
36 | log.warning(exception) |
||
37 | raise self.exceptions.InvalidImageLink from None |
||
38 | |||
39 | return image |
||
40 |