cave-utils 2.0.2__tar.gz → 2.0.3__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 (33) hide show
  1. {cave_utils-2.0.2 → cave_utils-2.0.3}/PKG-INFO +1 -1
  2. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/api_utils/general.py +19 -7
  3. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/api_utils/validator_utils.py +42 -1
  4. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils.egg-info/PKG-INFO +1 -1
  5. {cave_utils-2.0.2 → cave_utils-2.0.3}/pyproject.toml +1 -1
  6. {cave_utils-2.0.2 → cave_utils-2.0.3}/setup.cfg +1 -1
  7. {cave_utils-2.0.2 → cave_utils-2.0.3}/test/test_validator.py +1 -1
  8. {cave_utils-2.0.2 → cave_utils-2.0.3}/LICENSE +0 -0
  9. {cave_utils-2.0.2 → cave_utils-2.0.3}/NOTICE.md +0 -0
  10. {cave_utils-2.0.2 → cave_utils-2.0.3}/README.md +0 -0
  11. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/__init__.py +0 -0
  12. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/api/__init__.py +0 -0
  13. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/api/appBar.py +0 -0
  14. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/api/extraKwargs.py +0 -0
  15. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/api/globalOutputs.py +0 -0
  16. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/api/groupedOutputs.py +0 -0
  17. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/api/mapFeatures.py +0 -0
  18. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/api/maps.py +0 -0
  19. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/api/pages.py +0 -0
  20. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/api/panes.py +0 -0
  21. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/api/settings.py +0 -0
  22. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/api_utils/__init__.py +0 -0
  23. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/api_utils/validator.py +0 -0
  24. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/arguments.py +0 -0
  25. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/log.py +0 -0
  26. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils/socket.py +0 -0
  27. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils.egg-info/SOURCES.txt +0 -0
  28. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils.egg-info/dependency_links.txt +0 -0
  29. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils.egg-info/requires.txt +0 -0
  30. {cave_utils-2.0.2 → cave_utils-2.0.3}/cave_utils.egg-info/top_level.txt +0 -0
  31. {cave_utils-2.0.2 → cave_utils-2.0.3}/test/test_arguments.py +0 -0
  32. {cave_utils-2.0.2 → cave_utils-2.0.3}/test/test_import.py +0 -0
  33. {cave_utils-2.0.2 → cave_utils-2.0.3}/test/test_log.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cave_utils
3
- Version: 2.0.2
3
+ Version: 2.0.3
4
4
  Summary: Python wrapper for api use in the cave_app
5
5
  Author-email: Connor Makowski <conmak@mit.edu>
6
6
  Project-URL: Homepage, https://github.com/mit-cave/cave_utils
@@ -82,9 +82,12 @@ class props(ApiValidator):
82
82
  * `"hstepper"`: Select a unique option along a horizontal slider
83
83
  * `"vstepper"`: Select a unique option along a vertical slider
84
84
  * When **`type`** == `"date"`:
85
- * `"date"`: Select a date via a calendar pop-up that appears when the element is clicked
85
+ * `"date"`: Select a date via a calendar pop-up that appears when the element is clicked (default)
86
+ * **Note**: Passed as `YYYY-MM-DD`
86
87
  * `"time"`: Select a time via a clock pop-up that appears when the element is clicked
88
+ * **Note**: Passed as `HH:MM:SS`
87
89
  * `"datetime"`: Select date and time via a pop-up with calendar and clock tabs that appear when the element is clicked
90
+ * **Note**: Passed as `YYYY-MM-DDTHH:MM:SS`
88
91
  * When **`type`** == `"media"`:
89
92
  * `"picture"`: Show a PNG or JPG image
90
93
  * `"video"`: Display a YouTube, Vimeo, or Dailymotion video clip
@@ -509,10 +512,13 @@ class values(ApiValidator):
509
512
  options = list(prop_spec.get("options", {}).keys())
510
513
  self.__check_subset_valid__(prop_value, options, prepend_path=[prop_key])
511
514
  elif prop_type == "date":
512
- pass
513
- # TODO: Validate date string
515
+ self.__check_date_valid__(
516
+ prop_value,
517
+ date_variant=prop_spec.get("variant", "date"),
518
+ prepend_path=[prop_key],
519
+ )
514
520
  elif prop_type == "media":
515
- self.__check_url_valid__(prop_value)
521
+ self.__check_url_valid__(prop_value, prepend_path=[prop_key])
516
522
 
