def AEM_unpack(self, desc, codecs): try: return self._unpack(desc, codecs) except MacOS.Error, e: number, message = e[0], e.args[1:] and e[1] or None if number == -1700: # coercion error return False, EventHandlerError(number, message, object=desc, coercion=AEType(self.AEM_code)) else: return False, EventHandlerError(number, message, object=desc)
def AEM_unpack(self, desc, codecs): if desc.type == kAE.typeType and desc.data == self._cMissingValue: return True, codecs.unpack(desc) else: return False, EventHandlerError(-1704, "Not a 'missing value' constant.", desc)
def _unpackAppleEvent(event, includeAttributes, requiredArgDefs, optionalArgDefs, codecs): desiredResultType = None if includeAttributes: kargs = {_attributesArgName: _unpackEventAttributes(event)} else: kargs = {} params = dict([ event.AEGetNthDesc(i + 1, kae.typeWildCard) for i in range(event.AECountItems()) ]) for code, argName, datatypes in requiredArgDefs: try: argValue = params.pop(code) except KeyError: raise EventHandlerError(-1721, "Required parameter %r is missing." % code) else: kargs[argName] = _unpackValue(argValue, datatypes, codecs) for code, argValue in params.items(): try: argName, datatypes = optionalArgDefs[code] except KeyError: # (note: SIG says that any unrecognised parameters should be ignored) if code == kae.keyAERequestedType: # event contains a 'desired result type' parameter but callback doesn't handle this explicitly, so have callback wrapper attempt to perform coercion automatically when packing result desiredResultType = argValue else: kargs[argName] = _unpackValue(argValue, datatypes, codecs) return kargs, desiredResultType
def AEM_unpack(self, desc, codecs): if desc.type == kAE.typeNull: return True, None else: return False, EventHandlerError(-1704, "Not a typeNull descriptor.", desc)
def _unpack(self, desc, codecs): desc = desc.AECoerceDesc(kAE.typeEnumerated) if desc.data not in self._codes: return False, EventHandlerError(-1704, "Bad enumerator.", desc, AEType(kAE.typeEnumerated)) return True, codecs.unpack(desc)