当前位置: 首页>>代码示例>>Python>>正文


Python StatementValidator.validate_uuid方法代码示例

本文整理汇总了Python中StatementValidator.StatementValidator.validate_uuid方法的典型用法代码示例。如果您正苦于以下问题:Python StatementValidator.validate_uuid方法的具体用法?Python StatementValidator.validate_uuid怎么用?Python StatementValidator.validate_uuid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StatementValidator.StatementValidator的用法示例。


在下文中一共展示了StatementValidator.validate_uuid方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: activity_state_delete

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_uuid [as 别名]
def activity_state_delete(req_dict):
    rogueparams = set(req_dict['params']) - set(["activityId", "agent", "stateId", "registration"])
    if rogueparams:
        raise ParamError("The delete activity state 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 state")
    else:
        err_msg = "Error -- activity_state - method = %s, but activityId parameter is missing.." % req_dict['method']
        raise ParamError(err_msg)

    if 'registration' in req_dict['params']:
        validator.validate_uuid(req_dict['params']['registration'], "registration param for activity state")

    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 activity state is not valid")
        validator.validate_agent(agent, "Activity state agent param")
    else:
        err_msg = "Error -- activity_state - method = %s, but agent parameter is 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, "state")
    return req_dict
开发者ID:roadlit,项目名称:lrs,代码行数:32,代码来源:req_validate.py

示例2: activity_state_put

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_uuid [as 别名]
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_iri(
            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 'stateId' not 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']:
        validator.validate_uuid(
            req_dict['params']['registration'], "registration param for activity state")

    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 -- activity_state - method = %s, but agent parameter is missing.." % req_dict[
            'method']
        raise ParamError(err_msg)

    # Must have body included for state
    if 'body' not in req_dict:
        err_msg = "Could not find the state"
        raise ParamError(err_msg)

    # Extra validation if oauth
    if req_dict['auth']['type'] == 'oauth':
        validate_oauth_for_documents(req_dict, "state")

    # Set state
    req_dict['state'] = req_dict.pop('raw_body', req_dict.pop('body', None))
    return req_dict
开发者ID:adlnet,项目名称:ADL_LRS,代码行数:52,代码来源:req_validate.py

示例3: activity_state_get

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_uuid [as 别名]
def activity_state_get(req_dict):
    rogueparams = set(req_dict['params']) - set(["activityId",
                                                 "agent", "stateId", "registration", "since"])
    if rogueparams:
        raise ParamError(
            "The get activity state 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 state")
    else:
        err_msg = "Error -- activity_state - method = %s, but activityId parameter is missing.." % req_dict[
            'method']
        raise ParamError(err_msg)

    if 'registration' in req_dict['params']:
        validator.validate_uuid(
            req_dict['params']['registration'], "registration param for activity state")

    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 -- activity_state - method = %s, but agent parameter is 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, "state")
    return req_dict
开发者ID:adlnet,项目名称:ADL_LRS,代码行数:46,代码来源:req_validate.py

