Sebastian Rahlf avatar Sebastian Rahlf committed daac406 Merge

Preparing for a new release.

Comments (0)

Files changed (4)

 
-0.2.x (under development)
--------------------------
-
-- Support for Python 2.4 added. 
-
-0.2.0 "Westley"
----------------
+0.2 "Westley"
+-------------
 
 This is the first `public` release. We're now available via the Cheeseshop!
 http://pypi.python.org/pypi/python-amazon-product-api
 
+0.2.1
+~~~~~
+
+- Support for Python 2.4 added. 
+- Fixed #2: ResultPaginator now returns ``None`` if the XPath expression doesn't 
+  find the node it's looking for.
+  
+0.2.0
+~~~~~
+
 - The module is no longer a package. Please use ``import amazonproduct`` 
   (instead of ``import amazon.product``) now.
 - SimilarityLookup is now supported.
 from time import strftime, gmtime
 from urlparse import urlsplit
 from urllib import quote
-from urllib2 import urlopen
+from urllib2 import urlopen, HTTPError
 
 __docformat__ = "restructuredtext en"
 
     intersection of similar items.
     """
     
+class TooManyRequests (Exception):
+    """
+    You are submitting requests too quickly and your requests are being 
+    throttled. If this is the case, you need to slow your request rate to one 
+    request per second.
+    """
+
 INVALID_SEARCH_INDEX_REG = re.compile(
     'The value you specified for SearchIndex is invalid.')
 
     """
     
     VERSION = '2009-10-01' #: supported Amazon API version
-    REQUESTS_PER_SECOND = 2 #: max requests per second
+    REQUESTS_PER_SECOND = 1 #: max requests per second
     
     def __init__(self, access_key_id, secret_access_key, locale='de'):
         
             pass # Wait for it!
         self.last_call = datetime.now()
         
-        tree = objectify.parse(urlopen(url))
-        root = tree.getroot()
+        try:
+            tree = objectify.parse(urlopen(url))
+            root = tree.getroot()
+        except HTTPError, e:
+            if e.code == 503:
+                raise TooManyRequests
+            # otherwise re-raise
+            raise        
         
         #~ from lxml import etree
         #~ print etree.tostring(tree, pretty_print=True)
             yield root
             
             kwargs[self.counter] += 1
-        
+            
     def get_total_page_numer(self, root):
         """
         Get total number of paginator pages.
         """
-        return root.xpath(self.total_pages_xpath, 
+        try:
+            return root.xpath(self.total_pages_xpath, 
                           namespaces={'aws' : self.nspace})[0].pyval
+        except IndexError:
+            return None
         
     def get_current_page_numer(self, root):
         """
         Get number of current paginator page.
         """
-        return root.xpath(self.current_page_xpath, 
+        try:
+            return root.xpath(self.current_page_xpath, 
                           namespaces={'aws' : self.nspace})[0].pyval
+        except IndexError:
+            return None
     
     def get_total_results(self, root):
         """
-        Get number of current paginator page.
+        Get total number of results.
         """
-        return root.xpath(self.total_results_xpath, 
-                          namespaces={'aws' : self.nspace})[0].pyval
+        try:
+            return root.xpath(self.total_results_xpath, 
+                          namespaces={'aws' : self.nspace})
+        except IndexError:
+            return None
 
 # The short X.Y version.
 version = '0.2'
 # The full version, including alpha/beta/rc tags.
-release = '0.2.0'
+release = '0.2.1'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
 
 setup(
     name = 'python-amazon-product-api',
-    version = '0.2.0',
+    version = '0.2.1',
     author = 'Sebastian Rahlf',
     author_email = 'basti AT redtoad DOT de',
     url="http://bitbucket.org/basti/python-amazon-product-api/downloads/",
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.