'Add entry to Aria2'

def add_entry(self, aria2, entry, config):

    options = config[u'options']
    try:
        options[u'dir'] = os.path.expanduser(entry.render(config[u'path']).rstrip(u'/'))
    except RenderError as e:
        entry.fail((u"failed    to    render    'path':    %s" % e))
        return
    if (u'filename' in config):
        try:
            options[u'out'] = os.path.expanduser(entry.render(config[u'filename']))
        except RenderError as e:
            entry.fail((u"failed    to    render    'filename':    %s" % e))
            return
    secret = None
    if config[u'secret']:
        secret = (u'token:%s' % config[u'secret'])
    if (u'torrent' in entry):
        if (u'file' in entry):
            torrent_file = entry[u'file']
        elif (u'location' in entry):
            torrent_file = entry[u'location']
        else:
            entry.fail(u'Cannot    find    torrent    file')
            return
        if secret:
            return aria2.addTorrent(secret, xmlrpc.client.Binary(open(torrent_file, mode=u'rb').read()), [], options)
        return aria2.addTorrent(xmlrpc.client.Binary(open(torrent_file, mode=u'rb').read()), [], options)
    if secret:
        return aria2.addUri(secret, [entry[u'url']], options)
    return aria2.addUri([entry[u'url']], options)
