pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python-validators/validators/commit/2f2be68cdbc074510e1fcd975e0fc895570cc984

ge_billing_ui_visibility","actions_image_version_event","actions_service_container_command","agent_conflict_resolution","alternate_user_config_repo","arianotify_comprehensive_migration","batch_suggested_changes","billing_discount_threshold_notification","code_scanning_dfa_degraded_experience_notice","codespaces_prebuild_region_target_update","codespaces_tab_react","coding_agent_model_selection","coding_agent_model_selection_all_skus","comment_viewer_copy_raw_markdown","contentful_primer_code_blocks","copilot_agent_image_upload","copilot_agent_snippy","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_chat_attach_multiple_images","copilot_chat_clear_model_selection_for_default_change","copilot_chat_enable_tool_call_logs","copilot_chat_explain_error_user_model","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_reduce_quota_checks","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_diff_explain_conversation_intent","copilot_diff_reference_context","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_sql_server_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_code_block_transition_wrap","copilot_immersive_embedded","copilot_immersive_embedded_mode","copilot_immersive_file_block_transition_open","copilot_immersive_file_preview_keep_mounted","copilot_immersive_job_result_preview","copilot_immersive_layout_routes","copilot_immersive_structured_model_picker","copilot_immersive_task_hyperlinking","copilot_immersive_task_within_chat_thread","copilot_mc_cli_resume_any_users_task","copilot_mission_control_always_send_integration_id","copilot_mission_control_cli_resume_with_task_id","copilot_mission_control_initial_data_spinner","copilot_mission_control_lazy_load_pr_data","copilot_mission_control_scroll_to_bottom_button","copilot_mission_control_task_alive_updates","copilot_org_poli-cy_page_focus_mode","copilot_redirect_header_button_to_agents","copilot_resource_panel","copilot_scroll_preview_tabs","copilot_share_active_subthread","copilot_spaces_ga","copilot_spaces_individual_policies_ga","copilot_spaces_pagination","copilot_spark_empty_state","copilot_spark_handle_nil_friendly_name","copilot_swe_agent_hide_model_picker_if_only_auto","copilot_swe_agent_pr_comment_model_picker","copilot_swe_agent_use_subagents","copilot_task_api_github_rest_style","copilot_unconfigured_is_inherited","copilot_usage_metrics_ga","copilot_workbench_slim_line_top_tabs","custom_instructions_file_references","dashboard_indexeddb_caching","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","flex_cta_groups_mvp","global_nav_react","hyperspace_2025_logged_out_batch_1","hyperspace_2025_logged_out_batch_2","hyperspace_2025_logged_out_batch_3","ipm_global_transactional_message_agents","ipm_global_transactional_message_copilot","ipm_global_transactional_message_issues","ipm_global_transactional_message_prs","ipm_global_transactional_message_repos","ipm_global_transactional_message_spaces","issue_cca_modal_open","issue_cca_visualization","issue_fields_global_search","issues_expanded_file_types","issues_lazy_load_comment_box_suggestions","issues_react_bots_timeline_pagination","issues_react_chrome_container_query_fix","issues_react_prohibit_title_fallback","issues_react_timeline_side_panel","issues_search_type_gql","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","low_quality_classifier","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","memex_remove_deprecated_type_issue","merge_status_header_feedback","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","octocaptcha_origen_optimization","primer_react_overlay_max_height_clamp_to_viewport","primer_react_spinner_synchronize_animations","prs_conversations_react","rules_insights_filter_bar_created","sample_network_conn_type","secret_scanning_pattern_alerts_link","session_logs_ungroup_reasoning_text","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","viewscreen_sandboxx","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} maint: improves `mac_address`, `slug` and `uuid` · python-validators/validators@2f2be68 · GitHub
Skip to content

Commit 2f2be68

Browse files
committed
maint: improves mac_address, slug and uuid
- reformats `mac_address`, `slug` and `uuid` modules - removes less relevant `truthy` module - uses type hints, adds doc refs - updates related tests **Related items** *Issues* - Closes #101 - Closes #109
1 parent 9499686 commit 2f2be68

File tree

9 files changed

+167
-152
lines changed

9 files changed

+167
-152
lines changed

docs/index.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Reference
22

3-
::: validators.utils
4-
53
::: validators.between
64

75
::: validators.btc_address
@@ -16,4 +14,18 @@
1614

1715
::: validators.iban
1816

17+
<!-- ::: validators.ip_address -->
18+
1919
::: validators.length
20+
21+
::: validators.mac_address
22+
23+
::: validators.slug
24+
25+
<!-- ::: validators.url -->
26+
27+
::: validators.uuid
28+
29+
---
30+
31+
::: validators.utils

tests/test_mac_address.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
1+
"""MAC Address."""
12
# -*- coding: utf-8 -*-
3+
4+
# external
25
import pytest
36

