本文整理汇总了Python中StatementValidator.StatementValidator类的典型用法代码示例。如果您正苦于以下问题:Python StatementValidator类的具体用法?Python StatementValidator怎么用?Python StatementValidator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StatementValidator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: agent_profile_delete
def agent_profile_delete(req_dict):
rogueparams = set(req_dict['params']) - set(["agent", "profileId"])
if rogueparams:
raise ParamError("The delete agent profile request contained unexpected parameters: %s" % ", ".join(rogueparams))
validator = StatementValidator()
if 'agent' in req_dict['params']:
try:
agent = json.loads(req_dict['params']['agent'])
req_dict['params']['agent'] = agent
except Exception:
raise ParamError("agent param for agent profile is not valid")
validator.validate_agent(agent, "agent param for agent profile")
else:
err_msg = "Error -- agent_profile - method = %s, but agent parameter missing.." % req_dict['method']
raise ParamError(err_msg)
if not 'profileId' in req_dict['params']:
err_msg = "Error -- agent_profile - method = %s, but profileId parameter missing.." % req_dict['method']
raise ParamError(err_msg)
# Extra validation if oauth
if req_dict['auth']['type'] == 'oauth':
validate_oauth_state_or_profile_agent(req_dict, "profile")
return req_dict
示例2: activity_state_put
def activity_state_put(req_dict):
rogueparams = set(req_dict['params']) - set(["activityId", "agent", "stateId", "registration"])
if rogueparams:
raise ParamError("The put activity state request contained unexpected parameters: %s" % ", ".join(rogueparams))
validator = StatementValidator()
if 'activityId' in req_dict['params']:
validator.validate_uri(req_dict['params']['activityId'], "activityId param for activity state")
else:
err_msg = "Error -- activity_state - method = %s, but activityId parameter is missing.." % req_dict['method']
raise ParamError(err_msg)
if not 'stateId' in req_dict['params']:
err_msg = "Error -- activity_state - method = %s, but stateId parameter is missing.." % req_dict['method']
raise ParamError(err_msg)
if 'registration' in req_dict['params']:
if not validate_uuid(req_dict['params']['registration']):
raise ParamError("%s is not a valid uuid for the registration parameter")
if 'agent' in req_dict['params']:
try:
agent = json.loads(req_dict['params']['agent'])
except Exception, e:
raise ParamError("agent param for activity state is not valid")
validator.validate_agent(agent, "Activity state agent param")
示例3: agent_profile_put
def agent_profile_put(req_dict):
rogueparams = set(req_dict["params"]) - set(["agent", "profileId"])
if rogueparams:
raise ParamError("The put agent profile request contained unexpected parameters: %s" % ", ".join(rogueparams))
validator = StatementValidator()
if "agent" in req_dict["params"]:
try:
agent = json.loads(req_dict["params"]["agent"])
req_dict["params"]["agent"] = agent
except Exception:
raise ParamError("agent param for agent profile is not valid")
validator.validate_agent(agent, "agent param for agent profile")
else:
err_msg = "Error -- agent_profile - method = %s, but agent parameter missing.." % req_dict["method"]
raise ParamError(err_msg)
if not "profileId" in req_dict["params"]:
err_msg = "Error -- agent_profile - method = %s, but profileId parameter missing.." % req_dict["method"]
raise ParamError(err_msg)
if "body" not in req_dict:
err_msg = "Could not find the profile document"
raise ParamError(err_msg)
# Extra validation if oauth
if req_dict["auth"]["type"] == "oauth":
validate_oauth_state_or_profile_agent(req_dict, "profile")
req_dict["profile"] = req_dict.pop("raw_body", req_dict.pop("body", None))
return req_dict
示例4: agent_profile_put
def agent_profile_put(req_dict):
rogueparams = set(req_dict['params']) - set(["agent", "profileId"])
if rogueparams:
raise ParamError(
"The put agent profile request contained unexpected parameters: %s" % ", ".join(rogueparams))
validator = StatementValidator()
if 'agent' in req_dict['params']:
try:
agent = convert_to_datatype(req_dict['params']['agent'])
req_dict['params']['agent'] = agent
except Exception:
raise ParamError("agent param %s is not valid" % \
req_dict['params']['agent'])
validator.validate_agent(agent, "Agent param")
else:
err_msg = "Error -- agent_profile - method = %s, but agent parameter missing.." % req_dict[
'method']
raise ParamError(err_msg)
if 'profileId' not in req_dict['params']:
err_msg = "Error -- agent_profile - method = %s, but profileId parameter missing.." % req_dict[
'method']
raise ParamError(err_msg)
if 'body' not in req_dict:
err_msg = "Could not find the profile document"
raise ParamError(err_msg)
# Extra validation if oauth
if req_dict['auth']['type'] == 'oauth':
validate_oauth_for_documents(req_dict, "agent profile")
req_dict['profile'] = req_dict.pop('raw_body', req_dict.pop('body', None))
return req_dict
示例5: activities_get
def activities_get(req_dict):
rogueparams = set(req_dict['params']) - set(["activityId"])
if rogueparams:
raise ParamError(
"The get activities request contained unexpected parameters: %s" % ", ".join(rogueparams))
validator = StatementValidator()
try:
activity_id = req_dict['params']['activityId']
except KeyError:
err_msg = "Error -- activities - method = %s, but activityId parameter is missing" % req_dict[
'method']
raise ParamError(err_msg)
else:
validator.validate_iri(
activity_id, "activityId param")
# Try to retrieve activity, if DNE then return empty else return activity
# info
try:
Activity.objects.get(activity_id=activity_id, authority__isnull=False)
except Activity.DoesNotExist:
err_msg = "No activity found with ID %s" % activity_id
raise IDNotFoundError(err_msg)
return req_dict
示例6: agent_profile_get
def agent_profile_get(req_dict):
rogueparams = set(req_dict['params']) - \
set(["agent", "profileId", "since"])
if rogueparams:
raise ParamError(
"The get agent profile request contained unexpected parameters: %s" % ", ".join(rogueparams))
validator = StatementValidator()
if 'agent' in req_dict['params']:
try:
agent = convert_to_datatype(req_dict['params']['agent'])
req_dict['params']['agent'] = agent
except Exception:
raise ParamError("agent param %s is not valid" % \
req_dict['params']['agent'])
validator.validate_agent(agent, "Agent param")
else:
err_msg = "Error -- agent_profile - method = %s, but agent parameter missing.." % req_dict[
'method']
raise ParamError(err_msg)
if 'since' in req_dict['params']:
try:
parse_datetime(req_dict['params']['since'])
except (Exception, ISO8601Error):
raise ParamError(
"Since parameter was not a valid ISO8601 timestamp")
# Extra validation if oauth
if req_dict['auth']['type'] == 'oauth':
validate_oauth_for_documents(req_dict, "agent profile")
return req_dict
示例7: activity_profile_put
def activity_profile_put(req_dict):
rogueparams = set(req_dict['params']) - set(["activityId", "profileId"])
if rogueparams:
raise ParamError(
"The put activity profile request contained unexpected parameters: %s" % ", ".join(rogueparams))
validator = StatementValidator()
if 'activityId' in req_dict['params']:
validator.validate_iri(
req_dict['params']['activityId'], "activityId param for activity profile")
else:
err_msg = "Error -- activity_profile - method = %s, but activityId parameter missing.." % req_dict[
'method']
raise ParamError(err_msg)
if 'profileId' not in req_dict['params']:
err_msg = "Error -- activity_profile - method = %s, but profileId parameter missing.." % req_dict[
'method']
raise ParamError(err_msg)
if 'body' not in req_dict:
err_msg = "Could not find the profile document"
raise ParamError(err_msg)
# Set profile - req_parse converts all request bodies to dict, act profile needs it as string and need to replace single quotes with double quotes
# b/c of quotation issue when using javascript with activity profile
req_dict['profile'] = req_dict.pop('raw_body', req_dict.pop('body', None))
return req_dict
示例8: server_validation
def server_validation(stmt_set, auth, payload_sha2s):
auth_validated = False
if type(stmt_set) is list:
for stmt in stmt_set:
server_validation(stmt, auth, payload_sha2s)
else:
if 'id' in stmt_set:
statement_id = stmt_set['id']
if check_for_existing_statementId(statement_id):
err_msg = "A statement with ID %s already exists" % statement_id
raise ParamConflict(err_msg)
server_validate_statement_object(stmt_set['object'], auth)
if stmt_set['verb']['id'] == 'http://adlnet.gov/expapi/verbs/voided':
validate_void_statement(stmt_set['object']['id'])
if not 'objectType' in stmt_set['object'] or stmt_set['object']['objectType'] == 'Activity':
get_act_def_data(stmt_set['object'])
try:
validator = StatementValidator(None)
validator.validate_activity(stmt_set['object'])
except Exception, e:
raise BadRequest(e.message)
except ParamError, e:
raise ParamError(e.message)
示例9: agents_get
def agents_get(req_dict):
rogueparams = set(req_dict['params']) - set(["agent"])
if rogueparams:
raise ParamError(
"The get agent request contained unexpected parameters: %s" % ", ".join(rogueparams))
try:
req_dict['params']['agent']
except KeyError:
err_msg = "Error -- agents url, but no agent parameter.. the agent parameter is required"
raise ParamError(err_msg)
validator = StatementValidator()
if 'agent' in req_dict['params']:
try:
agent = convert_to_datatype(req_dict['params']['agent'])
except Exception:
raise ParamError("agent param %s is not valid" % \
req_dict['params']['agent'])
validator.validate_agent(agent, "Agent param")
params = get_agent_ifp(agent)
if not Agent.objects.filter(**params).exists():
raise IDNotFoundError(
"Error with Agent. The agent partial did not match any agents on record")
req_dict['agent_ifp'] = params
return req_dict
示例10: activity_profile_post
def activity_profile_post(req_dict):
rogueparams = set(req_dict['params']) - set(["activityId", "profileId"])
if rogueparams:
raise ParamError("The post activity profile request contained unexpected parameters: %s" % ", ".join(rogueparams))
validator = StatementValidator()
if 'activityId' in req_dict['params']:
validator.validate_uri(req_dict['params']['activityId'], "activityId param for activity profile")
else:
err_msg = "Error -- activity_profile - method = %s, but activityId parameter missing.." % req_dict['method']
raise ParamError(err_msg)
if not 'profileId' in req_dict['params']:
err_msg = "Error -- activity_profile - method = %s, but profileId parameter missing.." % req_dict['method']
raise ParamError(err_msg)
if 'headers' not in req_dict or ('CONTENT_TYPE' not in req_dict['headers'] or req_dict['headers']['CONTENT_TYPE'] != "application/json"):
err_msg = "The content type for activity profile POSTs must be application/json"
raise ParamError(err_msg)
if 'body' not in req_dict:
err_msg = "Could not find the profile document"
raise ParamError(err_msg)
req_dict['profile'] = req_dict.pop('raw_body', req_dict.pop('body', None))
return req_dict
示例11: agent_profile_get
def agent_profile_get(req_dict):
rogueparams = set(req_dict["params"]) - set(["agent", "profileId", "since"])
if rogueparams:
raise ParamError("The get agent profile request contained unexpected parameters: %s" % ", ".join(rogueparams))
validator = StatementValidator()
if "agent" in req_dict["params"]:
try:
agent = json.loads(req_dict["params"]["agent"])
req_dict["params"]["agent"] = agent
except Exception:
raise ParamError("agent param for agent profile is not valid")
validator.validate_agent(agent, "agent param for agent profile")
else:
err_msg = "Error -- agent_profile - method = %s, but agent parameter missing.." % req_dict["method"]
raise ParamError(err_msg)
if "since" in req_dict["params"]:
try:
parse_datetime(req_dict["params"]["since"])
except (Exception, ISO8601Error):
raise ParamError("Since parameter was not a valid ISO8601 timestamp")
# Extra validation if oauth
if req_dict["auth"]["type"] == "oauth":
validate_oauth_state_or_profile_agent(req_dict, "profile")
return req_dict
示例12: statements_post
def statements_post(req_dict):
if req_dict['params'].keys():
raise ParamError("The post statements request contained unexpected parameters: %s" % ", ".join(req_dict['params'].keys()))
try:
validator = StatementValidator(req_dict['body'])
validator.validate()
except Exception, e:
raise BadRequest(e.message)
示例13: statements_post
def statements_post(req_dict):
if req_dict['params'].keys() and not ignore_rogue_params:
raise ParamError("The post statements request contained unexpected parameters: %s" % ", ".join(req_dict['params'].keys()))
if isinstance(req_dict['body'], basestring):
req_dict['body'] = convert_to_dict(req_dict['body'])
try:
validator = StatementValidator(req_dict['body'])
validator.validate()
except Exception, e:
raise BadRequest(e.message)
示例14: agent_profile_delete
def agent_profile_delete(req_dict):
rogueparams = set(req_dict['params']) - set(["agent", "profileId"])
if rogueparams:
raise ParamError("The delete agent profile request contained unexpected parameters: %s" % ", ".join(rogueparams))
validator = StatementValidator()
if 'agent' in req_dict['params']:
try:
agent = json.loads(req_dict['params']['agent'])
except Exception, e:
raise ParamError("agent param for agent profile is not valid")
validator.validate_agent(agent, "agent param for agent profile")
示例15: activity_profile_post
def activity_profile_post(req_dict):
rogueparams = set(req_dict['params']) - set(["activityId", "profileId"])
if rogueparams:
raise ParamError(
"The post activity profile request contained unexpected parameters: %s" % ", ".join(rogueparams))
validator = StatementValidator()
if 'activityId' in req_dict['params']:
validator.validate_iri(
req_dict['params']['activityId'], "activityId param for activity profile")
else:
err_msg = "Error -- activity_profile - method = %s, but activityId parameter missing.." % req_dict[
'method']
raise ParamError(err_msg)
if 'profileId' not in req_dict['params']:
err_msg = "Error -- activity_profile - method = %s, but profileId parameter missing.." % req_dict[
'method']
raise ParamError(err_msg)
if 'body' not in req_dict:
err_msg = "Could not find the profile document"
raise ParamError(err_msg)
# Check json for incoming POSTed document
if "application/json" not in req_dict['headers']['CONTENT_TYPE']:
raise ParamError(
"Activity profile document to be posted does not have a Content-Type of 'application/json'")
# expected to be json
try:
raw_profile = req_dict.pop('raw_body', req_dict.pop('body', None))
convert_to_datatype(raw_profile)
except Exception:
raise ParamError("Activity profile document is not valid JSON")
else:
req_dict['profile'] = raw_profile
# Check the content type if the document already exists
exists = False
try:
p = ActivityProfile.objects.get(activity_id=req_dict['params']['activityId'],
profile_id=req_dict['params']['profileId'])
exists = True
except ActivityProfile.DoesNotExist:
pass
# Since document to be POSTed has to be json, so does the existing document
if exists and str(p.content_type) != "application/json":
raise ParamError("Activity profile already exists but is not JSON, cannot update it with new JSON document")
return req_dict