Exemplo n.º 1
0
    def test_expand_uri_no_document(self, db_session, normalized,
                                    expected_uris):
        uris = storage.expand_uri(db_session,
                                  "http://example.com/",
                                  normalized=normalized)

        assert uris == expected_uris
Exemplo n.º 2
0
    def _normalize_uris(self, query_uris, normalize_method=uri.normalize):
        uris = set()
        for query_uri in query_uris:
            expanded = storage.expand_uri(self.request.db, query_uri)

            uris.update([normalize_method(uri) for uri in expanded])
        return list(uris)
Exemplo n.º 3
0
    def _normalize_uris(self, query_uris, normalize_method=uri.normalize):
        uris = set()
        for query_uri in query_uris:
            expanded = storage.expand_uri(self.request.db, query_uri)

            us = [normalize_method(u) for u in expanded]
            uris.update(us)
        return list(uris)
Exemplo n.º 4
0
def _expand_uris(session, clause):
    uris = clause["value"]
    expanded = set()

    if not isinstance(uris, list):
        uris = [uris]

    for item in uris:
        expanded.update(storage.expand_uri(session, item))

    clause["value"] = list(expanded)
def _expand_uris(session, clause):
    uris = clause["value"]
    expanded = set()

    if not isinstance(uris, list):
        uris = [uris]

    for item in uris:
        expanded.update(storage.expand_uri(session, item))

    clause["value"] = list(expanded)
Exemplo n.º 6
0
    def test_expand_uri_document_uris(self, db_session):
        document = Document(document_uris=[
            DocumentURI(uri='http://foo.com/', claimant='http://bar.com'),
            DocumentURI(uri='http://bar.com/', claimant='http://bar.com'),
        ])
        db_session.add(document)
        db_session.flush()

        assert storage.expand_uri(db_session, 'http://foo.com/') == [
            'http://foo.com/', 'http://bar.com/'
        ]
Exemplo n.º 7
0
    def test_expand_uri_document_uris(self, db_session):
        document = Document(document_uris=[
            DocumentURI(uri='http://foo.com/', claimant='http://bar.com'),
            DocumentURI(uri='http://bar.com/', claimant='http://bar.com'),
        ])
        db_session.add(document)
        db_session.flush()

        assert storage.expand_uri(db_session, 'http://foo.com/') == [
            'http://foo.com/',
            'http://bar.com/'
        ]
Exemplo n.º 8
0
    def test_expand_uri_document_doesnt_expand_canonical_uris(self, db_session):
        document = Document(document_uris=[
            DocumentURI(uri='http://foo.com/', claimant='http://example.com'),
            DocumentURI(uri='http://bar.com/', claimant='http://example.com'),
            DocumentURI(uri='http://example.com/', type='rel-canonical',
                        claimant='http://example.com'),
        ])
        db_session.add(document)
        db_session.flush()

        assert storage.expand_uri(db_session, "http://example.com/") == [
            "http://example.com/"]
Exemplo n.º 9
0
    def test_expand_uri_document_uris(self, db_session):
        document = Document(document_uris=[
            DocumentURI(uri="http://foo.com/", claimant="http://bar.com"),
            DocumentURI(uri="http://bar.com/", claimant="http://bar.com"),
        ])
        db_session.add(document)
        db_session.flush()

        assert storage.expand_uri(db_session, "http://foo.com/") == [
            "http://foo.com/",
            "http://bar.com/",
        ]
Exemplo n.º 10
0
Arquivo: query.py Projeto: kael/h
    def __call__(self, search, params):
        if 'uri' not in params and 'url' not in params:
            return search
        query_uris = popall(params, 'uri') + popall(params, 'url')

        uris = set()
        for query_uri in query_uris:
            expanded = storage.expand_uri(self.request.db, query_uri)

            us = [uri.normalize(u) for u in expanded]
            uris.update(us)
        return search.filter('terms', **{'target.scope': list(uris)})
Exemplo n.º 11
0
    def test_expand_uri_document_doesnt_expand_canonical_uris(self, db_session):
        document = Document(document_uris=[
            DocumentURI(uri='http://foo.com/', claimant='http://example.com'),
            DocumentURI(uri='http://bar.com/', claimant='http://example.com'),
            DocumentURI(uri='http://example.com/', type='rel-canonical',
                        claimant='http://example.com'),
        ])
        db_session.add(document)
        db_session.flush()

        assert storage.expand_uri(db_session, "http://example.com/") == [
            "http://example.com/"]
Exemplo n.º 12
0
    def test_expand_uri_document_uris(self, db_session):
        document = Document(
            document_uris=[
                DocumentURI(uri="http://foo.com/", claimant="http://bar.com"),
                DocumentURI(uri="http://bar.com/", claimant="http://bar.com"),
            ]
        )
        db_session.add(document)
        db_session.flush()

        assert storage.expand_uri(db_session, "http://foo.com/") == [
            "http://foo.com/",
            "http://bar.com/",
        ]
