• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LeanderCS / flask-inputfilter / #72

18 Jan 2025 10:38PM UTC coverage: 98.065% (-1.2%) from 99.252%
#72

push

coveralls-python

web-flow
Merge pull request #21 from LeanderCS/17

17 | Add new filters and validators

156 of 173 new or added lines in 11 files covered. (90.17%)

1216 of 1240 relevant lines covered (98.06%)

0.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.0
/flask_inputfilter/Validator/IsVerticalImageValidator.py
1
import base64
1✔
2
import io
1✔
3
from typing import Any
1✔
4

5
from PIL import Image
1✔
6
from PIL.Image import Image as ImageType
1✔
7

8
from flask_inputfilter.Exception import ValidationError
1✔
9
from flask_inputfilter.Validator import BaseValidator
1✔
10

11

12
class IsVerticalImageValidator(BaseValidator):
1✔
13
    def __init__(self, error_message=None):
1✔
14
        self.error_message = (
1✔
15
            error_message or "The image is not vertically oriented."
16
        )
17

18
    def validate(self, value: Any) -> None:
1✔
19
        if not isinstance(value, (str, ImageType)):
1✔
NEW
20
            raise ValidationError(
×
21
                "The value is not an image or its base 64 representation."
22
            )
23

24
        try:
1✔
25
            if isinstance(value, str):
1✔
26
                value = Image.open(io.BytesIO(base64.b64decode(value)))
1✔
27

28
            if value.width > value.height:
1✔
29
                raise
1✔
30

31
        except Exception:
1✔
32
            raise ValidationError(self.error_message)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc