)]}'
{"keystone/common/utils.py":[{"author":{"_account_id":10795,"name":"Rajesh Tailor","email":"tailor.rajesh88@gmail.com","username":"rajeshtailor"},"change_message_id":"e218c68bde602bc428bcdce952d7c2598d42260b","unresolved":false,"context_lines":[{"line_number":162,"context_line":"        raise exception.ValidationError(msg)"},{"line_number":163,"context_line":""},{"line_number":164,"context_line":""},{"line_number":165,"context_line":"def check_type(property_name, value, expected_type, display_expected_type):"},{"line_number":166,"context_line":"    if not isinstance(value, expected_type):"},{"line_number":167,"context_line":"        msg \u003d (_(\"%(property_name)s is not a \""},{"line_number":168,"context_line":"                 \"%(display_expected_type)s\") % dict("}],"source_content_type":"text/x-python","patch_set":1,"id":"fa1b9901_b46ab6b1","line":165,"updated":"2015-08-20 11:24:52.000000000","message":"IMO instead of writing two separate methods (check_length and check_type) to validate string type and string length, you can club those and write validate_string_length method like this, which makes it much more readable:\n\n    def validate_string_length(property_name, value, min_length\u003d0, max_length\u003dNone):\n        if not isinstance(value, six.string_types):\t\n            msg \u003d _(\"%s is not a string or unicode\") % property_name\n            raise exception.ValidationError(msg)\n\n        name \u003d name.strip()\n\n        if len(value) \u003c min_length:\n            msg \u003d _(\"%(property_name)s has a minimum character requirement of \"\t\n                \"%(min_length)s.\") % {\u0027property_name\u0027: property_name,\n                                      \u0027min_length\u0027: min_length}\n            raise exception.ValidationError(msg)\n\n        if max_length and len(value) \u003e max_length:\n            msg \u003d _(\"%(property_name)s has more than %(max_length)s \"\n                    \"characters.\") % {\u0027property_name\u0027: property_name,\n                                  \u0027max_length\u0027: max_length}\n            raise exception.ValidationError(msg)","commit_id":"f663b5e8b6fb4ade3f14189adb9433c402e37a51"},{"author":{"_account_id":10795,"name":"Rajesh Tailor","email":"tailor.rajesh88@gmail.com","username":"rajeshtailor"},"change_message_id":"e218c68bde602bc428bcdce952d7c2598d42260b","unresolved":false,"context_lines":[{"line_number":171,"context_line":"        raise exception.ValidationError(msg)"},{"line_number":172,"context_line":""},{"line_number":173,"context_line":""},{"line_number":174,"context_line":"def check_enabled(property_name, enabled):"},{"line_number":175,"context_line":"    # Allow int and it\u0027s subclass bool"},{"line_number":176,"context_line":"    check_type(\u0027%s enabled\u0027 % property_name, enabled, int, \u0027boolean\u0027)"},{"line_number":177,"context_line":"    return bool(enabled)"}],"source_content_type":"text/x-python","patch_set":1,"id":"fa1b9901_14b92279","line":174,"updated":"2015-08-20 11:24:52.000000000","message":"You can implement check_enabled method separately like this:\n\n    def check_enabled(property_name, enabled):\n        if not isinstance(property_name, int):\n            msg \u003d _(\"%s is not boolean\") % property_name\n            raise ValidationError(msg)\n        return bool(enabled)","commit_id":"f663b5e8b6fb4ade3f14189adb9433c402e37a51"}]}
