Ejemplo n.º 1
0
def test_sqlite():
    url = 'sqlite3:///tmp/json.db'
    obj = URL.parse(url)
    eq_(obj.driver, 'sqlite3')
    eq_(obj.username, None)
    eq_(obj.password, None)
    eq_(obj.host, None)
    eq_(obj.port, None)
    eq_(obj.database, '/tmp/json.db')
    eq_(unicode(obj), unicode(url))
    eq_(str(obj), url)
Ejemplo n.º 2
0
def create(connstr, *args, **kws):
    if not connstr:
        # assume sqlite3
        fd, path = tempfile.mkstemp(suffix='.jsondb')
        connstr = 'sqlite3://%s' % (os.path.abspath(os.path.normpath(path)))

    try:
        url = URL.parse(connstr)
    except:
        path = connstr
        connstr = 'sqlite3:///%s' % (os.path.abspath(os.path.normpath(path)))
        url = URL.parse(connstr)

    if not url.driver:
        url.driver = 'sqlite3'

    name = url.driver
    cls = drivers.get(name.lower(), None)
    if not cls:
        raise NonAvailableError(name)
    return cls(url=url, *args, **kws) if cls else None
Ejemplo n.º 3
0
def create(connstr, *args, **kws):
    if not connstr:
        # assume sqlite3
        fd, path = tempfile.mkstemp(suffix='.jsondb')
        connstr = 'sqlite3://%s' % (os.path.abspath(os.path.normpath(path)))
        if IS_WINDOWS:
            connstr = 'sqlite3:///%s' % (os.path.abspath(os.path.normpath(path)))

    if IS_WINDOWS and not re.match(r'^[^:/]+://.*$', connstr):
        connstr = 'sqlite3:///%s' % (os.path.abspath(os.path.normpath(connstr)))

    url = URL.parse(connstr)

    if not url.driver:
        url.driver = 'sqlite3'

    name = url.driver
    cls = drivers.get(name.lower(), None)
    if not cls:
        raise NonAvailableSchemeError(name)
    return cls(url=url, *args, **kws) if cls else None