Skip to content

Commit

Permalink
python3: absolute import
Browse files Browse the repository at this point in the history
Use absolute import from the __future__ module to prepare
the library for use in python 3

partial: vmware#55
  • Loading branch information
hartsock committed Jul 28, 2014
1 parent 196e76c commit 8ee385a
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 66 deletions.
3 changes: 2 additions & 1 deletion pyVmomi/CoreTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import

# ******* WARNING - AUTO GENERATED CODE - DO NOT EDIT *******
from VmomiSupport import CreateDataType, CreateManagedType, CreateEnumType, AddVersion, AddVersionParent, F_LINK, F_LINKABLE, F_OPTIONAL
from pyVmomi.VmomiSupport import CreateDataType, CreateManagedType, CreateEnumType, AddVersion, AddVersionParent, F_LINK, F_LINKABLE, F_OPTIONAL

AddVersion("vmodl.query.version.version1", "", "", 0, "vim25")
AddVersion("vmodl.query.version.version2", "", "", 0, "vim25")
Expand Down
3 changes: 2 additions & 1 deletion pyVmomi/ServerObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import

# ******* WARNING - AUTO GENERATED CODE - DO NOT EDIT *******
from VmomiSupport import CreateDataType, CreateManagedType, CreateEnumType, AddVersion, AddVersionParent, F_LINK, F_LINKABLE, F_OPTIONAL
from pyVmomi.VmomiSupport import CreateDataType, CreateManagedType, CreateEnumType, AddVersion, AddVersionParent, F_LINK, F_LINKABLE, F_OPTIONAL

AddVersion("vim.version.version1", "vim2", "2.0", 1, "vim25")
AddVersion("vim.version.version2", "vim25", "2.5", 0, "vim25")
Expand Down
10 changes: 5 additions & 5 deletions pyVmomi/SoapAdapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
from six.moves import http_client
import sys
import os
Expand All @@ -26,9 +26,9 @@
# We have our own escape functionality.
# from xml.sax.saxutils import escape
from cStringIO import StringIO
from VmomiSupport import *
from StubAdapterAccessorImpl import StubAdapterAccessorMixin
import Iso8601
from pyVmomi.VmomiSupport import *
from pyVmomi.StubAdapterAccessorImpl import StubAdapterAccessorMixin
import pyVmomi.Iso8601
import base64
from xml.parsers.expat import ExpatError
import copy
Expand Down Expand Up @@ -665,7 +665,7 @@ def EndElementHandler(self, tag):
except UnicodeError:
obj = data
elif obj is datetime:
obj = Iso8601.ParseISO8601(data)
obj = pyVmomi.Iso8601.ParseISO8601(data)
if not obj:
raise TypeError(data)
# issubclass is very expensive. Test last
Expand Down
4 changes: 2 additions & 2 deletions pyVmomi/StubAdapterAccessorImpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from VmomiSupport import GetVmodlType
from __future__ import absolute_import
from pyVmomi.VmomiSupport import GetVmodlType

class StubAdapterAccessorMixin:
def __init__(self):
Expand Down
4 changes: 2 additions & 2 deletions pyVmomi/Version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from VmomiSupport import nsMap, versionMap, versionIdMap, serviceNsMap, parentMap
from __future__ import absolute_import
from pyVmomi.VmomiSupport import nsMap, versionMap, versionIdMap, serviceNsMap, parentMap

## Add an API version
def AddVersion(version, ns, versionId='', isLegacy=0, serviceNs=''):
Expand Down
9 changes: 5 additions & 4 deletions pyVmomi/VmomiSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@
# limitations under the License.

## VMOMI support code
from __future__ import absolute_import
from __future__ import with_statement # 2.5 only

from datetime import datetime
import Iso8601
import pyVmomi.Iso8601
import base64
import threading
NoneType = type(None)
try:
from pyVmomiSettings import allowGetSet
from pyVmomi.pyVmomiSettings import allowGetSet
_allowGetSet = allowGetSet
except:
_allowGetSet = True

try:
from pyVmomiSettings import allowCapitalizedNames
from pyVmomi.pyVmomiSettings import allowCapitalizedNames
_allowCapitalizedNames = allowCapitalizedNames
except:
_allowCapitalizedNames = True
Expand Down Expand Up @@ -1227,7 +1228,7 @@ def InverseMap(map):
serviceNsMap = { BASE_VERSION : XMLNS_VMODL_BASE.split(":")[-1] }
parentMap = {}

from Version import AddVersion, IsChildVersion
from pyVmomi.Version import AddVersion, IsChildVersion

if not isinstance(bool, type): # bool not a type in python <= 2.2
bool = type("bool", (int,),
Expand Down
102 changes: 51 additions & 51 deletions pyVmomi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
# In VmomiSupport, to support dynamic type loading, all the data types are
# wrapped around using a meta type which can intercept attribute access and
# load the necessary nested classes. This can be implemented only in python 2.5
Expand All @@ -22,170 +22,170 @@
sys.stderr.write("You need Python 2.5 or later to import pyVmomi module\n")
sys.exit(1)

import VmomiSupport
import CoreTypes
import pyVmomi.VmomiSupport
import pyVmomi.CoreTypes
try:
import ReflectTypes
except ImportError:
pass
try:
import ServerObjects
import pyVmomi.ServerObjects
except ImportError:
pass
try:
import InternalServerObjects
import pyVmomi.InternalServerObjects
except ImportError:
pass

# Import all the known product-specific types
# XXX: Make this search the package for types?
try:
import DrObjects
import pyVmomi.DrObjects
except ImportError:
pass

try:
import DrextObjects
import pyVmomi.DrextObjects
except ImportError:
pass

try:
import HbrReplicaTypes
import pyVmomi.HbrReplicaTypes
except ImportError:
pass
try:
import HmsObjects
import pyVmomi.HmsObjects
except ImportError:
pass
try:
import HostdObjects
import pyVmomi.HostdObjects
except ImportError:
pass
try:
import VpxObjects
import pyVmomi.VpxObjects
except ImportError:
pass
try:
import VorbTypes
import pyVmomi.VorbTypes
except ImportError:
pass
try:
import DodoTypes
import pyVmomi.DodoTypes
except ImportError:
pass
try:
import VmwauthproxyTypes
import pyVmomi.VmwauthproxyTypes
except ImportError:
pass
try:
import DmsTypes
import pyVmomi.DmsTypes
except ImportError:
pass
try:
import OmsTypes
import pyVmomi.OmsTypes
except ImportError:
pass
try:
import HmoTypes
import pyVmomi.HmoTypes
except ImportError:
pass
try:
import CimsfccTypes
import pyVmomi.CimsfccTypes
except ImportError:
pass
try:
import TaskupdaterTypes
import pyVmomi.TaskupdaterTypes
except ImportError:
pass
try:
import ImgFactTypes
import pyVmomi.ImgFactTypes
except ImportError:
pass

try:
import VpxapiTypes
import pyVmomi.VpxapiTypes
except ImportError:
pass
try:
import CsiObjects
import pyVmomi.CsiObjects
except ImportError:
pass

try:
import HostdTypes
import pyVmomi.HostdTypes
except ImportError:
pass

try:
import TaggingObjects
import pyVmomi.TaggingObjects
except ImportError:
pass

try:
import NfcTypes
import pyVmomi.NfcTypes
except ImportError:
pass

try:
import SmsObjects
import pyVmomi.SmsObjects
except ImportError:
pass

try:
import SpsObjects
import pyVmomi.SpsObjects
except ImportError:
pass

try:
import DataserviceObjects
import pyVmomi.DataserviceObjects
except ImportError:
pass

# Start of update manager specific types
try:
import IntegrityObjects
import pyVmomi.IntegrityObjects
except ImportError:
pass

try:
import SysimageObjects
import pyVmomi.SysimageObjects
except ImportError:
pass
# End of update manager specific types

try:
import RbdTypes
import pyVmomi.RbdTypes
except ImportError:
pass

# Import Profile based management specific VMODL
try:
import PbmObjects
import pyVmomi.PbmObjects
except ImportError:
pass

try:
import CisLicenseTypes
import pyVmomi.CisLicenseTypes
except ImportError:
pass

try:
import TestTypes
import pyVmomi.TestTypes
except ImportError:
pass

try:
import SsoTypes
import pyVmomi.SsoTypes
except ImportError:
pass

try:
import CisCmTypes
import pyVmomi.CisCmTypes
except ImportError:
pass

try:
import DataserviceTypes
import pyVmomi.DataserviceTypes
except ImportError:
pass

Expand All @@ -194,18 +194,18 @@
# As well load it proactively.
# Note: This should be done before importing SoapAdapter as it uses
# some fault types
VmomiSupport.GetVmodlType("vmodl.DynamicData")
pyVmomi.VmomiSupport.GetVmodlType("vmodl.DynamicData")

from SoapAdapter import SoapStubAdapter, StubAdapterBase, SoapCmdStubAdapter, \
from pyVmomi.SoapAdapter import SoapStubAdapter, StubAdapterBase, SoapCmdStubAdapter, \
SessionOrientedStub

types = VmomiSupport.types
types = pyVmomi.VmomiSupport.types

# This will allow files to use Create** functions
# directly from pyVmomi
CreateEnumType = VmomiSupport.CreateEnumType
CreateDataType = VmomiSupport.CreateDataType
CreateManagedType = VmomiSupport.CreateManagedType
CreateEnumType = pyVmomi.VmomiSupport.CreateEnumType
CreateDataType = pyVmomi.VmomiSupport.CreateDataType
CreateManagedType = pyVmomi.VmomiSupport.CreateManagedType

# For all the top level names, creating a LazyModule object
# in the global namespace of pyVmomi. Files can just import the
Expand All @@ -214,14 +214,14 @@
# ALLOWED: from pyVmomi import vim
# NOT ALLOWED: from pyVmomi import vim.host
_globals = globals()
for name in VmomiSupport._topLevelNames:
upperCaseName = VmomiSupport.Capitalize(name)
obj = VmomiSupport.LazyModule(name)
for name in pyVmomi.VmomiSupport._topLevelNames:
upperCaseName = pyVmomi.VmomiSupport.Capitalize(name)
obj = pyVmomi.VmomiSupport.LazyModule(name)
_globals[name] = obj
if VmomiSupport._allowCapitalizedNames:
if pyVmomi.VmomiSupport._allowCapitalizedNames:
_globals[upperCaseName] = obj
if not hasattr(VmomiSupport.types, name):
setattr(VmomiSupport.types, name, obj)
if VmomiSupport._allowCapitalizedNames:
setattr(VmomiSupport.types, upperCaseName, obj)
if not hasattr(pyVmomi.VmomiSupport.types, name):
setattr(pyVmomi.VmomiSupport.types, name, obj)
if pyVmomi.VmomiSupport._allowCapitalizedNames:
setattr(pyVmomi.VmomiSupport.types, upperCaseName, obj)
del _globals

0 comments on commit 8ee385a

Please sign in to comment.