sample_id stringlengths 21 196 | text stringlengths 105 936k | metadata dict | category stringclasses 6
values |
|---|---|---|---|
modelcontextprotocol/python-sdk:src/mcp/server/auth/json_response.py | from typing import Any
from starlette.responses import JSONResponse
class PydanticJSONResponse(JSONResponse):
# use pydantic json serialization instead of the stock `json.dumps`,
# so that we can handle serializing pydantic models like AnyHttpUrl
def render(self, content: Any) -> bytes:
return co... | {
"repo_id": "modelcontextprotocol/python-sdk",
"file_path": "src/mcp/server/auth/json_response.py",
"license": "MIT License",
"lines": 7,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
modelcontextprotocol/python-sdk:src/mcp/server/auth/middleware/auth_context.py | import contextvars
from starlette.types import ASGIApp, Receive, Scope, Send
from mcp.server.auth.middleware.bearer_auth import AuthenticatedUser
from mcp.server.auth.provider import AccessToken
# Create a contextvar to store the authenticated user
# The default is None, indicating no authenticated user is present
a... | {
"repo_id": "modelcontextprotocol/python-sdk",
"file_path": "src/mcp/server/auth/middleware/auth_context.py",
"license": "MIT License",
"lines": 35,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
modelcontextprotocol/python-sdk:src/mcp/server/auth/middleware/bearer_auth.py | import json
import time
from typing import Any
from pydantic import AnyHttpUrl
from starlette.authentication import AuthCredentials, AuthenticationBackend, SimpleUser
from starlette.requests import HTTPConnection
from starlette.types import Receive, Scope, Send
from mcp.server.auth.provider import AccessToken, TokenV... | {
"repo_id": "modelcontextprotocol/python-sdk",
"file_path": "src/mcp/server/auth/middleware/bearer_auth.py",
"license": "MIT License",
"lines": 96,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
modelcontextprotocol/python-sdk:src/mcp/server/auth/middleware/client_auth.py | import base64
import binascii
import hmac
import time
from typing import Any
from urllib.parse import unquote
from starlette.requests import Request
from mcp.server.auth.provider import OAuthAuthorizationServerProvider
from mcp.shared.auth import OAuthClientInformationFull
class AuthenticationError(Exception):
... | {
"repo_id": "modelcontextprotocol/python-sdk",
"file_path": "src/mcp/server/auth/middleware/client_auth.py",
"license": "MIT License",
"lines": 87,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
modelcontextprotocol/python-sdk:src/mcp/server/auth/provider.py | from dataclasses import dataclass
from typing import Generic, Literal, Protocol, TypeVar
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse
from pydantic import AnyUrl, BaseModel
from mcp.shared.auth import OAuthClientInformationFull, OAuthToken
class AuthorizationParams(BaseModel):
state: str |... | {
"repo_id": "modelcontextprotocol/python-sdk",
"file_path": "src/mcp/server/auth/provider.py",
"license": "MIT License",
"lines": 219,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | documentation |
modelcontextprotocol/python-sdk:src/mcp/server/auth/routes.py | from collections.abc import Awaitable, Callable
from typing import Any
from urllib.parse import urlparse
from pydantic import AnyHttpUrl
from starlette.middleware.cors import CORSMiddleware
from starlette.requests import Request
from starlette.responses import Response
from starlette.routing import Route, request_resp... | {
"repo_id": "modelcontextprotocol/python-sdk",
"file_path": "src/mcp/server/auth/routes.py",
"license": "MIT License",
"lines": 208,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
modelcontextprotocol/python-sdk:src/mcp/server/auth/settings.py | from pydantic import AnyHttpUrl, BaseModel, Field
class ClientRegistrationOptions(BaseModel):
enabled: bool = False
client_secret_expiry_seconds: int | None = None
valid_scopes: list[str] | None = None
default_scopes: list[str] | None = None
class RevocationOptions(BaseModel):
enabled: bool = Fa... | {
"repo_id": "modelcontextprotocol/python-sdk",
"file_path": "src/mcp/server/auth/settings.py",
"license": "MIT License",
"lines": 23,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
modelcontextprotocol/python-sdk:src/mcp/shared/auth.py | from typing import Any, Literal
from pydantic import AnyHttpUrl, AnyUrl, BaseModel, Field, field_validator
class OAuthToken(BaseModel):
"""See https://datatracker.ietf.org/doc/html/rfc6749#section-5.1"""
access_token: str
token_type: Literal["Bearer"] = "Bearer"
expires_in: int | None = None
sco... | {
"repo_id": "modelcontextprotocol/python-sdk",
"file_path": "src/mcp/shared/auth.py",
"license": "MIT License",
"lines": 128,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
modelcontextprotocol/python-sdk:tests/server/auth/middleware/test_auth_context.py | """Tests for the AuthContext middleware components."""
import time
import pytest
from starlette.types import Message, Receive, Scope, Send
from mcp.server.auth.middleware.auth_context import (
AuthContextMiddleware,
auth_context_var,
get_access_token,
)
from mcp.server.auth.middleware.bearer_auth import ... | {
"repo_id": "modelcontextprotocol/python-sdk",
"file_path": "tests/server/auth/middleware/test_auth_context.py",
"license": "MIT License",
"lines": 89,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
modelcontextprotocol/python-sdk:tests/server/auth/middleware/test_bearer_auth.py | """Tests for the BearerAuth middleware components."""
import time
from typing import Any, cast
import pytest
from starlette.authentication import AuthCredentials
from starlette.datastructures import Headers
from starlette.requests import Request
from starlette.types import Message, Receive, Scope, Send
from mcp.serv... | {
"repo_id": "modelcontextprotocol/python-sdk",
"file_path": "tests/server/auth/middleware/test_bearer_auth.py",
"license": "MIT License",
"lines": 362,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
modelcontextprotocol/python-sdk:tests/server/auth/test_error_handling.py | """Tests for OAuth error handling in the auth handlers."""
import base64
import hashlib
import secrets
import unittest.mock
from typing import Any
from urllib.parse import parse_qs, urlparse
import httpx
import pytest
from httpx import ASGITransport
from pydantic import AnyHttpUrl
from starlette.applications import S... | {
"repo_id": "modelcontextprotocol/python-sdk",
"file_path": "tests/server/auth/test_error_handling.py",
"license": "MIT License",
"lines": 247,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
modelcontextprotocol/python-sdk:tests/client/test_resource_cleanup.py | from typing import Any
from unittest.mock import patch
import anyio
import pytest
from pydantic import TypeAdapter
from mcp.shared.message import SessionMessage
from mcp.shared.session import BaseSession, RequestId, SendResultT
from mcp.types import ClientNotification, ClientRequest, ClientResult, EmptyResult, ErrorD... | {
"repo_id": "modelcontextprotocol/python-sdk",
"file_path": "tests/client/test_resource_cleanup.py",
"license": "MIT License",
"lines": 50,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/ipam/ui/panels.py | from django.contrib.contenttypes.models import ContentType
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from netbox.ui import actions, panels
class FHRPGroupAssignmentsPanel(panels.ObjectPanel):
"""
A panel which lists all FHRP group assignments for a given object.
... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/ipam/ui/panels.py",
"license": "Apache License 2.0",
"lines": 33,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/users/tests/test_tables.py | from django.test import RequestFactory, TestCase, tag
from users.models import Token
from users.tables import TokenTable
class TokenTableTest(TestCase):
@tag('regression')
def test_every_orderable_field_does_not_throw_exception(self):
tokens = Token.objects.all()
disallowed = {'actions'}
... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/users/tests/test_tables.py",
"license": "Apache License 2.0",
"lines": 19,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/virtualization/ui/panels.py | from django.utils.translation import gettext_lazy as _
from netbox.ui import attrs, panels
class ClusterPanel(panels.ObjectAttributesPanel):
name = attrs.TextAttr('name')
type = attrs.RelatedObjectAttr('type', linkify=True)
status = attrs.ChoiceAttr('status')
description = attrs.TextAttr('description... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/virtualization/ui/panels.py",
"license": "Apache License 2.0",
"lines": 61,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/core/tests/test_data_backends.py | from unittest import skipIf
from unittest.mock import patch
from django.test import TestCase
from core.data_backends import url_has_embedded_credentials
try:
import dulwich # noqa: F401
DULWICH_AVAILABLE = True
except ImportError:
DULWICH_AVAILABLE = False
class URLEmbeddedCredentialsTests(TestCase):
... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/core/tests/test_data_backends.py",
"license": "Apache License 2.0",
"lines": 90,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/netbox/graphql/pagination.py | import strawberry
from strawberry.types.unset import UNSET
from strawberry_django.pagination import _QS, apply
__all__ = (
'OffsetPaginationInfo',
'OffsetPaginationInput',
'apply_pagination',
)
@strawberry.type
class OffsetPaginationInfo:
offset: int = 0
limit: int | None = UNSET
start: int |... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/graphql/pagination.py",
"license": "Apache License 2.0",
"lines": 40,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/ipam/tests/test_tables.py | from django.test import RequestFactory, TestCase
from netaddr import IPNetwork
from ipam.models import IPAddress, IPRange, Prefix
from ipam.tables import AnnotatedIPAddressTable
from ipam.utils import annotate_ip_space
class AnnotatedIPAddressTableTest(TestCase):
@classmethod
def setUpTestData(cls):
... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/ipam/tests/test_tables.py",
"license": "Apache License 2.0",
"lines": 128,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/core/graphql/enums.py | import strawberry
from core.choices import *
__all__ = (
'DataSourceStatusEnum',
'ObjectChangeActionEnum',
)
DataSourceStatusEnum = strawberry.enum(DataSourceStatusChoices.as_enum(prefix='status'))
ObjectChangeActionEnum = strawberry.enum(ObjectChangeActionChoices.as_enum(prefix='action'))
| {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/core/graphql/enums.py",
"license": "Apache License 2.0",
"lines": 8,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/dcim/cable_profiles.py | from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
from dcim.choices import CableEndChoices
from dcim.models import CableTermination
class BaseCableProfile:
"""Base class for representing a cable profile."""
# Mappings of connectors to the number of pos... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/dcim/cable_profiles.py",
"license": "Apache License 2.0",
"lines": 331,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
netbox-community/netbox:netbox/dcim/models/base.py | from django.core.exceptions import ValidationError
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.utils.translation import gettext_lazy as _
from dcim.constants import PORT_POSITION_MAX, PORT_POSITION_MIN
__all__ = (
'PortMappingBase',
)
class Po... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/dcim/models/base.py",
"license": "Apache License 2.0",
"lines": 53,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/dcim/tests/test_cablepaths2.py | from unittest import skip
from circuits.models import CircuitTermination
from dcim.choices import CableProfileChoices
from dcim.models import *
from dcim.svg import CableTraceSVG
from dcim.tests.utils import CablePathTestCase
class CablePathTests(CablePathTestCase):
"""
Test the creation of CablePaths for Ca... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/dcim/tests/test_cablepaths2.py",
"license": "Apache License 2.0",
"lines": 1465,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/dcim/tests/utils.py | from django.test import TestCase
from circuits.models import *
from dcim.models import *
from dcim.utils import object_to_path_node
__all__ = (
'CablePathTestCase',
)
class CablePathTestCase(TestCase):
"""
Base class for test cases for cable paths.
"""
@classmethod
def setUpTestData(cls):
... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/dcim/tests/utils.py",
"license": "Apache License 2.0",
"lines": 71,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/dcim/ui/panels.py | from django.utils.translation import gettext_lazy as _
from netbox.ui import attrs, panels
class SitePanel(panels.ObjectAttributesPanel):
region = attrs.NestedObjectAttr('region', linkify=True)
group = attrs.NestedObjectAttr('group', linkify=True)
name = attrs.TextAttr('name')
status = attrs.ChoiceAt... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/dcim/ui/panels.py",
"license": "Apache License 2.0",
"lines": 178,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/extras/ui/panels.py | from django.contrib.contenttypes.models import ContentType
from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _
from netbox.ui import actions, panels
from utilities.data import resolve_attr_path
__all__ = (
'CustomFieldsPanel',
'ImageAttachmentsPanel',
... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/extras/ui/panels.py",
"license": "Apache License 2.0",
"lines": 63,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/netbox/api/gfk_fields.py | from drf_spectacular.utils import extend_schema_field
from rest_framework import serializers
from utilities.api import get_serializer_for_model
__all__ = (
'GFKSerializerField',
)
@extend_schema_field(serializers.JSONField(allow_null=True, read_only=True))
class GFKSerializerField(serializers.Field):
def t... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/api/gfk_fields.py",
"license": "Apache License 2.0",
"lines": 14,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/netbox/api/serializers/bulk.py | from rest_framework import serializers
from .features import ChangeLogMessageSerializer
__all__ = (
'BulkOperationSerializer',
)
class BulkOperationSerializer(ChangeLogMessageSerializer):
id = serializers.IntegerField()
| {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/api/serializers/bulk.py",
"license": "Apache License 2.0",
"lines": 7,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/netbox/api/serializers/models.py | from rest_framework import serializers
from users.api.serializers_.mixins import OwnerMixin
from .features import NetBoxModelSerializer
__all__ = (
'NestedGroupModelSerializer',
'OrganizationalModelSerializer',
'PrimaryModelSerializer',
)
class PrimaryModelSerializer(OwnerMixin, NetBoxModelSerializer):... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/api/serializers/models.py",
"license": "Apache License 2.0",
"lines": 23,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/netbox/forms/bulk_edit.py | from django import forms
from django.utils.translation import gettext_lazy as _
from core.models import ObjectType
from extras.choices import *
from extras.models import Tag
from utilities.forms import BulkEditForm
from utilities.forms.fields import CommentField, DynamicModelMultipleChoiceField
from .mixins import Ch... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/forms/bulk_edit.py",
"license": "Apache License 2.0",
"lines": 88,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/netbox/forms/bulk_import.py | from django import forms
from django.db import models
from django.utils.translation import gettext_lazy as _
from extras.choices import *
from extras.models import CustomField, Tag
from users.models import Owner
from utilities.forms import CSVModelForm
from utilities.forms.fields import CSVModelChoiceField, CSVModelMu... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/forms/bulk_import.py",
"license": "Apache License 2.0",
"lines": 81,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
netbox-community/netbox:netbox/netbox/forms/filtersets.py | from django import forms
from django.utils.translation import gettext_lazy as _
from extras.choices import *
from utilities.forms.fields import QueryField
from utilities.forms.mixins import FilterModifierMixin
from .mixins import CustomFieldsMixin, OwnerFilterMixin, SavedFiltersMixin
__all__ = (
'NestedGroupMode... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/forms/filtersets.py",
"license": "Apache License 2.0",
"lines": 55,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/netbox/forms/model_forms.py | import json
from django import forms
from django.contrib.contenttypes.models import ContentType
from extras.choices import *
from utilities.forms.fields import CommentField, SlugField
from utilities.forms.mixins import CheckLastUpdatedMixin
from .mixins import ChangelogMessageMixin, CustomFieldsMixin, OwnerMixin, Ta... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/forms/model_forms.py",
"license": "Apache License 2.0",
"lines": 81,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
netbox-community/netbox:netbox/netbox/forms/search.py | import re
from django import forms
from django.utils.translation import gettext_lazy as _
from netbox.search import LookupTypes
from netbox.search.backends import search_backend
LOOKUP_CHOICES = (
('', _('Partial match')),
(LookupTypes.EXACT, _('Exact match')),
(LookupTypes.STARTSWITH, _('Starts with')),... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/forms/search.py",
"license": "Apache License 2.0",
"lines": 46,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/netbox/graphql/filters.py | from dataclasses import dataclass
from typing import TYPE_CHECKING
import strawberry_django
from strawberry import ID
from strawberry_django import ComparisonFilterLookup, StrFilterLookup
from core.graphql.filter_mixins import ChangeLoggingMixin
from extras.graphql.filter_mixins import CustomFieldsFilterMixin, Journa... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/graphql/filters.py",
"license": "Apache License 2.0",
"lines": 46,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/netbox/tests/test_base_classes.py | from django.apps import apps
from django.test import TestCase
from django.utils.module_loading import import_string
from netbox.api.serializers import (
NestedGroupModelSerializer,
NetBoxModelSerializer,
OrganizationalModelSerializer,
PrimaryModelSerializer,
)
from netbox.filtersets import (
Nested... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/tests/test_base_classes.py",
"license": "Apache License 2.0",
"lines": 305,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/netbox/ui/actions.py | from urllib.parse import urlencode
from django.apps import apps
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from utilities.permissions import get_permission_for_model
from utilities.views import get_viewname
__all__ = (
... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/ui/actions.py",
"license": "Apache License 2.0",
"lines": 127,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/netbox/ui/attrs.py | from django.template.loader import render_to_string
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from netbox.config import get_config
from utilities.data import resolve_attr_path
__all__ = (
'AddressAttr',
'BooleanAttr',
'ChoiceAttr',
'ColorAttr'... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/ui/attrs.py",
"license": "Apache License 2.0",
"lines": 320,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
netbox-community/netbox:netbox/netbox/ui/layout.py | from netbox.ui.panels import Panel, PluginContentPanel
__all__ = (
'Column',
'Layout',
'Row',
'SimpleLayout',
)
#
# Base classes
#
class Layout:
"""
A collection of rows and columns comprising the layout of content within the user interface.
Parameters:
*rows: One or more Row in... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/ui/layout.py",
"license": "Apache License 2.0",
"lines": 77,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | documentation |
netbox-community/netbox:netbox/netbox/ui/panels.py | from django.apps import apps
from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _
from netbox.ui import attrs
from netbox.ui.actions import CopyContent
from utilities.data import resolve_attr_path
from utilities.querydict import dict_to_querydict
from utilities.str... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/ui/panels.py",
"license": "Apache License 2.0",
"lines": 301,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
netbox-community/netbox:netbox/users/api/serializers_/mixins.py | from rest_framework import serializers
from users.api.serializers_.owners import OwnerSerializer
__all__ = (
'OwnerMixin',
)
class OwnerMixin(serializers.Serializer):
"""
Adds an `owner` field for models which have a ForeignKey to users.Owner.
"""
owner = OwnerSerializer(
nested=True,
... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/users/api/serializers_/mixins.py",
"license": "Apache License 2.0",
"lines": 14,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/users/api/serializers_/owners.py | from netbox.api.fields import RelatedObjectCountField, SerializedPKRelatedField
from netbox.api.serializers import ValidatedModelSerializer
from users.models import Group, Owner, OwnerGroup, User
from .users import GroupSerializer, UserSerializer
__all__ = (
'OwnerGroupSerializer',
'OwnerSerializer',
)
clas... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/users/api/serializers_/owners.py",
"license": "Apache License 2.0",
"lines": 38,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/users/choices.py | from django.utils.translation import gettext_lazy as _
from utilities.choices import ChoiceSet
__all__ = (
'TokenVersionChoices',
)
class TokenVersionChoices(ChoiceSet):
V1 = 1
V2 = 2
CHOICES = [
(V1, _('v1')),
(V2, _('v2')),
]
| {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/users/choices.py",
"license": "Apache License 2.0",
"lines": 12,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/users/filterset_mixins.py | import django_filters
from django.utils.translation import gettext as _
from users.models import Owner, OwnerGroup
__all__ = (
'OwnerFilterMixin',
)
class OwnerFilterMixin(django_filters.FilterSet):
"""
Adds owner & owner_id filters for models which inherit from OwnerMixin.
"""
owner_group_id = ... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/users/filterset_mixins.py",
"license": "Apache License 2.0",
"lines": 35,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/users/graphql/mixins.py | from typing import TYPE_CHECKING, Annotated
import strawberry
if TYPE_CHECKING:
from users.graphql.types import OwnerType
__all__ = (
'OwnerMixin',
)
@strawberry.type
class OwnerMixin:
owner: Annotated['OwnerType', strawberry.lazy('users.graphql.types')] | None
| {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/users/graphql/mixins.py",
"license": "Apache License 2.0",
"lines": 10,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/users/models/owners.py | from django.db import models
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from netbox.models import AdminModel
from utilities.querysets import RestrictedQuerySet
__all__ = (
'Owner',
'OwnerGroup',
)
class OwnerGroup(AdminModel):
"""
An arbitrary grouping of ... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/users/models/owners.py",
"license": "Apache License 2.0",
"lines": 64,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/users/ui/panels.py | from django.utils.translation import gettext_lazy as _
from netbox.ui import actions, attrs, panels
class TokenPanel(panels.ObjectAttributesPanel):
version = attrs.NumericAttr('version')
key = attrs.TextAttr('key')
token = attrs.TextAttr('partial')
pepper_id = attrs.NumericAttr('pepper_id')
user ... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/users/ui/panels.py",
"license": "Apache License 2.0",
"lines": 20,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/utilities/filtersets.py | from netbox.registry import registry
__all__ = (
'register_filterset',
)
def register_filterset(filterset_class):
"""
Decorator for registering a FilterSet with the application registry.
Uses model identifier as key to match search index pattern.
"""
model = filterset_class._meta.model
l... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/utilities/filtersets.py",
"license": "Apache License 2.0",
"lines": 13,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/utilities/forms/widgets/modifiers.py | from django import forms
from django.conf import settings
from django.utils.translation import gettext_lazy as _
from utilities.forms.widgets.apiselect import APISelect, APISelectMultiple
__all__ = (
'MODIFIER_EMPTY_FALSE',
'MODIFIER_EMPTY_TRUE',
'FilterModifierWidget',
)
# Modifier codes for empty/null ... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/utilities/forms/widgets/modifiers.py",
"license": "Apache License 2.0",
"lines": 122,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
netbox-community/netbox:netbox/utilities/security.py | from django.core.exceptions import ImproperlyConfigured
__all__ = (
'validate_peppers',
)
def validate_peppers(peppers):
"""
Validate the given dictionary of cryptographic peppers for type & sufficient length.
"""
if type(peppers) is not dict:
raise ImproperlyConfigured("API_TOKEN_PEPPERS... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/utilities/security.py",
"license": "Apache License 2.0",
"lines": 21,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/utilities/tests/test_filter_modifiers.py | from django import forms
from django.conf import settings
from django.db import models
from django.http import QueryDict
from django.template import Context
from django.test import RequestFactory, TestCase
import dcim.filtersets # noqa: F401 - Import to register Device filterset
from dcim.forms.filtersets import Devi... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/utilities/tests/test_filter_modifiers.py",
"license": "Apache License 2.0",
"lines": 264,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/core/tests/test_openapi_schema.py | """
Unit tests for OpenAPI schema generation.
Refs: #20638
"""
import json
from django.test import TestCase
class OpenAPISchemaTestCase(TestCase):
"""Tests for OpenAPI schema generation."""
def setUp(self):
"""Fetch schema via API endpoint."""
response = self.client.get('/api/schema/', {'fo... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/core/tests/test_openapi_schema.py",
"license": "Apache License 2.0",
"lines": 90,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/netbox/tests/test_forms.py | from django.test import TestCase
from dcim.choices import InterfaceTypeChoices
from dcim.forms import InterfaceImportForm
from dcim.models import Device, DeviceRole, DeviceType, Interface, Manufacturer, Site
class NetBoxModelImportFormCleanTest(TestCase):
"""
Test the clean() method of NetBoxModelImportForm ... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/tests/test_forms.py",
"license": "Apache License 2.0",
"lines": 282,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/ipam/tests/test_lookups.py | from django.db.backends.postgresql.psycopg_any import NumericRange
from django.test import TestCase
from ipam.models import VLANGroup
class VLANGroupRangeContainsLookupTests(TestCase):
@classmethod
def setUpTestData(cls):
# Two ranges: [1,11) and [20,31)
cls.g1 = VLANGroup.objects.create(
... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/ipam/tests/test_lookups.py",
"license": "Apache License 2.0",
"lines": 59,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/netbox/monkey.py | from django.db.models import UniqueConstraint
from rest_framework.utils.field_mapping import get_unique_error_message
from rest_framework.validators import UniqueValidator
__all__ = (
'get_unique_validators',
)
def get_unique_validators(field_name, model_field):
"""
Extend Django REST Framework's get_uni... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/monkey.py",
"license": "Apache License 2.0",
"lines": 34,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/utilities/tests/test_templatetags.py | from unittest.mock import patch
from django.test import TestCase, override_settings
from utilities.templatetags.builtins.tags import static_with_params
class StaticWithParamsTest(TestCase):
"""
Test the static_with_params template tag functionality.
"""
def test_static_with_params_basic(self):
... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/utilities/tests/test_templatetags.py",
"license": "Apache License 2.0",
"lines": 36,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/utilities/tests/test_serialization.py | from django.test import TestCase
from dcim.choices import SiteStatusChoices
from dcim.models import Site
from extras.models import Tag
from utilities.serialization import deserialize_object, serialize_object
class SerializationTestCase(TestCase):
@classmethod
def setUpTestData(cls):
tags = (
... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/utilities/tests/test_serialization.py",
"license": "Apache License 2.0",
"lines": 41,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/core/api/serializers_/object_types.py | import inspect
from django.urls import NoReverseMatch
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import extend_schema_field
from rest_framework import serializers
from core.models import ObjectType
from netbox.api.serializers import BaseModelSerializer
from utilities.views import get_ac... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/core/api/serializers_/object_types.py",
"license": "Apache License 2.0",
"lines": 39,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/core/dataclasses.py | import logging
from dataclasses import dataclass, field
from datetime import datetime
from django.utils import timezone
__all__ = (
'JobLogEntry',
)
@dataclass
class JobLogEntry:
level: str
message: str
timestamp: datetime = field(default_factory=timezone.now)
@classmethod
def from_logrecor... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/core/dataclasses.py",
"license": "Apache License 2.0",
"lines": 15,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/core/models/object_types.py | import inspect
from collections import defaultdict
from django.contrib.contenttypes.models import ContentType
from django.contrib.postgres.fields import ArrayField
from django.contrib.postgres.indexes import GinIndex
from django.core.exceptions import ObjectDoesNotExist
from django.db import connection, models
from dj... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/core/models/object_types.py",
"license": "Apache License 2.0",
"lines": 197,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
netbox-community/netbox:netbox/core/object_actions.py | from django.utils.translation import gettext_lazy as _
from netbox.object_actions import ObjectAction
__all__ = (
'BulkSync',
)
class BulkSync(ObjectAction):
"""
Synchronize multiple objects at once.
"""
name = 'bulk_sync'
label = _('Sync Data')
multi = True
permissions_required = {'... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/core/object_actions.py",
"license": "Apache License 2.0",
"lines": 14,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/dcim/object_actions.py | from django.utils.translation import gettext_lazy as _
from netbox.object_actions import ObjectAction
__all__ = (
'BulkAddComponents',
'BulkDisconnect',
)
class BulkAddComponents(ObjectAction):
"""
Add components to the selected devices.
"""
label = _('Add Components')
multi = True
p... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/dcim/object_actions.py",
"license": "Apache License 2.0",
"lines": 28,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/netbox/metrics.py | from django_prometheus import middleware
from django_prometheus.conf import NAMESPACE
from prometheus_client import Counter
__all__ = (
'Metrics',
)
class Metrics(middleware.Metrics):
"""
Expand the stock Metrics class from django_prometheus to add our own counters.
"""
def register(self):
... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/metrics.py",
"license": "Apache License 2.0",
"lines": 34,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/netbox/object_actions.py | from django.db.models import ForeignKey
from django.template import loader
from django.urls.exceptions import NoReverseMatch
from django.utils.translation import gettext_lazy as _
from core.models import ObjectType
from extras.models import ExportTemplate
from utilities.querydict import prepare_cloned_fields
from util... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/object_actions.py",
"license": "Apache License 2.0",
"lines": 179,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
netbox-community/netbox:netbox/netbox/tests/dummy_plugin/webhook_callbacks.py | from extras.webhooks import register_webhook_callback
@register_webhook_callback
def set_context(object_type, event_type, data, request):
return {
'foo': 123,
}
| {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/tests/dummy_plugin/webhook_callbacks.py",
"license": "Apache License 2.0",
"lines": 6,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/netbox/tests/test_model_features.py | from unittest import skipIf
from django.conf import settings
from django.test import TestCase
from taggit.models import Tag
from core.models import AutoSyncRecord, DataSource
from dcim.models import Site
from extras.models import CustomLink
from ipam.models import Prefix
from netbox.models.features import get_model_f... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/tests/test_model_features.py",
"license": "Apache License 2.0",
"lines": 92,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/netbox/tests/test_object_actions.py | from unittest import skipIf
from django.conf import settings
from django.test import RequestFactory, TestCase
from dcim.models import Device, DeviceType, Manufacturer
from netbox.object_actions import AddObject, BulkEdit, BulkImport
class ObjectActionTest(TestCase):
def test_get_url_core_model(self):
"... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/tests/test_object_actions.py",
"license": "Apache License 2.0",
"lines": 43,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/utilities/apps.py | from django.apps import apps
def get_installed_apps():
"""
Return the name and version number for each installed Django app.
"""
installed_apps = {}
for app_config in apps.get_app_configs():
app = app_config.module
if version := getattr(app, 'VERSION', getattr(app, '__version__', N... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/utilities/apps.py",
"license": "Apache License 2.0",
"lines": 15,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/utilities/export.py | from django.utils.translation import gettext_lazy as _
from django_tables2.export import TableExport as TableExport_
from utilities.constants import CSV_DELIMITERS
__all__ = (
'TableExport',
)
class TableExport(TableExport_):
"""
A subclass of django-tables2's TableExport class which allows us to specif... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/utilities/export.py",
"license": "Apache License 2.0",
"lines": 21,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/utilities/jobs.py | from django.contrib import messages
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from netbox.jobs import AsyncViewJob
from utilities.request import copy_safe_request
__all__ = (
'is_background_request',
'process_request_as_job',
)
def is_background_req... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/utilities/jobs.py",
"license": "Apache License 2.0",
"lines": 38,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/virtualization/object_actions.py | from django.utils.translation import gettext_lazy as _
from netbox.object_actions import ObjectAction
__all__ = (
'BulkAddComponents',
)
class BulkAddComponents(ObjectAction):
"""
Add components to the selected virtual machines.
"""
label = _('Add Components')
multi = True
permissions_re... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/virtualization/object_actions.py",
"license": "Apache License 2.0",
"lines": 18,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/utilities/prefetch.py | from django.contrib.contenttypes.fields import GenericRelation
from django.db.models import ManyToManyField
from django.db.models.fields.related import ForeignObjectRel
from taggit.managers import TaggableManager
__all__ = (
'get_prefetchable_fields',
)
def get_prefetchable_fields(model):
"""
Return a li... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/utilities/prefetch.py",
"license": "Apache License 2.0",
"lines": 26,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
netbox-community/netbox:netbox/utilities/tests/test_prefetch.py | from circuits.models import Circuit, Provider
from utilities.prefetch import get_prefetchable_fields
from utilities.testing.base import TestCase
class GetPrefetchableFieldsTest(TestCase):
"""
Verify the operation of get_prefetchable_fields()
"""
def test_get_prefetchable_fields(self):
field_na... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/utilities/tests/test_prefetch.py",
"license": "Apache License 2.0",
"lines": 14,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/netbox/models/deletion.py | import logging
from django.contrib.contenttypes.fields import GenericRelation
from django.db import router
from django.db.models.deletion import CASCADE, Collector
logger = logging.getLogger("netbox.models.deletion")
class CustomCollector(Collector):
"""
Override Django's stock Collector to handle GenericRe... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/netbox/models/deletion.py",
"license": "Apache License 2.0",
"lines": 77,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
netbox-community/netbox:netbox/vpn/tests/test_tables.py | from django.test import RequestFactory, TestCase, tag
from vpn.models import TunnelTermination
from vpn.tables import TunnelTerminationTable
@tag('regression')
class TunnelTerminationTableTest(TestCase):
def test_every_orderable_field_does_not_throw_exception(self):
terminations = TunnelTermination.objec... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/vpn/tests/test_tables.py",
"license": "Apache License 2.0",
"lines": 18,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
netbox-community/netbox:netbox/circuits/tests/test_tables.py | from django.test import RequestFactory, TestCase, tag
from circuits.models import CircuitTermination
from circuits.tables import CircuitTerminationTable
@tag('regression')
class CircuitTerminationTableTest(TestCase):
def test_every_orderable_field_does_not_throw_exception(self):
terminations = CircuitTer... | {
"repo_id": "netbox-community/netbox",
"file_path": "netbox/circuits/tests/test_tables.py",
"license": "Apache License 2.0",
"lines": 18,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
nginx-proxy/nginx-proxy:test/test_dockergen/test_dockergen_network_segregation-custom-label.py | import pytest
@pytest.mark.flaky
def test_unknown_virtual_host_is_503(docker_compose, nginxproxy):
r = nginxproxy.get("http://unknown.nginx-proxy.tld/")
assert r.status_code == 503
@pytest.mark.flaky
def test_forwards_to_whoami(docker_compose, nginxproxy):
r = nginxproxy.get("http://whoami2.nginx-proxy.... | {
"repo_id": "nginx-proxy/nginx-proxy",
"file_path": "test/test_dockergen/test_dockergen_network_segregation-custom-label.py",
"license": "MIT License",
"lines": 11,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
ocrmypdf/OCRmyPDF:bin/bump_version.py | #!/usr/bin/env python3
# SPDX-FileCopyrightText: 2017-2019 Joe Rickerby and contributors
# SPDX-License-Identifier: BSD-2-Clause
"""Bump the version number in all the right places."""
from __future__ import annotations
import glob
import os
import subprocess
import sys
import time
import urllib.parse
from pathlib im... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "bin/bump_version.py",
"license": "Mozilla Public License 2.0",
"lines": 317,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:scripts/generate_glyphless_font.py | #!/usr/bin/env python3
# SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Generate the Occulta glyphless font for OCRmyPDF.
Occulta (Latin for "hidden") is a glyphless font designed for invisible text layers
in searchable PDFs. It has proper Unicode cmap coverage using format 13 (man... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "scripts/generate_glyphless_font.py",
"license": "Mozilla Public License 2.0",
"lines": 183,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:src/ocrmypdf/_exec/verapdf.py | # SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Interface to verapdf executable."""
from __future__ import annotations
import json
import logging
from pathlib import Path
from subprocess import PIPE
from typing import NamedTuple
from packaging.version import Version
from ocrmyp... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "src/ocrmypdf/_exec/verapdf.py",
"license": "Mozilla Public License 2.0",
"lines": 84,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:src/ocrmypdf/_options.py | # SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Internal options model for OCRmyPDF."""
from __future__ import annotations
import json
import logging
import os
import shlex
import unicodedata
from collections.abc import Sequence
from enum import StrEnum
from io import IOBase
from... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "src/ocrmypdf/_options.py",
"license": "Mozilla Public License 2.0",
"lines": 540,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:src/ocrmypdf/_plugin_registry.py | # SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Plugin option registry for dynamic model composition."""
from __future__ import annotations
import logging
from pydantic import BaseModel
log = logging.getLogger(__name__)
class PluginOptionRegistry:
"""Registry for plugin o... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "src/ocrmypdf/_plugin_registry.py",
"license": "Mozilla Public License 2.0",
"lines": 36,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:src/ocrmypdf/_validation_coordinator.py | # SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Validation coordinator for plugin options and cross-cutting concerns."""
from __future__ import annotations
import logging
import os
from typing import TYPE_CHECKING
if TYPE_CHECKING:
import pluggy
from ocrmypdf._options i... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "src/ocrmypdf/_validation_coordinator.py",
"license": "Mozilla Public License 2.0",
"lines": 117,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:src/ocrmypdf/builtin_plugins/null_ocr.py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Built-in plugin implementing a null OCR engine (no OCR).
This plugin provides an OCR engine that produces no text output. It is useful
when users want OCRmyPDF's image processing, PDF/A conversion, or optimization
features without pe... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "src/ocrmypdf/builtin_plugins/null_ocr.py",
"license": "Mozilla Public License 2.0",
"lines": 129,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:src/ocrmypdf/builtin_plugins/pypdfium.py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Built-in plugin to implement PDF page rasterization using pypdfium2."""
from __future__ import annotations
import logging
import threading
from contextlib import closing
from pathlib import Path
from typing import TYPE_CHECKING, Lite... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "src/ocrmypdf/builtin_plugins/pypdfium.py",
"license": "Mozilla Public License 2.0",
"lines": 239,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:src/ocrmypdf/font/font_manager.py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Base font management for PDF rendering.
This module provides the base FontManager class that handles font loading
and glyph checking using uharfbuzz.
"""
from __future__ import annotations
from pathlib import Path
import uharfbuzz... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "src/ocrmypdf/font/font_manager.py",
"license": "Mozilla Public License 2.0",
"lines": 87,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:src/ocrmypdf/font/font_provider.py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Font provider protocol and implementations for PDF rendering."""
from __future__ import annotations
import logging
from pathlib import Path
from typing import Protocol
from ocrmypdf.font.font_manager import FontManager
log = loggi... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "src/ocrmypdf/font/font_provider.py",
"license": "Mozilla Public License 2.0",
"lines": 148,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:src/ocrmypdf/font/multi_font_manager.py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Multi-font management for PDF rendering.
Provides automatic font selection for multilingual documents based on
language hints and glyph coverage analysis.
"""
from __future__ import annotations
import logging
from pathlib import Pa... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "src/ocrmypdf/font/multi_font_manager.py",
"license": "Mozilla Public License 2.0",
"lines": 287,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:src/ocrmypdf/font/system_font_provider.py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""System font discovery for PDF rendering.
Provides lazy discovery of Noto fonts installed on the system across
Linux, macOS, and Windows platforms.
"""
from __future__ import annotations
import logging
import os
import sys
from path... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "src/ocrmypdf/font/system_font_provider.py",
"license": "Mozilla Public License 2.0",
"lines": 259,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:src/ocrmypdf/fpdf_renderer/renderer.py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""fpdf2-based PDF renderer for OCR text layers.
This module provides PDF rendering using fpdf2 for creating searchable
OCR text layers.
"""
from __future__ import annotations
import logging
from dataclasses import dataclass
from math... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "src/ocrmypdf/fpdf_renderer/renderer.py",
"license": "Mozilla Public License 2.0",
"lines": 758,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:src/ocrmypdf/hocrtransform/hocr_parser.py | # SPDX-FileCopyrightText: 2010 Jonathan Brinley
# SPDX-FileCopyrightText: 2013-2014 Julien Pfefferkorn
# SPDX-FileCopyrightText: 2023-2025 James R. Barlow
# SPDX-License-Identifier: MIT
"""Parser for hOCR format files.
This module provides functionality to parse hOCR files (HTML-based OCR format)
and convert them to ... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "src/ocrmypdf/hocrtransform/hocr_parser.py",
"license": "Mozilla Public License 2.0",
"lines": 414,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:src/ocrmypdf/pdfinfo/_contentstream.py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""PDF content stream interpretation."""
from __future__ import annotations
import re
from collections import defaultdict
from collections.abc import Mapping
from math import hypot, inf, isclose
from typing import NamedTuple
from warnin... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "src/ocrmypdf/pdfinfo/_contentstream.py",
"license": "Mozilla Public License 2.0",
"lines": 184,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:src/ocrmypdf/pdfinfo/_image.py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""PDF image analysis."""
from __future__ import annotations
import logging
from collections.abc import Iterator
from decimal import Decimal
from pikepdf import (
Dictionary,
Matrix,
Name,
Object,
Pdf,
PdfImage,... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "src/ocrmypdf/pdfinfo/_image.py",
"license": "Mozilla Public License 2.0",
"lines": 325,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:src/ocrmypdf/pdfinfo/_types.py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""PDF type definitions and constants."""
from __future__ import annotations
from enum import Enum, auto
class Colorspace(Enum):
"""Description of common image colorspaces in a PDF."""
# pylint: disable=invalid-name
gray ... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "src/ocrmypdf/pdfinfo/_types.py",
"license": "Mozilla Public License 2.0",
"lines": 70,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:src/ocrmypdf/pdfinfo/_worker.py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""PDF page info worker process handling."""
from __future__ import annotations
import atexit
import logging
from collections.abc import Container, Sequence
from contextlib import contextmanager
from functools import partial
from pathli... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "src/ocrmypdf/pdfinfo/_worker.py",
"license": "Mozilla Public License 2.0",
"lines": 116,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
ocrmypdf/OCRmyPDF:tests/test_fpdf_renderer.py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Tests for fpdf2-based PDF renderer."""
from __future__ import annotations
from pathlib import Path
import pytest
from ocrmypdf.font import MultiFontManager
from ocrmypdf.fpdf_renderer import (
DebugRenderOptions,
Fpdf2Mult... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "tests/test_fpdf_renderer.py",
"license": "Mozilla Public License 2.0",
"lines": 432,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
ocrmypdf/OCRmyPDF:tests/test_hocr_parser.py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Unit tests for HocrParser class."""
from __future__ import annotations
from pathlib import Path
from textwrap import dedent
import pytest
from ocrmypdf.hocrtransform import (
HocrParseError,
HocrParser,
OcrClass,
)
@... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "tests/test_hocr_parser.py",
"license": "Mozilla Public License 2.0",
"lines": 442,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
ocrmypdf/OCRmyPDF:tests/test_json_serialization.py | """Test JSON serialization of OcrOptions for multiprocessing compatibility."""
from __future__ import annotations
import multiprocessing
from io import BytesIO
from pathlib import Path, PurePath
import pytest
from ocrmypdf._options import OcrOptions
from ocrmypdf.builtin_plugins.tesseract_ocr import TesseractOptions... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "tests/test_json_serialization.py",
"license": "Mozilla Public License 2.0",
"lines": 130,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
ocrmypdf/OCRmyPDF:tests/test_multi_font_manager.py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Unit tests for MultiFontManager and FontProvider."""
from __future__ import annotations
import logging
from pathlib import Path
import pytest
from ocrmypdf.font import BuiltinFontProvider, FontManager, MultiFontManager
@pytest.f... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "tests/test_multi_font_manager.py",
"license": "Mozilla Public License 2.0",
"lines": 307,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
ocrmypdf/OCRmyPDF:tests/test_null_ocr_engine.py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Unit tests for NullOcrEngine (--ocr-engine none).
Tests verify that the Null OCR engine exists and functions correctly
for scenarios where users want PDF processing without OCR.
"""
from __future__ import annotations
from pathlib i... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "tests/test_null_ocr_engine.py",
"license": "Mozilla Public License 2.0",
"lines": 117,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
ocrmypdf/OCRmyPDF:tests/test_ocr_element.py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Unit tests for OcrElement dataclass and related classes."""
from __future__ import annotations
import pytest
from ocrmypdf.hocrtransform import (
Baseline,
BoundingBox,
FontInfo,
OcrClass,
OcrElement,
)
class ... | {
"repo_id": "ocrmypdf/OCRmyPDF",
"file_path": "tests/test_ocr_element.py",
"license": "Mozilla Public License 2.0",
"lines": 189,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.