'Parse a sort direction query param from the request object.'

def _get_sort_dir(self, req):

    sort_dir = req.params.get('sort_dir', 'desc')
    if ((sort_dir is not None) and (sort_dir not in SUPPORTED_SORT_DIRS)):
        _keys = ',    '.join(SUPPORTED_SORT_DIRS)
        msg = (_('Unsupported    sort_dir.    Acceptable    values:    %s') % (_keys,))
        raise exc.HTTPBadRequest(explanation=msg)
    return sort_dir
