Changeset 79442 in vbox
- Timestamp:
- Jul 1, 2019 3:34:26 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/glue/vboxapi.py
r79139 r79442 1006 1006 self._dErrorValToName = None 1007 1007 1008 ## Dictionary for resolving enum values to names, two levels of dictionaries. 1009 ## First level is indexed by enum name, the next by value. 1010 self._ddEnumValueToName = {}; 1011 1008 1012 ## The exception class for the selected platform. 1009 1013 self.oXcptClass = self.platform.xcptGetBaseXcpt() … … 1146 1150 return VBoxSdkDir 1147 1151 1152 def getEnumValueName(self, sEnumTypeNm, oEnumValue, fTypePrefix = False): 1153 """ 1154 Returns the name (string) for the corresponding enum value. 1155 """ 1156 # Cache lookup: 1157 dValueNames = self._ddEnumValueToName.get(sEnumTypeNm); 1158 if dValueNames is not None: 1159 sValueName = dValueNames.get(oEnumValue); 1160 if sValueName: 1161 return sValueName if not fTypePrefix else '%s_%s' % (sEnumTypeNm, sValueName); 1162 else: 1163 # Cache miss. Build the reverse lookup dictionary and add it to the cache: 1164 dNamedValues = self.constants.all_values(sEnumTypeNm); 1165 if len(dNamedValues) > 0: 1166 1167 dValueNames = dict(); 1168 for sName in dNamedValues: 1169 dValueNames[dNamedValues[sName]] = sName; 1170 self._ddEnumValueToName[sEnumTypeNm] = dValueNames; 1171 1172 # Lookup the value: 1173 sValueName = dValueNames.get(oEnumValue); 1174 if sValueName: 1175 return sValueName if not fTypePrefix else '%s_%s' % (sEnumTypeNm, sValueName); 1176 1177 # Fallback: 1178 return '%s_Unknown_%s' % (sEnumTypeNm, oEnumValue); 1179 1148 1180 # 1149 1181 # Error code utilities. … … 1221 1253 if sKey[0].isupper(): 1222 1254 oValue = getattr(self.statuses, sKey) 1223 if type(oValue) is int:1224 dErrorValToName[ oValue] = sKey1255 if isinstance(oValue, (int, long)): 1256 dErrorValToName[int(oValue)] = sKey 1225 1257 # Always prefer the COM names (see aliasing in platform specific code): 1226 1258 for sKey in ('S_OK', 'E_FAIL', 'E_ABORT', 'E_POINTER', 'E_NOINTERFACE', 'E_INVALIDARG', … … 1236 1268 except KeyError: 1237 1269 hrLong = long(hrStatus) 1238 sStr = '%#x (%d)' % (hrLong , hrLong)1270 sStr = '%#x (%d)' % (hrLong & 0xffffffff, hrLong) 1239 1271 return sStr 1240 1272 … … 1251 1283 return sRet 1252 1284 1253 # Legacy, remove in a day or two.1254 errGetStatus = xcptGetStatus1255 errIsDeadInterface = xcptIsDeadInterface1256 errIsOurXcptKind = xcptIsOurXcptKind1257 errGetMessage = xcptGetMessage1258
Note:
See TracChangeset
for help on using the changeset viewer.