python _check_relational_existence.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python _check_relational_existence.py相关的知识,希望对你有一定的参考价值。

def _check_relational_existence(list_of_values, root_limetype):
  """
  check if the last element of the array is a valid lime property,
  other elements must be valid lime type and has BelongTo relationship to next element
  input:
    list_of_values: an array  contains lime type chain
    root_limetype: the limetype to start property checking
  return:
    raise Exception if not valid limetype detect, otherwise return True
  """
  assert(len(list_of_values) > 0)

  type_str = list_of_values[0]
  limetype = root_limetype.get_property(type_str)
  
  if len(list_of_values) == 1:
    if type_str not in [p.name for p in root_limetype.properties]:
      raise ValidationError('\'{}\' is not a property of \'{}\''.format(type_str, root_limetype.name))      
    return True
  else: # multiple element, check the first element is a valid lime type
    if not limetype:
      raise ValidationError('\'{}\' is not a valid limetype'.format(type_str))
    if not limetype.is_relation():
      raise ValidationError('\'{}\' is not a relation of \'{}\''.format(type_str, root_limetype.name))
    if not (limetype.type == 'belongsto'):
      raise ValidationError('Property \'{}\' is not a to one relation for \'{}\''.format(type_str, root_limetype.name))
    return _check_relational_existence(list_of_values[1:], limetype)

以上是关于python _check_relational_existence.py的主要内容,如果未能解决你的问题,请参考以下文章

python_特殊函数

求一道python编程题

python中的__name__

python中__call__方法解析

Python(和 Python C API):__new__ 与 __init__

python2:列表方法