| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ca23a8e commit 7a77373
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,14 @@ | |||
| 1 | 1 | Changelog | |
| 2 | 2 | --------- | |
| 3 | 3 | ||
| 4 | - 0.8.0 (unreleased) | ||
| 4 | + | ||
| 5 | + 0.9.0 (2015-10-10) | ||
| 6 | + ^^^^^^^^^^^^^^^^^^ | ||
| 7 | + | ||
| 8 | + - Added new validator: ``domain`` | ||
| 9 | + | ||
| 10 | + | ||
| 11 | + 0.8.0 (2015-06-24) | ||
| 5 | 12 | ^^^^^^^^^^^^^^^^^^ | |
| 6 | 13 | ||
| 7 | 14 | - Added new validator: ``iban`` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,6 +68,14 @@ between | |||
| 68 | 68 | .. autofunction:: between | |
| 69 | 69 | ||
| 70 | 70 | ||
| 71 | + domain | ||
| 72 | + ------ | ||
| 73 | + | ||
| 74 | + .. module:: validators.domain | ||
| 75 | + | ||
| 76 | + .. autofunction:: domain | ||
| 77 | + | ||
| 78 | + | ||
| 71 | 79 | email | |
| 72 | 80 | ----- | |
| 73 | 81 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,21 @@ | |||
| 1 | + # -*- coding: utf-8 -*- | ||
| 2 | + import pytest | ||
| 3 | + from validators import domain, ValidationFailure | ||
| 4 | + | ||
| 5 | + | ||
| 6 | + @pytest.mark.parametrize(('value',), [ | ||
| 7 | + ('example.com',), | ||
| 8 | + ]) | ||
| 9 | + def test_returns_true_on_valid_domain(value): | ||
| 10 | + assert domain(value) | ||
| 11 | + | ||
| 12 | + | ||
| 13 | + @pytest.mark.parametrize(('value',), [ | ||
| 14 | + ('example.com/',), | ||
| 15 | + ('example.com:4444',), | ||
| 16 | + ('example.-com',), | ||
| 17 | + ('example.',), | ||
| 18 | + ('example',), | ||
| 19 | + ]) | ||
| 20 | + def test_returns_failed_validation_on_invalid_domain(value): | ||
| 21 | + assert isinstance(domain(value), ValidationFailure) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,15 +1,16 @@ | |||
| 1 | - from .between import between | ||
| 2 | - from .email import email | ||
| 3 | - from .extremes import Min, Max | ||
| 4 | - from .iban import iban | ||
| 5 | - from .ip_address import ipv4, ipv6 | ||
| 6 | - from .i18n import fi_business_id, fi_ssn | ||
| 7 | - from .length import length | ||
| 8 | - from .mac_address import mac_address | ||
| 9 | - from .slug import slug | ||
| 10 | - from .truthy import truthy | ||
| 11 | - from .url import url | ||
| 12 | - from .utils import ValidationFailure, validator | ||
| 13 | - from .uuid import uuid | ||
| 1 | + from .between import between # noqa | ||
| 2 | + from .domain import domain # noqa | ||
| 3 | + from .email import email # noqa | ||
| 4 | + from .extremes import Min, Max # noqa | ||
| 5 | + from .iban import iban # noqa | ||
| 6 | + from .ip_address import ipv4, ipv6 # noqa | ||
| 7 | + from .i18n import fi_business_id, fi_ssn # noqa | ||
| 8 | + from .length import length # noqa | ||
| 9 | + from .mac_address import mac_address # noqa | ||
| 10 | + from .slug import slug # noqa | ||
| 11 | + from .truthy import truthy # noqa | ||
| 12 | + from .url import url # noqa | ||
| 13 | + from .utils import ValidationFailure, validator # noqa | ||
| 14 | + from .uuid import uuid # noqa | ||
| 14 | 15 | ||
| 15 | 16 | __version__ = '0.8' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + import re | ||
| 2 | + from .utils import validator | ||
| 3 | + | ||
| 4 | + pattern = re.compile( | ||
| 5 | + r'^(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.)' | ||
| 6 | + r'{1,126}(?!\d+)[a-zA-Z\d]{1,63}$' | ||
| 7 | + ) | ||
| 8 | + | ||
| 9 | + | ||
| 10 | + @validator | ||
| 11 | + def domain(value): | ||
| 12 | + """ | ||
| 13 | + Return whether or not given value is a valid domain. | ||
| 14 | + | ||
| 15 | + If the value is valid domain name this function returns ``True``, otherwise | ||
| 16 | + :class:`~validators.utils.ValidationFailure`. | ||
| 17 | + | ||
| 18 | + Examples:: | ||
| 19 | + | ||
| 20 | + >>> domain('example.com') | ||
| 21 | + True | ||
| 22 | + | ||
| 23 | + >>> domain('example.com/') | ||
| 24 | + ValidationFailure(func=domain, ...) | ||
| 25 | + | ||
| 26 | + :param value: domain string to validate | ||
| 27 | + """ | ||
| 28 | + return pattern.match(value) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1 +1 @@ | |||
| 1 | - from .fi import fi_ssn, fi_business_id | ||
| 1 | + from .fi import fi_ssn, fi_business_id # noqa | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments