net_utils.py¶
Net utilities.
__all__ = ['resolve_hostname', 'validate_scheme_host_port']
module-attribute
¶
is_valid_hostname(hostname)
¶
Validate a host name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hostname |
str
|
host name to validate. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if is valid else False. |
Source code in solnlib/net_utils.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
is_valid_ip(addr)
¶
Validate an IPV4 address.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
addr |
str
|
IP address to validate. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if is valid else False. |
Source code in solnlib/net_utils.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
is_valid_port(port)
¶
Validate a port.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
port |
Union[str, int]
|
port to validate. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if is valid else False. |
Source code in solnlib/net_utils.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
is_valid_scheme(scheme)
¶
Validate a scheme.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scheme |
str
|
scheme to validate. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if is valid else False. |
Source code in solnlib/net_utils.py
126 127 128 129 130 131 132 133 134 135 136 |
|
resolve_hostname(addr)
¶
Try to resolve an IP to a host name and returns None on common failures.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
addr |
str
|
IP address to resolve. |
required |
Returns:
Type | Description |
---|---|
Optional[str]
|
Host name if success else None. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in solnlib/net_utils.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
validate_scheme_host_port(scheme, host, port)
¶
Validates scheme, host and port.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scheme |
str
|
scheme to validate. |
required |
host |
str
|
hostname to validate. |
required |
port |
Union[str, int]
|
port to validate. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
if scheme, host or port are invalid. |
Source code in solnlib/net_utils.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|