Merge pull request #204 from palnabarun/fix-watch-py2-compatibility

Fix a Python 2 compatibility issue
This commit is contained in:
Kubernetes Prow Robot 2020-07-16 09:59:41 -07:00 committed by GitHub
commit fb86b8acb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,13 +167,14 @@ 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:
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