Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit bf9b301

Browse files
committed
Fix a Python 2 compatibility issue
code for `GONE` HTTP status. However, this doesn't work in Python 2.7. This commit checks if the interpreter is Python 2 and imports the status code from `httplib` module instead and unifies the approach to the checks. Signed-off-by: Nabarun Pal <[email protected]>
1 parent 7fc2c31 commit bf9b301

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

watch/watch.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import http
1615
import json
1716
import pydoc
17+
import sys
1818

1919
from kubernetes import client
2020

@@ -29,6 +29,15 @@
2929
TYPE_LIST_SUFFIX = "List"
3030

3131

32+
PY2 = sys.version_info[0] == 2
33+
if PY2:
34+
import httplib
35+
HTTP_STATUS_GONE = httplib.GONE
36+
else:
37+
import http
38+
HTTP_STATUS_GONE = http.HTTPStatus.GONE
39+
40+
3241
class SimpleNamespace:
3342

3443
def __init__(self, **kwargs):
@@ -158,7 +167,7 @@ def stream(self, func, *args, **kwargs):
158167
# Current request expired, let's retry,
159168
# but only if we have not already retried.
160169
if not retry_after_410 and \
161-
obj['code'] == http.HTTPStatus.GONE:
170+
obj['code'] == HTTP_STATUS_GONE:
162171
retry_after_410 = True
163172
break
164173
else:

0 commit comments

Comments
 (0)