Skip to content

Commit

Permalink
CP-46112: Remove python2 compatible code from XenAPI
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Cheng <stephen.cheng@cloud.com>
  • Loading branch information
stephenchengCloud committed Aug 1, 2024
1 parent 21174bb commit 74c38db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
21 changes: 6 additions & 15 deletions scripts/examples/python/XenAPI/XenAPI.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/python3
# Copyright (c) Citrix Systems, Inc.
# All rights reserved.
#
Expand Down Expand Up @@ -58,13 +59,8 @@
import os
import socket
import sys

if sys.version_info[0] == 2:
import httplib as httplib
import xmlrpclib as xmlrpclib
else:
import http.client as httplib
import xmlrpc.client as xmlrpclib
import http.client as httplib
import xmlrpc.client as xmlrpclib

otel = False
try:
Expand Down Expand Up @@ -150,15 +146,10 @@ class Session(xmlrpclib.ServerProxy):
def __init__(self, uri, transport=None, encoding=None, verbose=False,
allow_none=True, ignore_ssl=False):

if sys.version_info[0] > 2:
# this changed to be a 'bool' in Python3
verbose = bool(verbose)
allow_none = bool(allow_none)
verbose = bool(verbose)
allow_none = bool(allow_none)

# Fix for CA-172901 (+ Python 2.4 compatibility)
# Fix for context=ctx ( < Python 2.7.9 compatibility)
if not (sys.version_info[0] <= 2 and sys.version_info[1] <= 7 and sys.version_info[2] <= 9 ) \
and ignore_ssl:
if ignore_ssl:
import ssl
ctx = ssl._create_unverified_context()
xmlrpclib.ServerProxy.__init__(self, uri, transport, encoding,
Expand Down
7 changes: 2 additions & 5 deletions scripts/examples/python/XenAPIPlugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
"""XenAPI python plugin boilerplate code"""
# pylint: disable=invalid-name
# Module name "XenAPIPlugin" doesn't conform to snake_case naming style
Expand All @@ -9,11 +10,7 @@
import sys

import XenAPI

if sys.version_info[0] == 2:
import xmlrpclib
else:
import xmlrpc.client as xmlrpclib
import xmlrpc.client as xmlrpclib

class Failure(Exception):
"""Provide compatibility with plugins written against the XenServer 5.5 API"""
Expand Down

0 comments on commit 74c38db

Please sign in to comment.