<s> """<STR_LIT>""" <EOL> __author__ = "<STR_LIT>" <EOL> from pyVmomi import VmomiSupport , vmodl <EOL> from Cache import Cache <EOL> class DynamicTypeImporter : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , stub , hostSystem = None ) : <EOL> self . stub = stub <EOL> self . hostSystem = hostSystem <EOL> @ Cache <EOL> def GetTypeManager ( self ) : <EOL> """<STR_LIT>""" <EOL> dynTypeMgr = None <EOL> if self . hostSystem : <EOL> try : <EOL> dynTypeMgr = self . hostSystem . RetrieveDynamicTypeManager ( ) <EOL> except vmodl . fault . MethodNotFound as err : <EOL> pass <EOL> if not dynTypeMgr : <EOL> cmdlineTypesMoId = "<STR_LIT>" <EOL> dynTypeMgr = vmodl . reflect . DynamicTypeManager ( cmdlineTypesMoId , <EOL> self . stub ) <EOL> return dynTypeMgr <EOL> @ Cache <EOL> def ImportTypes ( self , prefix = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> dynTypeMgr = self . GetTypeManager ( ) <EOL> filterSpec = None <EOL> if prefix != '<STR_LIT>' : <EOL> filterSpec = vmodl . reflect . DynamicTypeManager . TypeFilterSpec ( <EOL> typeSubstr = prefix ) <EOL> allTypes = dynTypeMgr . QueryTypeInfo ( filterSpec ) <EOL> DynamicTypeConstructor ( ) . CreateTypes ( allTypes ) <EOL> return allTypes <EOL> class DynamicTypeConstructor : <EOL> """<STR_LIT>""" <EOL> _mapFlags = { "<STR_LIT>" : VmomiSupport . F_OPTIONAL , <EOL> "<STR_LIT>" : VmomiSupport . F_LINKABLE , <EOL> "<STR_LIT>" : VmomiSupport . F_LINK , <EOL> "<STR_LIT>" : VmomiSupport . F_SECRET } <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def CreateTypes ( self , allTypes ) : <EOL> """<STR_LIT>""" <EOL> enumTypes , dataTypes , managedTypes = self . _ConvertAllTypes ( allTypes ) <EOL> self . _CreateAllTypes ( enumTypes , dataTypes , managedTypes ) <EOL> def _ConvertAllTypes ( self , allTypes ) : <EOL> """<STR_LIT>""" <EOL> enumTypes = self . _Filter ( self . _ConvertEnumType , allTypes . enumTypeInfo ) <EOL> dataTypes = self . _Filter ( self . _ConvertDataType , allTypes . dataTypeInfo ) <EOL> managedTypes = self . _Filter ( self . _ConvertManagedType , <EOL> allTypes . managedTypeInfo ) <EOL> retAllTypes = ( enumTypes , dataTypes , managedTypes ) <EOL> return retAllTypes <EOL> def _CreateAllTypes ( self , enumTypes , dataTypes , managedTypes ) : <EOL> """<STR_LIT>""" <EOL> for typeInfo in managedTypes : <EOL> name = typeInfo [ <NUM_LIT:0> ] <EOL> version = typeInfo [ <NUM_LIT:3> ] <EOL> VmomiSupport . AddVersion ( version , '<STR_LIT>' , '<STR_LIT:1.0>' , <NUM_LIT:0> , name ) <EOL> VmomiSupport . AddVersionParent ( version , '<STR_LIT>' ) <EOL> VmomiSupport . AddVersionParent ( version , '<STR_LIT>' ) <EOL> VmomiSupport . AddVersionParent ( version , version ) <EOL> for fn , infos in ( VmomiSupport . CreateEnumType , enumTypes ) , ( VmomiSupport . CreateDataType , dataTypes ) , ( VmomiSupport . CreateManagedType , managedTypes ) : <EOL> for typeInfo in infos : <EOL> try : <EOL> fn ( * typeInfo ) <EOL> except Exception as err : <EOL> pass <EOL> def _ConvertAnnotations ( self , annotations ) : <EOL> """<STR_LIT>""" <EOL> flags = <NUM_LIT:0> <EOL> if annotations : <EOL> for annotation in annotations : <EOL> flags |= self . _mapFlags . get ( annotation . name , <NUM_LIT:0> ) <EOL> return flags <EOL> @ staticmethod <EOL> def _Filter ( fn , types ) : <EOL> """<STR_LIT>""" <EOL> if types : <EOL> return [ fn ( prop ) for prop in types if prop is not None ] <EOL> else : <EOL> return [ ] <EOL> def _ConvertParamType ( self , paramType ) : <EOL> """<STR_LIT>""" <EOL> if paramType : <EOL> name = paramType . name <EOL> version = paramType . version <EOL> aType = paramType . type <EOL> flags = self . _ConvertAnnotations ( paramType . annotation ) <EOL> privId = paramType . privId <EOL> param = ( name , aType , version , flags , privId ) <EOL> else : <EOL> param = None <EOL> return param <EOL> def _ConvertMethodType ( self , methodType ) : <EOL> """<STR_LIT>""" <EOL> if methodType : <EOL> name = methodType . name <EOL> wsdlName = methodType . wsdlName <EOL> version = methodType . version <EOL> params = self . _Filter ( self . _ConvertParamType , methodType . paramTypeInfo ) <EOL> privId = methodType . privId <EOL> faults = methodType . fault <EOL> if methodType . returnTypeInfo : <EOL> returnTypeInfo = methodType . returnTypeInfo <EOL> retFlags = self . _ConvertAnnotations ( returnTypeInfo . annotation ) <EOL> methodRetType = returnTypeInfo . type <EOL> else : <EOL> retFlags = <NUM_LIT:0> <EOL> methodRetType = "<STR_LIT>" <EOL> if wsdlName . endswith ( "<STR_LIT>" ) : <EOL> retType = "<STR_LIT>" <EOL> else : <EOL> retType = methodRetType <EOL> retInfo = ( retFlags , retType , methodRetType ) <EOL> method = ( name , wsdlName , version , params , retInfo , privId , faults ) <EOL> else : <EOL> method = None <EOL> return method <EOL> def _ConvertManagedPropertyType ( self , propType ) : <EOL> """<STR_LIT>""" <EOL> if propType : <EOL> name = propType . name <EOL> version = propType . version <EOL> aType = propType . type <EOL> flags = self . _ConvertAnnotations ( propType . annotation ) <EOL> privId = propType . privId <EOL> prop = ( name , aType , version , flags , privId ) <EOL> else : <EOL> prop = None <EOL> return prop <EOL> def _ConvertManagedType ( self , managedType ) : <EOL> """<STR_LIT>""" <EOL> if managedType : <EOL> vmodlName = managedType . name <EOL> wsdlName = managedType . wsdlName <EOL> version = managedType . version <EOL> parent = managedType . base [ <NUM_LIT:0> ] <EOL> props = self . _Filter ( self . _ConvertManagedPropertyType , managedType . property ) <EOL> methods = self . _Filter ( self . _ConvertMethodType , managedType . method ) <EOL> moType = ( vmodlName , wsdlName , parent , version , props , methods ) <EOL> else : <EOL> moType = None <EOL> return moType <EOL> def _ConvertDataPropertyType ( self , propType ) : <EOL> """<STR_LIT>""" <EOL> if propType : <EOL> name = propType . name <EOL> version = propType . version <EOL> aType = propType . type <EOL> flags = self . _ConvertAnnotations ( propType . annotation ) <EOL> prop = ( name , aType , version , flags ) <EOL> else : <EOL> prop = None <EOL> return prop <EOL> def _ConvertDataType ( self , dataType ) : <EOL> """<STR_LIT>""" <EOL> if dataType : <EOL> vmodlName = dataType . name <EOL> wsdlName = dataType . wsdlName <EOL> version = dataType . version <EOL> parent = dataType . base [ <NUM_LIT:0> ] <EOL> props = self . _Filter ( self . _ConvertDataPropertyType , dataType . property ) <EOL> doType = ( vmodlName , wsdlName , parent , version , props ) <EOL> else : <EOL> doType = None <EOL> return doType <EOL> def _ConvertEnumType ( self , enumType ) : <EOL> """<STR_LIT>""" <EOL> if enumType : <EOL> vmodlName = enumType . name <EOL> wsdlName = enumType . wsdlName <EOL> version = enumType . version <EOL> values = enumType . value <EOL> enumType = ( vmodlName , wsdlName , version , values ) <EOL> else : <EOL> enumType = None <EOL> return enumType </s>
