Rune Halvorsen  committed 3f47495

Added docstrings on the cache related methods

  • Participants
  • Parent commits d1467a4

Comments (0)

Files changed (1)

File spotimeta/

     def _do_request(self, url, headers):
+        """Perform an actual response. Deal with 200 and 304 responses
+        correctly. If another error occurs, raise the appropriate
+        exception"""
             req = urllib2.Request(url, None, headers)
             return urllib2.urlopen(req, timeout=self.timeout)
         except urllib2.URLError, e:
             """Probably timeout. should do a better check. FIXME"""
             raise RequestTimeout()
-        except: 
+        except:
             # all the exceptions we don't know about yet. Probably
             # some socket errors will come up here.
     def _get_url(self, url, query, if_modified_since=None):
-        """Perform an http requests and return the open file-like object."""
+        """Perform an http requests and return the open file-like object, if
+        there is one, as well as the expiry time and last-modified-time
+        if they were present in the reply.
+        If the if_modified_since variable is passed in, send it as the value
+        of the If-Modified-Since header."""
         if query:
             url = "%s?%s" %(url, urlencode(query))
         expires = None
         if "Expires" in headers:
             expires = mktime_tz(parsedate_tz(headers.get("Expires")))
         modified = None
         if "Last-Modified" in headers:
             modified = mktime_tz(parsedate_tz(headers.get("Last-Modified")))
         return fp, modified, expires
         for tracks. For the meaning of the detail levels, look at the
         Spotify api docs"""
-        key = "%s:%s" % (uri, detail)        
-        res, modified, expires = self._cache_get(key)        
+        key = "%s:%s" % (uri, detail)
+        res, modified, expires = self._cache_get(key)
         if res and time.time() < expires:
             return res
         res = parse_search_doc(fp)
         return res
-    def _cache_is_valid(self, key):
-        if not self._cache:
-            return False
-        entry = self.cache.get(key)
-        now = time.time()
-        return entry and now < entry[2]
     def _cache_get(self, key):
+        """Get a tuple containing data, last-modified, expires.
+        If entry is not in cache return None, 0, 0
+        """
         entry = None
         if self.cache is not None:
             entry = self.cache.get(key)
         return entry or (None, 0, 0)
     def _cache_put(self, key, value, modified, expires):
+        """Inverse of _cache_put"""
         if self.cache is not None:
             self.cache[key] = value, modified, expires