def test_find_in_list(self):
     hl = [
         ("content-length", "18031"),
         ("accept-ranges", "bytes"),
         ("server", "Apache/2.2.9 (Debian) DAV/2 SVN/1.5.1 mod_ssl/2.2.9 OpenSSL/0.9.8g mod_wsgi/2.5 Python/2.5.2"),
         ("last-modified", "Fri, 27 Nov 2009 22:03:14 GMT"),
         ("etag", '"105800d-466f-479617552ec80"'),
         ("date", "Sat, 28 Nov 2009 02:03:43 GMT"),
         ("content-type", "text/html"),
     ]
     last_modified = find_in_list(hl, "last-modified", 0, 1)
     self.assertEqual(last_modified, "Fri, 27 Nov 2009 22:03:14 GMT")
     content_type = find_in_list(hl, "content-type", 0, 1)
     self.assertEqual(content_type, "text/html")
     notThere = find_in_list(hl, "BADKEY", 0, 1)
     self.assertEqual(notThere, None)
    def _createList(self, detail=False, offset=0, limit=DEFAULT_PAGE_SIZE,
            lastModified=BEGINNING_OF_TIME):
        """
        Master function that can perform all possible combinations.

        Called by publicly accessible methods to do the actual work.

        What this really has to do is set up a ValueListIterator which will
        then ask us back for the actual data when it's requested.

        http://www.informit.com/articles/article.aspx?p=26148&seqNum=4

        This will actually fetch one page of results so, for efficiency, the
        iterator will have to be clever enough not to re-fetch on the first
        access.
        """
        
        print "_createList: ", detail, offset, limit
        
        # Set flags for parameters we have to act on
        conditionalGet = (lastModified != BEGINNING_OF_TIME)
        pagedGet = (offset != 0 or limit != DEFAULT_PAGE_SIZE)

        uri = self._requestPrefix
        if detail:
            uri += "/detail"
        params = {"offset":offset, "limit":limit}
        
        if conditionalGet:
            params['changes-since'] = lastModified
        
        retHeaders = [] # we may need "last-modified"
        if conditionalGet:
            deltaReturned = False
            while not deltaReturned:
                try:
                    ret_obj = self._cloudServersService.GET(uri, params, retHeaders=retHeaders)
                    deltaReturned = 'cloudServersFault' in ret_obj
                except OverLimitFault as olf:
                    # sleep until retry_after to avoid more OverLimitFaults
                    self._sleepUntilRetryAfter_(olf)
        else:
            ret_obj = self._cloudServersService.GET(uri, params, retHeaders=retHeaders)
        
        # print "ret_obj: " + str(ret_obj)
        
        theList = ret_obj[self._responseKey]

        # Create the entity list
        entityList = self.createEntityListFromResponse(ret_obj, detail)

        cslogger.debug(ret_obj)
        cslogger.debug(retHeaders)

        lastModifiedAsString = None
        if not conditionalGet:
            # For a non-conditional get, we store the one from the
            # returned headers for subsequent conditional gets
            lastModifiedAsString = find_in_list(retHeaders, "last-modified")

        # Now, make the entity list aware of enough state information to
        # perform future operations properly
        data = {'conditionalGet': conditionalGet,
                'pagedGet': pagedGet,
                'lastModified': lastModified }

        if lastModifiedAsString is not None:
            data['lastModifiedAsString'] = lastModifiedAsString
        return entityList