本文整理汇总了Python中services.managers.eve_api_manager.EveApiManager.validate_member_api方法的典型用法代码示例。如果您正苦于以下问题:Python EveApiManager.validate_member_api方法的具体用法?Python EveApiManager.validate_member_api怎么用?Python EveApiManager.validate_member_api使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类services.managers.eve_api_manager.EveApiManager
的用法示例。
在下文中一共展示了EveApiManager.validate_member_api方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean
# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import validate_member_api [as 别名]
def clean(self):
super(UpdateKeyForm, self).clean()
if 'api_id' in self.cleaned_data and 'api_key' in self.cleaned_data:
if EveManager.check_if_api_key_pair_exist(self.cleaned_data['api_id']):
logger.debug("UpdateKeyForm failed cleaning as API id %s already exists." % self.cleaned_data['api_id'])
raise forms.ValidationError(u'API key already exist')
if EveApiManager.api_key_is_valid(self.cleaned_data['api_id'], self.cleaned_data['api_key']) is False:
raise forms.ValidationError(u'API key is invalid')
chars = EveApiManager.get_characters_from_api(self.cleaned_data['api_id'], self.cleaned_data['api_key']).result
states = []
states.append(self.user_state)
for char in chars:
evechar = EveCharacter()
evechar.character_name = chars[char]['name']
evechar.corporation_id = chars[char]['corp']['id']
evechar.alliance_id = chars[char]['alliance']['id']
state = determine_membership_by_character(evechar)
logger.debug("API ID %s character %s has state %s" % (self.cleaned_data['api_id'], evechar, state))
states.append(state)
if 'MEMBER' in states:
if EveApiManager.validate_member_api(self.cleaned_data['api_id'], self.cleaned_data['api_key']) is False:
raise forms.ValidationError(u'API must meet member requirements')
if 'BLUE' in states:
if EveApiManager.validate_blue_api(self.cleaned_data['api_id'], self.cleaned_data['api_key']) is False:
raise forms.ValidationError(u'API must meet blue requirements')
return self.cleaned_data
示例2: clean
# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import validate_member_api [as 别名]
def clean(self):
super(UpdateKeyForm, self).clean()
if "api_id" in self.cleaned_data and "api_key" in self.cleaned_data:
try:
if EveManager.check_if_api_key_pair_exist(self.cleaned_data["api_id"]):
logger.debug(
"UpdateKeyForm failed cleaning as API id %s already exists." % self.cleaned_data["api_id"]
)
raise forms.ValidationError(u"API key already exist")
if EveApiManager.api_key_is_valid(self.cleaned_data["api_id"], self.cleaned_data["api_key"]) is False:
raise forms.ValidationError(u"API key is invalid")
chars = EveApiManager.get_characters_from_api(
self.cleaned_data["api_id"], self.cleaned_data["api_key"]
).result
states = []
states.append(self.user_state)
for char in chars:
evechar = EveCharacter()
evechar.character_name = chars[char]["name"]
evechar.corporation_id = chars[char]["corp"]["id"]
evechar.alliance_id = chars[char]["alliance"]["id"]
state = determine_membership_by_character(evechar)
logger.debug("API ID %s character %s has state %s" % (self.cleaned_data["api_id"], evechar, state))
states.append(state)
if "MEMBER" in states:
if (
EveApiManager.validate_member_api(self.cleaned_data["api_id"], self.cleaned_data["api_key"])
is False
):
raise forms.ValidationError(u"API must meet member requirements")
if "BLUE" in states:
if (
EveApiManager.validate_blue_api(self.cleaned_data["api_id"], self.cleaned_data["api_key"])
is False
):
raise forms.ValidationError(u"API must meet blue requirements")
return self.cleaned_data
except evelink.api.APIError as e:
logger.debug("Got error code %s while validating API %s" % (e.code, self.cleaned_data["api_id"]))
if int(e.code) in [221, 222]:
raise forms.ValidationError("API key failed validation")
else:
raise forms.ValidationError("Failed to reach API servers")
示例3: clean
# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import validate_member_api [as 别名]
def clean(self):
super(UpdateKeyForm, self).clean()
if 'api_id' in self.cleaned_data and 'api_key' in self.cleaned_data:
try:
if EveManager.check_if_api_key_pair_exist(self.cleaned_data['api_id']):
logger.debug("UpdateKeyForm failed cleaning as API id %s already exists." % self.cleaned_data['api_id'])
raise forms.ValidationError(u'API key already exist')
if EveApiManager.api_key_is_valid(self.cleaned_data['api_id'], self.cleaned_data['api_key']) is False:
raise forms.ValidationError(u'API key is invalid')
if (settings.REJECT_OLD_APIS and
EveManager.check_if_api_key_pair_is_new(self.cleaned_data['api_id'], settings.REJECT_OLD_APIS_MARGIN) is False):
raise forms.ValidationError(u'API key is too old. Please create a new key')
chars = EveApiManager.get_characters_from_api(self.cleaned_data['api_id'], self.cleaned_data['api_key']).result
states = []
states.append(self.user_state)
for char in chars:
evechar = EveCharacter()
evechar.character_name = chars[char]['name']
evechar.corporation_id = chars[char]['corp']['id']
evechar.alliance_id = chars[char]['alliance']['id']
state = determine_membership_by_character(evechar)
logger.debug("API ID %s character %s has state %s" % (self.cleaned_data['api_id'], evechar, state))
states.append(state)
if 'MEMBER' in states:
if EveApiManager.validate_member_api(self.cleaned_data['api_id'], self.cleaned_data['api_key']) is False:
raise forms.ValidationError(u'API must meet member requirements')
if 'BLUE' in states:
if EveApiManager.validate_blue_api(self.cleaned_data['api_id'], self.cleaned_data['api_key']) is False:
raise forms.ValidationError(u'API must meet blue requirements')
if 'BLUE_10' in states:
if EveApiManager.validate_blue_api(self.cleaned_data['api_id'], self.cleaned_data['api_key']) is False:
raise forms.ValidationError(u'API must meet blue requirements')
return self.cleaned_data
except evelink.api.APIError as e:
logger.debug("Got error code %s while validating API %s" % (e.code, self.cleaned_data['api_id']))
if int(e.code) in [221, 222]:
raise forms.ValidationError("API key failed validation")
else:
raise forms.ValidationError("Failed to reach API servers")