@view_config(
    route_name="bucket.sitemap.xml",
    renderer="sitemap/bucket.xml",
    decorator=[
        cache_control(1 * 60 * 60),              # 1 hour
        origin_cache(
            1 * 24 * 60 * 60,                    # 1 day
            stale_while_revalidate=6 * 60 * 60,  # 6 hours
            stale_if_error=1 * 24 - 60 * 60,     # 1 day
            keys=["all-projects"],
        ),
    ],
)
def sitemap_bucket(request):
    request.response.content_type = "text/xml"

    request.find_service(name="csp").merge(XML_CSP)

    bucket = request.matchdict["bucket"]

    projects = (
        request.db.query(Project.normalized_name)
                  .filter(Project.sitemap_bucket == bucket)
                  .all()
    )
    users = (
        request.db.query(User.username)
                  .filter(User.sitemap_bucket == bucket)
                  .all()
    )

    urls = [
        request.route_url("packaging.project", name=project.normalized_name)
        for project in projects
    ]
    urls += [
        request.route_url("accounts.profile", username=user.username)
        for user in users
    ]

    # If the length of our bucket name isn't enough to ensure that all of our
    # buckets have less than our maximum number of URLs then we want to error
    # out so that we can adjust our bucket size to spread the URLs out over
    # more buckets.
    if len(urls) > SITEMAP_MAXSIZE:
        raise ValueError(
            "Too many URLs in the sitemap for bucket: {!r}.".format(
                request.matchdict["bucket"],
            ),
        )

    return {"urls": sorted(urls)}
dataset/ETHPy150Open pypa/warehouse/warehouse/sitemap/views.py/sitemap_bucket/operator `*` -> `-`