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>
This commit is contained in:
parent
7fc2c315c8
commit
a54f404366
@ -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:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user