Exemplo n.º 13
0
    def test_expand_uri_document_uris(self, db_session, normalized,
                                      expected_uris):
        document = Document(document_uris=[
            DocumentURI(uri="http://example.com/",
                        claimant="http://example.com"),
            DocumentURI(uri="http://alt.example.com/",
                        claimant="http://example.com"),
        ])
        db_session.add(document)
        db_session.flush()

        uris = storage.expand_uri(db_session,
                                  "http://alt.example.com/",
                                  normalized=normalized)

        assert uris == expected_uris
Exemplo n.º 14
0
Arquivo: query.py Projeto: gnott/h
    def __call__(self, params):
        if 'uri' not in params and 'url' not in params:
            return None
        query_uris = [v for k, v in params.items() if k in ['uri', 'url']]
        if 'uri' in params:
            del params['uri']
        if 'url' in params:
            del params['url']

        uris = set()
        for query_uri in query_uris:
            expanded = storage.expand_uri(self.request.db, query_uri)

            us = [uri.normalize(u) for u in expanded]
            uris.update(us)

        return {"terms": {"target.scope": list(uris)}}
Exemplo n.º 15
0
    def __call__(self, params):
        if 'uri' not in params and 'url' not in params:
            return None
        query_uris = [v for k, v in params.items() if k in ['uri', 'url']]
        if 'uri' in params:
            del params['uri']
        if 'url' in params:
            del params['url']

        uris = set()
        for query_uri in query_uris:
            expanded = storage.expand_uri(self.request.db, query_uri)

            us = [uri.normalize(u) for u in expanded]
            uris.update(us)

        return {"terms": {"target.scope": list(uris)}}
Exemplo n.º 16
0
    def test_expand_uri_document_doesnt_expand_canonical_uris(
            self, db_session, normalized, expected_uris):
        document = Document(document_uris=[
            DocumentURI(
                uri="http://example.com/",
                type="rel-canonical",
                claimant="http://example.com",
            ),
            DocumentURI(uri="http://noise.example.com/",
                        claimant="http://example.com"),
        ])
        db_session.add(document)
        db_session.flush()

        uris = storage.expand_uri(db_session,
                                  "http://example.com/",
                                  normalized=normalized)

        assert uris == expected_uris
Exemplo n.º 17
0
Arquivo: filter.py Projeto: kaydoh/h
    def matching(cls, sockets, annotation, session):
        """
        Find sockets with matching filters for the given annotation.

        For this to work, the sockets must have first had `set_filter()` called
        on them.

        :param sockets: Iterable of sockets to check
        :param annotation: Annotation to match
        :param session: DB session

        :return: A generator of matching socket objects
        """

        values = {
            "/id": [annotation.id],
            "/group": [annotation.groupid],
            # Expand the URI to ensure we match any variants of it. This should
            # match the normalization when searching (see `h.search.query`)
            "/uri":
            set(
                storage.expand_uri(session,
                                   annotation.target_uri,
                                   normalized=True)),
            "/references":
            set(annotation.references),
        }

        for socket in sockets:
            # Some sockets might not yet have the filter applied (or had a non
            # parsable filter etc.)
            if not hasattr(socket, "filter_rows"):
                continue

            # Iterate over the filter_rows added by `set_filter()`
            for field, value in socket.filter_rows:
                try:  # pylint: disable=too-many-try-statements
                    if value in values[field]:
                        yield socket
                        break
                except KeyError:
                    continue
Exemplo n.º 18
0
Arquivo: flag.py Projeto: st-fresh/h
    def list(self, user, group=None, uris=None):
        """
        Return a list of flags made by the given user.

        :param user: The user to filter flags on.
        :type user: h.models.User

        :param group: The annotation group pubid for filtering flags.
        :type group: unicode

        :param uris: A list of annotation uris for filtering flags.
        :type uris: list of unicode

        :returns: list of flags (``h.models.Flag``)
        :rtype: list
        """

        query = self.session.query(models.Flag).filter_by(user=user)

        joined_annotation = False

        if group is not None:
            joined_annotation = True
            query = query.join(models.Annotation) \
                         .filter(models.Annotation.groupid == group)

        if uris:
            query_uris = set()
            for u in uris:
                expanded = storage.expand_uri(self.session, u)
                query_uris.update([uri.normalize(e) for e in expanded])

            if not joined_annotation:
                joined_annotation = True
                query = query.join(models.Annotation)
            query = query.filter(
                models.Annotation.target_uri_normalized.in_(query_uris))

        return query
Exemplo n.º 19
0
 def test_expand_uri_no_document(self, db_session):
     actual = storage.expand_uri(db_session, "http://example.com/")
     assert actual == ["http://example.com/"]
Exemplo n.º 20
0
 def test_expand_uri_no_document(self, db_session):
     actual = storage.expand_uri(db_session, 'http://example.com/')
     assert actual == ['http://example.com/']