Skip to content

Commit 8899cdd

Browse files
committed
Fixing isisntance check for strings depending on python 2 or 3 version
1 parent 138952b commit 8899cdd

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

github3/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
from datetime import datetime
22
import re
33

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+
411
# with thanks to https://code.google.com/p/jquery-localtime/issues/detail?id=4
512
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])"
613
"(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):
1724
if isinstance(timestamp, datetime):
1825
return timestamp.isoformat()
1926

20-
if isinstance(timestamp, basestring):
27+
if isinstance(timestamp, _base_string_class):
2128
if not ISO_8601.match(timestamp):
2229
raise ValueError("Invalid timestamp: %s is not a valid ISO-8601 formatted date" % timestamp)
2330
return timestamp

0 commit comments

Comments
 (0)