da53f143ee
below issures are removed from ignore cases: E114 indentation is not a multiple of four (comment) E116 unexpected indentation (comment) E121 continuation line under-indented for hanging indent E122 continuation line missing indentation or outdented E123 closing bracket does not match indentation of opening bracket's line E124 closing bracket does not match visual indentation E125 continuation line with same indent as next logical line E126 continuation line over-indented for hanging indent E127 continuation line over-indented for visual indent E128 continuation line under-indented for visual indent E129 visually indented line with same indent as next logical line E131 continuation line unaligned for hanging indent E201 whitespace after '(' E228 missing whitespace around modulo operator E231 missing whitespace after ',' E241 multiple spaces after ':' E251 unexpected spaces around keyword / parameter equals E265 block comment should start with '#' E271 multiple spaces after keyword E302 expected 2 blank lines, found 1 E303 too many blank lines E305 expected 2 blank lines after class or function definition, found 1 E704 multiple statements on one line (def) E713 test for membership should be 'not in' E714 test for object identity should be 'is not' E722 do not use bare except' E731 do not assign a lambda expression, use a def E999 SyntaxError: invalid syntax (this is likely python3) F401 <foo> imported but unused F841 local variable 'foo' is assigned to but never used H201: no 'except:' H233: Python 3.x incompatible use of print operator B001 Do not use bare `except:` B004 Using `hasattr(x, '__call__')` to test if `x` is callable is unreliable. B305 `.next()` is not a thing on Python 3. Use the `next()` builtin. B306 `BaseException.message` has been deprecated as of Python 2.6 and is removed in Python 3. B007 Loop control variable 'key' not used within the loop body. remain below issues in ignores: E402 module level import not at top of file ./service-mgmt-api/sm-api/sm_api/cmd/__init__.py:25 Hxxx since which are related with document format F811 redefinition of unused '<foo>' from line <x> ./service-mgmt-tools/sm-tools/sm_tools/sm_configure.py:18 F821 undefined name 'e' ./service-mgmt-api/sm-api/sm_api/common/utils.py:448 B006 Do not use mutable data structures for argument defaults. ./service-mgmt-api/sm-api/sm_api/common/service.py:59 B008 Do not perform calls in argument defaults. ./service-mgmt-api/sm-api/sm_api/openstack/common/timeutils.py:117 Test have been done:Build,Deploy,some smc command,such as smc service-list, smc service-show, sm-dump, etc Story: 2003430 Task: 26524 Change-Id: I3e2a4a31f87e3ff66cfce86f54285e830ee1c3dc Signed-off-by: Sun Austin <austin.sun@intel.com>
99 lines
3.1 KiB
Python
99 lines
3.1 KiB
Python
#!/usr/bin/env python
|
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
# Copyright 2013 Red Hat, Inc.
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
#
|
|
# Copyright (c) 2013-2014 Wind River Systems, Inc.
|
|
#
|
|
|
|
|
|
import jsonpatch
|
|
import re
|
|
import wsme
|
|
|
|
from oslo_config import cfg
|
|
|
|
CONF = cfg.CONF
|
|
|
|
|
|
JSONPATCH_EXCEPTIONS = (jsonpatch.JsonPatchException,
|
|
jsonpatch.JsonPointerException,
|
|
KeyError)
|
|
|
|
|
|
def validate_limit(limit):
|
|
if limit and limit < 0:
|
|
raise wsme.exc.ClientSideError(_("Limit must be positive"))
|
|
|
|
return min(CONF.api_limit_max, limit) or CONF.api_limit_max
|
|
|
|
|
|
def validate_sort_dir(sort_dir):
|
|
if sort_dir not in ['asc', 'desc']:
|
|
raise wsme.exc.ClientSideError(_("Invalid sort direction: %s. "
|
|
"Acceptable values are "
|
|
"'asc' or 'desc'") % sort_dir)
|
|
return sort_dir
|
|
|
|
|
|
def validate_patch(patch):
|
|
"""Performs a basic validation on patch."""
|
|
|
|
if not isinstance(patch, list):
|
|
patch = [patch]
|
|
|
|
for p in patch:
|
|
path_pattern = re.compile("^/[a-zA-Z0-9-_]+(/[a-zA-Z0-9-_]+)*$")
|
|
|
|
if not isinstance(p, dict) or \
|
|
any(key for key in ["path", "op"] if key not in p):
|
|
raise wsme.exc.ClientSideError(_("Invalid patch format: %s")
|
|
% str(p))
|
|
|
|
path = p["path"]
|
|
op = p["op"]
|
|
|
|
if op not in ["add", "replace", "remove"]:
|
|
raise wsme.exc.ClientSideError(_("Operation not supported: %s")
|
|
% op)
|
|
|
|
if not path_pattern.match(path):
|
|
raise wsme.exc.ClientSideError(_("Invalid path: %s") % path)
|
|
|
|
if op == "add":
|
|
if path.count('/') == 1:
|
|
raise wsme.exc.ClientSideError(_("Adding an additional "
|
|
"attribute (%s) to the "
|
|
"resource is not allowed")
|
|
% path)
|
|
|
|
|
|
class ValidTypes(wsme.types.UserType):
|
|
"""User type for validate that value has one of a few types."""
|
|
|
|
def __init__(self, *types):
|
|
self.types = types
|
|
|
|
def validate(self, value):
|
|
for t in self.types:
|
|
if t is wsme.types.text and isinstance(value, wsme.types.bytes):
|
|
value = value.decode()
|
|
if isinstance(value, t):
|
|
return value
|
|
else:
|
|
raise ValueError("Wrong type. Expected '%s', got '%s'" % (
|
|
self.types, type(value)))
|