示例4: activity_state_put

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_uuid [as 别名]
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_iri(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"]:
        validator.validate_uuid(req_dict["params"]["registration"], "registration param for activity state")

    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 activity state is not valid")
        validator.validate_agent(agent, "Activity state agent param")
    else:
        err_msg = "Error -- activity_state - method = %s, but agent parameter is missing.." % req_dict["method"]
        raise ParamError(err_msg)

    # Must have body included for state
    if "body" not in req_dict:
        err_msg = "Could not find the state"
        raise ParamError(err_msg)

    # Extra validation if oauth
    if req_dict["auth"]["type"] == "oauth":
        validate_oauth_state_or_profile_agent(req_dict, "state")

    # Set state
    req_dict["state"] = req_dict.pop("raw_body", req_dict.pop("body", None))
    return req_dict
开发者ID:xiaolidefeidao,项目名称:iccnu_adl_lrs,代码行数:44,代码来源:req_validate.py

示例5: activity_state_get

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_uuid [as 别名]
def activity_state_get(req_dict):
    rogueparams = set(req_dict["params"]) - set(["activityId", "agent", "stateId", "registration", "since"])
    if rogueparams:
        raise ParamError("The get activity state 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 state")
    else:
        err_msg = "Error -- activity_state - method = %s, but activityId parameter is missing.." % req_dict["method"]
        raise ParamError(err_msg)

    if "registration" in req_dict["params"]:
        validator.validate_uuid(req_dict["params"]["registration"], "registration param for activity state")

    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 activity state is not valid")
        validator.validate_agent(agent, "Activity state agent param")
    else:
        err_msg = "Error -- activity_state - method = %s, but agent parameter is 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, "state")
    return req_dict
开发者ID:xiaolidefeidao,项目名称:iccnu_adl_lrs,代码行数:38,代码来源:req_validate.py

示例6: activity_state_post

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_uuid [as 别名]
def activity_state_post(req_dict):
    rogueparams = set(req_dict['params']) - \
        set(["activityId", "agent", "stateId", "registration"])
    if rogueparams:
        raise ParamError(
            "The post activity state 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 state")
    else:
        err_msg = "Error -- activity_state - method = %s, but activityId parameter is missing.." % req_dict[
            'method']
        raise ParamError(err_msg)

    if 'stateId' not 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']:
        validator.validate_uuid(
            req_dict['params']['registration'], "registration param for activity state")

    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 -- activity_state - method = %s, but agent parameter is missing.." % req_dict[
            'method']
        raise ParamError(err_msg)

    # Must have body included for state
    if 'body' not in req_dict:
        err_msg = "Could not find the state"
        raise ParamError(err_msg)

    # Extra validation if oauth
    if req_dict['auth']['type'] == 'oauth':
        validate_oauth_for_documents(req_dict, "state")

    # Check json for incoming POSTed document
    if "application/json" not in req_dict['headers']['CONTENT_TYPE']:
        raise ParamError(
            "Activity state document to be posted does not have a Content-Type of 'application/json'")

    # expected to be json
    try:
        raw_state = req_dict.pop('raw_body', req_dict.pop('body', None))
        convert_to_datatype(raw_state)
    except Exception:
        raise ParamError("Activity state document is not valid JSON")
    else:
        req_dict['state'] = raw_state

    # Check the content type if the document already exists
    registration = req_dict['params'].get('registration', None)
    agent = req_dict['params']['agent']
    a = Agent.objects.retrieve_or_create(**agent)[0]
    exists = False
    if registration:
        try:
            s = ActivityState.objects.get(state_id=req_dict['params']['stateId'], agent=a,
                                          activity_id=req_dict['params']['activityId'], registration_id=req_dict['params']['registration'])
            exists = True
        except ActivityState.DoesNotExist:
            pass
    else:
        try:
            s = ActivityState.objects.get(state_id=req_dict['params']['stateId'], agent=a,
                                          activity_id=req_dict['params']['activityId'])
            exists = True
        except ActivityState.DoesNotExist:
            pass
    
    if exists and str(s.content_type) != "application/json":
        raise ParamError("Activity state already exists but is not JSON, cannot update it with new JSON document")
    return req_dict
开发者ID:adlnet,项目名称:ADL_LRS,代码行数:86,代码来源:req_validate.py

示例7: statements_get

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_uuid [as 别名]

