Example #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
Example #2
0
    def __call__(self, uri):
        # urlsplit doesnt understand zeo URLs so force to something that
        # doesn't break
        uri = uri.replace('zeo://', 'http://', 1)
        (scheme, netloc, path, query, frag) = urlsplit(uri)
        if netloc:
            # TCP URL
            if ':' in netloc:
                host, port = netloc.split(':')
                port = int(port)
            else:
                host = netloc
                port = 9991
            args = ((host, port), )
        else:
            # Unix domain socket URL
            path = os.path.normpath(path)
            args = (path, )
        kw = dict(parse_qsl(query))
        kw, unused = self.interpret_kwargs(kw)
        if 'demostorage' in kw:
            kw.pop('demostorage')

            def factory():
                return DemoStorage(base=ClientStorage(*args, **kw))
        else:

            def factory():
                return ClientStorage(*args, **kw)

        return factory, unused
Example #3
0
 def __call__(self, uri):
     # urlsplit doesnt understand zeo URLs so force to something that
     # doesn't break
     uri = uri.replace('zeo://', 'http://', 1)
     (scheme, netloc, path, query, frag) = urlsplit(uri)
     if netloc:
         # TCP URL
         if ':' in netloc:
             host, port = netloc.split(':')
             port = int(port)
         else:
             host = netloc
             port = 9991
         args = ((host, port),)
     else:
         # Unix domain socket URL
         path = os.path.normpath(path)
         args = (path,)
     kw = dict(parse_qsl(query))
     kw, unused = self.interpret_kwargs(kw)
     if 'demostorage' in kw:
         kw.pop('demostorage')
         def factory():
             return DemoStorage(base=ClientStorage(*args, **kw))
     else:
         def factory():
             return ClientStorage(*args, **kw)
     return factory, unused
Example #4
0
    def __call__(self, uri):
        def baduri(why):
            bad = 'demo: invalid uri %r' % uri
            if why:
                bad += ": " + why
            raise ValueError(bad)

        m = self._uri_re.match(uri)
        if m is None:
            baduri('')

        base_uri = m.group('base')
        delta_uri = m.group('changes')

        basef, base_dbkw = _resolve_uri(base_uri)
        if base_dbkw:
            baduri('DB arguments in base')
        deltaf, delta_dbkw = _resolve_uri(delta_uri)
        if delta_dbkw:
            baduri('DB arguments in changes')

        frag = m.group('frag')
        dbkw = {}
        if frag:
            dbkw = dict(parse_qsl(frag[1:]))

        def factory():
            base = basef()
            delta = deltaf()
            return DemoStorage(base=base, changes=delta)

        return factory, dbkw
Example #5
0
    def __call__(self, uri):
        # urlsplit doesnt understand zeo URLs so force to something that
        # doesn't break
        uri = uri.replace('zeo://', 'http://', 1)
        u = urlsplit(uri)
        if u.netloc:
            # TCP URL
            host = u.hostname
            port = u.port
            if port is None:
                port = 9991
            args = ((host, port), )
        else:
            # Unix domain socket URL
            path = os.path.normpath(u.path)
            args = (path, )
        kw = dict(parse_qsl(u.query))
        kw, unused = self.interpret_kwargs(kw)
        if 'demostorage' in kw:
            kw.pop('demostorage')

            def factory():
                return DemoStorage(base=ClientStorage(*args, **kw))
        else:

            def factory():
                return ClientStorage(*args, **kw)

        return factory, unused
Example #6
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
Example #7
0
    def __call__(self, uri):
        # we can't use urlsplit here due to Windows filenames
        prefix, rest = uri.split('file://', 1)
        result = rest.split('?', 1)
        if len(result) == 1:
            path = result[0]
            query = ''
        else:
            path, query = result
        path = os.path.normpath(path)
        args = (path, )
        kw = dict(parse_qsl(query))
        kw, unused = self.interpret_kwargs(kw)
        demostorage = False

        if 'demostorage' in kw:
            kw.pop('demostorage')
            demostorage = True

        blobstorage_dir = None
        blobstorage_layout = 'automatic'
        if 'blobstorage_dir' in kw:
            blobstorage_dir = kw.pop('blobstorage_dir')
        if 'blobstorage_layout' in kw:
            blobstorage_layout = kw.pop('blobstorage_layout')

        if demostorage and blobstorage_dir:

            def factory():
                filestorage = FileStorage(*args, **kw)
                blobstorage = BlobStorage(blobstorage_dir,
                                          filestorage,
                                          layout=blobstorage_layout)
                return DemoStorage(base=blobstorage)
        elif blobstorage_dir:

            def factory():
                filestorage = FileStorage(*args, **kw)
                return BlobStorage(blobstorage_dir,
                                   filestorage,
                                   layout=blobstorage_layout)
        elif demostorage:

            def factory():
                filestorage = FileStorage(*args, **kw)
                return DemoStorage(base=filestorage)
        else:

            def factory():
                return FileStorage(*args, **kw)

        return factory, unused
Example #8
0
 def __call__(self, uri):
     prefix, rest = uri.split('memory://', 1)
     result = rest.split('?', 1)
     if len(result) == 1:
         name = result[0]
         query = ''
     else:
         name, query = result
     kw = dict(parse_qsl(query))
     kw, unused = self.interpret_kwargs(kw)
     args = (name,)
     def factory():
         return MappingStorage(*args)
     return factory, unused
Example #9
0
    def __call__(self, uri):
        prefix, rest = uri.split('memory://', 1)
        result = rest.split('?', 1)
        if len(result) == 1:
            name = result[0]
            query = ''
        else:
            name, query = result
        kw = dict(parse_qsl(query))
        kw, unused = self.interpret_kwargs(kw)
        args = (name, )

        def factory():
            return MappingStorage(*args)

        return factory, unused
Example #10
0
    def __call__(self, uri):
        # we can't use urlsplit here due to Windows filenames
        prefix, rest = uri.split('file://', 1)
        result = rest.split('?', 1)
        if len(result) == 1:
            path = result[0]
            query = ''
        else:
            path, query = result
        path = os.path.normpath(path)
        args = (path,)
        kw = dict(parse_qsl(query))
        kw, unused = self.interpret_kwargs(kw)
        demostorage = False

        if 'demostorage'in kw:
            kw.pop('demostorage')
            demostorage = True

        blobstorage_dir = None
        blobstorage_layout = 'automatic'
        if 'blobstorage_dir' in kw:
            blobstorage_dir = kw.pop('blobstorage_dir')
        if 'blobstorage_layout' in kw:
            blobstorage_layout = kw.pop('blobstorage_layout')

        if demostorage and blobstorage_dir:
            def factory():
                filestorage = FileStorage(*args, **kw)
                blobstorage = BlobStorage(blobstorage_dir, filestorage,
                                          layout=blobstorage_layout)
                return DemoStorage(base=blobstorage)
        elif blobstorage_dir:
            def factory():
                filestorage = FileStorage(*args, **kw)
                return BlobStorage(blobstorage_dir, filestorage,
                                   layout=blobstorage_layout)
        elif demostorage:
            def factory():
                filestorage = FileStorage(*args, **kw)
                return DemoStorage(base=filestorage)
        else:
            def factory():
                return FileStorage(*args, **kw)

        return factory, unused