libdev 0.87__tar.gz → 0.88__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {libdev-0.87 → libdev-0.88}/PKG-INFO +1 -1
- {libdev-0.87 → libdev-0.88}/libdev/__init__.py +1 -1
- {libdev-0.87 → libdev-0.88}/libdev/check.py +23 -0
- {libdev-0.87 → libdev-0.88}/libdev/time.py +1 -0
- {libdev-0.87 → libdev-0.88}/libdev.egg-info/PKG-INFO +1 -1
- {libdev-0.87 → libdev-0.88}/tests/test_check.py +35 -0
- {libdev-0.87 → libdev-0.88}/LICENSE +0 -0
- {libdev-0.87 → libdev-0.88}/README.md +0 -0
- {libdev-0.87 → libdev-0.88}/libdev/cfg.py +0 -0
- {libdev-0.87 → libdev-0.88}/libdev/codes.py +0 -0
- {libdev-0.87 → libdev-0.88}/libdev/crypt.py +0 -0
- {libdev-0.87 → libdev-0.88}/libdev/dev.py +0 -0
- {libdev-0.87 → libdev-0.88}/libdev/doc.py +0 -0
- {libdev-0.87 → libdev-0.88}/libdev/fin.py +0 -0
- {libdev-0.87 → libdev-0.88}/libdev/gen.py +0 -0
- {libdev-0.87 → libdev-0.88}/libdev/img.py +0 -0
- {libdev-0.87 → libdev-0.88}/libdev/lang.py +0 -0
- {libdev-0.87 → libdev-0.88}/libdev/log.py +0 -0
- {libdev-0.87 → libdev-0.88}/libdev/num.py +0 -0
- {libdev-0.87 → libdev-0.88}/libdev/req.py +0 -0
- {libdev-0.87 → libdev-0.88}/libdev/s3.py +0 -0
- {libdev-0.87 → libdev-0.88}/libdev.egg-info/SOURCES.txt +0 -0
- {libdev-0.87 → libdev-0.88}/libdev.egg-info/dependency_links.txt +0 -0
- {libdev-0.87 → libdev-0.88}/libdev.egg-info/requires.txt +0 -0
- {libdev-0.87 → libdev-0.88}/libdev.egg-info/top_level.txt +0 -0
- {libdev-0.87 → libdev-0.88}/setup.cfg +0 -0
- {libdev-0.87 → libdev-0.88}/setup.py +0 -0
- {libdev-0.87 → libdev-0.88}/tests/test_cfg.py +0 -0
- {libdev-0.87 → libdev-0.88}/tests/test_codes.py +0 -0
- {libdev-0.87 → libdev-0.88}/tests/test_crypt.py +0 -0
- {libdev-0.87 → libdev-0.88}/tests/test_dev.py +0 -0
- {libdev-0.87 → libdev-0.88}/tests/test_doc.py +0 -0
- {libdev-0.87 → libdev-0.88}/tests/test_gen.py +0 -0
- {libdev-0.87 → libdev-0.88}/tests/test_img.py +0 -0
- {libdev-0.87 → libdev-0.88}/tests/test_lang.py +0 -0
- {libdev-0.87 → libdev-0.88}/tests/test_log.py +0 -0
- {libdev-0.87 → libdev-0.88}/tests/test_num.py +0 -0
- {libdev-0.87 → libdev-0.88}/tests/test_req.py +0 -0
- {libdev-0.87 → libdev-0.88}/tests/test_s3.py +0 -0
- {libdev-0.87 → libdev-0.88}/tests/test_time.py +0 -0
|
@@ -4,6 +4,7 @@ Checking functionality
|
|
|
4
4
|
|
|
5
5
|
import re
|
|
6
6
|
from typing import Union
|
|
7
|
+
from urllib.parse import urlparse
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
PATTERN_PHONE = r"\(?\+?[0-9\s\-\(\)./]{7,30}"
|
|
@@ -173,6 +174,28 @@ def check_url(data: str) -> bool:
|
|
|
173
174
|
)
|
|
174
175
|
|
|
175
176
|
|
|
177
|
+
def get_base_url(data: str, protocol: bool = False) -> str | None:
|
|
178
|
+
"""Get domain"""
|
|
179
|
+
|
|
180
|
+
if not data or "." not in data:
|
|
181
|
+
return None
|
|
182
|
+
data = data.strip().split()[0]
|
|
183
|
+
|
|
184
|
+
if "://" not in data:
|
|
185
|
+
data = "http://" + data
|
|
186
|
+
|
|
187
|
+
parsed = urlparse(data)
|
|
188
|
+
if not parsed.netloc:
|
|
189
|
+
return None
|
|
190
|
+
|
|
191
|
+
if protocol:
|
|
192
|
+
base_url = f"{parsed.scheme}://{parsed.netloc}"
|
|
193
|
+
else:
|
|
194
|
+
base_url = parsed.netloc
|
|
195
|
+
|
|
196
|
+
return base_url
|
|
197
|
+
|
|
198
|
+
|
|
176
199
|
def get_last_url(data: str) -> str:
|
|
177
200
|
"""Get the last part of a URL"""
|
|
178
201
|
if data is None:
|
|
@@ -320,6 +320,7 @@ def get_next_day(timestamp=None, tz=0):
|
|
|
320
320
|
return int(next_day.timestamp())
|
|
321
321
|
|
|
322
322
|
|
|
323
|
+
# TODO: get previous month (params=-1 +1)
|
|
323
324
|
def get_next_month(timestamp=None, tz=0):
|
|
324
325
|
"""
|
|
325
326
|
Get the start of the next month (midnight on the first day of the next month) for a given timestamp in a specified timezone.
|
|
@@ -6,6 +6,7 @@ from libdev.check import (
|
|
|
6
6
|
check_mail,
|
|
7
7
|
fake_mail,
|
|
8
8
|
check_url,
|
|
9
|
+
get_base_url,
|
|
9
10
|
get_last_url,
|
|
10
11
|
)
|
|
11
12
|
|
|
@@ -91,6 +92,40 @@ def test_check_url():
|
|
|
91
92
|
assert check_url("http://a.bc") == True
|
|
92
93
|
assert check_url("https://chill.services/") == True
|
|
93
94
|
assert check_url("https://t.me/kosyachniy") == True
|
|
95
|
+
assert check_url("http2://www.asd.atcsd.ru\nhttp://www.asd.atcsd.ru/") == False
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def test_get_base_url():
|
|
99
|
+
assert get_base_url(None) == None
|
|
100
|
+
assert get_base_url("") == None
|
|
101
|
+
assert get_base_url("http") == None
|
|
102
|
+
assert get_base_url("http://") == None
|
|
103
|
+
assert get_base_url("http://a/") == None
|
|
104
|
+
assert get_base_url("http://a.b") == "a.b"
|
|
105
|
+
assert get_base_url("http://a.bc", protocol=True) == "http://a.bc"
|
|
106
|
+
assert (
|
|
107
|
+
get_base_url("https://chill.services/", protocol=True)
|
|
108
|
+
== "https://chill.services"
|
|
109
|
+
)
|
|
110
|
+
assert get_base_url("https://t.me/kosyachniy", protocol=True) == "https://t.me"
|
|
111
|
+
assert (
|
|
112
|
+
get_base_url("http://www.atcsd.ru\nhttp://www.asd.atcsd.ru/", protocol=True)
|
|
113
|
+
== "http://www.atcsd.ru"
|
|
114
|
+
)
|
|
115
|
+
assert (
|
|
116
|
+
get_base_url(
|
|
117
|
+
"http2://www.asd.atcsd.ru\nhttp://www.asd.atcsd.ru/", protocol=True
|
|
118
|
+
)
|
|
119
|
+
== "http2://www.asd.atcsd.ru"
|
|
120
|
+
)
|
|
121
|
+
assert (
|
|
122
|
+
get_base_url("https2://127.0.0.1:8080?query=string#fragment", protocol=True)
|
|
123
|
+
== "https2://127.0.0.1:8080"
|
|
124
|
+
)
|
|
125
|
+
assert (
|
|
126
|
+
get_base_url("127.0.0.1:8080/path/to/page?query=string#fragment", protocol=True)
|
|
127
|
+
== "http://127.0.0.1:8080"
|
|
128
|
+
)
|
|
94
129
|
|
|
95
130
|
|
|
96
131
|
def test_get_last_url():
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|