Parses headers to create a pagination objects

    :param headers: HTTP Headers
    :type headers: dict
    :return: Navigation object for pagination
    :rtype: _Navigation
169749
def parse_pagination(headers):
    
    links = {
        link.rel: parse_qs(link.href).get("page", None)
        for link in link_header.parse(headers.get("Link", "")).links
    }
    return _Navigation(
        links.get("previous", [None])[0],
        links.get("next", [None])[0],
        links.get("last", [None])[0],
        links.get("current", [None])[0],
        links.get("first", [None])[0]
    )
67473
def load_header_chain( cls, chain_path ):
        

        header_parser = BlockHeaderSerializer()
        chain = []
        height = 0
        with open(chain_path, "rb") as f:

            h = SPVClient.read_header_at( f )
            h['block_height'] = height 

            height += 1
            chain.append(h)

        return chain
1333993
def add_headers(self, header_dict):
        # type: (Dict[str, str]) -> None
        
        if not self.response:
            return
        for name, data_type in header_dict.items():
            value = self.response.headers.get(name)
            value = self._deserialize(data_type, value)
            self.headers[name] = value
401545
def _header_getter(self, uri, headers):
        

        # perform Object HEAD request
        resp = self.http.head(url=uri, headers=headers)
        self._resp_exception(resp=resp)
        return resp
1051232
def _parse_request_headers(request: web.Request):
        
        headers = request.headers.get(hdrs.ACCESS_CONTROL_REQUEST_HEADERS)
        if headers is None:
            return frozenset()

        # FIXME: validate each header string, if parsing fails, raise
        # HTTPForbidden.
        # FIXME: check, that headers split and stripped correctly (according
        # to ABNF).
        headers = (h.strip(" \t").upper() for h in headers.split(","))
        # pylint: disable=bad-builtin
        return frozenset(filter(None, headers))
582708
def add_response_headers(self, headers, **overrides):
        """"""
        response_headers = self.route.get('response_headers', {}).copy()
        response_headers.update(headers)
        return self.where(response_headers=response_headers, **overrides)
1034269
def make_headers(headers):
    
    out = {}
    if 'etag' in headers:
        out['if-none-match'] = headers['etag']
    if 'last-modified' in headers:
        out['if-modified-since'] = headers['last-modified']
    return out
1142549
def _parse_paginated_members(self, direction="children"):
        

        page = self._last_page_parsed[direction]
        if not page:
            page = 1
        else:
            page = int(page)
        while page:
            if page > 1:
                response = self._resolver.endpoint.get_collection(
                    collection_id=self.id,
                    page=page,
                    nav=direction
                )
            else:
                response = self._resolver.endpoint.get_collection(
                    collection_id=self.id,
                    nav=direction
                )
            response.raise_for_status()

            data = response.json()
            data = expand(data)[0]

            if direction == "children":
                self.children.update({
                    o.id: o
                    for o in type(self).parse_member(
                        obj=data, collection=self, direction=direction, resolver=self._resolver
                    )
                })
            else:
                self.parents.update({
                    o
                    for o in type(self).parse_member(
                        obj=data, collection=self, direction=direction, resolver=self._resolver
                    )
                })
            self._last_page_parsed[direction] = page

            page = None
            if "https://www.w3.org/ns/hydra/core#view" in data:
                if "https://www.w3.org/ns/hydra/core#next" in data["https://www.w3.org/ns/hydra/core#view"][0]:
                    page = int(_re_page.findall(
                        data["https://www.w3.org/ns/hydra/core#view"]
                            [0]["https://www.w3.org/ns/hydra/core#next"]
                            [0]["@value"]
                    )[0])

        self._parsed[direction] = True
667122
def build_headers(self):
        '''
        
        '''
        if not 'Content-Type' in self.headers:
            content_type = self.content_type
            if self.encoding != DEFAULT_ENCODING:
                content_type += '; charset=%s' % self.encoding
            self.headers['Content-Type'] = content_type

        headers = list(self.headers.items())
        # Append cookies
        headers += [
            ('Set-Cookie', cookie.OutputString())
            for cookie in self.cookies.values()
        ]
        return headers
854117
def lookup_from_headers(cls, headers):
        

        # A single address, set by this server, returned as an Array
        remote_addr = cls.ips_from(headers.get("REMOTE_ADDR"))

        # Could be a CSV list and/or repeated headers that were concatenated.
        forwarded_ips = cls.ips_from(headers.get("HTTP_X_FORWARDED_FOR"))
        client_ips = cls.ips_from(headers.get("HTTP_CLIENT_IP"))

        # We assume these things about the IP headers:
        #
        #   - X-Forwarded-For will be a list of IPs, one per proxy, or blank.
        #       in order: `client,proxy1,proxy2`
        #   - Client-Ip is propagated from the outermost proxy, or is blank
        #   - REMOTE_ADDR will be the IP that made the request to this server
        #
        # X-Forwarded-For and Client-Ip shouldn't be set at the same time, but
        # if they are, use the one in Forwarded
        ips = forwarded_ips + client_ips + remote_addr

        try:
            return ips[0]
        except IndexError:
            return None
960902
def from_http(cls, headers: Mapping[str, str]) -> Optional["RateLimit"]:
        
        try:
            limit = int(headers["x-ratelimit-limit"])
            remaining = int(headers["x-ratelimit-remaining"])
            reset_epoch = float(headers["x-ratelimit-reset"])
        except KeyError:
            return None
        else:
            return cls(limit=limit, remaining=remaining, reset_epoch=reset_epoch)
495595
def headers(self):
        
        if self._headers is None:
            query = CellQuery()
            query.max_row = '1'
            feed = self._service.GetCellsFeed(self._ss.id, self.id,
                                              query=query)
            self._headers = feed.entry
        return [normalize_header(h.cell.text) for h in self._headers]
603835
def _parse_header(lines):
    
    header_count = _extract_header_number(lines)
    header_dict = {}
    for i in range(2, header_count + 2):
        pair = _extract_header_value(lines[i])

        if not pair:  # Ignore empty strings
            continue

        header_dict.update(pair)
    return header_dict
64351
def links(self):
        
        if not self._responses:
            return None
        if 'Link' in self._responses[-1].headers:
            links = []
            for l in headers.parse_link(self._responses[-1].headers['Link']):
                link = {'target': l.target}
                link.update({k: v for (k, v) in l.parameters})
                links.append(link)
            return links
697926
def _get_headers(self):
        

        header = self.lines[0]
        self.lines = self.lines[1:]

        self.headers = \
            [self.clean(h) for h in header.split(self.seperator)]
        if self.is_strip:
            self.headers = self.headers[1:-1]
        return self.headers
390882
def parse_headers
      s0 = @current_pos
      s1 = []
      s2 = parse_header
      while s2 != :failed
        s1 << s2
        s2 = parse_header
      end
      @reported_pos = s0
      s0 = -> (header) do
        ret = {}
        header.each do |data|
          ret[normalize_header_key(data["k"])] = data["v"]
        end
        ret
      end.call(s1)
      s0
    end
1064037
def write_headers(self):
        
        hlist = []
        for h in self.headers:
            hlist.append("{}: {}".format(h.key, h.value))
        return hlist