當前位置: 首頁>>代碼示例>>Python>>正文


Python colander.Invalid類代碼示例

本文整理匯總了Python中colander.Invalid的典型用法代碼示例。如果您正苦於以下問題:Python Invalid類的具體用法?Python Invalid怎麽用?Python Invalid使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Invalid類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: validator

 def validator(node, value):
     rate_validator = registry.getAdapter(value['object'], IRateValidator)
     if not rate_validator.validate(value['rate']):
         error = Invalid(node, msg='')
         msg = rate_validator.helpful_error_message()
         error.add(Invalid(node['rate'], msg=msg))
         raise error
開發者ID:Janaba,項目名稱:adhocracy3,代碼行數:7,代碼來源:rate.py

示例2: convert_types

def convert_types(mapping, row):
    """ Translate a row of input data (e.g. from a CSV file) into the
    structure understood by the dataset loader, i.e. where all 
    dimensions are dicts and all types have been converted. 

    This will validate the incoming data and emit a colander.Invalid
    exception if validation was unsuccessful."""
    out = {}
    errors = Invalid(SchemaNode(Mapping(unknown="preserve")))

    for dimension, meta in mapping.items():
        meta["dimension"] = dimension

        # handle AttributeDimensions, Measures and DateDimensions.
        # this is clever, but possibly not always true.
        if "column" in meta:
            try:
                out[dimension] = _cast(row, meta, dimension)
            except Invalid, i:
                errors.add(i)

        # handle CompoundDimensions.
        else:
            out[dimension] = {}

            for attribute, ameta in meta.get("attributes", {}).items():
                try:
                    out[dimension][attribute] = _cast(row, ameta, dimension + "." + attribute)
                except Invalid, i:
                    errors.add(i)
開發者ID:openspending-archive,項目名稱:osvalidate,代碼行數:30,代碼來源:data.py

示例3: deserialize

    def deserialize(self, field, pstruct):
        result = []
        error = None

        if pstruct is null:
            pstruct = []

        field.sequence_fields = []
        item_field = field.children[0]

        for num, substruct in enumerate(pstruct):
            subfield = item_field.clone()
            try:
                subval = subfield.deserialize(substruct)
            except Invalid as e:
                subval = e.value
                if error is None:
                    error = Invalid(field.schema, value=result)
                error.add(e, num)

            result.append(subval)
            field.sequence_fields.append(subfield)

        if error is not None:
            raise error

        return result
開發者ID:microvac,項目名稱:borobudur,代碼行數:27,代碼來源:widget.py

示例4: deserialize

    def deserialize(self, field, pstruct):
        error = None

        result = {}

        if pstruct is null:
            pstruct = {}

        checkbox_schema = pstruct.get(self.checkbox_element, null)
        if checkbox_schema is null:
            return null

        result[self.checkbox_element] = True

        for num, subfield in enumerate(field.children):
            name = subfield.name
            subval = pstruct.get(name, null)

            try:
                result[name] = subfield.deserialize(subval)
            except Invalid as e:
                result[name] = e.value
                if error is None:
                    error = Invalid(field.schema, value=result)
                error.add(e, num)

        if error is not None:
            raise error

        result[self.checkbox_element] = True
        return result
開發者ID:jcu-eresearch,項目名稱:TDH-rich-data-capture,代碼行數:31,代碼來源:deform_widgets.py

示例5: validate_user_is_active

 def validate_user_is_active(node: SchemaNode, value: dict):
     user = request.validated.get('user', None)
     if user is None:
         return
     elif not user.active:
         error = Invalid(node)
         error.add(Invalid(node[child_node_name],
                           msg='User account not yet activated'))
         raise error
開發者ID:Janaba,項目名稱:adhocracy3,代碼行數:9,代碼來源:schemas.py

示例6: validate_rate_is_unique

 def validate_rate_is_unique(node, value):
     existing = _get_rates_user_non_anonymized(context, request, value)
     existing += _get_rates_user_anonymized(context, request, value)
     existing = _remove_following_versions(existing, context, request)
     if existing:
         error = Invalid(node, msg='')
         msg = 'Another rate by the same user already exists'
         error.add(Invalid(node['object'], msg=msg))
         raise error
開發者ID:liqd,項目名稱:adhocracy3,代碼行數:9,代碼來源:rate.py

示例7: validate_login_password

 def validate_login_password(node: SchemaNode, value: dict):
     password = value['password']
     user = request.validated.get('user', None)
     if user is None:
         return
     valid = user.is_password_valid(registry, password)
     if not valid:
         error = Invalid(node)
         error.add(Invalid(node['password'], msg=error_msg_wrong_login))
         raise error
開發者ID:liqd,項目名稱:adhocracy3,代碼行數:10,代碼來源:schemas.py

