Пример #1
0
 def test_is_not_valid_url(self):
     test_cases = [
         ("htp://a.com", False),
         ("ttp://www.ifrade.es/#frade", False),
     ]
     for url, is_valid in test_cases:
         self.assertEqual(is_valid_url(url), is_valid, msg=url)
Пример #2
0
    def populate_resources(self, graph):
        namespace_short_notation_reverse_dict = {
            unicode(rdflib_url): prefix
            for rdflib_url, prefix in reverse_dict(
                safe_dict(dict(graph.namespace_manager.namespaces()))
            ).items()
        }
        reference_time = datetime.datetime.now()

        for subject, predicate, obj_ect in graph:
            assert hasattr(subject, "n3")

            # workaround for rdflib's unicode problems
            assert predicate.encode('utf8')

            if self.handle_owl_imports:
                if (predicate == rdflib.OWL.imports and type(obj_ect) == rdflib.URIRef):
                    uri = get_slash_url(obj_ect)
                    origin, created = Origin.objects.get_or_create(uri=uri)

                    logger.info("Interrupting to process owl:imports %s"
                                "first" % (origin.uri))
                    origin.GET()

            if ((
                self.only_follow_uris is not None and predicate in self.only_follow_uris
            ) or self.only_follow_uris is None):
                if type(obj_ect) == rdflib.URIRef:
                    # wrong scheme mailto, tel, callto --> should be Literal?
                    if is_valid_url(obj_ect):
                        obj_uriref = get_slash_url(obj_ect)
                        Origin.objects.get_or_create(uri=obj_uriref)

            resource, _created = Resource.objects.get_or_create(uri=subject, origin=self.origin)
            resource._add_property(predicate, obj_ect, namespace_short_notation_reverse_dict)

        now = datetime.datetime.now()
        self.origin.graph_handler_time = now - reference_time

        for resource in self.origin.get_resources():
            resource._has_changes = False
Пример #3
0
 def test_is_valid_url(self):
     test_cases = [
         ("http://a.com", True),
     ]
     for url, is_valid in test_cases:
         self.assertEqual(is_valid_url(url), is_valid, msg=url)
Пример #4
0
Файл: cli.py Проект: dmr/Ldtools
 def check_uri(url):
     if not is_valid_url(url):
         raise argparse.ArgumentTypeError("%r is not a valid URL" % url)
     return url