本文整理汇总了Python中karesansui.lib.checker.Checker类的典型用法代码示例。如果您正苦于以下问题:Python Checker类的具体用法?Python Checker怎么用?Python Checker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Checker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validates_src_id
def validates_src_id(obj):
"""<comment-ja>
ゲストOSコピー元のチェッカー
@param obj: karesansui.lib.rest.Rest オブジェクト
@type obj: karesansui.lib.rest.Rest
@return: check
@rtype: bool
</comment-ja>
<comment-en>
TODO: English Comment
</comment-en>
"""
checker = Checker()
check = True
_ = obj._
checker.errors = []
if not is_param(obj.input, 'src_id'):
check = False
checker.add_error(_('"%s" is required.') % _('Copy Source'))
else:
check = checker.check_number(_('Copy Source'),
obj.input.src_id,
CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX,
ID_MIN_LENGTH,
ID_MAX_LENGTH
) and check
obj.view.alert = checker.errors
return check
示例2: validates_uriguest_status
def validates_uriguest_status(obj):
checker = Checker()
check = True
_ = obj._
checker.errors = []
if is_param(obj.input, "status"):
check = (
checker.check_status(
_("Status"),
obj.input.status,
CHECK_EMPTY | CHECK_VALID,
[
GUEST_ACTION_CREATE,
GUEST_ACTION_SHUTDOWN,
GUEST_ACTION_DESTROY,
GUEST_ACTION_SUSPEND,
GUEST_ACTION_RESUME,
GUEST_ACTION_REBOOT,
GUEST_ACTION_ENABLE_AUTOSTART,
GUEST_ACTION_DISABLE_AUTOSTART,
],
)
and check
)
else:
check = False
checker.add_error(_('"%s" is required.') % _("Status"))
obj.view.alert = checker.errors
return check
示例3: validates_snapshot
def validates_snapshot(obj):
checker = Checker()
check = True
_ = obj._
checker.errors = []
if is_param(obj.input, 'title'):
check = checker.check_string(
_('Title'),
obj.input.title,
CHECK_LENGTH | CHECK_ONLYSPACE,
None,
min = NOTE_TITLE_MIN_LENGTH,
max = NOTE_TITLE_MAX_LENGTH,
) and check
if is_param(obj.input, 'value'):
check = checker.check_string(
_('Note'),
obj.input.value,
CHECK_ONLYSPACE,
None,
None,
None,
) and check
obj.view.alert = checker.errors
return check
示例4: validates_disk
def validates_disk(obj):
checker = Checker()
check = True
_ = obj._
checker.errors = []
""" TODO
# sparse
# disk
if is_param(obj.input, 'disk_size'):
check = checker.check_number(_('Disk Size (MB)'),
obj.input.disk_size,
CHECK_EMPTY | CHECK_VALID | CHECK_MIN,
min = DISK_MIN_SIZE,
) and check
else:
check = False
checker.add_error(_('"%s" is required.') % _('Disk Size (MB)'))
"""
obj.view.alert = checker.errors
return check
示例5: validates_guest_import
def validates_guest_import(obj):
checker = Checker()
check = True
_ = obj._
checker.errors = []
# TODO UUID check
obj.view.alert = checker.errors
return check
示例6: validates_nic
def validates_nic(obj):
checker = Checker()
check = True
_ = obj._
checker.errors = []
# nic_type - [phydev, virnet]
if is_param(obj.input, 'nic_type'):
if (obj.input.nic_type in ['phydev', 'virnet']) is False:
check = False
checker.add_error(_(""))
else:
check = False
checker.add_error(_('"%s" is required.') % _('Interface Type'))
# mac_address
if is_param(obj.input, 'mac_address'):
check = checker.check_macaddr(
_('MAC Address'),
obj.input.mac_address,
CHECK_EMPTY | CHECK_VALID
) and check
else:
check = False
checker.add_error(_('"%s" is required.') % _('MAC Address'))
obj.view.alert = checker.errors
return check
示例7: validates_mail
def validates_mail(obj):
checker = Checker()
check = True
_ = obj._
checker.errors = []
if not is_param(obj.input, 'hostname'):
check = False
checker.add_error(_('"%s" is required.') % _('Server Name'))
else:
check_server = checker.check_domainname(_('Server Name'),
obj.input.hostname,
CHECK_VALID,
) or \
checker.check_ipaddr(_('Server Name'),
obj.input.hostname,
CHECK_VALID,
)
check = check_server and check
if not is_param(obj.input, 'port'):
check = False
checker.add_error(_('"%s" is required.') % _('Port Number'))
else:
check = checker.check_number(_('Port Number'),
obj.input.port,
CHECK_VALID | CHECK_MIN | CHECK_MAX,
PORT_MIN_NUMBER,
PORT_MAX_NUMBER,
) and check
obj.view.alert = checker.errors
return check
示例8: compare_password
def compare_password(obj, user):
checker = Checker()
check = True
_ = obj._
checker.errors = []
if not sha1compare(user.password, obj.input.password, user.salt):
check = False
checker.add_error(_('%s is mismatched.') % _('Current Password'))
obj.view.alert = checker.errors
return check
示例9: validates_nicby1
def validates_nicby1(obj):
checker = Checker()
check = True
_ = obj._
checker.errors = []
# mac_address
if is_param(obj.input, "mac_address"):
check = checker.check_macaddr(_("MAC Address"), obj.input.mac_address, CHECK_EMPTY | CHECK_VALID) and check
obj.view.alert = checker.errors
return check
示例10: validates_staticroute
def validates_staticroute(obj):
checker = Checker()
check = True
_ = obj._
checker.errors = []
if not is_param(obj.input, 'target'):
check = False
checker.add_error(_('Specify target address for the route.'))
else:
check = checker.check_ipaddr(
_('Target'),
obj.input.target,
CHECK_EMPTY | CHECK_VALID,
) and check
if not is_param(obj.input, 'gateway'):
check = False
checker.add_error(_('Specify gateway address for the route.'))
else:
check = checker.check_ipaddr(
_('Gateway'),
obj.input.gateway,
CHECK_VALID,
) and check
obj.view.alert = checker.errors
return check
示例11: validates_tag
def validates_tag(obj):
checker = Checker()
check = True
_ = obj._
checker.errors = []
check = check and checker.check_length(
_('Tag'),
obj.input.name,
TAG_MIN_LENGTH,
TAG_MAX_LENGTH,
)
obj.view.alert = checker.errors
return check
示例12: validates_param_id
def validates_param_id(obj, user_id):
checker = Checker()
check = True
_ = obj._
checker.errors = []
check = checker.check_number(
_('User ID'),
user_id,
CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX,
min = ID_MIN_LENGTH,
max = ID_MAX_LENGTH,
) and check
obj.view.alert = checker.errors
return check
示例13: validates_iptables_save
def validates_iptables_save(obj, host):
checker = Checker()
check = True
_ = obj._
checker.errors = []
if not is_param(obj.input, 'iptables_save'):
check = False
checker.add_error(_('"%s" is required.') % _('Rule'))
else:
check = checker.check_string(
_('Rule'),
obj.input.iptables_save,
CHECK_EMPTY | CHECK_VALID,
'[^-a-zA-Z0-9_\,\.\@\$\%\!\#\*\[\]\:\/\r\n\+ ]+',
None,
None,
) and check
if check is True:
ret = iptables_lint_contents(obj.input.iptables_save, obj, host)
if str(ret) != "":
check = False
checker.add_error(ret)
"""
m = re.match(".* line (?P<line>[0-9]+).*",str(ret))
if m:
checker.add_error("LINE:"+m.group("line"))
"""
obj.view.alert = checker.errors
return check
示例14: validates_page
def validates_page(obj):
checker = Checker()
check = True
_ = obj._
checker.errors = []
if is_param(obj.input, 'p'):
check = checker.check_number(
_('Page Number'),
obj.input.p,
CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX,
min = PAGE_MIN_SIZE,
max = PAGE_MAX_SIZE,
) and check
obj.view.alert = checker.errors
return check
示例15: validates_query
def validates_query(obj):
checker = Checker()
check = True
_ = obj._
checker.errors = []
if is_param(obj.input, 'q'):
check = checker.check_string(_('Search Query'),
obj.input.q,
CHECK_EMPTY | CHECK_LENGTH | CHECK_VALID,
'[%_]',
min = SEARCH_MIN_LENGTH,
max = SEARCH_MAX_LENGTH,
) and check
obj.view.alert = checker.errors
return check