3030
3131def get_items_request (amazon_api , asin_chunk : List [str ], ** kwargs ) -> GetItemsRequest :
3232 try :
33- return GetItemsRequest (
34- resources = _get_request_resources (GetItemsResource ),
35- partner_type = PartnerType .ASSOCIATES ,
36- marketplace = amazon_api ._marketplace ,
37- partner_tag = amazon_api ._tag ,
38- item_ids = asin_chunk ,
39- ** kwargs
40- )
33+ return GetItemsRequest (resources = _get_request_resources (GetItemsResource ),
34+ partner_type = PartnerType .ASSOCIATES ,
35+ marketplace = amazon_api ._marketplace ,
36+ partner_tag = amazon_api ._tag ,
37+ item_ids = asin_chunk ,
38+ ** kwargs )
4139 except TypeError as e :
42- raise MalformedRequestException (
43- "Parameters for get_items request are not correct: " + str (e )
44- )
40+ raise MalformedRequestException ('Parameters for get_items request are not correct: ' + str (e ))
4541
4642
4743def get_items_response (amazon_api , request : GetItemsRequest ) -> List [Item ]:
@@ -51,24 +47,20 @@ def get_items_response(amazon_api, request: GetItemsRequest) -> List[Item]:
5147 _manage_response_exceptions (e )
5248
5349 if response .items_result == None :
54- raise ItemsNotFoundException (" No items have been found" )
50+ raise ItemsNotFoundException (' No items have been found' )
5551
5652 return response .items_result .items
5753
5854
5955def get_search_items_request (amazon_api , ** kwargs ) -> SearchItemsRequest :
6056 try :
61- return SearchItemsRequest (
62- resources = _get_request_resources (SearchItemsResource ),
63- partner_type = PartnerType .ASSOCIATES ,
64- marketplace = amazon_api ._marketplace ,
65- partner_tag = amazon_api ._tag ,
66- ** kwargs
67- )
57+ return SearchItemsRequest (resources = _get_request_resources (SearchItemsResource ),
58+ partner_type = PartnerType .ASSOCIATES ,
59+ marketplace = amazon_api ._marketplace ,
60+ partner_tag = amazon_api ._tag ,
61+ ** kwargs )
6862 except TypeError as e :
69- raise MalformedRequestException (
70- "Parameters for search_items request are not correct: " + str (e )
71- )
63+ raise MalformedRequestException ('Parameters for search_items request are not correct: ' + str (e ))
7264
7365
7466def get_search_items_response (amazon_api , request : SearchItemsRequest ) -> SearchResult :
@@ -78,97 +70,74 @@ def get_search_items_response(amazon_api, request: SearchItemsRequest) -> Search
7870 _manage_response_exceptions (e )
7971
8072 if response .search_result == None :
81- raise ItemsNotFoundException (" No items have been found" )
73+ raise ItemsNotFoundException (' No items have been found' )
8274
8375 return response .search_result
8476
8577
8678def get_variations_request (amazon_api , ** kwargs ) -> GetVariationsRequest :
8779 try :
88- return GetVariationsRequest (
89- resources = _get_request_resources (GetVariationsResource ),
90- partner_type = PartnerType .ASSOCIATES ,
91- marketplace = amazon_api ._marketplace ,
92- partner_tag = amazon_api ._tag ,
93- ** kwargs
94- )
80+ return GetVariationsRequest (resources = _get_request_resources (GetVariationsResource ),
81+ partner_type = PartnerType .ASSOCIATES ,
82+ marketplace = amazon_api ._marketplace ,
83+ partner_tag = amazon_api ._tag ,
84+ ** kwargs )
9585 except TypeError as e :
96- raise MalformedRequestException (
97- "Parameters for get_variations request are not correct: " + str (e )
98- )
86+ raise MalformedRequestException ('Parameters for get_variations request are not correct: ' + str (e ))
9987
10088
101- def get_variations_response (
102- amazon_api , request : GetVariationsRequest
103- ) -> VariationsResult :
89+ def get_variations_response (amazon_api , request : GetVariationsRequest ) -> VariationsResult :
10490 try :
10591 response = amazon_api ._api .get_variations (request )
10692 except ApiException as e :
10793 _manage_response_exceptions (e )
10894
10995 if response .variations_result == None :
110- raise ItemsNotFoundException (" No variation items have been found" )
96+ raise ItemsNotFoundException (' No variation items have been found' )
11197
11298 return response .variations_result
11399
114100
115101def get_browse_nodes_request (amazon_api , ** kwargs ) -> GetBrowseNodesRequest :
116102 try :
117- return GetBrowseNodesRequest (
118- resources = _get_request_resources (GetBrowseNodesResource ),
119- partner_type = PartnerType .ASSOCIATES ,
120- marketplace = amazon_api ._marketplace ,
121- partner_tag = amazon_api ._tag ,
122- ** kwargs
123- )
103+ return GetBrowseNodesRequest (resources = _get_request_resources (GetBrowseNodesResource ),
104+ partner_type = PartnerType .ASSOCIATES ,
105+ marketplace = amazon_api ._marketplace ,
106+ partner_tag = amazon_api ._tag ,
107+ ** kwargs )
124108 except TypeError as e :
125- raise MalformedRequestException (
126- "Parameters for get_browse_nodes request are not correct: " + str (e )
127- )
109+ raise MalformedRequestException ('Parameters for get_browse_nodes request are not correct: ' + str (e ))
128110
129111
130- def get_browse_nodes_response (
131- amazon_api , request : GetBrowseNodesRequest
132- ) -> List [BrowseNode ]:
112+ def get_browse_nodes_response (amazon_api , request : GetBrowseNodesRequest ) -> List [BrowseNode ]:
133113 try :
134114 response = amazon_api ._api .get_browse_nodes (request )
135115 except ApiException as e :
136116 _manage_response_exceptions (e )
137117
138118 if response .browse_nodes_result == None :
139- raise ItemsNotFoundException (" No browse nodes have been found" )
119+ raise ItemsNotFoundException (' No browse nodes have been found' )
140120
141121 return response .browse_nodes_result .browse_nodes
142122
143123
144124def _get_request_resources (resources ) -> List [str ]:
145- resources = inspect .getmembers (resources , lambda a : not (inspect .isroutine (a )))
146- resources = [
147- x [- 1 ] for x in resources if isinstance (x [- 1 ], str ) and x [0 ][0 :2 ] != "__"
148- ]
125+ resources = inspect .getmembers (resources , lambda a :not (inspect .isroutine (a )))
126+ resources = [x [- 1 ] for x in resources if isinstance (x [- 1 ], str ) and x [0 ][0 :2 ] != '__' ]
149127 return resources
150128
151-
152129def _manage_response_exceptions (error ) -> None :
153130 if isinstance (error , ApiException ):
154131 if error .status == 429 :
155- raise TooManyRequestsException (
156- "Requests limit reached, try increasing throttling or wait before"
157- " trying again"
158- )
159-
160- elif "InvalidParameterValue" in error .body :
161- raise InvalidArgumentException (
162- "The value provided in the request for atleast one parameter is"
163- " invalid."
164- )
165-
166- elif "InvalidPartnerTag" in error .body :
167- raise InvalidArgumentException ("The partner tag is invalid or not present." )
168-
169- elif "InvalidAssociate" in error .body :
170- raise AssociateValidationException (
171- "Used credentials are not valid for the selected country."
172- )
173-
174- raise ApiRequestException ("Request failed: " + str (error .reason ))
132+ raise TooManyRequestsException ('Requests limit reached, try increasing throttling or wait before trying again' )
133+
134+ elif 'InvalidParameterValue' in error .body :
135+ raise InvalidArgumentException ('The value provided in the request for atleast one parameter is invalid.' )
136+
137+ elif 'InvalidPartnerTag' in error .body :
138+ raise InvalidArgumentException ('The partner tag is invalid or not present.' )
139+
140+ elif 'InvalidAssociate' in error .body :
141+ raise AssociateValidationException ('Used credentials are not valid for the selected country.' )
142+
143+ raise ApiRequestException ('Request failed: ' + str (error .reason ))
0 commit comments