Пример #1
0
def make_example1_httpd(service=None, service_config=None):
    """Make a HTTPd running in a separate thread.

    Return the thread and the HTTPd.

    :param service: if provided

    NB: the service is assumed to be located on localhost:1234
    """
    if service is None:
        if service_config is None:
            service_config = get_service_configuration()
            service_config.set('server', 'port', '1234')
            service_config.set('server', 'base-path', '/foo')

        service = make_example1_service(service_config)

    # cache_control="max-age=60")
    app = HttpFrontend(service, service_config)
    _httpd = make_server(service_config.get('server', 'host-name', 1),
                         service_config.getint('server', 'port'),
                         app)
    thread = Thread(target=_httpd.serve_forever)
    thread.start()
    return thread, _httpd
Пример #2
0
 def test_logging_loggers(self):
     cfg = get_service_configuration()
     cfg.set('logging', 'loggers', 'root ktbs rdfrest')
     log_cfg = make_log_config_dict(cfg)
     assert 'root' in log_cfg
     assert 'ktbs' in log_cfg['loggers']
     assert 'rdfrest' in log_cfg['loggers']
Пример #3
0
def make_example1_httpd(service=None, service_config=None):
    """Make a HTTPd running in a separate thread.

    Return the thread and the HTTPd.

    :param service: if provided

    NB: the service is assumed to be located on localhost:1234
    """
    BASE_PATH = '/foo'
    if service is None:
        if service_config is None:
            service_config = get_service_configuration()
            service_config.set('server', 'port', '1234')
            service_config.set('server', 'base-path', BASE_PATH)

        service = make_example1_service(service_config)

    # cache_control="max-age=60")
    app = SimpleRouter([(BASE_PATH, HttpFrontend(service, service_config))])
    _httpd = make_server(service_config.get('server', 'host-name', 1),
                         service_config.getint('server', 'port'),
                         app)
    thread = Thread(target=_httpd.serve_forever)
    thread.start()
    return thread, _httpd
Пример #4
0
 def test_logging_loggers(self):
     cfg = get_service_configuration()
     cfg.set('logging', 'loggers', 'root ktbs rdfrest')
     log_cfg = make_log_config_dict(cfg)
     assert 'root' in log_cfg
     assert 'ktbs' in log_cfg['loggers']
     assert 'rdfrest' in log_cfg['loggers']
Пример #5
0
 def test_logging_console_format(self):
     cfg = get_service_configuration()
     cfg.set('logging', 'console-format', 'foo')
     log_cfg = make_log_config_dict(cfg)
     assert 'console' in log_cfg['formatters']
     assert log_cfg['formatters']['console']['format'] == 'foo'
     assert log_cfg['handlers']['console']['formatter'] == 'console'
Пример #6
0
 def test_logging_console_format(self):
     cfg = get_service_configuration()
     cfg.set('logging', 'console-format', 'foo')
     log_cfg = make_log_config_dict(cfg)
     assert 'console' in log_cfg['formatters']
     assert log_cfg['formatters']['console']['format'] == 'foo'
     assert log_cfg['handlers']['console']['formatter'] == 'console'
Пример #7
0
def main():
    """Runs an HTTP server serving items and groups.

    If 'test' is passed as argument, first run :func:`do_tests` from
    :mod:`.example1` on the service.
    """
    test = len(argv) > 1 and argv[1] == "test"

    service_config = get_service_configuration()
    service_config.set('server', 'port', '1234')
    service_config.set('server', 'base-path', '/foo')

    # TODO Store management : special tests ?

    serv = make_example2_service(service_config)

    root_uri = serv.root_uri

    if test:
        do_tests(serv.get(root_uri))
        print "Local tests passed"

    app = HttpFrontend(serv, service_config)
    _httpd = make_server(service_config.get('server', 'host-name', 1),
                         service_config.getint('server', 'port'), app)
    print "Now listening on", root_uri
    _httpd.serve_forever()
