我们从Python开源项目中,提取了以下36个代码示例,用于说明如何使用sqlalchemy.exc.ArgumentError()。
def create_connect_args(self, url): if url.username or url.password or url.host or url.port: raise exc.ArgumentError( "Invalid SQLite URL: %s\n" "Valid SQLite URL forms are:\n" " sqlite:///:memory: (or, sqlite://)\n" " sqlite:///relative/path/to/file.db\n" " sqlite:////absolute/path/to/file.db" % (url,)) filename = url.database or ':memory:' if filename != ':memory:': filename = os.path.abspath(filename) opts = url.query.copy() util.coerce_kw_type(opts, 'timeout', float) util.coerce_kw_type(opts, 'isolation_level', str) util.coerce_kw_type(opts, 'detect_types', int) util.coerce_kw_type(opts, 'check_same_thread', bool) util.coerce_kw_type(opts, 'cached_statements', int) return ([filename], opts)
def load(self, name): if name in self.impls: return self.impls[name]() if self.auto_fn: loader = self.auto_fn(name) if loader: self.impls[name] = loader return loader() try: import pkg_resources except ImportError: pass else: for impl in pkg_resources.iter_entry_points( self.group, name): self.impls[name] = impl.load return impl.load() from sqlalchemy import exc raise exc.ArgumentError( "Can't load plugin: %s:%s" % (self.group, name))
def configure_connection(connection, create_tables=True): if isinstance(connection, basestring): try: eng = create_engine(connection) except exc.ArgumentError: eng = SQLiteConnectionRecipe(connection)() elif isinstance(connection, Connectable): eng = connection elif isinstance(connection, ConnectionRecipe): eng = connection() elif isinstance(connection, scoped_session): eng = connection.get_bind() else: raise ValueError( "Could not determine how to get a database connection from %r" % connection) if create_tables: Base.metadata.create_all(bind=eng) return eng
def __init__(self, precision=None, scale=None, asdecimal=True, **kw): if isinstance(self, (REAL, DOUBLE)) and \ ( (precision is None and scale is not None) or (precision is not None and scale is None) ): raise exc.ArgumentError( "You must specify both precision and scale or omit " "both altogether.") super(_FloatType, self).__init__(precision=precision, asdecimal=asdecimal, **kw) self.scale = scale
def set_isolation_level(self, connection, level): try: isolation_level = self._isolation_lookup[level.replace('_', ' ')] except KeyError: raise exc.ArgumentError( "Invalid value '%s' for isolation_level. " "Valid isolation levels for %s are %s" % (level, self.name, ", ".join(self._isolation_lookup)) ) cursor = connection.cursor() cursor.execute("PRAGMA read_uncommitted = %d" % isolation_level) cursor.close()
def assert_arg_type(arg, argtype, name): if isinstance(arg, argtype): return arg else: if isinstance(argtype, tuple): raise exc.ArgumentError( "Argument '%s' is expected to be one of type %s, got '%s'" % (name, ' or '.join("'%s'" % a for a in argtype), type(arg))) else: raise exc.ArgumentError( "Argument '%s' is expected to be of type '%s', got '%s'" % (name, argtype, type(arg)))
def main(args): import multiprocessing try: multiprocessing.set_start_method("fork") except RuntimeError as ex: log.warn("multiprocessing.set_start_method: " + str(ex)) if not args.command: # No command was given. args.app.arg_parser.print_help() return 1 # In the case fileConfig undid the command line, which has precedence. args.applyLoggingOpts(args.log_levels, args.log_files) if args.db_url: args.config.set(MAIN_SECT, SA_KEY, args.db_url) # Don't want commands and such to use this, so reset. args.db_url = None elif "MISHMASH_DBURL" in os.environ: log.verbose("Using environment MISHMASH_DBURL over configuration: {}" .format(os.environ["MISHMASH_DBURL"])) args.config.set(MAIN_SECT, SA_KEY, os.environ["MISHMASH_DBURL"]) try: # Run command retval = args.command_func(args, args.config) or 0 except (KeyboardInterrupt, PromptExit) as ex: # PromptExit raised when CTRL+D during prompt, or prompts disabled retval = 0 except (sql_exceptions.ArgumentError, sql_exceptions.OperationalError) as ex: _pErr("Database error") retval = 1 except Exception as ex: log.exception(ex) _pErr("General error") retval = 2 return retval
def test_lambda_is_callable(self): with self.assertRaises(exc.ArgumentError) as ex: self.compile(Lambda(1)) self.assertEqual(str(ex.exception), 'func must be callable')
def __init__(self, func): if not util.callable(func): raise exc.ArgumentError('func must be callable') self.type = type_api.NULLTYPE self.func = func