Renamed validators to shop_validators to fix clash between existing validators library
This commit is contained in:
parent
a659bbfffc
commit
bd685cfa72
2 changed files with 23 additions and 0 deletions
0
shop_validators/__init__.py
Normal file
0
shop_validators/__init__.py
Normal file
23
shop_validators/image_validator.py
Normal file
23
shop_validators/image_validator.py
Normal 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
|
||||||
Loading…
Reference in a new issue