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.
Files changed (40) hide show
  1. {libdev-0.87 → libdev-0.88}/PKG-INFO +1 -1
  2. {libdev-0.87 → libdev-0.88}/libdev/__init__.py +1 -1
  3. {libdev-0.87 → libdev-0.88}/libdev/check.py +23 -0
  4. {libdev-0.87 → libdev-0.88}/libdev/time.py +1 -0
  5. {libdev-0.87 → libdev-0.88}/libdev.egg-info/PKG-INFO +1 -1
  6. {libdev-0.87 → libdev-0.88}/tests/test_check.py +35 -0
  7. {libdev-0.87 → libdev-0.88}/LICENSE +0 -0
  8. {libdev-0.87 → libdev-0.88}/README.md +0 -0
  9. {libdev-0.87 → libdev-0.88}/libdev/cfg.py +0 -0
  10. {libdev-0.87 → libdev-0.88}/libdev/codes.py +0 -0
  11. {libdev-0.87 → libdev-0.88}/libdev/crypt.py +0 -0
  12. {libdev-0.87 → libdev-0.88}/libdev/dev.py +0 -0
  13. {libdev-0.87 → libdev-0.88}/libdev/doc.py +0 -0
  14. {libdev-0.87 → libdev-0.88}/libdev/fin.py +0 -0
  15. {libdev-0.87 → libdev-0.88}/libdev/gen.py +0 -0
  16. {libdev-0.87 → libdev-0.88}/libdev/img.py +0 -0
  17. {libdev-0.87 → libdev-0.88}/libdev/lang.py +0 -0
  18. {libdev-0.87 → libdev-0.88}/libdev/log.py +0 -0
  19. {libdev-0.87 → libdev-0.88}/libdev/num.py +0 -0
  20. {libdev-0.87 → libdev-0.88}/libdev/req.py +0 -0
  21. {libdev-0.87 → libdev-0.88}/libdev/s3.py +0 -0
  22. {libdev-0.87 → libdev-0.88}/libdev.egg-info/SOURCES.txt +0 -0
  23. {libdev-0.87 → libdev-0.88}/libdev.egg-info/dependency_links.txt +0 -0
  24. {libdev-0.87 → libdev-0.88}/libdev.egg-info/requires.txt +0 -0
  25. {libdev-0.87 → libdev-0.88}/libdev.egg-info/top_level.txt +0 -0
  26. {libdev-0.87 → libdev-0.88}/setup.cfg +0 -0
  27. {libdev-0.87 → libdev-0.88}/setup.py +0 -0
  28. {libdev-0.87 → libdev-0.88}/tests/test_cfg.py +0 -0
  29. {libdev-0.87 → libdev-0.88}/tests/test_codes.py +0 -0
  30. {libdev-0.87 → libdev-0.88}/tests/test_crypt.py +0 -0
  31. {libdev-0.87 → libdev-0.88}/tests/test_dev.py +0 -0
  32. {libdev-0.87 → libdev-0.88}/tests/test_doc.py +0 -0
  33. {libdev-0.87 → libdev-0.88}/tests/test_gen.py +0 -0
  34. {libdev-0.87 → libdev-0.88}/tests/test_img.py +0 -0
  35. {libdev-0.87 → libdev-0.88}/tests/test_lang.py +0 -0
  36. {libdev-0.87 → libdev-0.88}/tests/test_log.py +0 -0
  37. {libdev-0.87 → libdev-0.88}/tests/test_num.py +0 -0
  38. {libdev-0.87 → libdev-0.88}/tests/test_req.py +0 -0
  39. {libdev-0.87 → libdev-0.88}/tests/test_s3.py +0 -0
  40. {libdev-0.87 → libdev-0.88}/tests/test_time.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: libdev
3
- Version: 0.87
3
+ Version: 0.88
4
4
  Summary: Set of standard functions for development
5
5
  Home-page: https://github.com/chilleco/lib
6
6
  Author: Alex Poloz
@@ -2,6 +2,6 @@
2
2
  Initializing the Python package
3
3
  """
4
4
 
5
- __version__ = "0.87"
5
+ __version__ = "0.88"
6
6
 
7
7
  __all__ = ("__version__",)
@@ -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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: libdev
3
- Version: 0.87
3
+ Version: 0.88
4
4
  Summary: Set of standard functions for development
5
5
  Home-page: https://github.com/chilleco/lib
6
6
  Author: Alex Poloz
@@ -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