Skip to content

Commit

Permalink
Merge pull request kubernetes-client#204 from palnabarun/fix-watch-py…
Browse files Browse the repository at this point in the history
…2-compatibility

Fix a Python 2 compatibility issue
  • Loading branch information
k8s-ci-robot authored Jul 16, 2020
2 parents 7fc2c31 + b68ca30 commit fb86b8a
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 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,13 +167,14 @@ 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:
reason = "%s: %s" % (obj['reason'], obj['message'])
raise client.rest.ApiException(status=obj['code'],
reason=reason)
reason = "%s: %s" % (
obj['reason'], obj['message'])
raise client.rest.ApiException(
status=obj['code'], reason=reason)
else:
retry_after_410 = False
yield event
Expand Down

0 comments on commit fb86b8a

Please sign in to comment.