Skip to content

Commit

Permalink
Fix a Python 2 compatibility issue
Browse files Browse the repository at this point in the history
PR kubernetes-client#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 <[email protected]>
  • Loading branch information
palnabarun committed Jul 16, 2020
1 parent 7fc2c31 commit a54f404
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions watch/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -29,6 +29,15 @@
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):
Expand Down Expand Up @@ -158,7 +167,7 @@ def stream(self, func, *args, **kwargs):
# 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:
Expand Down

0 comments on commit a54f404

Please sign in to comment.