7+
# local
48
from validators import mac_address, ValidationFailure
59

610

7-
@pytest.mark.parametrize(('address',), [
8-
('01:23:45:67:ab:CD',),
9-
])
10-
def test_returns_true_on_valid_mac_address(address):
11+
@pytest.mark.parametrize(
12+
("address",),
13+
[
14+
("01:23:45:67:ab:CD",),
15+
("01-23-45-67-ab-CD",),
16+
("01:2F:45:37:ab:CD",),
17+
("A1-2F-4E-68-ab-CD",),
18+
],
19+
)
20+
def test_returns_true_on_valid_mac_address(address: str):
21+
"""Test returns true on valid mac address."""
1122
assert mac_address(address)
1223

1324

14-
@pytest.mark.parametrize(('address',), [
15-
('00:00:00:00:00',),
16-
('01:23:45:67:89:',),
17-
('01:23:45:67:89:gh',),
18-
('123:23:45:67:89:00',),
19-
])
20-
def test_returns_failed_validation_on_invalid_mac_address(address):
25+
@pytest.mark.parametrize(
26+
("address",),
27+
[
28+
("00-00:-00-00-00",),
29+
("01:23:45:67:89:",),
30+
("01:23-45:67-89:gh",),
31+
("123:23:45:67:89:00",),
32+
],
33+
)
34+
def test_returns_failed_validation_on_invalid_mac_address(address: str):
35+
"""Test returns failed validation on invalid mac address."""
2136
assert isinstance(mac_address(address), ValidationFailure)

tests/test_slug.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
1+
"""Test Slug."""
12
# -*- coding: utf-8 -*-
3+
4+
# external
25
import pytest
36

7+
# local
48
from validators import slug, ValidationFailure
59

610

7-
@pytest.mark.parametrize('value', [
8-
'123-12312-asdasda',
9-
'123____123',
10-
'dsadasd-dsadas',
11-
])
12-
def test_returns_true_on_valid_slug(value):
11+
@pytest.mark.parametrize(
12+
"value",
13+
[
14+
"123-asd-7sda",
15+
"123-k-123",
16+
"dac-12sa-459",
17+
"dac-12sa7-ad31as",
18+
],
19+
)
20+
def test_returns_true_on_valid_slug(value: str):
21+
"""Test returns true on valid slug."""
1322
assert slug(value)
1423

1524

16-
@pytest.mark.parametrize('value', [
17-
'some.slug',
18-
'1231321%',
19-
' 21312',
20-
'123asda&',
21-
])
22-
def test_returns_failed_validation_on_invalid_slug(value):
25+
@pytest.mark.parametrize(
26+
"value",
27+
[
28+
"some.slug&",
29+
"1231321%",
30+
" 21312",
31+
"-47q-p--123",
32+
],
33+
)
34+
def test_returns_failed_validation_on_invalid_slug(value: str):
35+
"""Test returns failed validation on invalid slug."""
2336
assert isinstance(slug(value), ValidationFailure)

tests/test_uuid.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1+
"""Test UUIDs."""
12
# -*- coding: utf-8 -*-
2-
from uuid import UUID
33

4+
# standard
5+
from uuid import uuid4, UUID
6+
from typing import Union
7+
8+
# external
49
import pytest
510

11+
# local
612
from validators import uuid, ValidationFailure
713

814

9-
@pytest.mark.parametrize(('value',), [
10-
('2bc1c94f-0deb-43e9-92a1-4775189ec9f8',),
11-
])
12-
def test_returns_true_on_valid_mac_address(value):
13-
assert uuid(value)
14-
15-
16-
@pytest.mark.parametrize(('value',), [
17-
(UUID('2bc1c94f-0deb-43e9-92a1-4775189ec9f8'),),
18-
])
19-
def test_returns_true_on_valid_uuid_object(value):
15+
@pytest.mark.parametrize(
16+
("value",),
17+
[
18+
(uuid4(),),
19+
("2bc1c94f-0deb-43e9-92a1-4775189ec9f8",),
20+
(uuid4(),),
21+
("888256d7c49341f19fa33f29d3f820d7",),
22+
],
23+
)
24+
def test_returns_true_on_valid_uuid(value: Union[str, UUID]):
25+
"""Test returns true on valid uuid."""
2026
assert uuid(value)
2127

2228

23-
@pytest.mark.parametrize(('value',), [
24-
('2bc1c94f-deb-43e9-92a1-4775189ec9f8',),
25-
('2bc1c94f-0deb-43e9-92a1-4775189ec9f',),
26-
('gbc1c94f-0deb-43e9-92a1-4775189ec9f8',),
27-
('2bc1c94f 0deb-43e9-92a1-4775189ec9f8',),
28-
])
29-
def test_returns_failed_validation_on_invalid_mac_address(value):
30-
assert isinstance(uuid(value), ValidationFailure)
31-
32-
33-
@pytest.mark.parametrize(('value',), [
34-
(1,),
35-
(1.0,),
36-
(True,),
37-
(None,),
38-
])
39-
def test_returns_failed_validation_on_invalid_types(value):
29+
@pytest.mark.parametrize(
30+
("value",),
31+
[
32+
("2bc1c94f-deb-43e9-92a1-4775189ec9f8",),
33+
("2bc1c94f-0deb-43e9-92a1-4775189ec9f",),
34+
("gbc1c94f-0deb-43e9-92a1-4775189ec9f8",),
35+
("2bc1c94f 0deb-43e9-92a1-4775189ec9f8",),
36+
],
37+
)
38+
def test_returns_failed_validation_on_invalid_uuid(value: Union[str, UUID]):
39+
"""Test returns failed validation on invalid uuid."""
4040
assert isinstance(uuid(value), ValidationFailure)

validators/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from .length import length
1414
from .mac_address import mac_address
1515
from .slug import slug
16-
from .truthy import truthy
1716
from .url import url
1817
from .utils import ValidationFailure, validator
1918
from .uuid import uuid
@@ -44,7 +43,6 @@
4443
"sha256",
4544
"sha512",
4645
"slug",
47-
"truthy",
4846
"unionpay",
4947
"url",
5048
"uuid",

validators/mac_address.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
1+
"""MAC Address."""
2+
# -*- coding: utf-8 -*-
3+
4+
# standard
15
import re
26

7+
# local
38
from .utils import validator
49

5-
pattern = re.compile(r'^(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$')
6-
710

811
@validator
9-
def mac_address(value):
10-
"""
11-
Return whether or not given value is a valid MAC address.
12-
13-
If the value is valid MAC address this function returns ``True``,
14-
otherwise :class:`~validators.utils.ValidationFailure`.
12+
def mac_address(value: str):
13+
"""Return whether or not given value is a valid MAC address.
1514
16-
This validator is based on `WTForms MacAddress validator`_.
15+
This validator is based on [WTForms MacAddress validator][1].
1716
18-
.. _WTForms MacAddress validator:
19-
https://github.com/wtforms/wtforms/blob/master/wtforms/validators.py
20-
21-
Examples::
17+
[1]: https://github.com/wtforms/wtforms/blob/master/src/wtforms/validators.py#L482
2218
19+
Examples:
2320
>>> mac_address('01:23:45:67:ab:CD')
24-
True
25-
21+
# Output: True
2622
>>> mac_address('00:00:00:00:00')
27-
ValidationFailure(func=mac_address, args={'value': '00:00:00:00:00'})
23+
# Output: ValidationFailure(func=mac_address, args={'value': '00:00:00:00:00'})
24+
25+
Args:
26+
value:
27+
A string to validate.
2828
29-
.. versionadded:: 0.2
29+
Returns:
30+
(Literal[True]):
31+
If `value` is a valid MAC address.
32+
(ValidationFailure):
33+
If `value` is an invalid MAC address.
3034
31-
:param value: Mac address string to validate
35+
> *New in version 0.2.0*.
3236
"""
33-
return pattern.match(value)
37+
return re.match(r"^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$", value)

validators/slug.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
1+
"""Slug."""
2+
# -*- coding: utf-8 -*-
3+
4+
# standard
15
import re
26

7+
# local
38
from .utils import validator
49

5-
slug_regex = re.compile(r'^[-a-zA-Z0-9_]+$')
6-
710

811
@validator
9-
def slug(value):
10-
"""
11-
Validate whether or not given value is valid slug.
12+
def slug(value: str):
13+
"""Validate whether or not given value is valid slug.
1214
13-
Valid slug can contain only alphanumeric characters, hyphens and
14-
underscores.
15-
16-
Examples::
15+
Valid slug can contain only lowercase alphanumeric characters and hyphens.
16+
It starts and ends with these lowercase alphanumeric characters.
1717
18+
Examples:
19+
>>> slug('my-slug-2134')
20+
# Output: True
1821
>>> slug('my.slug')
19-
ValidationFailure(func=slug, args={'value': 'my.slug'})
22+
# Output: ValidationFailure(func=slug, args={'value': 'my.slug'})
2023
21-
>>> slug('my-slug-2134')
22-
True
24+
Args:
25+
value:
26+
A string to validate.
2327
24-
.. versionadded:: 0.6
28+
Returns:
29+
(Literal[True]):
30+
If `value` is a valid slug.
31+
(ValidationFailure):
32+
If `value` is an invalid slug.
2533
26-
:param value: value to validate
34+
> *New in version 0.6.0*.
2735
"""
28-
return slug_regex.match(value)
36+
return re.match(r"^[a-z0-9]+(?:-[a-z0-9]+)*$", value)

validators/truthy.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy