File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change 1
1
from datetime import datetime
2
2
import re
3
3
4
+ try :
5
+ # python 2
6
+ _base_string_class = basestring
7
+ except NameError :
8
+ # python 3: no basestring class any more, everything is a str
9
+ _base_string_class = str
10
+
4
11
# with thanks to https://code.google.com/p/jquery-localtime/issues/detail?id=4
5
12
ISO_8601 = re .compile ("^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])"
6
13
"(T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?"
@@ -17,7 +24,7 @@ def timestamp_parameter(timestamp, allow_none=True):
17
24
if isinstance (timestamp , datetime ):
18
25
return timestamp .isoformat ()
19
26
20
- if isinstance (timestamp , basestring ):
27
+ if isinstance (timestamp , _base_string_class ):
21
28
if not ISO_8601 .match (timestamp ):
22
29
raise ValueError ("Invalid timestamp: %s is not a valid ISO-8601 formatted date" % timestamp )
23
30
return timestamp
You can’t perform that action at this time.
0 commit comments