@tornado.gen.coroutine
def render_focus(task, loctx, conn, focusobj):
    if focusobj is None:
        return (False, False)

    assert conn.uid == loctx.uid
    
    if type(focusobj) is list:
        restype = focusobj[0]
        
        if restype == 'player':
            player = yield motor.Op(task.app.mongodb.players.find_one,
                                    {'_id':focusobj[1]},
                                    {'name':1, 'desc':1})
            if not player:
                return ('There is no such person.', False)
            focusdesc = '%s is %s' % (player.get('name', '???'), player.get('desc', '...'))
            conn.focusdependencies.add( ('players', focusobj[1], 'desc') )
            conn.focusdependencies.add( ('players', focusobj[1], 'name') )
            return (focusdesc, False)
        
        if restype == 'portlist':
            # We've already checked access level (if indeed this portlist
            # focus array came from a {portlist} with a readaccess level).
            (dummy, plistid, editable, extratext, withback, portid) = focusobj
            
            if extratext:
                # Look up the extra text in a separate context.
                ctx = EvalPropContext(task, loctx=loctx, level=LEVEL_DISPLAY)
                extratext = yield ctx.eval(extratext, evaltype=EVALTYPE_TEXT)
                if ctx.linktargets:
                    conn.focusactions.update(ctx.linktargets)
                if ctx.dependencies:
                    conn.focusdependencies.update(ctx.dependencies)

            portlist = yield motor.Op(task.app.mongodb.portlists.find_one,
                                      {'_id':plistid})
            if not portlist:
                raise ErrorMessageException('No such portal list.')
            if 'uid' in portlist and portlist['uid'] != conn.uid:
                raise ErrorMessageException('This portal list is not yours.')
            if 'wid' in portlist and portlist['wid'] != loctx.wid:
                raise ErrorMessageException('This portal list is not available.')

            if portid:
                # We are focussed on a predetermined portal in the list.
                # Render it.
                portal = yield motor.Op(task.app.mongodb.portals.find_one,
                                        {'_id':portid})
                if not portal:
                    raise ErrorMessageException('No such portal.')
                if portal.get('plistid', None) != plistid:
                    raise ErrorMessageException('Portal does not match portlist.')

                if withback:
                    # If the player has poked into a bookshelf, show the
                    # back link (but not the bookshelf description).
                    backkey = 'plistback' + EvalPropContext.build_action_key()
                    conn.focusactions[backkey] = ('focusportal', None, plistid)
                    extratext = None
                else:
                    # Got here by an autofocus portlist, or by selecting from
                    # the player's personal portlist.
                    backkey = None
                
                yield two.execute.portal_in_reach(task.app, portal, conn.uid, loctx.wid)

                portalobj = yield two.execute.portal_description(task.app, portal, conn.uid, uidiid=loctx.iid, location=True)
                portalobj['portid'] = str(portal['_id'])
                ackey = 'port' + EvalPropContext.build_action_key()
                conn.focusactions[ackey] = ('portal', portid)
                if portalobj.get('copyable', False):
                    copykey = 'copy' + EvalPropContext.build_action_key()
                    conn.focusactions[copykey] = ('copyportal', portid)
                    portalobj['copyable'] = copykey
                    
                altloctx = two.task.LocContext(None, wid=portal['wid'], locid=portal['locid'])
                ctx = EvalPropContext(task, loctx=altloctx, level=LEVEL_FLAT)
                try:
                    desttext = yield ctx.eval('portaldesc')
                except:
                    desttext = None
                # This is a dependency on 'portaldesc', whether or not the
                # property was found.
                if ctx.linktargets:
                    conn.focusactions.update(ctx.linktargets)
                if ctx.dependencies:
                    conn.focusdependencies.update(ctx.dependencies)
                
                if not desttext:
                    desttext = task.app.localize('message.no_portaldesc') # 'The destination is hazy.'
                portalobj['view'] = desttext;
                specres = ['portal', ackey, portalobj, backkey, extratext]
                return (specres, True)

            # Render the portlist.
            if not loctx.iid:
                query = {'plistid':plistid, 'iid':None}
            else:
                query = {'plistid':plistid, '$or':[{'iid':None}, {'iid':loctx.iid}]}
            cursor = task.app.mongodb.portals.find(query)
            ls = []
            while (yield cursor.fetch_next):
                portal = cursor.next_object()
                ls.append(portal)
            # cursor autoclose
            ls.sort(key=lambda portal:portal.get('listpos', 0))

            # Note the dependencies on the world and instance portlist.
            conn.focusdependencies.add( ('portlist', plistid, None) )
            if loctx.iid:
                conn.focusdependencies.add( ('portlist', plistid, loctx.iid) )
            
            subls = []
            for portal in ls:
                desc = yield two.execute.portal_description(task.app, portal, conn.uid, uidiid=loctx.iid, short=True)
                if not desc:
                    continue
                ackey = 'plist' + EvalPropContext.build_action_key()
                conn.focusactions[ackey] = ('focusportal', portal['_id'], plistid)
                desc['target'] = ackey
                if editable and withback:
                    desc['portid'] = str(portal['_id'])
                subls.append(desc)

            editkey = None
            if editable and withback:
                editkey = 'editplist' + EvalPropContext.build_action_key()
                conn.focusactions[editkey] = ('editplist', plistid)
            specres = ['portlist', subls, extratext, editkey]
            return (specres, True)

        # Unknown format, complain
        focusdesc = '[Focus: %s]' % (focusobj,)
        return (focusdesc, False)

    if type(focusobj) is not str:
        return (str(focusobj), False)

    if focusobj.startswith('_'):
        raise Exception('Temporary variable cannot be focus: %s' % (focusobj,))

    ctx = EvalPropContext(task, loctx=loctx, level=LEVEL_DISPSPECIAL)
    focusdesc = yield ctx.eval(focusobj, evaltype=EVALTYPE_SYMBOL)
    if ctx.linktargets:
        conn.focusactions.update(ctx.linktargets)
    if ctx.dependencies:
        conn.focusdependencies.update(ctx.dependencies)
    return (focusdesc, ctx.wasspecial)
Returns ParamBag object for component "k" of self.
dataset/ETHPy150Open erkyrath/tworld/lib/two/execute.py/render_focus--crossover with--dataset/ETHPy150Open daeilkim/refinery/refinery/bnpy/bnpy-dev/bnpy/suffstats/ParamBag.py/ParamBag.getComp