def _compile_callable(self, schema):
        """ Compile callable: wrap exceptions with correct paths """
        # Prepare self
        self.compiled_type = const.COMPILED_TYPE.CALLABLE
        self.name = get_callable_name(schema)

        # Error utils
        enrich_exception = lambda e, value: e.enrich(
            expected=self.name,
            provided=get_literal_name(value),
            path=self.path,
            validator=schema)

        # Validator
        def validate_with_callable(v):
            try:
                # Try this callable
                return schema(v)
            except Invalid as e:
                # Enrich & re-raise
                enrich_exception(e, v)
                raise
            except const.transformed_exceptions as e:
                message = _(u'{message}').format(
                    Exception=type(e).__name__,
                    message=six.text_type(e))
                e = Invalid(message)
                raise enrich_exception(e, v)

        # Matcher
        if self.matcher:
            def match_with_callable(v):
                try:
                    return True, validate_with_callable(v)
                except Invalid:
                    return False, v
            return match_with_callable

        return validate_with_callable
def _compile_callable ( self , schema ) : self . compiled_type = const . COMPILED_TYPE . CALLABLE self . name = get_callable_name ( schema ) enrich_exception = lambda e , value : e . enrich ( expected = self . name , provided = get_literal_name ( value ) , path = self . path , validator = schema ) def validate_with_callable ( v ) : try : return schema ( v ) except Invalid as e : enrich_exception ( e , v ) raise except const . transformed_exceptions as e : message = _ ( u'{message}' ) . format ( Exception = type ( e ) . __name__ , message = six . text_type ( e ) ) e = Invalid ( message ) raise enrich_exception ( e , v ) if self . matcher : def match_with_callable ( v ) : try : return True , validate_with_callable ( v ) except Invalid : return False , v return match_with_callable return validate_with_callable
Compile callable: wrap exceptions with correct paths