#.........这里部分代码省略.........
    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")    

    formats = ['exact', 'canonical', 'ids']
    if 'format' in req_dict['params']:
        if req_dict['params']['format'] not in formats:
            raise ParamError("The format filter value (%s) was not one of the known values: %s" % (
                req_dict['params']['format'], ','.join(formats)))
    else:
        req_dict['params']['format'] = 'exact'

    # StatementId could be for voided statement as well
    if 'statementId' in req_dict['params'] or 'voidedStatementId' in req_dict['params']:
        req_dict['statementId'] = validate_statementId(req_dict)

    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")

    if 'until' in req_dict['params']:
        try:
            parse_datetime(req_dict['params']['until'])
        except (Exception, ISO8601Error):
            raise ParamError(
                "until parameter was not a valid ISO8601 timestamp")

    if 'ascending' in req_dict['params']:
        if req_dict['params']['ascending'].lower() == 'true':
            req_dict['params']['ascending'] = True
        elif req_dict['params']['ascending'].lower() == 'false':
            req_dict['params']['ascending'] = False
        else:
            raise ParamError(
                "ascending parameter was not a boolean value")
    else:
        req_dict['params']['ascending'] = False

    if 'related_agents' in req_dict['params']:
        if req_dict['params']['related_agents'].lower() == 'true':
            req_dict['params']['related_agents'] = True
        elif req_dict['params']['related_agents'].lower() == 'false':
            req_dict['params']['related_agents'] = False
        else:
            raise ParamError(
                "related_agents parameter was not a boolean value")
    else:
        req_dict['params']['related_agents'] = False

    if 'related_activities' in req_dict['params']:
        if req_dict['params']['related_activities'].lower() == 'true':
            req_dict['params']['related_activities'] = True
        elif req_dict['params']['related_activities'].lower() == 'false':
            req_dict['params']['related_activities'] = False
        else:
            raise ParamError(
                "related_activities parameter was not a boolean value")
    else:
        req_dict['params']['related_activities'] = False

    if 'attachments' in req_dict['params']:
        if req_dict['params']['attachments'].lower() == 'true':
            req_dict['params']['attachments'] = True
        elif req_dict['params']['attachments'].lower() == 'false':
            req_dict['params']['attachments'] = False
        else:
            raise ParamError(
                "attachments parameter was not a boolean value")
    else:
        req_dict['params']['attachments'] = False

    if 'limit' in req_dict['params']:
        try:
            req_dict['params']['limit'] = int(req_dict['params']['limit'])
        except Exception:
            raise ParamError(
                "limit parameter was not a non-negative integer")
        else:
            if req_dict['params']['limit'] < 0:
                raise ParamError(
                    "limit parameter was not a non-negative integer")                
    else:
        req_dict['params']['limit'] = 0

    if 'registration' in req_dict['params']:
        validator.validate_uuid(req_dict['params']['registration'], "Registration param")          

    if 'verb' in req_dict['params']:
        validator.validate_iri(
                    req_dict['params']['verb'], "verb param")
    return req_dict
开发者ID:adlnet,项目名称:ADL_LRS,代码行数:104,代码来源:req_validate.py

示例8: activity_state_post

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_uuid [as 别名]
def activity_state_post(req_dict):
    rogueparams = set(req_dict["params"]) - set(["activityId", "agent", "stateId", "registration"])
    if rogueparams:
        raise ParamError("The post activity state 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 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"]:
        validator.validate_uuid(req_dict["params"]["registration"], "registration param for activity state")

    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 activity state is not valid")
        validator.validate_agent(agent, "Activity state agent param")
    else:
        err_msg = "Error -- activity_state - method = %s, but agent parameter is missing.." % req_dict["method"]
        raise ParamError(err_msg)

    # Must have body included for state
    if "body" not in req_dict:
        err_msg = "Could not find the state"
        raise ParamError(err_msg)

    # Extra validation if oauth
    if req_dict["auth"]["type"] == "oauth":
        validate_oauth_state_or_profile_agent(req_dict, "state")

    # Check the content type if the document already exists
    registration = req_dict["params"].get("registration", None)
    agent = req_dict["params"]["agent"]
    a = Agent.objects.retrieve_or_create(**agent)[0]
    exists = False
    if registration:
        try:
            s = ActivityState.objects.get(
                state_id=req_dict["params"]["stateId"],
                agent=a,
                activity_id=req_dict["params"]["activityId"],
                registration_id=req_dict["params"]["registration"],
            )
            exists = True
        except ActivityState.DoesNotExist:
            pass
    else:
        try:
            s = ActivityState.objects.get(
                state_id=req_dict["params"]["stateId"], agent=a, activity_id=req_dict["params"]["activityId"]
            )
            exists = True
        except ActivityState.DoesNotExist:
            pass
    if exists:
        if str(s.content_type) != "application/json" or (
            "application/json" not in req_dict["headers"]["CONTENT_TYPE"]
            or req_dict["headers"]["CONTENT_TYPE"] != "application/json"
        ):
            raise ParamError(
                "Neither original document or document to be posted has a Content-Type of 'application/json'"
            )

    # Set state
    req_dict["state"] = req_dict.pop("raw_body", req_dict.pop("body", None))
    return req_dict
开发者ID:xiaolidefeidao,项目名称:iccnu_adl_lrs,代码行数:77,代码来源:req_validate.py


注:本文中的StatementValidator.StatementValidator.validate_uuid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。