

def _primative_to_document(data, base_url=None):
    '\n    Take Python primatives as returned from parsing JSON content,\n    and return a Core API document.\n    '
    if (isinstance(data, dict) and (data.get('_type') == 'document')):
        meta = _get_dict(data, '_meta')
        url = _get_string(meta, 'url')
        url = urlparse.urljoin(base_url, url)
        title = _get_string(meta, 'title')
        content = _get_content(data, base_url=url)
        return Document(url=url, title=title, content=content)
    if (isinstance(data, dict) and (data.get('_type') == 'error')):
        meta = _get_dict(data, '_meta')
        title = _get_string(meta, 'title')
        content = _get_content(data, base_url=base_url)
        return Error(title=title, content=content)
    elif (isinstance(data, dict) and (data.get('_type') == 'link')):
        url = _get_string(data, 'url')
        url = urlparse.urljoin(base_url, url)
        action = _get_string(data, 'action')
        encoding = _get_string(data, 'encoding')
        transform = _get_string(data, 'transform')
        description = _get_string(data, 'description')
        fields = _get_list(data, 'fields')
        fields = [Field(name=_get_string(item, 'name'), required=_get_bool(item, 'required'), location=_get_string(item, 'location'), description=_get_string(item, 'description')) for item in fields if isinstance(item, dict)]
        return Link(url=url, action=action, encoding=encoding, transform=transform, description=description, fields=fields)
    elif isinstance(data, dict):
        content = _get_content(data, base_url=base_url)
        return Object(content)
    elif isinstance(data, list):
        content = [_primative_to_document(item, base_url) for item in data]
        return Array(content)
    return data

dataset/ETHPy150Open core-api/python-client/coreapi/codecs/corejson.py _primative_to_document/original