File: utils.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (31 lines) | stat: -rw-r--r-- 1,122 bytes parent folder | download | duplicates (2)
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
26
27
28
29
30
31
"""Pagination control model for Route53."""

from .exceptions import InvalidPaginationToken, UnsupportedCharacter

PAGINATION_MODEL = {
    "list_hosted_zones": {
        "input_token": "marker",
        "limit_key": "max_size",
        "limit_default": 100,
        "unique_attribute": "id",
    },
    "list_query_logging_configs": {
        "input_token": "next_token",
        "limit_key": "max_results",
        "limit_default": 100,
        "unique_attribute": "hosted_zone_id",
        "fail_on_invalid_token": InvalidPaginationToken,
    },
}


def validate_domain_name(domain_name: str, code: str = "InvalidInput") -> None:
    # https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/DomainNameFormat.html
    # Domain names can get wacky with international alphabets/emojis
    # (https://i❤️.ws is valid!)
    # We only validate that some reserved characters (0-40, 177-377) are prefaced with a backslash
    prev = ""
    for char in domain_name:
        if (ord(char) <= 32 or (127 < ord(char) < 255)) and prev != "\\":
            raise UnsupportedCharacter(code=code, char=char)
        prev = char