本文整理汇总了Python中ui.UI.get_error_types方法的典型用法代码示例。如果您正苦于以下问题:Python UI.get_error_types方法的具体用法?Python UI.get_error_types怎么用?Python UI.get_error_types使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ui.UI
的用法示例。
在下文中一共展示了UI.get_error_types方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: filter_parse
# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_error_types [as 别名]
def filter_parse(self, command):
"""
Parses and validates the filter command
Input:
command - the user command
Return:
True on valid and False otherwise
"""
self.set_command(command)
# filter by total amount greater than
pattern_total_greater = self._regex_search(self._PATTERN_FILTER_GREATER_THAN_TOTAL)
if pattern_total_greater:
greater = pattern_total_greater.group(1)
self._parsed_command = {"greater": greater, "type": None}
return True
# filter by only apartments having that type
pattern_by_type = self._regex_search(self._PATTERN_FILTER_BY_TYPE)
if pattern_by_type:
expense_type = pattern_by_type.group(1)
if not Apartment.is_expense_type(expense_type):
UI.set_message(UI.get_error_types())
return False
self._parsed_command = {"greater": None, "type": expense_type}
return True
UI.set_message(UI.get_error_filter())
return False
示例2: sort_parse
# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_error_types [as 别名]
def sort_parse(self, command, reverse=False):
"""
Parses and validates the sort command
Input:
command - the user command
reverse - the order of the sort
Return:
True on valid and False otherwise
"""
self.set_command(command)
# simple sort no type use total expense
pattern_sort = self._regex_search(self._PATTERN_SORT)
if pattern_sort:
self._parsed_command = {"type": None, "reverse": reverse}
return True
# use an expense type for the sort
pattern_sort_by_type = self._regex_search(self._PATTERN_SORT_BY_TYPE)
if pattern_sort_by_type:
expense_type = pattern_sort_by_type.group(1)
if not Apartment.is_expense_type(expense_type):
UI.set_message(UI.get_error_types())
return False
self._parsed_command = {"type": expense_type, "reverse": reverse}
return True
UI.set_message(UI.get_error_sort())
return False
示例3: _insert_or_replace_apartment_parse
# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_error_types [as 别名]
def _insert_or_replace_apartment_parse(self, command, command_type):
"""
Protected parse method for insert and replace
Input:
command - the user command
command_type - the command_type, can be insert or replace
Return:
True on valid and False otherwise
Raises:
Exception on invalid command_type
"""
self.set_command(command)
# get the correct pattern
if command_type is "insert":
pattern = self._regex_search(self._PATTERN_INSERT)
if not pattern:
UI.set_message(UI.get_error("insert <amount>, <expense_type> at <apartment_id>"))
return False
elif command_type is "replace":
pattern = self._regex_search(self._PATTERN_REPLACE)
if not pattern:
UI.set_message(UI.get_error("replace <amount>, <expense_type> at <apartment_id>"))
return False
else:
raise Exception("command type is incorrect")
# get the data
amount = pattern.group(1)
expense_type = pattern.group(2)
apartment_id = pattern.group(3)
# wrong type
if not Apartment.is_expense_type(expense_type):
UI.set_message(UI.get_error_types())
return False
if command_type is "insert":
# apartment does exist in the list
if self.is_apartment(apartment_id):
UI.set_message("Apartment " + apartment_id + " does exist in the list. "
"Use this command to replace: replace " + amount + ", " +
expense_type + " at " + apartment_id)
return False
elif command_type is "replace":
# apartment does not exist in the list
if not self.is_apartment(apartment_id):
UI.set_message("Apartment " + apartment_id + " does not exist in the list. "
"Use this command to add: insert " + amount + ", " +
expense_type + " at " + apartment_id)
return False
# all good
self._parsed_command = {"type": expense_type, "amount": amount, "id": apartment_id}
return True
示例4: remove_apartment_parse
# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_error_types [as 别名]
def remove_apartment_parse(self, command):
"""
Parses and validates the remove command
Input:
command - the user command
Return:
True on valid and False otherwise
"""
self.set_command(command)
# first case by apartment id
pattern_remove_by_id = self._regex_search(self._PATTERN_REMOVE_BY_ID)
if pattern_remove_by_id:
apartment_id = pattern_remove_by_id.group(1)
if not self.is_apartment(apartment_id):
UI.set_message(
"Apartment " + apartment_id + " does not exist in this list so all the expenses are by default 0")
return False
self._parsed_command = {"id": apartment_id}
return True
# second case remove from interval
pattern_remove_by_interval = self._regex_search(self._PATTERN_REMOVE_BY_INTERVAL)
if pattern_remove_by_interval:
id_min = pattern_remove_by_interval.group(1)
id_max = pattern_remove_by_interval.group(2)
self._parsed_command = {"id_min": id_min, "id_max": id_max}
return True
# third case by type
pattern_remove_by_type = self._regex_search(self._PATTERN_REMOVE_BY_TYPE)
if pattern_remove_by_type:
expense_type = pattern_remove_by_type.group(1)
if not Apartment.is_expense_type(expense_type):
UI.set_message(UI.get_error_types())
return False
self._parsed_command = {"type": expense_type}
return True
UI.set_message(UI.get_error("remove <apartment_id> \n\tremove from 5 to 10 \n\tremove type"))
return False
示例5: stat_total_type_parse
# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_error_types [as 别名]
def stat_total_type_parse(self, command):
"""
Parses and validates the 'sum type' command
Input:
command - the user command
Return:
True on valid and False otherwise
"""
self.set_command(command)
# sum <type>
pattern_sum = self._regex_search(self._PATTERN_STAT_TOTAL_TYPE)
if pattern_sum:
expense_type = pattern_sum.group(1)
if not Apartment.is_expense_type(expense_type):
UI.set_message(UI.get_error_types())
return False
self._parsed_command = {"expense_type": expense_type}
return True
UI.set_message(UI.get_error("sum <type>"))
return False
示例6: list_by_type_parse
# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_error_types [as 别名]
def list_by_type_parse(self, command):
"""
Parses and validates the list command
Input:
command - the user command
Return:
True on valid and False otherwise
"""
self.set_command(command)
# list <type>
pattern_type = self._regex_search(self._PATTERN_LIST_BY_TYPE)
if pattern_type:
expense_type = pattern_type.group(1)
if not Apartment.is_expense_type(expense_type):
UI.set_message(UI.get_error_types())
return False
self._parsed_command = {"expense_type": expense_type}
return True
UI.set_message(UI.get_error("list <expense_type>"))
return False