How to use the arxiv.status.HTTP_404_NOT_FOUND function in arxiv

To help you get started, we’ve selected a few arxiv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github arXiv / arxiv-browse / tests / test_exceptions.py View on Github external
f'should get 404 for {path}')
            self.assertIn('text/html', response.content_type)

        response = self.client.get('/abs/1307.0001v999')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         f'should get 404 for known paper ID with '
                         'nonexistent version')
        response = self.client.get('/abs/alg-geom/07059999')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         f'should get 404 for valid old paper ID '
                         'with nonexistent paper number affix')
        response = self.client.get('/abs/astro-ph/0110242')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         f'should get 404 for known deleted paper')
        response = self.client.get('/abs/foo-bar/11223344')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         f'should get 404 for bad paper ID')
github arXiv / arxiv-search / tests / test_exceptions.py View on Github external
def test_404(self):
        """A 404 response should be returned."""
        response = self.client.get('/foo')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        self.assertIn('text/html', response.content_type)
github arXiv / arxiv-browse / tests / test_exceptions.py View on Github external
def test_404(self):
        """A 404 response should be returned."""
        for path in ('/foo', '/abs', '/abs/'):
            response = self.client.get(path)
            self.assertEqual(response.status_code,
                             status.HTTP_404_NOT_FOUND,
                             f'should get 404 for {path}')
            self.assertIn('text/html', response.content_type)

        response = self.client.get('/abs/1307.0001v999')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         f'should get 404 for known paper ID with '
                         'nonexistent version')
        response = self.client.get('/abs/alg-geom/07059999')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         f'should get 404 for valid old paper ID '
                         'with nonexistent paper number affix')
        response = self.client.get('/abs/astro-ph/0110242')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         f'should get 404 for known deleted paper')
        response = self.client.get('/abs/foo-bar/11223344')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
github arXiv / arxiv-search / tests / test_advanced_search.py View on Github external
def test_nonexistant_archive_shortcut(self):
        """User requests a sub-path with non-existant archive."""
        response = self.client.get('/advanced/fooarchive')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         "Should return a 404 error")
github arXiv / arxiv-browse / browse / controllers / archive_page / __init__.py View on Github external
def get_archive(archive_id: str) -> Tuple[Dict[str, Any], int, Dict[str, Any]]:
    """Gets archive page."""
    data: Dict[str, Any] = {}
    response_headers: Dict[str, Any] = {}

    if archive_id == "list":
        return archive_index(archive_id, status=status.HTTP_200_OK)

    archive = ARCHIVES.get(archive_id, None)
    if not archive:
        cat_id = CATEGORIES.get(archive_id, {}).get("in_archive", None)
        archive = ARCHIVES.get(cat_id, None)
        if not archive:
            return archive_index(archive_id,
                                 status=status.HTTP_404_NOT_FOUND)
        else:
            archive_id = cat_id

    _write_expires_header(response_headers)

    subsumed_by = ARCHIVES_SUBSUMED.get(archive_id, None)
    if subsumed_by:
        data["subsumed_id"] = archive_id
        data["subsumed_category"] = CATEGORIES.get(archive_id, {})
        data["subsumed_by"] = subsumed_by
        subsuming_category = CATEGORIES.get(subsumed_by, {})
        data["subsuming_category"] = subsuming_category
        archive_id = subsuming_category.get("in_archive", None)
        archive = ARCHIVES.get(archive_id, None)

    years = years_operating(archive)
github arXiv / arxiv-search / search / routes / api / exceptions.py View on Github external
def handle_not_found(error: NotFound) -> Response:
    """Render the base 404 error page."""
    rendered = jsonify({'code': error.code, 'error': error.description})
    response: Response = make_response(rendered)
    response.status_code = status.HTTP_404_NOT_FOUND
    return response
github arXiv / arxiv-browse / browse / controllers.py View on Github external
abs_meta = metadata.get_abs(arxiv_id)
        response_data['abs_meta'] = abs_meta
        response_data['meta_tags'] = meta_tag_metadata(abs_meta)
        response_data['author_links'] = queries_for_authors(abs_meta.authors)
        response_data['author_search_url_fn'] = search_author
    except AbsNotFoundException:
        return {'not_found': True, 'arxiv_id': arxiv_id}, \
                 status.HTTP_404_NOT_FOUND, {}
    except AbsVersionNotFoundException:
        arxiv_id_latest = re.sub(r'(v[\d]+)$', '', arxiv_id)
        return {'version_not_found': True,
                'arxiv_id': arxiv_id,
                'arxiv_id_latest': arxiv_id_latest}, \
            status.HTTP_404_NOT_FOUND, {}
    except IdentifierException:
        return {'arxiv_id': arxiv_id}, status.HTTP_404_NOT_FOUND, {}
    except IOError:
        # TODO: handle differently?
        raise InternalServerError(
            "There was a problem. If this problem "
            "persists, please contact help@arxiv.org."
        )

    return response_data, status.HTTP_200_OK, {}
github arXiv / arxiv-browse / browse / exceptions.py View on Github external
def handle_abs_not_found(error: AbsNotFound) -> Response:
    """Render the base 404 error page for abs."""
    rendered = render_template('abs/404.html', **error.data)
    response = make_response(rendered)
    response.status_code = status.HTTP_404_NOT_FOUND
    return response
github arXiv / arxiv-browse / browse / routes / ui.py View on Github external
def archive(archive: str):  # type: ignore
    """Landing page for an archive."""
    response, code, headers = archive_page.get_archive(archive)
    if code == status.HTTP_200_OK or code == status.HTTP_404_NOT_FOUND:
        return render_template(response['template'], **response), code, headers
    elif code == status.HTTP_301_MOVED_PERMANENTLY:
        return redirect(headers['Location'], code=code)
    elif code == status.HTTP_304_NOT_MODIFIED:
        return '', code, headers
    return response, code, headers