Source

hydra / apps / all_docs / updates / doc.py

def update_doc(doc, req):
    http = require('lib/http')

    new_doc = {}
    if req.get('body'):
        content = require('lib/content')['provider']()
        new_doc = content.decode(req)
        if not isinstance(new_doc, dict):
            msg = 'body as object expected, got %r' % type(new_doc)
            return [None, http['400'](msg, req)]

    if not doc:
        new_doc['_id'] = req.get('id') or new_doc.get('_id') or req['uuid']
    else:
        require('lib/doc/version')['make_as_attachment'](doc)
        for key in list(doc):
            if key.startswith(('_', '.')):
                new_doc[key] = doc[key]

    require('lib/doc/meta')['sign'](new_doc, req)

    return [new_doc, http['201']({'status': 'ok', 'id': new_doc['_id']}, req)]