Пример #8
0
def main():
    """Runs an HTTP server serving items and groups.

    If 'test' is passed as argument, first run :func:`do_tests` from
    :mod:`.example1` on the service.
    """
    test = len(argv) > 1 and argv[1] == "test"
    BASE_PATH = '/foo'

    service_config = get_service_configuration()
    service_config.set('server', 'port', '1234')
    service_config.set('server', 'base-path', BASE_PATH)

    # TODO Store management : special tests ?

    serv = make_example2_service(service_config)

    root_uri = serv.root_uri

    if test:
        do_tests(serv.get(root_uri))
        print "Local tests passed"

    app = SimpleRouter([(BASE_PATH, HttpFrontend(serv, service_config))])
    _httpd = make_server(service_config.get('server', 'host-name', 1),
                         service_config.getint('server', 'port'),
                         app)
    print "Now listening on", root_uri
    _httpd.serve_forever()
Пример #9
0
def service_config(request):
    config = get_service_configuration()
    cfg = getattr(request.cls, "CONFIG", None)
    if cfg:
        for section, options in cfg.items():
            for option, value in options.items():
                config.set(section, option, value)
    return config
Пример #10
0
 def setup(self):
     service_config = get_service_configuration()
     service_config.set('server', 'port', '11235')
     service_config.set('server', 'base-path', '/foo')
     self.service = make_example1_service(service_config)
     self.ROOT_URI = self.service.root_uri
     self.root = self.service.get(self.ROOT_URI, [EXAMPLE.Group])
     assert isinstance(self.root, GroupMixin)
Пример #11
0
 def setUp(self):
     service_config = get_service_configuration()
     service_config.set('server', 'port', '11235')
     service_config.set('server', 'base-path', '/foo')
     self.service = make_example1_service(service_config)
     self.ROOT_URI = self.service.root_uri
     self.root = self.service.get(self.ROOT_URI, [EXAMPLE.Group])
     assert isinstance(self.root, GroupMixin)
Пример #12
0
 def test_logging_file(self):
     cfg = get_service_configuration()
     cfg.set('logging', 'loggers', 'root ktbs rdfrest')
     cfg.set('logging', 'filename', '/tmp/test.log')
     log_cfg = make_log_config_dict(cfg)
     assert 'filelog' in log_cfg['handlers']
     assert log_cfg['handlers']['filelog']['class'] == 'logging.FileHandler'
     assert log_cfg['handlers']['filelog']['filename'] == '/tmp/test.log'
Пример #13
0
 def test_logging_ktbs(self):
     cfg = get_service_configuration()
     cfg.set('logging', 'loggers', 'root ktbs rdfrest')
     cfg.set('logging', 'ktbs-logurl', 'http://localhost:8001/logs/log/')
     log_cfg = make_log_config_dict(cfg)
     assert 'ktbslog' in log_cfg['handlers']
     assert log_cfg['handlers']['ktbslog']['class'] == 'rdfrest.util.ktbsloghandler.kTBSHandler'
     assert log_cfg['handlers']['ktbslog']['url'] == 'http://localhost:8001/logs/log/'
Пример #14
0
 def test_logging_file(self):
     cfg = get_service_configuration()
     cfg.set('logging', 'loggers', 'root ktbs rdfrest')
     cfg.set('logging', 'filename', '/tmp/test.log')
     log_cfg = make_log_config_dict(cfg)
     assert 'filelog' in log_cfg['handlers']
     assert log_cfg['handlers']['filelog']['class'] == 'logging.FileHandler'
     assert log_cfg['handlers']['filelog']['filename'] == '/tmp/test.log'
Пример #15
0
 def test_logging_console_level(self):
     cfg = get_service_configuration()
     cfg.set('logging', 'loggers', 'root ktbs rdfrest')
     cfg.set('logging', 'console-level', 'DEBUG')
     log_cfg = make_log_config_dict(cfg)
     assert log_cfg['handlers']['console']['level'] == logging.DEBUG
     # also check that the added loggers "inherit" that level
     assert log_cfg['root']['level'] == logging.DEBUG
     assert log_cfg['loggers']['ktbs']['level'] == logging.DEBUG
     assert log_cfg['loggers']['rdfrest']['level'] == logging.DEBUG
