dcicutils 8.6.0.1b3__py3-none-any.whl → 8.7.0.1b1__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.
@@ -0,0 +1,185 @@
1
+ from typing import Any, Dict, List
2
+
3
+
4
+ class JsonSchemaConstants:
5
+ ANY_OF = "anyOf"
6
+ ARRAY = "array"
7
+ BOOLEAN = "boolean"
8
+ DEFAULT = "default"
9
+ ENUM = "enum"
10
+ FORMAT = "format"
11
+ INTEGER = "integer"
12
+ ITEMS = "items"
13
+ NUMBER = "number"
14
+ OBJECT = "object"
15
+ ONE_OF = "oneOf"
16
+ PATTERN = "pattern"
17
+ PROPERTIES = "properties"
18
+ REF = "$ref"
19
+ REQUIRED = "required"
20
+ STRING = "string"
21
+ TYPE = "type"
22
+
23
+
24
+ class EncodedSchemaConstants:
25
+ IDENTIFYING_PROPERTIES = "identifyingProperties"
26
+ LINK_TO = "linkTo"
27
+ MERGE_REF = "$merge"
28
+ MIXIN_PROPERTIES = "mixinProperties"
29
+ UNIQUE_KEY = "uniqueKey"
30
+
31
+
32
+ class SchemaConstants(JsonSchemaConstants, EncodedSchemaConstants):
33
+ pass
34
+
35
+
36
+ def get_properties(schema: Dict[str, Any]) -> Dict[str, Any]:
37
+ """Return the properties of a schema."""
38
+ return schema.get(SchemaConstants.PROPERTIES, {})
39
+
40
+
41
+ def get_property(schema: Dict[str, Any], property_name: str) -> Dict[str, Any]:
42
+ """Return property in properties, if found."""
43
+ return get_properties(schema).get(property_name, {})
44
+
45
+
46
+ def has_property(schema: Dict[str, Any], property_name: str) -> bool:
47
+ """Return True if the schema has the given property."""
48
+ return property_name in get_properties(schema)
49
+
50
+
51
+ def get_required(schema: Dict[str, Any]) -> List[str]:
52
+ """Return the required properties of a schema."""
53
+ return schema.get(SchemaConstants.REQUIRED, [])
54
+
55
+
56
+ def get_pattern(schema: Dict[str, Any]) -> str:
57
+ """Return the pattern property of a schema."""
58
+ return schema.get(SchemaConstants.PATTERN, "")
59
+
60
+
61
+ def get_any_of(schema: Dict[str, Any]) -> List[Dict[str, Any]]:
62
+ """Return the anyOf properties of a schema."""
63
+ return schema.get(SchemaConstants.ANY_OF, [])
64
+
65
+
66
+ def get_one_of(schema: Dict[str, Any]) -> List[Dict[str, Any]]:
67
+ """Return the oneOf properties of a schema."""
68
+ return schema.get(SchemaConstants.ONE_OF, [])
69
+
70
+
71
+ def get_conditional_required(schema: Dict[str, Any]) -> List[str]:
72
+ """Get required + possibly required properties.
73
+
74
+ Using heuristics here; update as needed.
75
+ """
76
+ return sorted(
77
+ list(
78
+ set(
79
+ get_required(schema)
80
+ + get_any_of_required(schema)
81
+ + get_one_of_required(schema)
82
+ )
83
+ )
84
+ )
85
+
86
+
87
+ def get_any_of_required(schema: Dict[str, Any]) -> List[str]:
88
+ """Get required properties from anyOf."""
89
+ return [
90
+ property_name
91
+ for any_of_schema in get_any_of(schema)
92
+ for property_name in get_required(any_of_schema)
93
+ ]
94
+
95
+
96
+ def get_one_of_required(schema: Dict[str, Any]) -> List[str]:
97
+ """Get required properties from oneOf."""
98
+ return [
99
+ property_name
100
+ for one_of_schema in get_one_of(schema)
101
+ for property_name in get_required(one_of_schema)
102
+ ]
103
+
104
+
105
+ def get_mixin_properties(schema: Dict[str, Any]) -> List[Dict[str, Any]]:
106
+ """Return the mixin properties of a schema."""
107
+ return schema.get(SchemaConstants.MIXIN_PROPERTIES, [])
108
+
109
+
110
+ def get_identifying_properties(schema: Dict[str, Any]) -> List[str]:
111
+ """Return the identifying properties of a schema."""
112
+ return schema.get(SchemaConstants.IDENTIFYING_PROPERTIES, [])
113
+
114
+
115
+ def get_schema_type(schema: Dict[str, Any]) -> str:
116
+ """Return the type of a schema."""
117
+ return schema.get(SchemaConstants.TYPE, "")
118
+
119
+
120
+ def is_array_schema(schema: Dict[str, Any]) -> bool:
121
+ """Return True if the schema is an array."""
122
+ return get_schema_type(schema) == SchemaConstants.ARRAY
123
+
124
+
125
+ def is_object_schema(schema: Dict[str, Any]) -> bool:
126
+ """Return True if the schema is an object."""
127
+ return get_schema_type(schema) == SchemaConstants.OBJECT
128
+
129
+
130
+ def is_string_schema(schema: Dict[str, Any]) -> bool:
131
+ """Return True if the schema is a string."""
132
+ return get_schema_type(schema) == SchemaConstants.STRING
133
+
134
+
135
+ def is_number_schema(schema: Dict[str, Any]) -> bool:
136
+ """Return True if the schema is a number."""
137
+ return get_schema_type(schema) == SchemaConstants.NUMBER
138
+
139
+
140
+ def is_integer_schema(schema: Dict[str, Any]) -> bool:
141
+ """Return True if the schema is an integer."""
142
+ return get_schema_type(schema) == SchemaConstants.INTEGER
143
+
144
+
145
+ def is_boolean_schema(schema: Dict[str, Any]) -> bool:
146
+ """Return True if the schema is a boolean."""
147
+ return get_schema_type(schema) == SchemaConstants.BOOLEAN
148
+
149
+
150
+ def get_items(schema: Dict[str, Any]) -> Dict[str, Any]:
151
+ """Return the items of a schema."""
152
+ return schema.get(SchemaConstants.ITEMS, {})
153
+
154
+
155
+ def get_format(schema: Dict[str, Any]) -> str:
156
+ """Return the format of a schema."""
157
+ return schema.get(SchemaConstants.FORMAT, "")
158
+
159
+
160
+ def get_conditional_formats(schema: Dict[str, Any]) -> List[str]:
161
+ """Return the format of a schema, as directly given or as listed
162
+ as an option via oneOf or anyOf.
163
+ """
164
+ formats = set(
165
+ get_any_of_formats(schema) + get_one_of_formats(schema) + [get_format(schema)]
166
+ )
167
+ return sorted(list([format_ for format_ in formats if format_]))
168
+
169
+
170
+ def get_any_of_formats(schema: Dict[str, Any]) -> List[str]:
171
+ """Return the formats of a schema's anyOf properties."""
172
+ return [
173
+ get_format(any_of_schema)
174
+ for any_of_schema in get_any_of(schema)
175
+ if get_format(any_of_schema)
176
+ ]
177
+
178
+
179
+ def get_one_of_formats(schema: Dict[str, Any]) -> List[str]:
180
+ """Return the formats of a schema's oneOf properties."""
181
+ return [
182
+ get_format(one_of_schema)
183
+ for one_of_schema in get_one_of(schema)
184
+ if get_format(one_of_schema)
185
+ ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dcicutils
3
- Version: 8.6.0.1b3
3
+ Version: 8.7.0.1b1
4
4
  Summary: Utility package for interacting with the 4DN Data Portal and other 4DN resources
5
5
  Home-page: https://github.com/4dn-dcic/utils
6
6
  License: MIT
@@ -50,6 +50,7 @@ dcicutils/qa_utils.py,sha256=TT0SiJWiuxYvbsIyhK9VO4uV_suxhB6CpuC4qPacCzQ,160208
50
50
  dcicutils/redis_tools.py,sha256=qkcSNMtvqkpvts-Cm9gWhneK523Q_oHwhNUud1be1qk,7055
51
51
  dcicutils/redis_utils.py,sha256=VJ-7g8pOZqR1ZCtdcjKz3-6as2DMUcs1b1zG6wSprH4,6462
52
52
  dcicutils/s3_utils.py,sha256=LauLFQGvZLfpBJ81tYMikjLd3SJRz2R_FrL1n4xSlyI,28868
53
+ dcicutils/schema_utils.py,sha256=3Gd9QboOjQ3FHFawerylvYYU8Lor1Ma2pFv4JmezCdg,5501
53
54
  dcicutils/scripts/publish_to_pypi.py,sha256=QriqcnqeLd9zQZwE5pwEMxagR5HGr7M1I0OjkI6Cp6o,13795
54
55
  dcicutils/scripts/run_license_checker.py,sha256=z2keYnRDZsHQbTeo1XORAXSXNJK5axVzL5LjiNqZ7jE,4184
55
56
  dcicutils/secrets_utils.py,sha256=8dppXAsiHhJzI6NmOcvJV5ldvKkQZzh3Fl-cb8Wm7MI,19745
@@ -63,8 +64,8 @@ dcicutils/trace_utils.py,sha256=g8kwV4ebEy5kXW6oOrEAUsurBcCROvwtZqz9fczsGRE,1769
63
64
  dcicutils/validation_utils.py,sha256=cMZIU2cY98FYtzK52z5WUYck7urH6JcqOuz9jkXpqzg,14797
64
65
  dcicutils/variant_utils.py,sha256=2H9azNx3xAj-MySg-uZ2SFqbWs4kZvf61JnK6b-h4Qw,4343
65
66
  dcicutils/zip_utils.py,sha256=rnjNv_k6L9jT2SjDSgVXp4BEJYLtz9XN6Cl2Fy-tqnM,2027
66
- dcicutils-8.6.0.1b3.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
67
- dcicutils-8.6.0.1b3.dist-info/METADATA,sha256=oeYZc0-BBik9x4YoeqsgqvMNC8Nx7n9yJuauNAecftE,3314
68
- dcicutils-8.6.0.1b3.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
69
- dcicutils-8.6.0.1b3.dist-info/entry_points.txt,sha256=8wbw5csMIgBXhkwfgsgJeuFcoUc0WsucUxmOyml2aoA,209
70
- dcicutils-8.6.0.1b3.dist-info/RECORD,,
67
+ dcicutils-8.7.0.1b1.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
68
+ dcicutils-8.7.0.1b1.dist-info/METADATA,sha256=ySO6_vG5SPHNlCvxkNCBjeDuKcmhcThC1HoCkTZeHk0,3314
69
+ dcicutils-8.7.0.1b1.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
70
+ dcicutils-8.7.0.1b1.dist-info/entry_points.txt,sha256=8wbw5csMIgBXhkwfgsgJeuFcoUc0WsucUxmOyml2aoA,209
71
+ dcicutils-8.7.0.1b1.dist-info/RECORD,,