We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
1 parent138952b commit8899cddCopy full SHA for 8899cdd
github3/utils.py
@@ -1,6 +1,13 @@
1
fromdatetimeimportdatetime
2
importre
3
4
+try:
5
+# python 2
6
+_base_string_class=basestring
7
+exceptNameError:
8
+# python 3: no basestring class any more, everything is a str
9
+_base_string_class=str
10
+
11
# with thanks to https://code.google.com/p/jquery-localtime/issues/detail?id=4
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])"
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
ifisinstance(timestamp,datetime):
18
25
returntimestamp.isoformat()
19
26
20
-ifisinstance(timestamp,basestring):
27
+ifisinstance(timestamp,_base_string_class):
21
28
ifnotISO_8601.match(timestamp):
22
29
raiseValueError("Invalid timestamp: %s is not a valid ISO-8601 formatted date"%timestamp)
23
30
returntimestamp