Commits

book...@0c1241d1-2811-0410-b6f5-f555c02b9b86  committed d8a6b94

Add recursive collapse to handle the heriachy of the responseGroups

  • Participants
  • Parent commits 24ff945

Comments (0)

Files changed (2)

 	Operation => { 'isByPassed'=>(...), 'isPivoted'=>(...), 
 		'isCollective'=>(...), 'isCollected'=>(...), 
 		isPaged=> { key1: (...), key2: (...), ... }  
+	"""
+
+	"""
+	ResponseGroups heirachy:
+	Parent => children,
+
+	The benefit of this layer is to reduce the redundency, when
+	the child ResponseGroup change, it propaged to the parent
+	automatically
+	"""
+	rgh = {
+		'CustomerFull': ('CustomerInfo', 'CustomerLists', 'CustomerReviews'), 
+		'Large': ('Accessories', 'BrowseNodes', 'ListmaniaLists', 'Medium', 'Offers', 'Reviews', 'Similarities', 'Tracks'),
+		'ListFull': ('ListInfo', 'ListItems'),
+		'ListInfo': ('ListMinimum', ),
+		'ListItems': ('ListMinimum', ),
+		'Medium': ('EditorialReview', 'Images', 'ItemAttributes', 'OfferSummary', 'Request', 'SalesRank', 'Small'),
+		'OfferFull': ('Offers',),
+		'Offers': ('OfferSummary',),
+		'Variation': ('VariationMinimum', 'VariationSummary')
+	}
+
+	"""
+	ResponseGroup and corresponding plugins:
+	ResponseGroup=>(isBypassed, isPivoted, isCollective, isCollected, isPaged)
+
 	isPaged is defined as:
 	{ kwItems : (kwPage, kwTotalResults, pageSize) }
 
 	- kwItems: string, the tagname of collection
-	- kwPage: integer, current page
-	- kwTotalResults: integer, the length of collection
+	- kwPage: string, the tagname of page 
+	- kwTotalResults: string, the tagname of length 
 	- pageSize: constant integer, the size of each page
 
 	"""
-
-	"""
-	ResponseGroup and corresponding plugins:
-	ResponseGroup=>(isBypassed, isPivoted, isCollective, isCollected, isPaged)
-	TODO: Use the following sequence for optimization:
-		isCollective, isCollected, isPaged, isBypassed, isPivoted
-
-	isPaged is defined as:
-		(collective, collected, totalItems, page) 
-		
-	"""
 	rgps = {
 		'Accessories': ((), (), (), (), {}), 
 		'AlternateVersions': ((), (), (), (), {}), 
 		'ListFull': ((), (), (), (), {}),
 		'ListInfo': ((), (), (), (), {}),
 		'ListItems': ((), (), (), (), {}),
-		'ListManiaLists': ((), (), (), (), {}),
+		'ListmaniaLists': ((), (), (), (), {}),
 		'ListMinimum': ((), (), (), (), {}),
 		'Medium': ((), (), (), (), {}),
 		'MerchantItemAttributes': ((), (), (), (), {}),
 		'Seller': ((), (), (), (), {}),
 		'SellerListing': ((), (), (), (), {}),
 		'Similarities': ((), (), (), (), {}),
-		'Small': ((), (), (), (), {}),
+		'Small': ((), ('ItemAttributes',), (), ('Item',), 
+			{ 'Items': ('OfferPage', 'TotalResults', 10) }),
 		'Subjects': ((), (), (), (), {}),
 		'TopSellers': ((), (), ('TopSellers',), ('TopSeller',), {}),
 		'Tracks': ((), (), (), (), {}),
 		'TransactionDetails': ((), (), ('Transactions', 'TransactionItems', 'Shipments'),
 			('Transaction', 'TransactionItem', 'Shipment'), {}),
+		'Variations': ((), (), (), (), {}),
 		'VariationMinimum': ((), (), (), (), {}),
-		'Variations': ((), (), (), (), {}),
 		'VariationImages': ((), (), (), (), {}),
 		'VariationSummary':((), (), (), (), {}) 
 	}
 		'CustomerContentLookup': ('Request', 'CustomerInfo', 'CustomerReviews', 'CustomerLists', 'CustomerFull'),
 		'CustomerContentSearch': ('Request', 'CustomerInfo'),
 		'Help': ('Request', 'Help'),
-		'ItemLookup': ('Request', 'Small', 'Accessories', 'BrowseNodes', 'EditorialReview', 'Images', 'ItemAttributes', 'ItemIds', 'Large', 'ListManiaLists', 'Medium', 'MerchantItemAttributes', 'OfferFull', 'Offers', 'OfferSummary', 'Reviews', 'SalesRank', 'Similarities', 'Subjects', 'Tracks', 'VariationImages', 'VariationMinimum', 'Variations', 'VariationSummary'),
-		'ItemSearch': ('Request', 'Small', 'Accessories', 'BrowseNodes', 'EditorialReview', 'ItemAttributes', 'ItemIds', 'Large', 'ListManiaLists', 'Medium', 'MerchantItemAttributes', 'OfferFull', 'Offers', 'OfferSummary', 'Reviews', 'SalesRank', 'SearchBins', 'Similarities', 'Subjects', 'Tracks', 'VariationMinimum', 'Variations', 'VariationSummary'),
-		'ListLookup': ('Request', 'ListInfo', 'Accessories', 'BrowseNodes', 'EditorialReview', 'Images', 'ItemAttributes', 'ItemIds', 'Large', 'ListFull', 'ListItems', 'ListManiaLists', 'Medium', 'Offers', 'OfferSummary', 'Reviews', 'SalesRank', 'Similarities', 'Subjects', 'Tracks', 'VariationMinimum', 'Variations', 'VariationSummary'),
+		'ItemLookup': ('Request', 'Small', 'Accessories', 'BrowseNodes', 'EditorialReview', 'Images', 'ItemAttributes', 'ItemIds', 'Large', 'ListmaniaLists', 'Medium', 'MerchantItemAttributes', 'OfferFull', 'Offers', 'OfferSummary', 'Reviews', 'SalesRank', 'Similarities', 'Subjects', 'Tracks', 'VariationImages', 'VariationMinimum', 'Variations', 'VariationSummary'),
+		'ItemSearch': ('Request', 'Small', 'Accessories', 'BrowseNodes', 'EditorialReview', 'ItemAttributes', 'ItemIds', 'Large', 'ListmaniaLists', 'Medium', 'MerchantItemAttributes', 'OfferFull', 'Offers', 'OfferSummary', 'Reviews', 'SalesRank', 'SearchBins', 'Similarities', 'Subjects', 'Tracks', 'VariationMinimum', 'Variations', 'VariationSummary'),
+		'ListLookup': ('Request', 'ListInfo', 'Accessories', 'BrowseNodes', 'EditorialReview', 'Images', 'ItemAttributes', 'ItemIds', 'Large', 'ListFull', 'ListItems', 'ListmaniaLists', 'Medium', 'Offers', 'OfferSummary', 'Reviews', 'SalesRank', 'Similarities', 'Subjects', 'Tracks', 'VariationMinimum', 'Variations', 'VariationSummary'),
 		'ListSearch': ('Request', 'ListInfo', 'ListMinimum'),
 		'SellerListingLookup': ('Request', 'SellerListing'),
 		'SellerListingSearch': ('Request', 'SellerListing'),
 		'SellerLookup': ('Request', 'Seller'),
-		'SimilarityLookup': ('Request', 'Small', 'Accessories', 'BrowseNodes', 'EditorialReview', 'Images', 'ItemAttributes', 'ItemIds', 'Large', 'ListManiaLists', 'Medium', 'Offers', 'OfferSummary', 'Reviews', 'SalesRank', 'Similarities', 'Tracks', 'VariationMinimum', 'Variations', 'VariationSummary'),
+		'SimilarityLookup': ('Request', 'Small', 'Accessories', 'BrowseNodes', 'EditorialReview', 'Images', 'ItemAttributes', 'ItemIds', 'Large', 'ListmaniaLists', 'Medium', 'Offers', 'OfferSummary', 'Reviews', 'SalesRank', 'Similarities', 'Tracks', 'VariationMinimum', 'Variations', 'VariationSummary'),
 		'TransactionLookup':('Request', 'TransactionDetails') 
 	}
+	
+	def collapse(responseGroups):
+		l = []
+		for x in responseGroups:
+			l.append(x)
+			if x in rgh.keys():
+				l.extend( collapse(rgh[x]) )
+		return l
+
 
 	def mergePlugins(responseGroups, index):
 		#return reduce(lambda x, y: x.update(set(rgps[y][index])), responseGroups, set()) 
 		# CODEDEBT: magic number !
 		if index == 4:
 			s = dict()
-			for x in responseGroups:
-				s.update(rgps[x][index])
-		else:	
+		else:
 			s = set()
-			for x in responseGroups:
-				s.update(set(rgps[x][index]))
+
+		map(lambda x: s.update(rgps[x][index]), responseGroups)
 		return s
 			
 	def unionPlugins(responseGroups):
-		return dict( [ (key, mergePlugins(responseGroups, index)) for index, key in enumerate(['isBypassed', 'isPivoted', 'isCollective', 'isCollected', 'isPaged']) ])
+		return dict( [ (key, mergePlugins(collapse(responseGroups), index)) for index, key in enumerate(['isBypassed', 'isPivoted', 'isCollective', 'isCollected', 'isPaged']) ])
 
 	return dict( [ (k, unionPlugins(v)) for k, v in orgs.items() ] )
 	
 	    this object is ignored.
 	- if tagname in plugins['isPaged'].keys():
 	    this pagedIterator is constructed for the object
-	kwItems = keywords.keys()[0]
-	kws = [kwItems]
-	kws += keywords[kwItems]
 
 	CODE DEBT:
 	
 					setattr(rc, key, [getattr(rc, key)])
 				setattr(rc, key, getattr(rc, key) + [unmarshal(XMLSearch, arguments, child, plugins)])
 			elif isinstance(child, minidom.Element):
-				if child.tagName in plugins['isPivoted']:
+				if child.tagName in plugins['isCollected']:
+					rc.append(unmarshal(XMLSearch, arguments, child, plugins))
+				elif child.tagName in plugins['isCollective']:
+					setattr(rc, key, unmarshal(XMLSearch, arguments, child, plugins, listIterator([])))
+				elif child.tagName in plugins['isPaged'].keys():
+					setattr(rc, key, pagedIterator(XMLSearch, arguments, dict2tuple(plugins['isPaged'], child.tagName), child, plugins))
+				elif child.tagName in plugins['isPivoted']:
 					unmarshal(XMLSearch, arguments, child, plugins, rc)
 				elif child.tagName in plugins['isBypassed']:
 					continue
-				elif child.tagName in plugins['isCollective']:
-					setattr(rc, key, unmarshal(XMLSearch, arguments, child, plugins, listIterator([])))
-				elif child.tagName in plugins['isCollected']:
-					rc.append(unmarshal(XMLSearch, arguments, child, plugins))
-				elif child.tagName in plugins['isPaged'].keys():
-					setattr(rc, key, pagedIterator(XMLSearch, arguments, dict2tuple(plugins['isPaged'], child.tagName), child, plugins))
 	    			else:
 					setattr(rc, key, unmarshal(XMLSearch, arguments, child, plugins))
 	else:
 		'isPaged' : { 'Items': ('OfferPage', 'TotalResults', 10) }
 		
 	}
-	return pagedWrapper(XMLItemLookup, argv, plugins['isPaged'], plugins)
+	return pagedWrapper(XMLItemLookup, argv, __plugins['ItemLookup']['isPaged'], __plugins['ItemLookup'])
 
 	
 def XMLItemLookup(ItemId, IdType=None, SearchIndex=None, MerchantId=None, Condition=None, DeliveryMethod=None, ISPUPostalCode=None, OfferPage=None, ReviewPage=None, ReviewSort=None, VariationPage=None, ResponseGroup=None, AWSAccessKeyId=None): 

File tests/main-test.py

 		except :
 			pass
 
-	def testItemLookup(self):
-		books = ecs.ItemLookup("0596009259")
-		self.assertEqual(len(books), 1)
-		book = books[0]
-		self.assertNotEqual(book, None)
-
-		self.assertEqual(book.ASIN, '0596009259')
-		self.assertEqual(book.Title, 'Programming Python')
-		self.assertEqual(book.Manufacturer, "O'Reilly Media, Inc.")
-		self.assertEqual(book.ProductGroup, 'Book')
-		self.assertEqual(book.Author, 'Mark Lutz')
-
-
 	def testItemSearch(self):
 		books = ecs.ItemSearch("", Title="Python", SearchIndex="Books")
 		self.assert_(len(books) > 200, "We are expect more than 200 books are returned.")