61 lines
1.8 KiB
Diff
61 lines
1.8 KiB
Diff
From a54f404366c0800497f8b62122d7be77c143297f Mon Sep 17 00:00:00 2001
|
|
From: Nabarun Pal <pal.nabarun95@gmail.com>
|
|
Date: Thu, 16 Jul 2020 14:02:12 +0530
|
|
Subject: [PATCH 09/13] Fix a Python 2 compatibility issue
|
|
|
|
PR #133 introduces the usage of `http` module for checking the status
|
|
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 <pal.nabarun95@gmail.com>
|
|
---
|
|
watch/watch.py | 13 +++++++++++--
|
|
1 file changed, 11 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/watch/watch.py b/watch/watch.py
|
|
index f67dbe4..6410dfa 100644
|
|
--- a/watch/watch.py
|
|
+++ b/watch/watch.py
|
|
@@ -12,9 +12,9 @@
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
-import http
|
|
import json
|
|
import pydoc
|
|
+import sys
|
|
|
|
from kubernetes import client
|
|
|
|
@@ -29,6 +29,15 @@ PYDOC_FOLLOW_PARAM = ":param bool follow:"
|
|
TYPE_LIST_SUFFIX = "List"
|
|
|
|
|
|
+PY2 = sys.version_info[0] == 2
|
|
+if PY2:
|
|
+ import httplib
|
|
+ HTTP_STATUS_GONE = httplib.GONE
|
|
+else:
|
|
+ import http
|
|
+ HTTP_STATUS_GONE = http.HTTPStatus.GONE
|
|
+
|
|
+
|
|
class SimpleNamespace:
|
|
|
|
def __init__(self, **kwargs):
|
|
@@ -158,7 +167,7 @@ class Watch(object):
|
|
# Current request expired, let's retry,
|
|
# but only if we have not already retried.
|
|
if not retry_after_410 and \
|
|
- obj['code'] == http.HTTPStatus.GONE:
|
|
+ obj['code'] == HTTP_STATUS_GONE:
|
|
retry_after_410 = True
|
|
break
|
|
else:
|
|
--
|
|
2.25.1
|
|
|