示例#1
0
 def get_links():
     links = site.get_resources_as_linkheader()
     links.links.append(Link("/t", anchor="sensors/temp", rel="alternate"))
     links.links.append(
         Link("http://www.example.com/sensors/t123",
              anchor="sensors/temp",
              rel="describedby"))
     return LinkFormat(links.links)
示例#2
0
 def get_host_link(self):
     attr_pairs = []
     for (k, values) in self.registration_parameters.items():
         for v in values:
             attr_pairs.append([k, v])
     return Link(href=self.href,
                 attr_pairs=attr_pairs,
                 base=self.base,
                 rt="coire.rd-ep")
示例#3
0
    async def render_get(self, request):
        query = query_split(request)

        eps = self.common_rd.get_endpoints()
        candidates = ((e, c) for e in eps for c in e.get_based_links().links)

        for search_key, search_values in query.items():
            if search_key in ('page', 'count'):
                continue  # filtered last

            for search_value in search_values:
                if search_value is not None and search_value.endswith('*'):

                    def matches(x, start=search_value[:-1]):
                        return x.startswith(start)
                else:

                    def matches(x, search_value=search_value):
                        return x == search_value

                if search_key in ('if', 'rt'):

                    def matches(x, original_matches=matches):
                        return any(original_matches(v) for v in x.split())

                if search_key == 'href':
                    candidates = (
                        (e, c)
                        for (e, c) in candidates if matches(c.href) or matches(
                            e.href
                        )  # FIXME: They SHOULD give this as relative as we do, but don't have to
                    )
                    continue

                candidates = (
                    (e, c) for (e, c) in candidates
                    if _link_matches(c, search_key, matches) or (
                        search_key in e.registration_parameters and any(
                            matches(x)
                            for x in e.registration_parameters[search_key])))

        # strip endpoint
        candidates = (c for (e, c) in candidates)

        candidates = _paginate(candidates, query)

        # strip needless anchors
        candidates = [
            Link(l.href, [(k, v) for (k, v) in l.attr_pairs if k != 'anchor'])
            if dict(l.attr_pairs)['anchor'] == urljoin(l.href, '/') else l
            for l in candidates
        ]

        return link_format_to_message(request, LinkFormat(candidates))
示例#4
0
 def get_based_links(self):
     """Produce a LinkFormat object that represents all statements in
     the registration, resolved to the registration's base (and thus
     suitable for comparing anchors)."""
     result = []
     for l in self.links.links:
         href = urljoin(self.base, l.href)
         if 'anchor' in l:
             absanchor = urljoin(self.base, l.anchor)
             data = [(k, v) for (k, v) in l.attr_pairs if k != 'anchor'
                     ] + [['anchor', absanchor]]
         else:
             data = l.attr_pairs + [['anchor', urljoin(href, '/')]]
         result.append(Link(href, data))
     return LinkFormat(result)
示例#5
0
        def get_based_links(self):
            """Produce a LinkFormat object that represents all statements in
            the registration, resolved to the registration's base (and thus
            suitable for serving from the lookup interface).

            This implements Limited Link Format as described in Appendix C
            of draft-ietf-core-resource-directory-25."""
            result = []
            for l in self.links.links:
                if 'anchor' in l:
                    absanchor = urljoin(self.base, l.anchor)
                    data = [(k, v) for (k, v) in l.attr_pairs if k != 'anchor'
                            ] + [['anchor', absanchor]]
                else:
                    data = l.attr_pairs + [['anchor', self.base]]
                href = urljoin(self.base, l.href)
                result.append(Link(href, data))
            return LinkFormat(result)
示例#6
0
文件: rd.py 项目: ltn22/aiocoap
        def get_based_links(self):
            """Produce a LinkFormat object that represents all statements in
            the registration, resolved to the registration's base (and thus
            suitable for serving from the lookup interface).

            If protocol negotiation is implemented and base becomes a list, this
            function will probably grow parameters that hint at which base to
            use.
            """
            result = []
            for l in self.links.links:
                if 'anchor' in l:
                    absanchor = urljoin(self.base, l.anchor)
                    data = [(k, v) for (k, v) in l.attr_pairs if k != 'anchor'] + [['anchor', absanchor]]
                    href = urljoin(absanchor, l.href)
                else:
                    data = l.attr_pairs + [['anchor', self.base]]
                    href = urljoin(self.base, l.href)
                result.append(Link(href, data))
            return LinkFormat(result)
示例#7
0
文件: rd.py 项目: ltn22/aiocoap
 def get_host_link(self):
     args = dict(self.registration_parameters, base=self.base, rt="core.rd-ep")
     args.pop('lt', None)
     return Link(href=self.href, **args)
示例#8
0
文件: rd.py 项目: zhouzuixin/aiocoap
 def get_host_link(self):
     args = dict(self.registration_parameters, con=self.con)
     return Link(href=self.href, **args)