示例8: validate_login_password

 def validate_login_password(node: SchemaNode, value: dict):
     password = value['password']
     user = request.validated.get('user', None)
     if user is None:
         return
     sheet = registry.content.get_sheet(user, IPasswordAuthentication)
     valid = sheet.check_plaintext_password(password)
     if not valid:
         error = Invalid(node)
         error.add(Invalid(node['password'], msg=error_msg_wrong_login))
         raise error
開發者ID:Janaba,項目名稱:adhocracy3,代碼行數:11,代碼來源:schemas.py

示例9: validate_login

 def validate_login(node: SchemaNode, value: dict):
     login = value[child_node_name]
     locator = registry.getMultiAdapter((context, request), IUserLocator)
     if child_node_name == 'email':
         login = login.lower().strip()
         user = locator.get_user_by_email(login)
     else:
         user = locator.get_user_by_login(login)
     if user is None:
         error = Invalid(node)
         error.add(Invalid(node['password'], msg=error_msg_wrong_login))
         raise error
     else:
         request.validated['user'] = user
開發者ID:Janaba,項目名稱:adhocracy3,代碼行數:14,代碼來源:schemas.py

示例10: validate_entity

def validate_entity(data, schema, context, deep=True):
    schema = entity_schema(schema)
    inv = Invalid(schema)
    try:
        data = schema.deserialize(data)
    except Invalid as inv_real:
        inv = inv_real

    if deep:
        for direction, attribute in (('incoming', 'source'), ('outgoing', 'target')):
            data[direction], i = validate_deep(data, context, direction, attribute)
            if len(i.children):
                inv.add(i)

    if len(inv.children):
        raise inv
    return data
開發者ID:jmorenoamor,項目名稱:grano,代碼行數:17,代碼來源:entity.py

示例11: _raise_if_unknown_field_value

 def _raise_if_unknown_field_value(self, field_name: str,
                                   err: Invalid,
                                   json_object: dict):
     """Raise an 'unknown_xxx' WebSocketError error if appropriate."""
     errdict = err.asdict()
     if (self._is_only_key(errdict, field_name) and
             field_name in json_object):
         field_value = json_object[field_name]
         raise WebSocketError('unknown_' + field_name, field_value)
開發者ID:Janaba,項目名稱:adhocracy3,代碼行數:9,代碼來源:server.py

示例12: deserialize

    def deserialize(self, field, pstruct):
        error = None
        
        result = {}

        if pstruct is null:
            pstruct = {}

        for num, subfield in enumerate(field.children):
            name = subfield.name
            subval = pstruct.get(name, null)
                            
            try:
                result[name] = subfield.deserialize(subval)
            except Invalid, e:
                result[name] = e.value
                if error is None:
                    error = Invalid(field.schema, value=result)
                error.add(e, num)
開發者ID:cguardia,項目名稱:deform,代碼行數:19,代碼來源:widget.py

示例13: validate_deep

def validate_deep(data, context, direction, attribute):
    relations = []
    node = sequence(direction)
    inv = Invalid(node)
    for i, relation_data in enumerate(data.get(direction, [])):
        try:
            other = relation_data.get(attribute, {})
            schema = context.network.get_relation_schema(relation_data.get('type'))
            if schema is None:
                raise Invalid(node, "Invalid relation type: %e" % relation_data.get('type'))
            relation = validate_relation(relation_data, schema, context, ignore_entities=True)

            schema = context.network.get_entity_schema(other.get('type'))
            if schema is None:
                raise Invalid(node, "Invalid entity type: %e" % other.get('type'))
            relation[attribute] = validate_entity(other, schema, context, deep=False)

            relations.append(relation)
        except Invalid as sub:
            inv.add(sub, i)
    return relations, inv
開發者ID:jmorenoamor,項目名稱:grano,代碼行數:21,代碼來源:entity.py

示例14: _impl

    def _impl(self, node, value, callback):
        value = self._validate(node, value)

        error = None
        result = {}

        for index, (k, v) in enumerate(value.iteritems()):
            key_node = node["key"]
            value_node = node["value"].clone()
            value_node.name = k

            try:
                name = callback(key_node, k)
                result[name] = callback(value_node, v)
            except Invalid as e:
                if error is None:
                    error = Invalid(node)
                error.add(e, index)

        if error is not None:
            raise error

        return result
開發者ID:platformsh,項目名稱:colander-tools,代碼行數:23,代碼來源:mapping.py

示例15: sequence_impl

def sequence_impl(self, node, value, callback, accept_scalar):
    if accept_scalar is None:
        accept_scalar = self.accept_scalar

    value = self._validate(node, value, accept_scalar)

    error = None
    result = []

    for num, subval in enumerate(value):
        try:
            result.append(callback(node.children[0], subval))
        except Invalid as e:
            if error is None:
                error = Invalid(node)
            error.add(e, num)

    if error is not None:
        raise error

    if not result:
        return null
    return result
開發者ID:hugobranquinho,項目名稱:ines,代碼行數:23,代碼來源:fields.py


注:本文中的colander.Invalid類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。