# Path: src/werkzeug/_internal.py
# def _get_environ(obj: t.Union["WSGIEnvironment", "Request"]) -> "WSGIEnvironment":
#     env = getattr(obj, "environ", obj)
#     assert isinstance(
#         env, dict
#     ), f"{type(obj).__name__!r} is not a WSGI environment (has to be a dict)"
#     return env


import typing as t
    import typing_extensions as te
from datetime import datetime
from html import escape
from ._internal import _get_environ
    from _typeshed.wsgi import StartResponse
    from _typeshed.wsgi import WSGIEnvironment
    from .datastructures import WWWAuthenticate
    from .sansio.response import Response
    from .wrappers.request import Request as WSGIRequest  # noqa: F401
    from .wrappers.response import Response as WSGIResponse  # noqa: F401
        from .http import HTTP_STATUS_CODES
        from .wrappers.response import Response as WSGIResponse  # noqa: F811
        from .datastructures import WWWAuthenticate
                from .http import http_date
        from .sansio.response import Response
    """*405* `Method Not Allowed`

    Raise if the server used a method the resource does not handle.  For
    example `POST` if the resource is view only.  Especially useful for REST.

    The first argument for this exception should be a list of allowed methods.
    Strictly speaking the response would be invalid if you don't provide valid
    methods in the header which you can do with that list.
    """

    code = 405
    description = "The method is not allowed for the requested URL."

    def __init__(
        self,
        valid_methods: t.Optional[t.Iterable[str]] = None,
        description: t.Optional[str] = None,
        response: t.Optional["Response"] = None,
    ) -> None:
        """Takes an optional list of valid http methods
        starting with werkzeug 0.3 the list will be mandatory."""
        super().__init__(description=description, response=response)
        self.valid_methods = valid_methods

    def get_headers(
        self,
        environ: t.Optional["WSGIEnvironment"] = None,
        scope: t.Optional[dict] = None,
    ) -> t.List[t.Tuple[str, str]]:
        headers = super().get_headers(environ, scope)

# Path: src/werkzeug/_internal.py
# def _get_environ(obj: t.Union["WSGIEnvironment", "Request"]) -> "WSGIEnvironment":
#     env = getattr(obj, "environ", obj)
#     assert isinstance(
#         env, dict
#     ), f"{type(obj).__name__!r} is not a WSGI environment (has to be a dict)"
#     return env


# Path: src/werkzeug/exceptions.py
import typing as t
    import typing_extensions as te
from datetime import datetime
from html import escape
from ._internal import _get_environ
    from _typeshed.wsgi import StartResponse
    from _typeshed.wsgi import WSGIEnvironment
    from .datastructures import WWWAuthenticate
    from .sansio.response import Response
    from .wrappers.request import Request as WSGIRequest  # noqa: F401
    from .wrappers.response import Response as WSGIResponse  # noqa: F401
        from .http import HTTP_STATUS_CODES
        from .wrappers.response import Response as WSGIResponse  # noqa: F811
        from .datastructures import WWWAuthenticate
                from .http import http_date
        from .sansio.response import Response

    """*405* `Method Not Allowed`

    Raise if the server used a method the resource does not handle.  For
    example `POST` if the resource is view only.  Especially useful for REST.

    The first argument for this exception should be a list of allowed methods.
    Strictly speaking the response would be invalid if you don't provide valid
    methods in the header which you can do with that list.
    """

    code = 405
    description = "The method is not allowed for the requested URL."

    def __init__(
        self,
        valid_methods: t.Optional[t.Iterable[str]] = None,
        description: t.Optional[str] = None,
        response: t.Optional["Response"] = None,
    ) -> None:
        """Takes an optional list of valid http methods
        starting with werkzeug 0.3 the list will be mandatory."""
        super().__init__(description=description, response=response)
        self.valid_methods = valid_methods

    def get_headers(
        self,
        environ: t.Optional["WSGIEnvironment"] = None,
        scope: t.Optional[dict] = None,
    ) -> t.List[t.Tuple[str, str]]:
        headers = super().get_headers(environ, scope)

        if self.valid_methods: