Skip to content

Commit 2dd10b0

Browse files
committed
lib upgrades: pyproj, lxml, owslib, libpass - removed: wtforms, passlib
1 parent 7b2cac4 commit 2dd10b0

5 files changed

Lines changed: 264 additions & 204 deletions

File tree

GeoHealthCheck/models.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
import json
3232
import logging
33-
from flask_babel import gettext as _
3433
from datetime import datetime, timedelta, timezone
3534
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
3635
from sqlalchemy import func, and_
@@ -43,7 +42,6 @@
4342
from factory import Factory
4443
from init import App
4544
from resourceauth import ResourceAuth
46-
from wtforms.validators import Email, ValidationError
4745
from owslib.util import bind_url
4846

4947
APP = App.get_app()
@@ -246,30 +244,21 @@ def _validate_webhook(value):
246244
try:
247245
_parse_webhook_location(value)
248246
except ValueError as err:
249-
raise ValidationError('{}: {}'.format(value, err))
247+
raise ValueError('{}: {}'.format(value, err))
250248
return value
251249

252250

253251
def _validate_email(value):
254252
if not value:
255-
raise ValidationError("Email cannot be empty value")
253+
raise ValueError("Email cannot be empty value")
256254
try:
257255
if not value.strip():
258-
raise ValidationError("Email cannot be empty value")
256+
raise ValueError("Email cannot be empty value")
259257
except AttributeError:
260-
raise ValidationError("Email cannot be empty value")
258+
raise ValueError("Email cannot be empty value")
261259

262-
v = Email()
263-
264-
class dummy_value(object):
265-
data = value
266-
267-
@staticmethod
268-
def gettext(*args, **kwargs):
269-
return _(*args, **kwargs)
270-
271-
dummy_form = None
272-
v(dummy_form, dummy_value())
260+
if not util.validate_email(value):
261+
raise ValueError("Invalid email address")
273262

274263

275264
class Recipient(DB.Model):
@@ -313,7 +302,7 @@ def validate(cls, channel, value):
313302
for v in validators:
314303
try:
315304
v(value)
316-
except (ValidationError, TypeError) as err:
305+
except (ValueError, TypeError) as err:
317306
raise ValueError("Bad value: {}".format(err), err)
318307

319308
def is_email(self):
@@ -337,7 +326,7 @@ def burry_dead(cls):
337326
def get_or_create(cls, channel, location):
338327
try:
339328
cls.validate(channel, location)
340-
except ValidationError as err:
329+
except ValueError as err:
341330
raise ValueError("invalid value {}: {}".format(location, err))
342331

343332
try:

GeoHealthCheck/plugins/probe/ogcfeat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from owslib.ogcapi.features import Features
2-
from openapi_spec_validator import openapi_v3_spec_validator
2+
from openapi_spec_validator import openapi_v30_spec_validator
33

44
from GeoHealthCheck.probe import Probe
55
from GeoHealthCheck.result import Result, push_result
@@ -339,7 +339,7 @@ def perform_request(self):
339339
result.start()
340340
try:
341341
# Call the openapi-spec-validator and iterate through errors
342-
errors_iterator = openapi_v3_spec_validator.iter_errors(api_doc)
342+
errors_iterator = openapi_v30_spec_validator.iter_errors(api_doc)
343343
for error in errors_iterator:
344344
# Add each validation error as separate Result object
345345
result = push_result(

GeoHealthCheck/util.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io
3131
import logging
3232
import os
33+
import re
3334
import smtplib
3435
import base64
3536
import requests
@@ -47,6 +48,7 @@
4748
APP = App.get_app()
4849
CONFIG = App.get_config()
4950
LOGGER = logging.getLogger(__name__)
51+
EMAIL_REGEX = r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,7}"
5052

5153

5254
def average(values):
@@ -193,6 +195,12 @@ def send_email(mail_config, fromaddr, toaddr, msg):
193195
return True
194196

195197

198+
def validate_email(email):
199+
"""convenience function to validate an email address"""
200+
201+
return re.fullmatch(EMAIL_REGEX, email)
202+
203+
196204
def geocode(value, spatial_keyword_type='hostname'):
197205
"""convenience function to geocode a value"""
198206
lat, lon = 0.0, 0.0

0 commit comments

Comments
 (0)