from io import BufferedReader, TextIOWrapper
from typing import Any, Optional, Union
from xml.dom.minidom import Element
from xml.sax.expatreader import ExpatParser as _ExpatParser

from django.core.serializers import base
from django.core.serializers.base import DeserializedObject
from django.db.models.base import Model
from django.db.models.fields import Field
from django.db.models.fields.related import ForeignKey, ManyToManyField


class Serializer(base.Serializer):
    options: Dict[str, None]
    selected_fields: None
    stream: django.core.management.base.OutputWrapper
    use_natural_foreign_keys: bool
    use_natural_primary_keys: bool
    def indent(self, level: int) -> None: ...
    xml: django.utils.xmlutils.SimplerXMLGenerator = ...
    def start_serialization(self) -> None: ...
    def end_serialization(self) -> None: ...
    def start_object(self, obj: Model) -> None: ...
    def end_object(self, obj: Model) -> None: ...
    def handle_field(self, obj: Model, field: Field) -> None: ...
    def handle_fk_field(self, obj: Model, field: ForeignKey) -> None: ...
    def handle_m2m_field(self, obj: Model, field: ManyToManyField) -> None: ...

class Deserializer(base.Deserializer):
    options: Dict[Any, Any]
    stream: _io.BufferedReader
    event_stream: Any = ...
    db: Any = ...
    ignore: Any = ...
    def __init__(
        self,
        stream_or_string: Union[BufferedReader, TextIOWrapper, str],
        *,
        using: Any = ...,
        ignorenonexistent: bool = ...,
        **options: Any
    ) -> None: ...
    def __next__(self) -> DeserializedObject: ...

def getInnerText(node: Element) -> str: ...

class DefusedExpatParser(_ExpatParser):
    def __init__(self, *args: Any, **kwargs: Any) -> None: ...
    def start_doctype_decl(
        self, name: str, sysid: str, pubid: None, has_internal_subset: int
    ) -> Any: ...
    def entity_decl(
        self,
        name: Any,
        is_parameter_entity: Any,
        value: Any,
        base: Any,
        sysid: Any,
        pubid: Any,
        notation_name: Any,
    ) -> None: ...
    def unparsed_entity_decl(
        self, name: Any, base: Any, sysid: Any, pubid: Any, notation_name: Any
    ) -> None: ...
    def external_entity_ref_handler(
        self, context: Any, base: Any, sysid: Any, pubid: Any
    ) -> None: ...
    def reset(self) -> None: ...

class DefusedXmlException(ValueError): ...

class DTDForbidden(DefusedXmlException):
    name: str = ...
    sysid: str = ...
    pubid: None = ...
    def __init__(self, name: str, sysid: str, pubid: None) -> None: ...

class EntitiesForbidden(DefusedXmlException):
    name: Any = ...
    value: Any = ...
    base: Any = ...
    sysid: Any = ...
    pubid: Any = ...
    notation_name: Any = ...
    def __init__(
        self,
        name: Any,
        value: Any,
        base: Any,
        sysid: Any,
        pubid: Any,
        notation_name: Any,
    ) -> None: ...

class ExternalReferenceForbidden(DefusedXmlException):
    context: Any = ...
    base: Any = ...
    sysid: Any = ...
    pubid: Any = ...
    def __init__(
        self, context: Any, base: Any, sysid: Any, pubid: Any
    ) -> None: ...