Пример #16
0
 def setup(self):
     service_config = get_service_configuration()
     service_config.set('server', 'port', '11235')
     service_config.set('server', 'base-path', '/foo')
     self.service = make_example2_service(service_config,
                                          additional = [TstItem])
     self.ROOT_URI = self.service.root_uri
     self.root = self.service.get(self.ROOT_URI, [EXAMPLE.Group2])
     assert isinstance(self.root, Group2Implementation)
     self.items = []
Пример #17
0
 def test_logging_ktbs(self):
     cfg = get_service_configuration()
     cfg.set('logging', 'loggers', 'root ktbs rdfrest')
     cfg.set('logging', 'ktbs-logurl', 'http://localhost:8001/logs/log/')
     log_cfg = make_log_config_dict(cfg)
     assert 'ktbslog' in log_cfg['handlers']
     assert log_cfg['handlers']['ktbslog'][
         'class'] == 'rdfrest.util.ktbsloghandler.kTBSHandler'
     assert log_cfg['handlers']['ktbslog'][
         'url'] == 'http://localhost:8001/logs/log/'
Пример #18
0
 def test_logging_console_level(self):
     cfg = get_service_configuration()
     cfg.set('logging', 'loggers', 'root ktbs rdfrest')
     cfg.set('logging', 'console-level', 'DEBUG')
     log_cfg = make_log_config_dict(cfg)
     assert log_cfg['handlers']['console']['level'] == logging.DEBUG
     # also check that the added loggers "inherit" that level
     assert log_cfg['root']['level'] == logging.DEBUG
     assert log_cfg['loggers']['ktbs']['level'] == logging.DEBUG
     assert log_cfg['loggers']['rdfrest']['level'] == logging.DEBUG
Пример #19
0
 def test_logging_ktbs_level(self):
     cfg = get_service_configuration()
     cfg.set('logging', 'loggers', 'root ktbs rdfrest')
     cfg.set('logging', 'console-level', 'WARNING')
     cfg.set('logging', 'ktbs-logurl', 'http://localhost:8001/logs/log/')
     cfg.set('logging', 'ktbs-level', 'DEBUG')
     log_cfg = make_log_config_dict(cfg)
     assert log_cfg['handlers']['ktbslog']['level'] == logging.DEBUG
     # also check that the added loggers "inherit" that level
     assert log_cfg['root']['level'] == logging.DEBUG
     assert log_cfg['loggers']['ktbs']['level'] == logging.DEBUG
     assert log_cfg['loggers']['rdfrest']['level'] == logging.DEBUG
 def setUp(self):
     try:
         service_config = get_service_configuration()
         self.service = make_example2_service(service_config)
         #root = self.service.get(URIRef(URL))
         root = self.service.get(self.service.root_uri, [EXAMPLE.Group2])
         assert isinstance(root, Group2Implementation)
         root.create_new_simple_item("foo")
         # max-age is now deprecated, cache_control="max-age=60")
         self.app = HttpFrontend(self.service, service_config)
     except:
         raise
Пример #21
0
 def test_logging_ktbs_level(self):
     cfg = get_service_configuration()
     cfg.set('logging', 'loggers', 'root ktbs rdfrest')
     cfg.set('logging', 'console-level', 'WARNING')
     cfg.set('logging', 'ktbs-logurl', 'http://localhost:8001/logs/log/')
     cfg.set('logging', 'ktbs-level', 'DEBUG')
     log_cfg = make_log_config_dict(cfg)
     assert log_cfg['handlers']['ktbslog']['level'] == logging.DEBUG
     # also check that the added loggers "inherit" that level
     assert log_cfg['root']['level'] == logging.DEBUG
     assert log_cfg['loggers']['ktbs']['level'] == logging.DEBUG
     assert log_cfg['loggers']['rdfrest']['level'] == logging.DEBUG
