class Callback(BaseModel): id: pydantic.NonNegativeInt base: pydantic.stricturl(max_length=255, tld_required=False, allowed_schemes=_URL_SCHEMES) app: Optional[pydantic.NonNegativeInt] username: Optional[pydantic.constr(max_length=255)] password: Optional[pydantic.constr(max_length=255)] __allowed_updates__ = ["base", "username", "password"]
def test_pydantic_stricturl_field(self, normalize_sdl): value = pydantic2graphene.to_graphene( to_pydantic_class(pydantic.stricturl())) expected_value = """ type FakeGql { field: String! } """ assert normalize_sdl(value) == normalize_sdl(expected_value)
class Settings(BaseSettings): """ See https://pydantic-docs.helpmanual.io/#settings for details on using and overriding this """ name = "metricq-wizard-backend" auth_key = "u0zlRwkhWiMCaIfNuS_eIF9PXMVzw9aSYA-88jI-Y48=" cookie_name = "metricq_wizard_backend" token = name amqp_server: stricturl( tld_required=False, allowed_schemes={"amqp", "amqps"} # noqa: F821 ) = "amqp://*****:*****@localhost/" couchdb_url: AnyHttpUrl = "http://localhost:5984" couchdb_user = "******" couchdb_password = "******" dry_run = False
class SonarScanner(pyd.BaseModel): sonar_login: NonBlankStr = 'admin' sonar_password: NonBlankStr = 'admin' sonar_host_url: pyd.stricturl(allowed_schemes={'http', 'https'}) = "http://localhost:9000" sonar_scm_disabled: bool = True sonar_exclusions: t.Optional[str] = '**/writers/latex2e/__init__.py, **/test/**/*, **/tests/**/*' def get_base_scan_args(self) -> t.List[str]: return [f'-D{k.replace("_", ".")}={v!s}' for k, v in self.__fields__.items() if v] def scan(self, name: str, src_dir: t.Union[str, Path], key: t.Optional[str] = None, raise_error: bool = True, scanner_cmd: str = 'sonar-scanner', docker_cmd: str = 'docker', docker_container_id: t.Optional[str] = None) -> sub.CompletedProcess: name = name.strip() key = (key.strip() if key else None) or name src_dir = Path(src_dir).resolve() scanner_args = [ scanner_cmd, f'-Dsonar.projectBaseDir={src_dir!s}', f'-Dsonar.projectKey={key}', f'-Dsonar.projectName={name}', *self.get_base_scan_args() ] if docker_container_id: scanner_args = [docker_cmd, 'exec', docker_container_id] + scanner_args return sub.run(scanner_args, check=raise_error)
class Model(BaseModel): v: stricturl(strip_whitespace=False, allowed_schemes={'ws', 'wss'})
class Config: validate_all = True validated = PydanticTypes() validated.my_pyobject_str(2021, 1, 1) validated.my_pyobject_callable(2021, 1, 1) validated.my_uuid1.hex validated.my_uuid1_str.hex validated.my_file_path.absolute() validated.my_file_path_str.absolute() validated.my_dir_path.absolute() validated.my_dir_path_str.absolute() stricturl(allowed_schemes={'http'}) stricturl(allowed_schemes=frozenset({'http'})) stricturl(allowed_schemes=('s3', 's3n', 's3a')) class SomeDict(TypedDict): val: int name: str obj: SomeDict = { 'val': 12, 'name': 'John', }
from typing import Any, Union from documented import DocumentedError from libcst import BaseCompoundStatement, SimpleStatementLine from pydantic import BaseModel, stricturl BodyStatement = Union[SimpleStatementLine, BaseCompoundStatement] PythonIRI = stricturl(allowed_schemes={'python'}, tld_required=False) class WPSConstant(BaseModel): """WPS constant description.""" name: str about: PythonIRI description: str value: Any class GenerationFailed(DocumentedError): """Generation of a WPSConstant has failed.""" class NotAnAssignment(GenerationFailed): """This is not an assignment.""" class NotPublicConstant(GenerationFailed): """This constant is not public."""
class CallbackCreation(BaseModel): base: pydantic.stricturl(max_length=255, tld_required=False, allowed_schemes=_URL_SCHEMES) app: Optional[pydantic.NonNegativeInt] username: Optional[pydantic.constr(max_length=255)] password: Optional[pydantic.constr(max_length=255)]
class Model2(BaseModel): v: stricturl(host_required=False, allowed_schemes={'foo'}) # noqa: F821
Field, FilePath, PositiveInt, SecretStr, conint, root_validator, stricturl, ) from pydantic.env_settings import SettingsError from pydantic.error_wrappers import ValidationError if TYPE_CHECKING: OpcUrl = AnyUrl PortField = int else: OpcUrl = stricturl(tld_required=False, allowed_schemes={"opc.tcp"}) PortField = conint(gt=0, le=2 ** 16) class ConfigError(ValueError): """Configuration error exception.""" def __init__(self, field: Union[str, None], error: str) -> None: """Initializes configuration error exception. Args: field: Configuration field the error is about. error: A string describing the error. """ msg = f"{field.upper()} environment variable: " if field else "" msg += error
This software is licensed under the MIT Licence: https://opensource.org/licenses/MIT """ import secrets from typing import TYPE_CHECKING, List, Optional, Union from argon2 import ( # type: ignore DEFAULT_MEMORY_COST, DEFAULT_PARALLELISM, DEFAULT_TIME_COST, ) from pydantic import AnyHttpUrl, BaseSettings, Field, stricturl if TYPE_CHECKING: _PostgresURL = str else: _PostgresURL = stricturl( strip_whitespace=True, tld_required=False, allowed_schemes={"postgresql"}, ) class _UniversalSet: """(psuedo)-universal set - contains everything""" def __contains__(self, item): return True UNIVERSAL_SET = _UniversalSet() class _Settings(BaseSettings): dsn: _PostgresURL = "postgresql://db/notebook"
class Peer(BaseModel): peer_id: constr(max_length=128, regex=r"^(?:[0-9a-fA-F]{2})*$") url: stricturl(allowed_schemes={"ws", "wss"})
def test_pydantic_stricturl_field(self): with pytest.raises(pydantic2graphene.FieldNotSupported): pydantic2graphene.to_graphene( to_pydantic_class(pydantic.stricturl()))