517
523
 
518
524
  @type_enforced.Enforcer
@@ -593,8 +599,14 @@ class valueLists(ApiValidator):
593
599
  msg=f"`{prop_key}` with the prop type of `{prop_type}` can not have an associated value."
594
600
  )
595
601
  elif prop_type == "date":
596
- pass
597
- # TODO: Validate date string
602
+ prop_value_list_set = list(set(prop_value_list))
603
+ date_variant = prop_spec.get("variant", "date")
604
+ for prop_value in prop_value_list:
605
+ if not self.__check_date_valid__(
606
+ prop_value, date_variant=date_variant, prepend_path=[prop_key]
607
+ ):
608
+ continue
598
609
  elif prop_type == "media":
599
610
  for prop_value in prop_value_list:
600
- self.__check_url_valid__(prop_value)
611
+ if not self.__check_url_valid__(prop_value, prepend_path=[prop_key]):
612
+ continue
@@ -3,7 +3,7 @@ Special utility functions to help in validating your data against the CAVE API.
3
3
  """
4
4
  from pamda import pamda
5
5
  import type_enforced
6
- import re
6
+ import re, datetime
7
7
  from cave_utils.log import LogHelper, LogObject
8
8
 
9
9
 
@@ -143,6 +143,47 @@ class ApiValidator:
143
143
  )
144
144
  if re.match(regex, url) is None:
145
145
  self.__error__(path=prepend_path, msg="Invalid url")
146
+ return False
147
+ return True
148
+
149
+ def __check_date_valid__(self, input: str, date_variant: str, prepend_path: list = list()):
150
+ """
151
+ Validate a date string and if an issue is present, log an error.
152
+ """
153
+ if date_variant == "date":
154
+ try:
155
+ datetime.datetime.strptime(input, "%Y-%m-%d")
156
+ except ValueError:
157
+ self.__error__(
158
+ path=prepend_path,
159
+ msg=f"Invalid input for type of `date` with variant `date`. Must be in the format `YYYY-MM-DD`",
160
+ )
161
+ return False
162
+ elif date_variant == "datetime":
163
+ try:
164
+ datetime.datetime.strptime(input, "%Y-%m-%dT%H:%M:%S")
165
+ except ValueError:
166
+ self.__error__(
167
+ path=prepend_path,
168
+ msg=f"Invalid input for type of `date` with variant `datetime`. Must be in the format `YYYY-MM-DDTHH:MM:SS`",
169
+ )
170
+ return False
171
+ elif date_variant == "time":
172
+ try:
173
+ datetime.datetime.strptime(input, "%H:%M:%S")
174
+ except ValueError:
175
+ self.__error__(
176
+ path=prepend_path,
177
+ msg=f"Invalid input for type of `date` with variant `time`. Must be in the format `HH:MM:SS`",
178
+ )
179
+ return False
180
+ else:
181
+ self.__error__(
182
+ path=prepend_path,
183
+ msg=f"Invalid variant ({date_variant}) for prop with type `date`. Must be one of `date`, `datetime`, or `time`",
184
+ )
185
+ return False
186
+ return True
146
187
 
147
188
  def __check_subset_valid__(
148
189
  self,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cave-utils
3
- Version: 2.0.2
3
+ Version: 2.0.3
4
4
  Summary: Python wrapper for api use in the cave_app
5
5
  Author-email: Connor Makowski <conmak@mit.edu>
6
6
  Project-URL: Homepage, https://github.com/mit-cave/cave_utils
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
12
12
 
13
13
  [project]
14
14
  name = "cave_utils"
15
- version = "2.0.2"
15
+ version = "2.0.3"
16
16
  description = "Python wrapper for api use in the cave_app"
17
17
  authors = [
18
18
  {name="Connor Makowski", email="conmak@mit.edu"}
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = cave_utils
3
- version = 2.0.2
3
+ version = 2.0.3
4
4
  description_file = README.md
5
5
 
6
6
  [options]
@@ -391,7 +391,7 @@ example = {
391
391
  "t2_b1_tw1",
392
392
  "t2_b1_tw2",
393
393
  ],
394
- "dateItemExample": "07/20/1969",
394
+ "dateItemExample": "1969-07-20",
395
395
  "timeItemExample": "20:17:40",
396
396
  "dateTimeItemExample": "1969-07-20T20:17:40",
397
397
  },
File without changes
File without changes
File without changes
File without changes
File without changes