Пример #22
0
def get_ktbs_configuration(configfile_handler=None):
    """I set kTBS default configuration options and possibly override them
    with the values extracted from a configuration file.

    :param configfile_handler: optional file handler of a configuration file

    :return: Configuration object.
    """
    ktbs_config = get_service_configuration(configfile_handler)

    if ktbs_config.has_section('ns_prefix'):
        ktbs_config.set('ns_prefix', '_', str(KTBS))
        ktbs_config.set('ns_prefix', 'skos', str(SKOS))

    return ktbs_config
Пример #23
0
def get_ktbs_configuration(configfile_handler=None):
    """I set kTBS default configuration options and possibly override them
    with the values extracted from a configuration file.

    :param configfile_handler: optional file handler of a configuration file

    :return: Configuration object.
    """
    ktbs_config = get_service_configuration(configfile_handler)

    _set_default(ktbs_config, 'ns_prefix', '_', str(KTBS)),
    _set_default(ktbs_config, 'ns_prefix', 'skos', str(SKOS))

    # plugins enabled by default for backward compatibility
    _set_default(ktbs_config, 'plugins', 'stats_per_type', 'true')

    return ktbs_config
Пример #24
0
def get_ktbs_configuration(configfile_handler=None):
    """I set kTBS default configuration options and possibly override them
    with the values extracted from a configuration file.

    :param configfile_handler: optional file handler of a configuration file

    :return: Configuration object.
    """
    ktbs_config = get_service_configuration(configfile_handler)

    _set_default(ktbs_config, 'ns_prefix', '_', str(KTBS)),
    _set_default(ktbs_config, 'ns_prefix', 'skos', str(SKOS))

    # plugins enabled by default for backward compatibility
    _set_default(ktbs_config, 'plugins', 'stats_per_type', 'true')


    return ktbs_config
Пример #25
0
    def setUp(self):
        config = get_service_configuration()
        config.set('server', 'fixed-root-uri', _ErrorMethod.uri)
        self.error_method_service = Service(classes=[_ErrorMethodResource],
                               service_config=config,
                               init_with=_ErrorMethodResource.init_service)
        self.method_impl = _ErrorMethod()
        register_builtin_method_impl(self.method_impl)

        KtbsTestCase.setUp(self)

        base = self.base = self.my_ktbs.create_base("b/")
        model = base.create_model("m")
        otype1 = model.create_obsel_type("#ot1")
        otype2 = model.create_obsel_type("#ot2")
        atype = model.create_attribute_type("#at")
        origin = "orig-abc"
        src1 = self.src1 = base.create_stored_trace("s1/", model, origin=origin)
Пример #26
0
    def setUp(self):
        config = get_service_configuration()
        config.set('server', 'fixed-root-uri', _ErrorMethod.uri)
        self.error_method_service = Service(
            classes=[_ErrorMethodResource],
            service_config=config,
            init_with=_ErrorMethodResource.init_service)
        self.method_impl = _ErrorMethod()
        register_builtin_method_impl(self.method_impl)

        KtbsTestCase.setUp(self)

        base = self.base = self.my_ktbs.create_base("b/")
        model = base.create_model("m")
        otype1 = model.create_obsel_type("#ot1")
        otype2 = model.create_obsel_type("#ot2")
        atype = model.create_attribute_type("#at")
        origin = "orig-abc"
        src1 = self.src1 = base.create_stored_trace("s1/",
                                                    model,
                                                    origin=origin)
Пример #27
0
def main():
    """Runs an HTTP server serving items and groups.

    If 'test' is passed as argument, first run :func:`do_tests` on both a
    local service and through HTTP.
    """
    test = len(argv) > 1 and argv[1] == "test"

    #root_uri = URIRef("http://localhost:1234/foo/")

    service_config = get_service_configuration()
    service_config.set('server', 'port', '1234')
    service_config.set('server', 'base-path', '/foo')

    # TODO Store management : special tests ?

    serv = make_example1_service(service_config)

    root_uri = serv.root_uri

    if test:
        local_root = serv.get(root_uri, [EXAMPLE.Group])
        assert isinstance(local_root, GroupImplementation)
        do_tests(local_root)
        print "Local tests passed"

    thread, _httpd = make_example1_httpd(serv)
    try:
        if test:
            remote_root = HttpClientCore.factory(root_uri, EXAMPLE.Group)
            assert isinstance(remote_root, GroupMixin)
            do_tests(remote_root)
            print "Remote tests passed"
        print "Now listening on", root_uri
        sleep(3600) # allows to catch KeyboardInterrupt (thread.join doesn't)
        thread.join() # prevents 'finally' clause if sleep above expires
    finally:
        _httpd.shutdown()
        print "httpd stopped"
