示例#1
0
def InternObject(obj):
    """Copies and interns strings in a recursive object."""
    obj_cls = obj.__class__
    if obj_cls is str:
        return sys.intern(obj)

    if obj_cls is str:
        return sys.intern(str(obj))

    if obj_cls is dict:
        result = {}
        for k, v in list(obj.items()):
            k = InternObject(k)
            v = InternObject(v)
            result[k] = v

        return result

    if obj_cls is list:
        return [InternObject(x) for x in obj]

    return obj
示例#2
0
文件: utils.py 项目: scudette/rekall
def InternObject(obj):
    """Copies and interns strings in a recursive object."""
    obj_cls = obj.__class__
    if obj_cls is str:
        return sys.intern(obj)

    if obj_cls is str:
        return sys.intern(str(obj))

    if obj_cls is dict:
        result = {}
        for k, v in list(obj.items()):
            k = InternObject(k)
            v = InternObject(v)
            result[k] = v

        return result

    if obj_cls is list:
        return [InternObject(x) for x in obj]

    return obj