streamlit-octostar-utils 0.2.4__py3-none-any.whl → 0.2.5__py3-none-any.whl

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.
@@ -6,20 +6,26 @@ def add_filetypes():
6
6
  mimetypes.add_type("text/csv", ".csv")
7
7
 
8
8
 
9
- def recognize_filetype(file, filename):
10
- from_name_guess, _ = mimetypes.guess_type(filename)
11
- from_file_guess = filetype.guess(file)
12
- if from_file_guess:
13
- from_file_guess = from_file_guess.mime
14
- recognized_filetype = None
9
+ def recognize_filetype(file=None, filename=None):
10
+ if not (file or filename):
11
+ raise ValueError("Must provide either file content or filename")
12
+ from_name_guess = None
13
+ from_file_guess = None
14
+ if filename:
15
+ from_name_guess, _ = mimetypes.guess_type(filename)
16
+ if file:
17
+ ft = filetype.guess(file)
18
+ from_file_guess = ft.mime if ft else None
19
+ def _family(m):
20
+ return m.split("/", 1)[0] if isinstance(m, str) and "/" in m else None
21
+ def _subtype(m):
22
+ return m.split("/", 1)[-1] if isinstance(m, str) and "/" in m else None
15
23
  if not from_file_guess and not from_name_guess:
16
- recognized_filetype = "unknown"
17
- elif not (from_file_guess and from_name_guess):
18
- recognized_filetype = from_file_guess or from_name_guess
19
- elif from_file_guess.split("/", 1)[0] != from_name_guess.split("/", 1)[0]:
20
- recognized_filetype = from_file_guess
21
- elif from_file_guess.split("/", 1)[-1] != from_name_guess.split("/", 1)[-1]:
22
- recognized_filetype = from_name_guess
23
- else:
24
- recognized_filetype = from_name_guess
25
- return recognized_filetype
24
+ return "unknown"
25
+ if not (from_file_guess and from_name_guess):
26
+ return from_file_guess or from_name_guess
27
+ if _family(from_file_guess) != _family(from_name_guess):
28
+ return from_file_guess
29
+ if _subtype(from_file_guess) != _subtype(from_name_guess):
30
+ return from_name_guess
31
+ return from_name_guess
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: streamlit-octostar-utils
3
- Version: 0.2.4
3
+ Version: 0.2.5
4
4
  Summary:
5
5
  License: MIT
6
6
  Author: Octostar
@@ -15,7 +15,7 @@ streamlit_octostar_utils/api_crafter/parser/rules.py,sha256=hY2saX-CYpDBoxfK7BqZ
15
15
  streamlit_octostar_utils/api_crafter/parser/signals.py,sha256=cX1mHHGoolls7DBUwBZNHItlkKNYImEIUrr4M3btQko,4408
16
16
  streamlit_octostar_utils/core/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
17
17
  streamlit_octostar_utils/core/dict.py,sha256=b-gOCXLNuTY6WePCOeq20QLYHAPHpfivG6sxZZMw-b8,2802
18
- streamlit_octostar_utils/core/filetypes.py,sha256=C4h4WDU8voMIdQETC3n1cd-CDgw9aN_kinxXcwWpU0c,915
18
+ streamlit_octostar_utils/core/filetypes.py,sha256=kOcEnQUj4RKkyIekhrBzDBQsgWHDNe12JiQjt3mlUNc,1104
19
19
  streamlit_octostar_utils/core/threading/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
20
20
  streamlit_octostar_utils/core/threading/key_queue.py,sha256=7CJpj0gvZMQd8eC5wKQi3Ak5SQQ4zQ1OPTs_OP_kD20,2255
21
21
  streamlit_octostar_utils/core/timestamp.py,sha256=a3s4xfm1nctLzYsHOJxqoWIDTdbNY_yN1OByl8ahLc8,383
@@ -36,7 +36,7 @@ streamlit_octostar_utils/threading/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzp
36
36
  streamlit_octostar_utils/threading/async_task_manager.py,sha256=q7N6YZwUvIYMzkSHmsJNheNVCv93c03H6Hyg9uH8pvk,4747
37
37
  streamlit_octostar_utils/threading/session_callback_manager.py,sha256=LvZVP4g6tvKtYmI13f2j1sX_7hm61Groqp5xJine9_k,3973
38
38
  streamlit_octostar_utils/threading/session_state_hot_swapper.py,sha256=6eeCQI6A42hp4DmW2NQw2rbeR-k9N8DhfBKQdN_fbLU,811
39
- streamlit_octostar_utils-0.2.4.dist-info/LICENSE,sha256=dkwVPyV03fPHHtERnF6RnvRXcll__tud9gWca1RcgnQ,1073
40
- streamlit_octostar_utils-0.2.4.dist-info/METADATA,sha256=BOVhRaR1Sz8WEu-FxFKN3v7S-YoEqZP1yiZw_Ts5TII,2256
41
- streamlit_octostar_utils-0.2.4.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
42
- streamlit_octostar_utils-0.2.4.dist-info/RECORD,,
39
+ streamlit_octostar_utils-0.2.5.dist-info/LICENSE,sha256=dkwVPyV03fPHHtERnF6RnvRXcll__tud9gWca1RcgnQ,1073
40
+ streamlit_octostar_utils-0.2.5.dist-info/METADATA,sha256=3wOatPx3Q2H3rqp3Y9ynkoKTeNf77SlL2YK-DdhgaPE,2256
41
+ streamlit_octostar_utils-0.2.5.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
42
+ streamlit_octostar_utils-0.2.5.dist-info/RECORD,,