Пример #28
0
def main():
    """Runs an HTTP server serving items and groups.

    If 'test' is passed as argument, first run :func:`do_tests` on both a
    local service and through HTTP.
    """
    test = len(argv) > 1 and argv[1] == "test"

    #root_uri = URIRef("http://localhost:1234/foo/")

    service_config = get_service_configuration()
    service_config.set('server', 'port', '1234')
    service_config.set('server', 'base-path', '/foo')

    # TODO Store management : special tests ?

    serv = make_example1_service(service_config)

    root_uri = serv.root_uri

    if test:
        local_root = serv.get(root_uri, [EXAMPLE.Group])
        assert isinstance(local_root, GroupImplementation)
        do_tests(local_root)
        print "Local tests passed"

    thread, _httpd = make_example1_httpd(serv)
    try:
        if test:
            remote_root = HttpClientCore.factory(root_uri, EXAMPLE.Group)
            assert isinstance(remote_root, GroupMixin)
            do_tests(remote_root)
            print "Remote tests passed"
        print "Now listening on", root_uri
        sleep(3600) # allows to catch KeyboardInterrupt (thread.join doesn't)
        thread.join() # prevents 'finally' clause if sleep above expires
    finally:
        _httpd.shutdown()
        print "httpd stopped"
Пример #29
0
 def setup(self):
     self.service_config = get_service_configuration()
Пример #30
0
 def setup(self):
     self.service_config = get_service_configuration()
Пример #31
0
    KTBS_NS_SERVICE provides a local copy of the kTBS namespace.
    """
    # too few public methods (1/2) #pylint: disable=R0903
    RDF_MAIN_TYPE = URIRef("http://www.w3.org/2002/07/owl#Ontology")

    @classmethod
    def init_service(cls, service):
        """I populate a service the kTBS namespace at its root.
        """
        cls.create(service, KTBS_NS_URIREF, KTBS_NS_GRAPH)


from rdfrest.util.config import get_service_configuration

service_config = get_service_configuration()

service_config.set('server', 'fixed-root-uri', KTBS_NS_URI)
#rdflib_plugin.get("IOMemory", Store)(""),

KTBS_NS_SERVICE = Service(classes=[_KtbsNsResource],
                          service_config=service_config,
                          init_with=_KtbsNsResource.init_service)

if __name__ == "__main__":
    import sys
    if len(sys.argv) == 1:
        print KTBS_NS_TTL
    else:
        KTBS_NS_GRAPH.serialize(sys.stdout, sys.argv[1])
Пример #32
0
class _KtbsNsResource(LocalCore):
    """I am the only resource class of KTBS_NS_SERVICE.

    KTBS_NS_SERVICE provides a local copy of the kTBS namespace.
    """
    # too few public methods (1/2) #pylint: disable=R0903
    RDF_MAIN_TYPE = URIRef("http://www.w3.org/2002/07/owl#Ontology")

    @classmethod
    def init_service(cls, service):
        """I populate a service the kTBS namespace at its root.
        """
        cls.create(service, KTBS_NS_URIREF, KTBS_NS_GRAPH)

from rdfrest.util.config import get_service_configuration

service_config = get_service_configuration()

service_config.set('server', 'fixed-root-uri', KTBS_NS_URI)
#rdflib_plugin.get("IOMemory", Store)(""),

KTBS_NS_SERVICE = Service(classes=[_KtbsNsResource], service_config=service_config,
                          init_with=_KtbsNsResource.init_service)

if __name__ == "__main__":
    import sys
    if len(sys.argv) == 1:
        print KTBS_NS_TTL
    else:
        KTBS_NS_GRAPH.serialize(sys.stdout, sys.argv[1])