Exemplo n.º 1
0
def _execute(executor_type, pathitems, params):
    """Execute an action as specified by the path"""
    try:
        executor = executor_type(params).__getattribute__(
            pathitems[0] if pathitems else 'root')
    except AttributeError:
        raise InvalidPathError('Unknown action {}'.format('/'.join(pathitems)))
    debug('Invoking action: {}', executor.__name__)
    executor(pathitems=pathitems)
Exemplo n.º 2
0
def _call(instance, func_name, data):
    try:
        func = getattr(instance, func_name)
    except AttributeError:
        raise InvalidPathError('Name of the method {} not found'.format(func_name))
    if isinstance(data, dict):
        return func(**data)
    if data is not None:
        return func(data)
    return func()
Exemplo n.º 3
0
def route(pathitems):
    """Route to the appropriate handler"""
    debug('Routing navigation request')
    root_handler = pathitems[0] if pathitems else g.MODE_DIRECTORY
    if root_handler == g.MODE_PLAY:
        from resources.lib.navigation.player import play
        play(videoid=pathitems[1:])
        return
    if root_handler == 'extrafanart':
        warn('Route: ignoring extrafanart invocation')
        _handle_endofdirectory()
        return
    nav_handler = _get_nav_handler(root_handler)
    if not nav_handler:
        from resources.lib.api.exceptions import InvalidPathError
        raise InvalidPathError('No root handler for path {}'.format(
            '/'.join(pathitems)))
    _execute(nav_handler, pathitems[1:], g.REQUEST_PARAMS)
Exemplo n.º 4
0
def route(pathitems):
    """Route to the appropriate handler"""
    debug('Routing navigation request')
    root_handler = pathitems[0] if pathitems else G.MODE_DIRECTORY
    if root_handler == G.MODE_PLAY:
        from resources.lib.navigation.player import play
        play(videoid=pathitems[1:])
    elif root_handler == G.MODE_PLAY_STRM:
        from resources.lib.navigation.player import play_strm
        play_strm(videoid=pathitems[1:])
    elif root_handler == 'extrafanart':
        warn('Route: ignoring extrafanart invocation')
        return False
    else:
        nav_handler = _get_nav_handler(root_handler)
        if not nav_handler:
            raise InvalidPathError('No root handler for path {}'.format(
                '/'.join(pathitems)))
        _execute(nav_handler, pathitems[1:], G.REQUEST_PARAMS)
    return True