Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8899cdd

Browse files
committed
Fixing isisntance check for strings depending on python 2 or 3 version
1 parent138952b commit8899cdd

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
fromdatetimeimportdatetime
22
importre
33

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+
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
ifisinstance(timestamp,datetime):
1825
returntimestamp.isoformat()
1926

20-
ifisinstance(timestamp,basestring):
27+
ifisinstance(timestamp,_base_string_class):
2128
ifnotISO_8601.match(timestamp):
2229
raiseValueError("Invalid timestamp: %s is not a valid ISO-8601 formatted date"%timestamp)
2330
returntimestamp

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp