def _paginated(self, endpoint, records=None, if_none_match=None, **kwargs): if records is None: records = collections.OrderedDict() headers = {} if if_none_match is not None: headers['If-None-Match'] = utils.quote(if_none_match) record_resp, headers = self.session.request( 'get', endpoint, headers=headers, params=kwargs) if record_resp: records_tuples = [(r['id'], r) for r in record_resp['data']] records.update(collections.OrderedDict(records_tuples)) if 'next-page' in map(str.lower, headers.keys()): # Paginated wants a relative URL, but the returned one is # absolute. next_page = headers['Next-Page'] return self._paginated(next_page, records, if_none_match=if_none_match) return records.values()
def _paginated(self, endpoint, records=None, if_none_match=None, **kwargs): if records is None: records = collections.OrderedDict() headers = {} if if_none_match is not None: headers['If-None-Match'] = utils.quote(if_none_match) record_resp, headers = self.session.request('get', endpoint, headers=headers, params=kwargs) if record_resp: records_tuples = [(r['id'], r) for r in record_resp['data']] records.update(collections.OrderedDict(records_tuples)) if 'next-page' in map(str.lower, headers.keys()): # Paginated wants a relative URL, but the returned one is # absolute. next_page = headers['Next-Page'] return self._paginated(next_page, records, if_none_match=if_none_match) return records.values()
def _get_cache_headers(self, safe, data=None, last_modified=None): has_data = data is not None and data.get('last_modified') if (last_modified is None and has_data): last_modified = data['last_modified'] if safe and last_modified is not None: return {'If-Match': utils.quote(last_modified)}
def _get_cache_headers(self, safe, data=None, if_match=None): has_data = data is not None and data.get('last_modified') if (if_match is None and has_data): if_match = data['last_modified'] if safe and if_match is not None: return {'If-Match': utils.quote(if_match)}
def test_quotes_can_take_integers(self): assert utils.quote(1234) == '"1234"'
def test_quote_strips_extra_quotes(self): assert utils.quote('"1234"') == '"1234"'