Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 4
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
Ejemplo n.º 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
Ejemplo n.º 6
0
from ZConfig import loadSchemaFile
from ZEO.ClientStorage import ClientStorage
from ZODB.blob import BlobStorage
from ZODB.config import ZODBDatabase
from ZODB.DemoStorage import DemoStorage
from ZODB.FileStorage.FileStorage import FileStorage
from ZODB.MappingStorage import MappingStorage

from zodburi.datatypes import convert_bytesize
from zodburi.datatypes import convert_int
from zodburi.datatypes import convert_tuple
from zodburi._compat import parse_qsl
from zodburi._compat import urlsplit

# Capability test for older Pythons (2.x < 2.7.4, 3.x < 3.2.4)
(scheme, netloc, path, query, frag) = urlsplit('scheme:///path/#frag')
_BROKEN_URLSPLIT = frag != 'frag'

class Resolver(object):
    _int_args = ()
    _string_args = ()
    _bytesize_args = ()
    _float_args = ()
    _tuple_args = ()

    def interpret_kwargs(self, kw):
        unused = kw.copy()
        new = {}
        convert_string = lambda s: s
        converters = [
            (convert_int, self._int_args),
Ejemplo n.º 7
0
from ZConfig import loadSchemaFile
from ZEO.ClientStorage import ClientStorage
from ZODB.blob import BlobStorage
from ZODB.config import ZODBDatabase
from ZODB.DemoStorage import DemoStorage
from ZODB.FileStorage.FileStorage import FileStorage
from ZODB.MappingStorage import MappingStorage

from zodburi.datatypes import convert_bytesize
from zodburi.datatypes import convert_int
from zodburi.datatypes import convert_tuple
from zodburi._compat import parse_qsl
from zodburi._compat import urlsplit

# Capability test for older Pythons (2.x < 2.7.4, 3.x < 3.2.4)
(scheme, netloc, path, query, frag) = urlsplit('scheme:///path/#frag')
_BROKEN_URLSPLIT = frag != 'frag'


class Resolver(object):
    _int_args = ()
    _string_args = ()
    _bytesize_args = ()
    _float_args = ()
    _tuple_args = ()

    def interpret_kwargs(self, kw):
        unused = kw.copy()
        new = {}
        convert_string = lambda s: s
        converters = [