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

Commit fb86b8a

Browse files
authored
Merge pull request #204 from palnabarun/fix-watch-py2-compatibility
Fix a Python 2 compatibility issue
2 parents 7fc2c31 + b68ca30 commit fb86b8a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

watch/watch.py

+15-5
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,13 +167,14 @@ 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:
165-
reason = "%s: %s" % (obj['reason'], obj['message'])
166-
raise client.rest.ApiException(status=obj['code'],
167-
reason=reason)
174+
reason = "%s: %s" % (
175+
obj['reason'], obj['message'])
176+
raise client.rest.ApiException(
177+
status=obj['code'], reason=reason)
168178
else:
169179
retry_after_410 = False
170180
yield event

0 commit comments

Comments
 (0)