Пример #1
0
    def __call__(self, uri):
        (scheme, netloc, path, query, frag) = urlsplit(uri)
        if _BROKEN_URLSPLIT: #pragma NO COVER
            # urlsplit used not to allow fragments in non-standard schemes,
            # stuffed everything into 'path'
            (scheme, netloc, path, query, frag
            ) = urlsplit('http:' + path)
        path = os.path.normpath(path)
        schema_xml = self.schema_xml_template
        schema = loadSchemaFile(BytesIO(schema_xml))
        config, handler = loadConfig(schema, path)
        for config_item in config.databases + config.storages:
            if not frag:
                # use the first defined in the file
                break
            elif frag == config_item.name:
                # match found
                break
        else:
            raise KeyError("No storage or database named %s found" % frag)

        if isinstance(config_item, ZODBDatabase):
            config = config_item.config
            factory = config.storage
            dbkw = {
                'connection_cache_size': config.cache_size,
                'connection_pool_size': config.pool_size,
            }
            if config.database_name:
                dbkw['database_name'] = config.database_name
        else:
            factory = config_item
            dbkw = dict(parse_qsl(query))

        return factory.open, dbkw
Пример #2
0
    def __call__(self, uri):
        (scheme, netloc, path, query, frag) = urlsplit(uri)
        if _BROKEN_URLSPLIT:  #pragma NO COVER
            # urlsplit used not to allow fragments in non-standard schemes,
            # stuffed everything into 'path'
            (scheme, netloc, path, query, frag) = urlsplit('http:' + path)
        path = os.path.normpath(path)
        schema_xml = self.schema_xml_template
        schema = loadSchemaFile(BytesIO(schema_xml))
        config, handler = loadConfig(schema, path)
        for config_item in config.databases + config.storages:
            if not frag:
                # use the first defined in the file
                break
            elif frag == config_item.name:
                # match found
                break
        else:
            raise KeyError("No storage or database named %s found" % frag)

        if isinstance(config_item, ZODBDatabase):
            config = config_item.config
            factory = config.storage
            dbkw = {
                'connection_cache_size': config.cache_size,
                'connection_pool_size': config.pool_size,
            }
            if config.database_name:
                dbkw['database_name'] = config.database_name
        else:
            factory = config_item
            dbkw = dict(parse_qsl(query))

        return factory.open, dbkw
Пример #3
0
 def _loadConfig(self, text):
     f = open('test.conf', 'w')
     f.write(self.getConfigPrefix())
     f.write(text)
     f.write(self.getConfigPostfix())
     f.close()
     config, handlers = loadConfig(self.schema, 'test.conf')
     return config
Пример #4
0
 def _loadConfig(self,text):
     f = open('test.conf','w')
     f.write(self.getConfigPrefix())
     f.write(text)
     f.write(self.getConfigPostfix())
     f.close()
     config, handlers = loadConfig(self.schema, 'test.conf')
     return config