예제 #1
0
파일: storage_test.py 프로젝트: kaydoh/h
    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
예제 #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)
예제 #3
0
파일: query.py 프로젝트: hypothesis/h
    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)
예제 #4
0
파일: websocket.py 프로젝트: hypothesis/h
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)
예제 #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/'
        ]
예제 #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/'
        ]
예제 #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/"]
예제 #9
0
파일: storage_test.py 프로젝트: tarsbase/h
    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/",
        ]
예제 #10
0
파일: query.py 프로젝트: 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)})
예제 #11
0
파일: storage_test.py 프로젝트: welhefna/h
    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/"]
예제 #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/",
        ]
예제 #13
0
파일: storage_test.py 프로젝트: kaydoh/h
    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
예제 #14
0
파일: query.py 프로젝트: 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)}}
예제 #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)}}
예제 #16
0
파일: storage_test.py 프로젝트: kaydoh/h
    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
예제 #17
0
파일: filter.py 프로젝트: 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
예제 #18
0
파일: flag.py 프로젝트: 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
예제 #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/"]
예제 #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/']