Renamed validators to shop_validators to fix clash between existing validators library

This commit is contained in:
Yarninator 2024-08-05 13:40:37 +02:00
parent a659bbfffc
commit bd685cfa72
2 changed files with 23 additions and 0 deletions

View file

View file

@ -0,0 +1,23 @@
import re
from PIL import Image
def is_valid_image(file_name):
try:
with Image.open(file_name) as img:
img.verify()
return True
except (IOError, SyntaxError):
return False
def is_valid_svg(file_name):
SVG_R = r'(?:<\?xml\b[^>]*>[^<]*)?(?:<!--.*?-->[^<]*)*(?:<svg|<!DOCTYPE svg)\b'
SVG_RE = re.compile(SVG_R, re.DOTALL)
file_object = open(file_name, 'r')
file_contents = file_object.read()
is_svg = SVG_RE.match(file_contents) is not None
return is_svg