def make_stone_friendly(self, data_type, val, validate):
if isinstance(data_type, bv.Timestamp):<EOL><INDENT>try:<EOL><INDENT>ret = datetime.datetime.strptime(val, data_type.format)<EOL><DEDENT>except (TypeError, ValueError) as e:<EOL><INDENT>raise bv.ValidationError(e.args[<NUM_LIT:0>])<EOL><DEDENT><DEDENT>elif isinstance(data_type, bv.Bytes):<EOL><INDENT>if self.for_msgpack:<EOL><INDENT>if isinstance(val, six.text_type):<EOL><INDENT>ret = val.encode('<STR_LIT:utf-8>')<EOL><DEDENT>else:<EOL><INDENT>ret = val<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>ret = base64.b64decode(val)<EOL><DEDENT>except TypeError:<EOL><INDENT>raise bv.ValidationError('<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>elif isinstance(data_type, bv.Void):<EOL><INDENT>if self.strict and val is not None:<EOL><INDENT>raise bv.ValidationError("<STR_LIT>")<EOL><DEDENT>return None<EOL><DEDENT>else:<EOL><INDENT>if validate:<EOL><INDENT>if self.caller_permissions.permissions:<EOL><INDENT>data_type.validate_with_permissions(val, self.caller_permissions)<EOL><DEDENT>else:<EOL><INDENT>data_type.validate(val)<EOL><DEDENT><DEDENT>ret = val<EOL><DEDENT>if self.alias_validators is not None and data_type in self.alias_validators:<EOL><INDENT>self.alias_validators[data_type](ret)<EOL><DEDENT>return ret<EOL>
Convert a Python object to a type that will pass validation by its
validator.
Validation by ``alias_validators`` is performed even if ``validate`` is
false.