-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathutils.py
285 lines (241 loc) · 7.37 KB
/
utils.py
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
import re
from typing import Union, Match, Optional, Any
HEX_REGEX = re.compile(r'^([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6})$')
def is_hex_color_string(hex_string: Optional[str]) -> Union[Match[Any], bool]:
return HEX_REGEX.match(hex_string) if hex_string else False
class BaseDefClass:
@classmethod
def get(cls, key, default=None):
return cls.__dict__.get(key, default)
# The following classes names violate PEP8 for the sake of keeping backwards compatibility, at least for the meantime
class number_formats(BaseDefClass):
"""
:cvar str general: 'General'
:cvar str general_integer: '0'
:cvar str general_float: '0.00'
:cvar str percent: '0.0%'
:cvar str thousands_comma_sep: '#,##0'
:cvar str date: 'DD/MM/YY'
:cvar str time_24_hours: 'HH:MM'
:cvar str time_24_hours_with_seconds: 'HH:MM:SS'
:cvar str time_12_hours: 'h:MM AM/PM'
:cvar str time_12_hours_with_seconds: 'h:MM:SS AM/PM'
:cvar str date_time: 'DD/MM/YY HH:MM'
:cvar str date_time_with_seconds: 'DD/MM/YY HH:MM:SS'
"""
general = 'General'
general_integer = '0'
general_float = '0.00'
percent = '0.0%'
thousands_comma_sep = '#,##0'
date = 'DD/MM/YY'
time_24_hours = 'HH:MM'
time_24_hours_with_seconds = 'HH:MM:SS'
time_12_hours = 'h:MM AM/PM'
time_12_hours_with_seconds = 'h:MM:SS AM/PM'
date_time = 'DD/MM/YY HH:MM'
date_time_with_seconds = 'DD/MM/YY HH:MM:SS'
default_date_format = date
default_time_format = time_24_hours
default_date_time_format = date_time
@staticmethod
def decimal_with_num_of_digits(num_of_digits: int) -> str:
"""
.. versionadded:: 1.6
:param int num_of_digits: Number of digits after the decimal point
:return: A format string that represents a floating point number with the provided number of digits after the
decimal point.
For example, ``utils.number_formats.decimal_with_num_of_digits(2)`` will return ``'0.00'``
:rtype: str
"""
return '0.{}'.format('0' * num_of_digits)
class colors(BaseDefClass):
"""
:cvar str white: '00FFFFFF'
:cvar str blue: '000000FF'
:cvar str dark_blue: '00000080'
:cvar str yellow: '00FFFF00'
:cvar str dark_yellow: '00808000'
:cvar str green: '0000FF00'
:cvar str dark_green: '00008000'
:cvar str black: '00000000'
:cvar str red: '00FF0000'
:cvar str dark_red: '00800000'
:cvar str purple: '800080'
:cvar str grey: 'D3D3D3'
"""
white = '00FFFFFF'
blue = '000000FF'
dark_blue = '00000080'
yellow = '00FFFF00'
dark_yellow = '00808000'
green = '0000FF00'
dark_green = '00008000'
black = '00000000'
red = '00FF0000'
dark_red = '00800000'
purple = '800080'
grey = 'D3D3D3'
class fonts(BaseDefClass):
"""
.. versionadded:: 1.1
:cvar str aegean: 'Aegean'
:cvar str aegyptus: 'Aegyptus'
:cvar str aharoni: 'Aharoni CLM'
:cvar str anaktoria: 'Anaktoria'
:cvar str analecta: 'Analecta'
:cvar str anatolian: 'Anatolian'
:cvar str arial: 'Arial'
:cvar str calibri: 'Calibri'
:cvar str david: 'David CLM'
:cvar str dejavu_sans: 'DejaVu Sans'
:cvar str ellinia: 'Ellinia CLM'
"""
aegean = 'Aegean'
aegyptus = 'Aegyptus'
aharoni = 'Aharoni CLM'
anaktoria = 'Anaktoria'
analecta = 'Analecta'
anatolian = 'Anatolian'
arial = 'Arial'
calibri = 'Calibri'
david = 'David CLM'
dejavu_sans = 'DejaVu Sans'
ellinia = 'Ellinia CLM'
class borders(BaseDefClass):
"""
:cvar str dash_dot: 'dashDot'
:cvar str dash_dot_dot: 'dashDotDot'
:cvar str dashed: 'dashed'
:cvar str default_grid: 'default_grid'
:cvar str dotted: 'dotted'
:cvar str double: 'double'
:cvar str hair: 'hair'
:cvar str medium: 'medium'
:cvar str medium_dash_dot: 'mediumDashDot'
:cvar str medium_dash_dot_dot: 'mediumDashDotDot'
:cvar str medium_dashed: 'mediumDashed'
:cvar str slant_dash_dot: 'slantDashDot'
:cvar str thick: 'thick'
:cvar str thin: 'thin'
"""
dash_dot = 'dashDot'
dash_dot_dot = 'dashDotDot'
dashed = 'dashed'
default_grid = 'default_grid'
dotted = 'dotted'
double = 'double'
hair = 'hair'
medium = 'medium'
medium_dash_dot = 'mediumDashDot'
medium_dash_dot_dot = 'mediumDashDotDot'
medium_dashed = 'mediumDashed'
slant_dash_dot = 'slantDashDot'
thick = 'thick'
thin = 'thin'
class border_locations(BaseDefClass):
"""
.. versionadded:: 4.2
:cvar str top: 'top'
:cvar str bottom: 'bottom'
:cvar str left: 'left'
:cvar str right: 'right'
"""
top = 'top'
bottom = 'bottom'
left = 'left'
right = 'right'
class horizontal_alignments(BaseDefClass):
"""
:cvar str general: 'general'
:cvar str left: 'left'
:cvar str center: 'center'
:cvar str right: 'right'
:cvar str fill: 'fill'
:cvar str justify: 'justify'
:cvar str center_continuous: 'centerContinuous'
:cvar str distributed: 'distributed'
"""
general = 'general'
left = 'left'
center = 'center'
right = 'right'
fill = 'fill'
justify = 'justify'
center_continuous = 'centerContinuous'
distributed = 'distributed'
class vertical_alignments(BaseDefClass):
"""
:cvar str top: 'top'
:cvar str center: 'center'
:cvar str bottom: 'bottom'
:cvar str justify: 'justify'
:cvar str distributed: 'distributed'
"""
top = 'top'
center = 'center'
bottom = 'bottom'
justify = 'justify'
distributed = 'distributed'
class underline(BaseDefClass):
"""
:cvar str single: 'single'
:cvar str double: 'double'
"""
single = 'single'
double = 'double'
class fill_pattern_types(BaseDefClass):
"""
.. versionadded:: 1.2
:cvar str solid: 'solid'
:cvar str dark_down: 'darkDown'
:cvar str dark_gray: 'darkGray'
:cvar str dark_grid: 'darkGrid'
:cvar str dark_horizontal: 'darkHorizontal'
:cvar str dark_trellis: 'darkTrellis'
:cvar str dark_up: 'darkUp'
:cvar str dark_vertical: 'darkVertical'
:cvar str gray0625: 'gray0625'
:cvar str gray125: 'gray125'
:cvar str light_down: 'lightDown'
:cvar str light_gray: 'lightGray'
:cvar str light_grid: 'lightGrid'
:cvar str light_horizontal: 'lightHorizontal'
:cvar str light_trellis: 'lightTrellis'
:cvar str light_up: 'lightUp'
:cvar str light_vertical: 'lightVertical'
:cvar str medium_gray: 'mediumGray'
"""
solid = 'solid'
dark_down = 'darkDown'
dark_gray = 'darkGray'
dark_grid = 'darkGrid'
dark_horizontal = 'darkHorizontal'
dark_trellis = 'darkTrellis'
dark_up = 'darkUp'
dark_vertical = 'darkVertical'
gray0625 = 'gray0625'
gray125 = 'gray125'
light_down = 'lightDown'
light_gray = 'lightGray'
light_grid = 'lightGrid'
light_horizontal = 'lightHorizontal'
light_trellis = 'lightTrellis'
light_up = 'lightUp'
light_vertical = 'lightVertical'
medium_gray = 'mediumGray'
class conditional_formatting_types(BaseDefClass):
"""
:cvar str num: 'num'
:cvar str percent: 'percent'
:cvar str max: 'max'
:cvar str min: 'min'
:cvar str formula: 'formula'
:cvar str percentile: 'percentile'
"""
num = 'num'
percent = 'percent'
max = 'max'
min = 'min'
formula = 'formula'
percentile = 'percentile'