Changeset 48043 in vbox for trunk/src/VBox
- Timestamp:
- Aug 25, 2013 7:12:55 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/glue/vboxapi.py
r47984 r48043 297 297 # 298 298 299 def errGetStatus(self, oXcpt):299 def xcptGetStatus(self, oXcpt): 300 300 """ 301 301 Returns the COM status code from the VBox API given exception. … … 303 303 return None; 304 304 305 def errIsDeadInterface(self, oXcpt):305 def xcptIsDeadInterface(self, oXcpt): 306 306 """ 307 307 Returns True if the exception indicates that the interface is dead, False if not. … … 309 309 return False; 310 310 311 def errIsEqual(oXcpt, hrStatus):311 def xcptIsEqual(self, oXcpt, hrStatus): 312 312 """ 313 313 Checks if the exception oXcpt is equal to the COM/XPCOM status code … … 320 320 """ 321 321 try: 322 hrXcpt = self. errGetStatus(oXcpt);322 hrXcpt = self.xcptGetStatus(oXcpt); 323 323 except AttributeError: 324 324 return False; 325 return hrXcpt == hrStatus; 326 327 def errGetMessage(self, oXcpt): 325 if hrXcpt == hrStatus: 326 return True; 327 328 # Fudge for 32-bit signed int conversion. 329 if hrStatus > 0x7fffffff and hrStatus <= 0xffffffff and hrXcpt < 0: 330 if (hrStatus - 0x100000000) == hrXcpt: 331 return True; 332 return False; 333 334 def xcptGetMessage(self, oXcpt): 328 335 """ 329 336 Returns the best error message found in the COM-like exception. 330 Returns None to fall back on errToString.337 Returns None to fall back on xcptToString. 331 338 Raises exception if oXcpt isn't our kind of exception object. 332 339 """ 333 340 return None; 334 341 335 def errGetBaseXcpt(self):342 def xcptGetBaseXcpt(self): 336 343 """ 337 344 Returns the base exception class. … … 339 346 return None; 340 347 341 def errSetupConstants(self, oDst):348 def xcptSetupConstants(self, oDst): 342 349 """ 343 350 Copy/whatever all error constants onto oDst. … … 346 353 347 354 @staticmethod 348 def errCopyErrorConstants(oDst, oSrc):355 def xcptCopyErrorConstants(oDst, oSrc): 349 356 """ 350 357 Copy everything that looks like error constants from oDst to oSrc. … … 612 619 return CastTo(oIUnknown, sClassName) 613 620 614 def errGetStatus(self, oXcpt):621 def xcptGetStatus(self, oXcpt): 615 622 # The DISP_E_EXCEPTION + excptinfo fun needs checking up, only 616 623 # empirical info on it so far. … … 621 628 return hrXcpt; 622 629 623 def errIsDeadInterface(self, oXcpt):624 return self. errGetStatus(oXcpt) in [630 def xcptIsDeadInterface(self, oXcpt): 631 return self.xcptGetStatus(oXcpt) in [ 625 632 0x800706ba, -2147023174, # RPC_S_SERVER_UNAVAILABLE. 626 633 0x800706be, -2147023170, # RPC_S_CALL_FAILED. 627 634 0x800706bf, -2147023169, # RPC_S_CALL_FAILED_DNE. 628 635 0x80010108, -2147417848, # RPC_E_DISCONNECTED. 636 0x800706b5, -2147023179, # RPC_S_UNKNOWN_IF 629 637 ]; 630 638 631 639 632 def errGetMessage(self, oXcpt):640 def xcptGetMessage(self, oXcpt): 633 641 if hasattr(oXcpt, 'excepinfo'): 634 642 try: … … 648 656 return None; 649 657 650 def errGetBaseXcpt(self):658 def xcptGetBaseXcpt(self): 651 659 import pythoncom; 652 660 return pythoncom.com_error; 653 661 654 def errSetupConstants(self, oDst):662 def xcptSetupConstants(self, oDst): 655 663 import winerror; 656 oDst = self. errCopyErrorConstants(oDst, winerror);664 oDst = self.xcptCopyErrorConstants(oDst, winerror); 657 665 658 666 # XPCOM compatability constants. … … 734 742 return oIUnknown.queryInterface(getattr(xpcom.components.interfaces, sClassName)) 735 743 736 def errGetStatus(self, oXcpt):744 def xcptGetStatus(self, oXcpt): 737 745 return oXcpt.errno; 738 746 739 def errIsDeadInterface(self, oXcpt):740 return self. errGetStatus(oXcpt) in [747 def xcptIsDeadInterface(self, oXcpt): 748 return self.xcptGetStatus(oXcpt) in [ 741 749 0x80004004, -2147467260, # NS_ERROR_ABORT 742 750 0x800706be, -2147023170, # NS_ERROR_CALL_FAILED (RPC_S_CALL_FAILED) 743 751 ]; 744 752 745 def errGetMessage(self, oXcpt):753 def xcptGetMessage(self, oXcpt): 746 754 if hasattr(oXcpt, 'msg'): 747 755 try: … … 753 761 return None; 754 762 755 def errGetBaseXcpt(self):763 def xcptGetBaseXcpt(self): 756 764 import xpcom; 757 765 return xpcom.Exception; 758 766 759 def errSetupConstants(self, oDst):767 def xcptSetupConstants(self, oDst): 760 768 import xpcom; 761 oDst = self. errCopyErrorConstants(oDst, xpcom.nsError);769 oDst = self.xcptCopyErrorConstants(oDst, xpcom.nsError); 762 770 763 771 # COM compatability constants. … … 923 931 924 932 ## Status constants. 925 self.statuses = self.platform. errSetupConstants(VirtualBoxManager.Statuses());933 self.statuses = self.platform.xcptSetupConstants(VirtualBoxManager.Statuses()); 926 934 ## @todo Add VBOX_E_XXX to statuses? They're already in constants... 927 935 ## Dictionary for errToString, built on demand. … … 929 937 930 938 ## The exception class for the selected platform. 931 self.oXcptClass = self.platform. errGetBaseXcpt();939 self.oXcptClass = self.platform.xcptGetBaseXcpt(); 932 940 global CurXcptClass; 933 941 CurXcptClass = self.oXcptClass; … … 1077 1085 ## @todo port to webservices! 1078 1086 1079 def errGetStatus(self, oXcpt): 1080 """ 1081 Gets the status code from an exception. 1082 """ 1083 return self.platform.errGetStatus(oXcpt); 1084 1085 def errIsDeadInterface(self, oXcpt): 1086 """ 1087 Returns True if the exception indicates that the interface is dead, False if not. 1088 """ 1089 return self.platform.errIsDeadInterface(oXcpt); 1090 1091 def errIsOurXcptKind(self, oXcpt): 1092 """ 1093 Checks if the exception is one that could come from the VBox API. 1087 def xcptGetStatus(self, oXcpt = None): 1088 """ 1089 Gets the status code from an exception. If the exception parameter 1090 isn't specified, the current exception is examined. 1091 """ 1092 if oXcpt is None: 1093 oXcpt = sys.exc_info()[1]; 1094 return self.platform.xcptGetStatus(oXcpt); 1095 1096 def xcptIsDeadInterface(self, oXcpt = None): 1097 """ 1098 Returns True if the exception indicates that the interface is dead, 1099 False if not. If the exception parameter isn't specified, the current 1100 exception is examined. 1101 """ 1102 if oXcpt is None: 1103 oXcpt = sys.exc_info()[1]; 1104 return self.platform.xcptIsDeadInterface(oXcpt); 1105 1106 def xcptIsOurXcptKind(self, oXcpt = None): 1107 """ 1108 Checks if the exception is one that could come from the VBox API. If 1109 the exception parameter isn't specified, the current exception is 1110 examined. 1094 1111 """ 1095 1112 if self.oXcptClass is None: ## @todo find the exception class for web services! 1096 1113 return False; 1114 if oXcpt is None: 1115 oXcpt = sys.exc_info()[1]; 1097 1116 return isinstance(oXcpt, self.oXcptClass); 1098 1117 1099 def errIsEqual(self, oXcpt, hrStatus): 1100 """ See PlatformBase::errIsEqual(). """ 1101 return self.platform.errIsEqual(oXcpt, hrStatus); 1102 1103 def errIsNotEqual(self, oXcpt, hrStatus): 1104 """ 1105 Negated errIsEqual. 1106 """ 1107 return self.errIsEqual(oXcpt, hrStatus); 1108 1109 def errToString(self, hrStatusOrXcpt): 1118 def xcptIsEqual(self, oXcpt, hrStatus): 1119 """ 1120 Checks if the exception oXcpt is equal to the COM/XPCOM status code 1121 hrStatus. 1122 1123 The oXcpt parameter can be any kind of object, we'll just return True 1124 if it doesn't behave like a our exception class. If it's None, we'll 1125 query the current exception and examine that. 1126 1127 Will not raise any exception as long as hrStatus and self are not bad. 1128 """ 1129 if oXcpt is None: 1130 oXcpt = sys.exc_info()[1]; 1131 return self.platform.xcptIsEqual(oXcpt, hrStatus); 1132 1133 def xcptIsNotEqual(self, oXcpt, hrStatus): 1134 """ 1135 Negated xcptIsEqual. 1136 """ 1137 return not self.xcptIsEqual(oXcpt, hrStatus); 1138 1139 def xcptToString(self, hrStatusOrXcpt = None): 1110 1140 """ 1111 1141 Converts the specified COM status code, or the status code of the 1112 specified exception, to a C constant string. 1142 specified exception, to a C constant string. If the parameter isn't 1143 specified (is None), the current exception is examined. 1113 1144 """ 1114 1145 1115 1146 # Deal with exceptions. 1116 if self.errIsOurXcptKind(hrStatusOrXcpt):1117 hrStatus = self. errGetStatus(hrStatusOrXcpt);1147 if hrStatusOrXcpt is None or self.xcptIsOurXcptKind(hrStatusOrXcpt): 1148 hrStatus = self.xcptGetStatus(hrStatusOrXcpt); 1118 1149 else: 1119 1150 hrStatus = hrStatusOrXcpt; … … 1137 1168 return sStr; 1138 1169 1139 def errGetMessage(self, oXcpt): 1140 """ 1141 Returns the best error message found in the COM-like exception. 1142 """ 1143 sRet = self.platform.errGetMessage(oXcpt); 1170 def xcptGetMessage(self, oXcpt = None): 1171 """ 1172 Returns the best error message found in the COM-like exception. If the 1173 exception parameter isn't specified, the current exception is examined. 1174 """ 1175 if oXcpt is None: 1176 oXcpt = sys.exc_info()[1]; 1177 sRet = self.platform.xcptGetMessage(oXcpt); 1144 1178 if sRet is None: 1145 sRet = self. errToString(oXcpt);1179 sRet = self.xcptToString(oXcpt); 1146 1180 return sRet; 1147 1181 1182 # Legacy, remove in a day or two. 1183 errGetStatus = xcptGetStatus 1184 errIsDeadInterface = xcptIsDeadInterface 1185 errIsOurXcptKind = xcptIsOurXcptKind 1186 errGetMessage = xcptGetMessage 1187
Note:
See TracChangeset
for help on using the changeset viewer.