File: formats.py

package info (click to toggle)
coreschema 0.0.4-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 172 kB
  • sloc: python: 743; makefile: 3
file content (25 lines) | stat: -rw-r--r-- 481 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import re


email_pattern = re.compile('^[^@]+@[^@]')
uri_pattern = re.compile('^[A-Za-z][A-Za-z0-9+.-]+:')


def validate_format(value, format):
    function = {
        'email': validate_email,
        'uri': validate_uri
    }.get(format, unknown_format)
    return function(value)


def unknown_format(value):
    return value


def validate_email(value):
    return bool(re.match(email_pattern, value))


def validate_uri(value):
    return bool(re.match(uri_pattern, value))