repo stringclasses 454
values | file_path stringlengths 5 201 | extension stringclasses 1
value | content stringlengths 8 509k | num_lines int64 3 16.9k | size_bytes int64 8 511k |
|---|---|---|---|---|---|
mkdocs-material | material/plugins/blog/config.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 103 | 4,698 |
mkdocs-material | material/plugins/blog/plugin.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 1,084 | 45,378 |
mkdocs-material | material/plugins/blog/readtime/parser.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 75 | 2,760 |
mkdocs-material | material/plugins/blog/structure/options.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 129 | 5,081 |
mkdocs-material | material/plugins/blog/structure/__init__.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 338 | 13,811 |
mkdocs-material | material/plugins/blog/structure/markdown.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 62 | 2,528 |
mkdocs-material | material/plugins/privacy/config.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 79 | 3,227 |
mkdocs-material | material/plugins/privacy/plugin.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 681 | 28,438 |
mkdocs-material | material/plugins/info/patterns.py | .py | def get_exclusion_patterns():
"""
Regex patterns, which will be compared against directory and file names
case-sensitively. https://docs.python.org/3/library/re.html#re.search is the
matching function and scans the whole string to find any pattern match. Used
with the https://pypi.org/project/regex/... | 28 | 1,073 |
mkdocs-material | material/plugins/info/plugin.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 564 | 23,793 |
mkdocs-material | material/plugins/typeset/plugin.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 124 | 4,955 |
mkdocs-material | material/plugins/search/config.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 64 | 2,524 |
mkdocs-material | material/plugins/search/plugin.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 595 | 20,512 |
mkdocs-material | material/plugins/optimize/config.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 53 | 2,326 |
mkdocs-material | material/plugins/optimize/plugin.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 389 | 14,982 |
mkdocs-material | material/plugins/group/plugin.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 162 | 7,109 |
mkdocs-material | material/plugins/projects/config.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 65 | 2,480 |
mkdocs-material | material/plugins/projects/plugin.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 293 | 12,024 |
mkdocs-material | material/plugins/projects/builder/__init__.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 321 | 13,007 |
mkdocs-material | material/plugins/projects/builder/log.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 101 | 4,033 |
mkdocs-material | material/plugins/projects/builder/watcher/__init__.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 99 | 3,883 |
mkdocs-material | material/plugins/projects/builder/watcher/handler.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 106 | 3,874 |
mkdocs-material | material/plugins/projects/structure/__init__.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 242 | 10,645 |
mkdocs-material | material/plugins/meta/plugin.py | .py | # Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, c... | 123 | 5,067 |
readthedocs.org | manage.py | .py | #!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault(
"DJANGO_SETTINGS_MODULE", "readthedocs.settings.docker_compose"
)
sys.path.append(os.getcwd())
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
| 14 | 316 |
readthedocs.org | setup.py | .py | from setuptools import setup
# Configuration is in setup.cfg
setup()
| 6 | 71 |
readthedocs.org | tasks.py | .py | """Read the Docs tasks."""
import os
from invoke import Collection
from invoke import task
import common.dockerfiles.tasks
import common.tasks
ROOT_PATH = os.path.dirname(__file__)
namespace = Collection()
namespace.add_collection(
Collection(
common.tasks.setup_labels,
),
name="github",
)
... | 95 | 2,169 |
readthedocs.org | readthedocs/wsgi.py | .py | """WSGI application helper."""
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "readthedocs.settings.docker_compose")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.co... | 14 | 402 |
readthedocs.org | readthedocs/__init__.py | .py | """Read the Docs."""
__version__ = "2026.08.11"
| 4 | 49 |
readthedocs.org | readthedocs/constants.py | .py | """Common constants."""
import re
from readthedocs.builds.version_slug import VERSION_SLUG_REGEX
from readthedocs.projects.constants import DOWNLOADABLE_MEDIA_TYPES
from readthedocs.projects.constants import LANGUAGES_REGEX
from readthedocs.projects.constants import PROJECT_SLUG_REGEX
from readthedocs.projects.consta... | 21 | 692 |
readthedocs.org | readthedocs/worker.py | .py | """Celery worker application instantiation."""
import os
from celery import Celery
from django.conf import settings
from django_structlog.celery.steps import DjangoStructLogInitStep
def create_application():
"""Create a Celery application using Django settings."""
os.environ.setdefault(
"DJANGO_SETT... | 75 | 2,466 |
readthedocs.org | readthedocs/urls.py | .py | import os
from functools import reduce
from operator import add
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include
from django.urls import path
from django.urls import re_path
from django.views.generic.base import RedirectView
fr... | 202 | 6,065 |
readthedocs.org | readthedocs/forms.py | .py | """Community site-wide form overrides."""
import structlog
from allauth.account.forms import SignupForm
from django import forms
from readthedocs.core.models import UserProfile
log = structlog.get_logger(__name__) # noqa
class SignupFormWithNewsletter(SignupForm):
"""Custom signup form that includes a checkb... | 38 | 940 |
readthedocs.org | readthedocs/conftest.py | .py | import pytest
from django.core.cache import cache
from rest_framework.test import APIClient
pytest_plugins = ("sphinx.testing.fixtures",)
@pytest.fixture
def api_client():
return APIClient()
@pytest.fixture(autouse=True)
def clear_cache():
"""
Clear the cache after each test.
We don't usually want... | 26 | 571 |
readthedocs.org | readthedocs/proxito/middleware.py | .py | """
Middleware for Proxito.
This is used to take the request and map the host to the proper project slug.
Additional processing is done to get the project from the URL in the ``views.py`` as well.
"""
import re
from urllib.parse import urlparse
import structlog
from corsheaders.middleware import ACCESS_CONTROL_ALLO... | 383 | 16,052 |
readthedocs.org | readthedocs/proxito/exceptions.py | .py | from django.http import Http404
from django.utils.translation import pgettext_lazy
_not_found_subject_translation_context = (
"Names a subject that was not found in a 404 error message. Used like "
"'The {{ not_found_subject }} you are looking for at <code>{{ path_not_found }}</code> "
"was not found.'"
)... | 167 | 5,599 |
readthedocs.org | readthedocs/proxito/redirects.py | .py | from urllib.parse import urlparse
import structlog
from django.http import HttpResponseRedirect
from readthedocs.core.resolver import Resolver
from readthedocs.core.utils.url import unsafe_join_url_path
from readthedocs.proxito.cache import cache_response
from readthedocs.proxito.constants import RedirectType
from re... | 89 | 3,623 |
readthedocs.org | readthedocs/proxito/constants.py | .py | from enum import Enum
from enum import auto
class RedirectType(Enum):
http_to_https = auto()
to_canonical_domain = auto()
subproject_to_main_domain = auto()
# Application defined redirect.
system = auto()
# User defined redirect.
user = auto()
| 13 | 274 |
readthedocs.org | readthedocs/proxito/urls.py | .py | """
A quick rundown of all the URL's we are hoping to parse.
## Projects
pip.rtfd.io/<lang>/<version>/
* Can be single version (pip.rtfd.io/index.html)
* Can be translated (pip.rtfd.io/cz/latest/index.html)
* Can have subprojects (pip.rtfd.io/projects/foo/en/latest/index.html)
## Subprojects
pip.rtfd.io/projects/<... | 232 | 7,506 |
readthedocs.org | readthedocs/proxito/cache.py | .py | import structlog
from django.conf import settings
log = structlog.get_logger(__name__)
CACHE_TAG_HEADER = "Cache-Tag"
CDN_CACHE_CONTROL_HEADER = "CDN-Cache-Control"
def add_cache_tags(response, cache_tags):
"""
Add cache tags to the response.
New cache tags will be appended to the existing ones.
... | 74 | 2,623 |
readthedocs.org | readthedocs/proxito/tests/storage.py | .py | """
Helper Django Storage class to use in El Proxito tests.
"""
from readthedocs.builds.storage import BuildMediaFileSystemStorage
class BuildMediaStorageTest(BuildMediaFileSystemStorage):
"""
Storage to use in El Proxito tests to have more control.
Allow to specify when to return ``True`` or ``False``... | 27 | 699 |
readthedocs.org | readthedocs/proxito/tests/test_subproject_aliases.py | .py | """End-to-end coverage for subproject aliases that contain slashes."""
import django_dynamic_fixture as fixture
import pytest
from django.test.utils import override_settings
from readthedocs.core.resolver import Resolver
from readthedocs.projects.constants import (
DOWNLOADABLE_MEDIA_TYPES,
MEDIA_TYPE_HTMLZIP... | 90 | 3,876 |
readthedocs.org | readthedocs/proxito/tests/test_middleware.py | .py | # Copied from test_middleware.py
import pytest
from django.core.exceptions import SuspiciousOperation
from django.http import HttpRequest, HttpResponse
from django.test import TestCase
from django.test.utils import override_settings
from django_dynamic_fixture import get
from readthedocs.projects.constants import PUB... | 270 | 9,992 |
readthedocs.org | readthedocs/proxito/tests/test_old_redirects.py | .py | """
Most of this code is copied from:
readthedocs/rtd_tests/tests/test_redirects.py
and adapted to use:
* El Proxito
"""
from django.urls import reverse
import django_dynamic_fixture as fixture
from django.test.utils import override_settings
from readthedocs.builds.constants import EXTERNAL
from readthedocs.bui... | 1,625 | 56,074 |
readthedocs.org | readthedocs/proxito/tests/test_headers.py | .py | import django_dynamic_fixture as fixture
from corsheaders.middleware import (
ACCESS_CONTROL_ALLOW_CREDENTIALS,
ACCESS_CONTROL_ALLOW_METHODS,
ACCESS_CONTROL_ALLOW_ORIGIN,
)
from django.test import override_settings
from django_dynamic_fixture import get
from readthedocs.builds.constants import EXTERNAL
fro... | 423 | 16,949 |
readthedocs.org | readthedocs/proxito/tests/mixins.py | .py | from readthedocs.proxito.tests.storage import BuildMediaStorageTest
class MockStorageMixin:
"""
Mixin to controls ``BuildMediaStorageTests.exists`` method.
This mixin provides a helper to update which files does exist in the storage
backend and reset them to an empty list on tear down.
"""
... | 19 | 511 |
readthedocs.org | readthedocs/proxito/tests/test_custom_path_prefixes.py | .py | from django.test.utils import override_settings
from readthedocs.projects.constants import (
MULTIPLE_VERSIONS_WITHOUT_TRANSLATIONS,
SINGLE_VERSION_WITHOUT_TRANSLATIONS,
)
from readthedocs.proxito.tests.base import BaseDocServing
@override_settings(
PYTHON_MEDIA=False,
PUBLIC_DOMAIN="readthedocs.io",... | 624 | 23,842 |
readthedocs.org | readthedocs/proxito/tests/test_hosting.py | .py | """Test hosting views."""
import json
from pathlib import Path
from unittest import mock
import django_dynamic_fixture as fixture
import pytest
from django.contrib.auth.models import User
from django.test import TestCase, override_settings
from django.urls import reverse
from django.utils import timezone
from django_... | 1,392 | 48,046 |
readthedocs.org | readthedocs/proxito/tests/handler_404_urls.py | .py | """
This URL file is to be used in tests to emulate NGINX 404 internal redirects.
Instead of using ``fast_404`` to just return a 404, we use ``ServeError404`` and
force passing ``request.full_path()`` as ``proxito_path`` argument to the view.
``proxito_path`` is everything coming after ``_proxito_404_`` in the URL
ge... | 41 | 1,387 |
readthedocs.org | readthedocs/proxito/tests/base.py | .py | # Copied from .org
import django_dynamic_fixture as fixture
import pytest
from django.contrib.auth.models import User
from django.core.files.storage import storages
from django.test import TestCase
from readthedocs.builds.constants import LATEST
from readthedocs.projects.constants import PUBLIC, SSL_STATUS_VALID
from... | 95 | 3,301 |
readthedocs.org | readthedocs/proxito/tests/test_redirects.py | .py | # Copied from .org test_redirects
from django.test import override_settings
from django_dynamic_fixture import get
from readthedocs.builds.models import Version
from readthedocs.projects.constants import PUBLIC, SINGLE_VERSION_WITHOUT_TRANSLATIONS
from readthedocs.proxito.constants import RedirectType
from readthedocs... | 535 | 21,850 |
readthedocs.org | readthedocs/proxito/tests/test_full.py | .py | import os
from textwrap import dedent
from unittest import mock
import django_dynamic_fixture as fixture
from django.conf import settings
from django.core.cache import cache
from django.http import HttpResponse
from django.test.utils import override_settings
from django.urls import reverse
from django_dynamic_fixture ... | 2,018 | 77,707 |
readthedocs.org | readthedocs/proxito/views/utils.py | .py | import structlog
from django.http import HttpResponse
from django.shortcuts import render
from readthedocs.core.views import ErrorView
from ..exceptions import ContextualizedHttp404
log = structlog.get_logger(__name__) # noqa
class ProxitoErrorView(ErrorView):
base_path = "errors/proxito"
def fast_404(requ... | 61 | 1,930 |
readthedocs.org | readthedocs/proxito/views/hosting.py | .py | """Views for hosting features."""
from functools import lru_cache
import packaging
import structlog
from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.db.models import Q
from django.http import Http404
from django.http import JsonResponse
from django.shortcuts import get... | 702 | 28,433 |
readthedocs.org | readthedocs/proxito/views/mixins.py | .py | import mimetypes
from urllib.parse import parse_qsl
from urllib.parse import urlencode
from urllib.parse import urlparse
import structlog
from django.conf import settings
from django.core.exceptions import BadRequest
from django.http import HttpResponse
from django.http import HttpResponsePermanentRedirect
from django... | 410 | 16,101 |
readthedocs.org | readthedocs/proxito/views/serve.py | .py | """Views for doc serving."""
from urllib.parse import urlparse
import structlog
from django.conf import settings
from django.http import Http404
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.shortcuts import render
from dja... | 985 | 38,251 |
readthedocs.org | readthedocs/settings/docker_compose.py | .py | import os
import socket
from .base import CommunityBaseSettings
class DockerBaseSettings(CommunityBaseSettings):
"""Settings for local development with Docker"""
DEBUG = bool(os.environ.get("RTD_DJANGO_DEBUG", False))
DOCKER_ENABLE = True
RTD_DOCKER_COMPOSE = True
RTD_DOCKER_COMPOSE_NETWORK = ... | 283 | 10,839 |
readthedocs.org | readthedocs/settings/base.py | .py | # pylint: disable=missing-docstring
import os
import re
import socket
import subprocess
import structlog
from pathlib import Path
from celery.schedules import crontab
from corsheaders.defaults import default_headers
from django.conf.global_settings import PASSWORD_HASHERS
from readthedocs.builds import constants_doc... | 1,251 | 46,297 |
readthedocs.org | readthedocs/settings/test.py | .py | import os
from pathlib import Path
import textwrap
from .base import CommunityBaseSettings
class CommunityTestSettings(CommunityBaseSettings):
"""Settings for testing environment (e.g. tox)"""
SLUMBER_API_HOST = "http://localhost:8000"
# A bunch of our tests check this value in a returned URL/Domain
... | 184 | 7,991 |
readthedocs.org | readthedocs/settings/proxito/base.py | .py | """
Base settings for Proxito
Some of these settings will eventually be backported into the main settings file,
but currently we have them to be able to run the site with the old middleware for
a staged rollout of the proxito code.
"""
import structlog
log = structlog.get_logger(__name__)
class CommunityProxitoSett... | 50 | 1,646 |
readthedocs.org | readthedocs/settings/proxito/test.py | .py | from ..test import CommunityTestSettings
from .base import CommunityProxitoSettingsMixin
class CommunityProxitoTestSettings(
CommunityProxitoSettingsMixin, CommunityTestSettings
):
PUBLIC_DOMAIN = "dev.readthedocs.io"
RTD_BUILD_MEDIA_STORAGE = "readthedocs.proxito.tests.storage.BuildMediaStorageTest"
Co... | 13 | 371 |
readthedocs.org | readthedocs/redirects/admin.py | .py | """Django admin configuration for the redirects app."""
from django.contrib import admin
from .models import Redirect
@admin.register(Redirect)
class RedirectAdmin(admin.ModelAdmin):
list_display = [
"project",
"redirect_type",
"from_url",
"to_url",
"position",
"e... | 27 | 594 |
readthedocs.org | readthedocs/redirects/exceptions.py | .py | """Redirects related exceptions."""
class InfiniteRedirectException(Exception):
"""Exception raised when a redirect loops forever."""
| 6 | 140 |
readthedocs.org | readthedocs/redirects/models.py | .py | """Django models for the redirects app."""
import re
import structlog
from django.db import models
from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _
from readthedocs.core.resolver import Resolver
from readthedocs.projects.models import Project
from readthedocs.projec... | 337 | 11,282 |
readthedocs.org | readthedocs/redirects/querysets.py | .py | """Queryset for the redirects app."""
from urllib.parse import urlparse
import structlog
from django.db import models
from django.db.models import CharField
from django.db.models import F
from django.db.models import Q
from django.db.models import Value
from readthedocs.core.permissions import AdminPermission
from r... | 172 | 6,754 |
readthedocs.org | readthedocs/redirects/constants.py | .py | from django.utils.translation import gettext_lazy as _
HTTP_STATUS_CHOICES = (
(302, _("302 - Temporary Redirect")),
(301, _("301 - Permanent Redirect")),
)
PAGE_REDIRECT = "page"
EXACT_REDIRECT = "exact"
CLEAN_URL_TO_HTML_REDIRECT = "clean_url_to_html"
HTML_TO_CLEAN_URL_REDIRECT = "html_to_clean_url"
SPLAT... | 22 | 606 |
readthedocs.org | readthedocs/redirects/validators.py | .py | from django.conf import settings
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
from readthedocs.redirects.constants import CLEAN_URL_TO_HTML_REDIRECT
from readthedocs.redirects.constants import EXACT_REDIRECT
from readthedocs.redirects.constants import HTML_T... | 64 | 2,814 |
readthedocs.org | readthedocs/redirects/tests/test_views.py | .py | from django.contrib.auth.models import User
from django.test import TestCase, override_settings
from django.urls import reverse
from django_dynamic_fixture import get
from readthedocs.organizations.models import Organization
from readthedocs.projects.models import Project
from readthedocs.redirects.constants import (
... | 329 | 11,285 |
readthedocs.org | readthedocs/allauth/providers/githubapp/provider.py | .py | from allauth.socialaccount.providers.github.provider import GitHubProvider
from readthedocs.allauth.providers.githubapp.views import GitHubAppOAuth2Adapter
class GitHubAppProvider(GitHubProvider):
"""
Provider for GitHub App.
We subclass the GitHubProvider to have two separate providers for the GitHub O... | 18 | 470 |
readthedocs.org | readthedocs/allauth/providers/githubapp/views.py | .py | """Copied from allauth.socialaccount.providers.github.views."""
from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter
from allauth.socialaccount.providers.oauth2.views import OAuth2CallbackView
from allauth.socialaccount.providers.oauth2.views import OAuth2LoginView
class GitHubAppOAuth2Adapte... | 14 | 518 |
readthedocs.org | readthedocs/allauth/providers/githubapp/urls.py | .py | """Copied from allauth.socialaccount.providers.github.urls."""
from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns
from readthedocs.allauth.providers.githubapp.provider import GitHubAppProvider
urlpatterns = default_urlpatterns(GitHubAppProvider)
| 9 | 275 |
readthedocs.org | readthedocs/storage/filesystem.py | .py | import shutil
from functools import cached_property
import structlog
from django.core.exceptions import SuspiciousFileOperation
from django.core.files.storage import FileSystemStorage
from readthedocs.storage.mixins import RTDBaseStorage
from readthedocs.storage.rclone import RCloneLocal
from readthedocs.storage.util... | 75 | 2,725 |
readthedocs.org | readthedocs/storage/utils.py | .py | """Storage utilities."""
from storages.utils import clean_name
from storages.utils import safe_join as safe_join_storage
def safe_join(base, path):
"""
Safely join paths, ensuring that the final path isn't outside the directory.
We use clean_name before using safe_join,
replicating the logic from dj... | 20 | 649 |
readthedocs.org | readthedocs/storage/__init__.py | .py | """
Provides lazy loaded storage instances for use throughout Read the Docs.
For static files storage, use django.contrib.staticfiles.storage.staticfiles_storage.
Some storage backends (notably S3) have a slow instantiation time
so doing those upfront improves performance.
"""
from django.core.files.storage import st... | 37 | 1,072 |
readthedocs.org | readthedocs/storage/s3_storage.py | .py | """
AWS S3 Storage backends.
We override the backends provided by django-storages to add some small pieces
that we need to make our project to work as we want. For example, using
ManifestFilesMixin for static files and OverrideHostnameMixin to make it work
in our Docker Development environment.
"""
# Disable abstract... | 174 | 6,285 |
readthedocs.org | readthedocs/storage/mixins.py | .py | """Django storage mixin classes for different storage backends (Azure, S3)."""
from functools import cached_property
from pathlib import Path
from typing import Iterator
from urllib.parse import urlsplit
from urllib.parse import urlunsplit
import structlog
from django.conf import settings
from django.core.exceptions ... | 124 | 4,029 |
readthedocs.org | readthedocs/storage/rclone.py | .py | """
Wrapper around the rclone command.
See https://rclone.org/docs.
"""
import os
import subprocess
import structlog
from django.utils._os import safe_join as safe_join_fs
from readthedocs.storage.utils import safe_join
log = structlog.get_logger(__name__)
class BaseRClone:
"""
RClone base class.
T... | 203 | 6,129 |
readthedocs.org | readthedocs/storage/tests/test_s3_storage.py | .py | from unittest import mock
import pytest
from django.core.exceptions import SuspiciousFileOperation, SuspiciousOperation
from django.test import TestCase
from readthedocs.storage.s3_storage import RTDS3Storage
class TestRTDS3Storage(TestCase):
def setUp(self):
self.storage = RTDS3Storage()
def test... | 65 | 2,433 |
readthedocs.org | readthedocs/aws/security_token_service.py | .py | """
Module to interact with AWS STS (Security Token Service) to assume a role and get temporary scoped credentials.
This is mainly used to generate temporary credentials to interact with S3 buckets from the builders.
In order to make use of STS, we need:
- Create a role in IAM with a trusted entity type set to the A... | 267 | 10,168 |
readthedocs.org | readthedocs/aws/tests/test_security_token_service.py | .py | import json
from unittest import mock
from django.contrib.auth.models import User
from django.test import TestCase, override_settings
from django_dynamic_fixture import get
from readthedocs.builds.constants import EXTERNAL
from readthedocs.builds.models import Build
from readthedocs.projects.models import Project
fro... | 294 | 12,421 |
readthedocs.org | readthedocs/filetreediff/__init__.py | .py | """
Module for the file tree diff feature (FTD).
This feature is used to compare the files of two versions of a project.
The process is as follows:
- A build is triggered for a version.
- A task is triggered after the build has succeeded
to generate a manifest of the files of the version.
Currently, we only cons... | 205 | 7,931 |
readthedocs.org | readthedocs/filetreediff/dataclasses.py | .py | import fnmatch
from dataclasses import asdict
from dataclasses import dataclass
from enum import StrEnum
from enum import auto
from functools import cached_property
from typing import Iterator
from readthedocs.builds.models import Build
from readthedocs.builds.models import Version
from readthedocs.core.resolver impor... | 183 | 5,698 |
readthedocs.org | readthedocs/filetreediff/tests/test_filetreediff.py | .py | import json
from contextlib import contextmanager
from unittest import mock
from django.test import TestCase
from django_dynamic_fixture import get
from readthedocs.builds.constants import BUILD_STATE_FINISHED, EXTERNAL, LATEST
from readthedocs.builds.models import Build, Version
from readthedocs.filetreediff import ... | 243 | 8,942 |
readthedocs.org | readthedocs/domains/notifications.py | .py | """Notifications related to custom domains."""
import textwrap
from django.utils.translation import gettext_noop as _
from readthedocs.notifications.constants import INFO
from readthedocs.notifications.email import EmailNotification
from readthedocs.notifications.messages import Message
from readthedocs.notification... | 54 | 1,877 |
readthedocs.org | readthedocs/domains/querysets.py | .py | """Querysets for domain related models."""
from datetime import timedelta
from django.conf import settings
from django.db.models import Q
from django.utils import timezone
from readthedocs.projects.constants import SSL_STATUS_VALID
from readthedocs.projects.querysets import RelatedProjectQuerySet
class DomainQuery... | 42 | 1,636 |
readthedocs.org | readthedocs/domains/apps.py | .py | """Custom domains application."""
from django.apps import AppConfig
class DomainsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "readthedocs.domains"
def ready(self):
import readthedocs.domains.tasks # noqa
| 12 | 264 |
readthedocs.org | readthedocs/domains/tasks.py | .py | """Tasks related to custom domains."""
from django.conf import settings
from django.urls import reverse
from django.utils import timezone
from readthedocs.core.permissions import AdminPermission
from readthedocs.domains.notifications import MESSAGE_DOMAIN_VALIDATION_PENDING
from readthedocs.domains.notifications impo... | 54 | 1,988 |
readthedocs.org | readthedocs/domains/validators.py | .py | from django.conf import settings
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
from readthedocs.subscriptions.constants import TYPE_CNAME
from readthedocs.subscriptions.products import get_feature
def check_domains_limit(project, error_class=ValidationError... | 26 | 964 |
readthedocs.org | readthedocs/domains/tests/test_tasks.py | .py | from unittest import mock
from django.conf import settings
from django.contrib.auth.models import User
from django.test import TestCase, override_settings
from django.utils import timezone
from django_dynamic_fixture import get
from readthedocs.domains.tasks import email_pending_custom_domains
from readthedocs.organi... | 148 | 5,602 |
readthedocs.org | readthedocs/domains/tests/test_querysets.py | .py | from datetime import timedelta
from django.conf import settings
from django.contrib.auth.models import User
from django.test import TestCase
from django.utils import timezone
from django_dynamic_fixture import get
from readthedocs.projects.constants import (
SSL_STATUS_INVALID,
SSL_STATUS_PENDING,
SSL_STA... | 77 | 2,711 |
readthedocs.org | readthedocs/oauth/notifications.py | .py | """Notifications related to OAuth."""
import textwrap
from django.utils.translation import gettext_lazy as _
from readthedocs.notifications.constants import ERROR
from readthedocs.notifications.constants import INFO
from readthedocs.notifications.constants import WARNING
from readthedocs.notifications.messages impor... | 180 | 7,117 |
readthedocs.org | readthedocs/oauth/admin.py | .py | """Admin configuration for the OAuth app."""
from django.contrib import admin
from .models import GitHubAppInstallation
from .models import RemoteOrganization
from .models import RemoteOrganizationRelation
from .models import RemoteRepository
from .models import RemoteRepositoryRelation
@admin.register(GitHubAppIns... | 135 | 3,092 |
readthedocs.org | readthedocs/oauth/utils.py | .py | """Support code for OAuth, including webhook support."""
import structlog
from readthedocs.integrations.models import Integration
from readthedocs.oauth.clients import get_oauth2_client
from readthedocs.oauth.services import BitbucketService
from readthedocs.oauth.services import GitHubService
from readthedocs.oauth.... | 36 | 1,097 |
readthedocs.org | readthedocs/oauth/models.py | .py | """OAuth service models."""
from functools import cached_property
import structlog
from allauth.socialaccount.models import SocialAccount
from django.conf import settings
from django.contrib.auth.models import User
from django.db import models
from django.urls import reverse
from django.utils.translation import gette... | 424 | 14,327 |
readthedocs.org | readthedocs/oauth/querysets.py | .py | """Managers for OAuth models."""
from django.db import models
from readthedocs.allauth.providers.githubapp.provider import GitHubAppProvider
from readthedocs.core.querysets import NoReprQuerySet
from readthedocs.oauth.constants import GITHUB
from readthedocs.oauth.constants import GITHUB_APP
def _has_account_connec... | 78 | 3,213 |
readthedocs.org | readthedocs/oauth/apps.py | .py | """OAuth app config."""
from django.apps import AppConfig
class OAuthConfig(AppConfig):
name = "readthedocs.oauth"
def ready(self):
import readthedocs.oauth.signals # noqa
| 11 | 193 |
readthedocs.org | readthedocs/oauth/clients.py | .py | from datetime import datetime
import structlog
from django.conf import settings
from django.utils import timezone
from github import Auth
from github import GithubIntegration
from requests_oauthlib import OAuth2Session
log = structlog.get_logger(__name__)
def _get_token_updater(token):
"""
Update token giv... | 88 | 2,558 |
readthedocs.org | readthedocs/oauth/constants.py | .py | GITHUB = "github"
GITHUB_APP = "githubapp"
GITLAB = "gitlab"
BITBUCKET = "bitbucket"
VCS_PROVIDER_CHOICES = (
(GITHUB, "GitHub"),
(GITHUB_APP, "GitHub"),
(GITLAB, "GitLab"),
(BITBUCKET, "Bitbucket"),
)
| 12 | 219 |
readthedocs.org | readthedocs/oauth/views.py | .py | import hmac
import structlog
from django.conf import settings
from rest_framework.exceptions import ValidationError
from rest_framework.response import Response
from rest_framework.views import APIView
from readthedocs.api.v2.views.integrations import GITHUB_EVENT_HEADER
from readthedocs.api.v2.views.integrations imp... | 78 | 2,926 |
readthedocs.org | readthedocs/oauth/signals.py | .py | import structlog
from allauth.account.signals import user_logged_in
from allauth.socialaccount.models import SocialLogin
from allauth.socialaccount.signals import social_account_added
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver
from re... | 89 | 3,472 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.