@@ -19,39 +19,45 @@ def last_index_of(target: str, needle: str):
19
19
20
20
21
21
def left_part (str_val : Optional [str ], needle : str ):
22
- if str_val is None : return None
22
+ if str_val is None :
23
+ return None
23
24
pos = index_of (str_val , needle )
24
25
return str_val if pos == - 1 else str_val [:pos ]
25
26
26
27
27
28
def right_part (str_val : Optional [str ], needle : str ):
28
- if str_val is None : return None
29
+ if str_val is None :
30
+ return None
29
31
pos = index_of (str_val , needle )
30
32
return str_val if pos == - 1 else str_val [pos + len (needle ):]
31
33
32
34
33
35
def last_left_part (str_val : Optional [str ], needle : str ):
34
- if str_val is None : return None
36
+ if str_val is None :
37
+ return None
35
38
pos = last_index_of (str_val , needle )
36
39
return str_val if pos == - 1 else str_val [:pos ]
37
40
38
41
39
42
def last_right_part (str_val : Optional [str ], needle : str ):
40
- if str_val is None : return None
43
+ if str_val is None :
44
+ return None
41
45
pos = last_index_of (str_val , needle )
42
46
return str_val if pos == - 1 else str_val [pos + len (needle ):]
43
47
44
48
45
49
def split_on_first (s : Optional [str ], c : str ):
46
- if str is None or str == "" : return [s ]
50
+ if str is None or str == "" :
51
+ return [s ]
47
52
pos = index_of (s , c )
48
53
if pos >= 0 :
49
54
return [s [:pos ], s [pos + 1 :]]
50
55
return [s ]
51
56
52
57
53
58
def split_on_last (s : Optional [str ], c : str ):
54
- if str is None or str == "" : return [s ]
59
+ if str is None or str == "" :
60
+ return [s ]
55
61
pos = last_index_of (s , c )
56
62
if pos >= 0 :
57
63
return [s [:pos ], s [pos + 1 :]]
@@ -95,19 +101,20 @@ def to_timespan(duration: timedelta):
95
101
return xsd
96
102
97
103
98
- def from_timespan (str : Optional [str ]):
99
- if str is None : return None
104
+ def from_timespan (s : Optional [str ]):
105
+ if s is None :
106
+ return None
100
107
days = 0
101
108
hours = 0
102
109
minutes = 0
103
110
seconds = 0
104
111
ms = 0.0
105
112
106
- if str [0 ] != "P" :
107
- raise ValueError (f"{ str } is not a valid XSD Duration" )
113
+ if s [0 ] != "P" :
114
+ raise ValueError (f"{ s } is not a valid XSD Duration" )
108
115
109
- str = str [1 :] # strip P
110
- t = split_on_first (str , 'T' )
116
+ s = s [1 :] # strip P
117
+ t = split_on_first (s , 'T' )
111
118
has_time = len (t ) == 2
112
119
113
120
d = split_on_first (t [0 ], 'D' )
@@ -147,7 +154,6 @@ def from_datetime(json_date: str):
147
154
epoch_str = last_left_part (epoch_and_zone , '-' )
148
155
if index_of (epoch_and_zone [1 :], '+' ) >= 0 :
149
156
epoch_str = last_left_part (epoch_and_zone , '+' )
150
- # print(f"epoch_str = {epoch_str}")
151
157
epoch = int (epoch_str )
152
158
try :
153
159
return datetime .fromtimestamp (epoch / 1000 , timezone .utc )
@@ -195,4 +201,3 @@ def inspect_jwt(jwt: str):
195
201
body = _decode_base64url_payload (left_part (right_part (jwt , '.' ), '.' ))
196
202
exp = int (body ['exp' ])
197
203
return head , body , datetime .fromtimestamp (exp , timezone .utc )
198
-
0 commit comments