How to use the pony.utils.throw function in pony

To help you get started, we’ve selected a few pony examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ponyorm / pony / pony / orm / serialization.py View on Github external
def to_dict(objects):
    if isinstance(objects, Entity): objects = [ objects ]
    objects = iter(objects)
    try: first_object = next(objects)
    except StopIteration: return {}
    if not isinstance(first_object, Entity): throw(TypeError,
        'Entity instance or a sequence of instances expected. Got: %r' % first_object)
    database = first_object._database_
    bag = Bag(database)
    bag.put(first_object)
    bag.put(objects)
    return dict(bag.to_dict())
github ponyorm / pony / pony / orm / dbproviders / oracle.py View on Github external
def setdefault(kwargs, key, value):
            kwargs_value = kwargs.setdefault(key, value)
            if value is not None and value != kwargs_value:
                throw(ValueError, 'Ambiguous value for ' + key)
github ponyorm / pony / pony / orm / dbproviders / oracle.py View on Github external
def build_json_path(builder, path):
        path_sql, has_params, has_wildcards = SQLBuilder.build_json_path(builder, path)
        if has_params: throw(TranslationError, "Oracle doesn't allow parameters in JSON paths")
        return path_sql, has_params, has_wildcards
    def JSON_QUERY(builder, expr, path):
github ponyorm / pony / pony / orm / sqlbuilding.py View on Github external
def JSON_ARRAY_LENGTH(builder, value):
        throw(NotImplementedError)
    def JSON_PARAM(builder, expr):
github ponyorm / pony / pony / orm / sqltranslation.py View on Github external
def strip(monad, chars, strip_type):
        translator = monad.translator
        if chars is not None and not are_comparable_types(monad.type, chars.type, None):
            if chars.type == 'METHOD': raise_forgot_parentheses(chars)
            throw(TypeError, "'chars' argument must be of %r type in {EXPR}, got: %r"
                            % (type2str(monad.type), type2str(chars.type)))
        parent_sql = monad.getsql()[0]
        sql = [ strip_type, parent_sql ]
        if chars is not None: sql.append(chars.getsql()[0])
        return translator.StringExprMonad(translator, monad.type, sql)
    def call_strip(monad, chars=None):
github ponyorm / pony / pony / orm / sqltranslation.py View on Github external
def check_comparable(left_monad, right_monad, op='=='):
    t1, t2 = left_monad.type, right_monad.type
    if t1 == 'METHOD': raise_forgot_parentheses(left_monad)
    if t2 == 'METHOD': raise_forgot_parentheses(right_monad)
    if not are_comparable_types(t1, t2, op):
        if op in ('in', 'not in') and isinstance(t2, SetType): t2 = t2.item_type
        throw(IncomparableTypesError, t1, t2)
github ponyorm / pony / pony / orm / sqltranslation.py View on Github external
def default_post(translator, node):
        throw(NotImplementedError)  # pragma: no cover
github ponyorm / pony / pony / orm / sqltranslation.py View on Github external
def call(monad, *args):
        if len(args) < 2: throw(TranslationError, 'concat() function requires at least two arguments')
        translator = args[0].translator
        result_ast = [ 'CONCAT' ]
        for arg in args:
            t = arg.type
            if isinstance(t, EntityMeta) or type(t) in (tuple, SetType):
                throw(TranslationError, 'Invalid argument of concat() function: %s' % ast2src(arg.node))
            result_ast.extend(arg.getsql())
        return translator.ExprMonad.new(translator, unicode, result_ast)
github ponyorm / pony / pony / orm / sqltranslation.py View on Github external
def numeric_binop(monad, monad2):
        translator = monad.translator
        if isinstance(monad2, (translator.AttrSetMonad, translator.NumericSetExprMonad)):
            return translator.NumericSetExprMonad(op, sqlop, monad, monad2)
        if monad2.type == 'METHOD': raise_forgot_parentheses(monad2)
        result_type, monad, monad2 = coerce_monads(monad, monad2)
        if result_type is None:
            throw(TypeError, _binop_errmsg % (type2str(monad.type), type2str(monad2.type), op))
        left_sql = monad.getsql()[0]
        right_sql = monad2.getsql()[0]
        return translator.NumericExprMonad(translator, result_type, [ sqlop, left_sql, right_sql ])
    numeric_binop.__name__ = sqlop