properties.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:core-framework 作者: RedhawkSDR 项目源码 文件源码
def struct_fields(value):
    if isinstance(value, types.ClassType) or hasattr(value, '__bases__'):
        clazz = value
    else:
        clazz = type(value)
    # Try to get the correct field ordering, if it is available, otherwise
    # just look at the class dictionary to find the fields.
    fields = getattr(clazz, '__fields', None)
    if fields is None:
        fields = [p for p in clazz.__dict__.itervalues() if isinstance(p, simple_property)]
        fields += [p for p in clazz.__dict__.itervalues() if isinstance(p, simpleseq_property)]
    members = inspect.getmembers(value)
    for member in members:
        if isinstance(member[1], simple_property) or isinstance(member[1], simpleseq_property):
            foundMatch = False
            for field in fields:
                if member[1].id_ == field.id_:
                    foundMatch = True
                    break
            if not foundMatch:
                fields += [member[1]]
    return fields
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号