FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
commoncode/src/commoncode/datautils.py at main · aboutcode-org/commoncode · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
aboutcode-org
/
commoncode
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
22
Star
4
Code
Issues
13
Pull requests
7
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
commoncode
/
src
/
commoncode
/
datautils.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
289 lines (260 loc) · 5.6 KB
Breadcrumbs
commoncode
/
src
/
commoncode
/
datautils.py
Copy path
File metadata and controls
289 lines (260 loc) · 5.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/aboutcode-org/commoncode for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#
import
typing
import
attr
from
attr
.
validators
import
in_
as
choices
# NOQA
"""
Utilities and helpers for data classes.
"""
HELP_METADATA
=
"__field_help"
LABEL_METADATA
=
"__field_label"
def
attribute
(
default
=
attr
.
NOTHING
,
validator
=
None
,
repr
=
False
,
eq
=
True
,
order
=
True
,
# NOQA
init
=
True
,
type
=
None
,
converter
=
None
,
# NOQA
help
=
None
,
label
=
None
,
metadata
=
None
,
):
# NOQA
"""
Return a generic attribute with help metadata and that is not included in the
representation by default.
"""
metadata
=
metadata
or
dict
()
if
help
:
metadata
[
HELP_METADATA
]
=
help
if
label
:
metadata
[
LABEL_METADATA
]
=
label
return
attr
.
attrib
(
default
=
default
,
validator
=
validator
,
repr
=
repr
,
eq
=
eq
,
order
=
order
,
init
=
init
,
metadata
=
metadata
,
type
=
type
,
converter
=
converter
,
)
def
Boolean
(
default
=
False
,
validator
=
None
,
repr
=
False
,
eq
=
True
,
order
=
True
,
# NOQA
converter
=
None
,
label
=
None
,
help
=
None
,
):
# NOQA
"""
Return a boolean attribute.
"""
return
attribute
(
default
=
default
,
validator
=
validator
,
repr
=
repr
,
eq
=
eq
,
order
=
order
,
init
=
True
,
type
=
bool
,
converter
=
converter
,
help
=
help
,
label
=
label
,
)
def
TriBoolean
(
default
=
None
,
validator
=
None
,
repr
=
False
,
eq
=
True
,
order
=
True
,
# NOQA
converter
=
None
,
label
=
None
,
help
=
None
,
):
# NOQA
"""
Return a tri-boolean attribute with possible values of None, True and False.
"""
return
attribute
(
default
=
default
,
validator
=
validator
,
repr
=
repr
,
eq
=
eq
,
order
=
order
,
init
=
True
,
type
=
bool
,
converter
=
converter
,
help
=
help
,
label
=
label
,
)
def
String
(
default
=
None
,
validator
=
None
,
repr
=
False
,
eq
=
True
,
order
=
True
,
# NOQA
converter
=
None
,
label
=
None
,
help
=
None
,
):
# NOQA
"""
Return a string attribute.
"""
return
attribute
(
default
=
default
,
validator
=
validator
,
repr
=
repr
,
eq
=
eq
,
order
=
order
,
init
=
True
,
type
=
str
,
converter
=
converter
,
help
=
help
,
label
=
label
,
)
def
Integer
(
default
=
0
,
validator
=
None
,
repr
=
False
,
eq
=
True
,
order
=
True
,
# NOQA
converter
=
None
,
label
=
None
,
help
=
None
,
):
# NOQA
"""
Return an integer attribute.
"""
converter
=
converter
or
attr
.
converters
.
optional
(
int
)
return
attribute
(
default
=
default
,
validator
=
validator
,
repr
=
repr
,
eq
=
eq
,
order
=
order
,
init
=
True
,
type
=
int
,
converter
=
converter
,
help
=
help
,
label
=
label
,
)
def
Float
(
default
=
0.0
,
validator
=
None
,
repr
=
False
,
eq
=
True
,
order
=
True
,
# NOQA
converter
=
None
,
label
=
None
,
help
=
None
,
):
# NOQA
"""
Return a float attribute.
"""
return
attribute
(
default
=
default
,
validator
=
validator
,
repr
=
repr
,
eq
=
eq
,
order
=
order
,
init
=
True
,
type
=
float
,
converter
=
converter
,
help
=
help
,
label
=
label
,
)
def
List
(
item_type
=
typing
.
Any
,
default
=
attr
.
NOTHING
,
validator
=
None
,
repr
=
False
,
eq
=
True
,
order
=
True
,
# NOQA
converter
=
None
,
label
=
None
,
help
=
None
,
):
# NOQA
"""
Return a list attribute: the optional item_type defines the type of items it stores.
"""
if
default
is
attr
.
NOTHING
:
default
=
attr
.
Factory
(
list
)
return
attribute
(
default
=
default
,
validator
=
validator
,
repr
=
repr
,
eq
=
eq
,
order
=
order
,
init
=
True
,
type
=
typing
.
List
[
item_type
],
converter
=
converter
,
help
=
help
,
label
=
label
,
)
def
Mapping
(
value_type
=
typing
.
Any
,
default
=
attr
.
NOTHING
,
validator
=
None
,
repr
=
False
,
eq
=
True
,
order
=
True
,
# NOQA
converter
=
None
,
help
=
None
,
label
=
None
,
):
# NOQA
"""
Return a mapping attribute: the optional value_type defines the type of values it
stores. The key is always a string.
Notes: in Python 2 the type is Dict as there is no typing available for
dict for now.
"""
if
default
is
attr
.
NOTHING
:
default
=
attr
.
Factory
(
dict
)
return
attribute
(
default
=
default
,
validator
=
validator
,
repr
=
repr
,
eq
=
eq
,
order
=
order
,
init
=
True
,
type
=
typing
.
Dict
[
str
,
value_type
],
converter
=
converter
,
help
=
help
,
label
=
label
,
)
##################################################
# FIXME: add proper support for dates!!!
##################################################
def
Date
(
default
=
None
,
validator
=
None
,
repr
=
False
,
eq
=
True
,
order
=
True
,
# NOQA
converter
=
None
,
label
=
None
,
help
=
None
,
):
# NOQA
"""
Return a date attribute. It always serializes to an ISO date string.
Behavior is TBD and for now this is exactly a string.
"""
return
String
(
default
=
default
,
validator
=
validator
,
repr
=
repr
,
eq
=
eq
,
order
=
order
,
converter
=
converter
,
help
=
help
,
label
=
label
,
)
Back
|
FazBrowse Home
|
New Git URL