Exemplo n.º 1
0
 def packdict(self, val):
     record = NSAppleEventDescriptor.recordDescriptor()
     usrf = desctype = None
     for key, value in val.items():
         if isinstance(key, AEType):
             if key.code == kae.pClass and isinstance(
                     value, AEType
             ):  # AS packs records that contain a 'class' property by coercing the packed record to the descriptor type specified by the property's value (assuming it's an AEType)
                 desctype = value
             else:
                 record.setDescriptor_forKeyword_(self.pack(value),
                                                  fourcharcode(key.code))
         else:
             if not usrf:
                 usrf = NSAppleEventDescriptor.listDescriptor()
             usrf.insertDescriptor_atIndex_(self.pack(key), 0)
             usrf.insertDescriptor_atIndex_(self.pack(value), 0)
     if usrf:
         record.setDescriptor_forKeyword_(usrf, self.kUSRF)
     if desctype:
         newrecord = record.coerceToDescriptorType_(
             fourcharcode(desctype.code))
         if newrecord:
             record = newrecord
         else:  # coercion failed for some reason, so pack as normal key-value pair
             record.setDescriptor_forKeyword_(self.pack(desctype),
                                              fourcharcode(key.code))
     return record
Exemplo n.º 2
0
	def packdict(self, val):
		record = NSAppleEventDescriptor.recordDescriptor()
		usrf = desctype = None
		for key, value in val.items():
			if isinstance(key, AEType):
				if key.code == kae.pClass and isinstance(value, AEType): # AS packs records that contain a 'class' property by coercing the packed record to the descriptor type specified by the property's value (assuming it's an AEType)
					desctype = value
				else:
					record.setDescriptor_forKeyword_(self.pack(value), fourcharcode(key.code))
			else:
				if not usrf:
					usrf = NSAppleEventDescriptor.listDescriptor()
				usrf.insertDescriptor_atIndex_(self.pack(key), 0)
				usrf.insertDescriptor_atIndex_(self.pack(value), 0)
		if usrf:
			record.setDescriptor_forKeyword_(usrf, self.kUSRF)
		if desctype:
			newrecord = record.coerceToDescriptorType_(fourcharcode(desctype.code))
			if newrecord:
				record = newrecord
			else: # coercion failed for some reason, so pack as normal key-value pair
				record.setDescriptor_forKeyword_(self.pack(desctype), fourcharcode(key.code))
		return record
Exemplo n.º 3
0
 def packlist(self, val):
     lst = NSAppleEventDescriptor.listDescriptor()
     for item in val:
         lst.insertDescriptor_atIndex_(self.pack(item), 0)
     return lst
Exemplo n.º 4
0
	def packlist(self, val):
		lst = NSAppleEventDescriptor.listDescriptor()
		for item in val:
			lst.insertDescriptor_atIndex_(self.pack(item), 0)
		return lst