# Stubs for xml.etree.ElementTree (Python 3.4)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.

from typing import Any, AnyStr, Union, IO, Callable, Dict, List, Tuple, Sequence, Iterator, TypeVar, Optional, KeysView, ItemsView, Generator
import io

VERSION = ... # type: str

_Ss = TypeVar('_Ss', str, bytes)
_T = TypeVar('_T')
_str_or_bytes = Union[str, bytes]

class _ElementInterface:
    tag = ... # type: _str_or_bytes
    attrib = ... # type: Dict[_str_or_bytes, _str_or_bytes]
    text = ... # type: Optional[_str_or_bytes]
    tail = ... # type: Optional[_str_or_bytes]
    def __init__(self, tag: Union[AnyStr, Callable[..., '_ElementInterface']], attrib: Dict[AnyStr, AnyStr]) -> None: ...
    def makeelement(self, tag: _Ss, attrib: Dict[_Ss, _Ss]) -> '_ElementInterface': ...
    def __len__(self) -> int: ...
    def __getitem__(self, index: int) -> '_ElementInterface': ...
    def __setitem__(self, index: int, element: '_ElementInterface') -> None: ...
    def __delitem__(self, index: int) -> None: ...
    def __getslice__(self, start: int, stop: int) -> Sequence['_ElementInterface']: ...
    def __setslice__(self, start: int, stop: int, elements: Sequence['_ElementInterface']) -> None: ...
    def __delslice__(self, start: int, stop: int) -> None: ...
    def append(self, element: '_ElementInterface') -> None: ...
    def insert(self, index: int, element: '_ElementInterface') -> None: ...
    def remove(self, element: '_ElementInterface') -> None: ...
    def getchildren(self) -> List['_ElementInterface']: ...
    def find(self, path: str) -> Optional['_ElementInterface']: ...
    def findtext(self, path: str, default: _T=...) -> Union[str, _T]: ...
    def findall(self, path: str) -> List['_ElementInterface']: ...
    def clear(self) -> None: ...
    def get(self, key: AnyStr, default: _T=...) -> Union[AnyStr, _T]: ...
    def set(self, key: AnyStr, value: AnyStr) -> None: ...
    def keys(self) -> KeysView[AnyStr]: ...
    def items(self) -> ItemsView[AnyStr, AnyStr]: ...
    def getiterator(self, tag: Union[str, AnyStr]=...) -> List['_ElementInterface']: ...

def Element(tag: Union[AnyStr, Callable[..., _ElementInterface]], attrib: Dict[AnyStr, AnyStr]=..., **extra: Dict[str, AnyStr]) -> _ElementInterface: ...
def SubElement(parent: _ElementInterface, tag: AnyStr, attrib: Dict[AnyStr, AnyStr]=..., **extra: Dict[str, AnyStr]) -> _ElementInterface: ...
def Comment(text: _str_or_bytes=...) -> _ElementInterface: ...
def ProcessingInstruction(target: str, text: str=...) -> _ElementInterface: ...

PI = ... # type: Callable[..., _ElementInterface]

class QName:
    text = ... # type: str
    def __init__(self, text_or_uri: str, tag: str=...) -> None: ...


_file_or_filename = Union[str, bytes, int, IO[Any]]

class ElementTree:
    def __init__(self, element: _ElementInterface=..., file: _file_or_filename=...) -> None: ...
    def getroot(self) -> _ElementInterface: ...
    def parse(self, source: _file_or_filename, parser: 'XMLTreeBuilder'=...) -> _ElementInterface: ...
    def getiterator(self, tag: Union[str, AnyStr]=...) -> List[_ElementInterface]: ...
    def find(self, path: str) -> Optional[_ElementInterface]: ...
    def findtext(self, path: str, default: _T=...) -> Union[_T, str]: ...
    def findall(self, path: str) -> List[_ElementInterface]: ...
    def write(self, file_or_filename: _file_or_filename, encoding: str=...) -> None: ...

def iselement(element: _ElementInterface) -> bool: ...
def dump(elem: _ElementInterface) -> None: ...
def fixtag(tag: Union[str, QName], namespaces: Dict[str, str]) -> Tuple[str, Optional[str]]: ...
def parse(source: _file_or_filename, parser: 'XMLTreeBuilder'=...) -> ElementTree: ...


class iterparse:
    def __init__(self, source: _file_or_filename, events: Sequence[str]=...) -> None: ...
    # TODO-figure out this type...
    def __next__(self) -> Tuple[str, _ElementInterface]: ...

def XML(text: AnyStr) -> _ElementInterface: ...
def XMLID(text: AnyStr) -> Tuple[_ElementInterface, Dict[str, _ElementInterface]]: ...

# TODO-improve this type
fromstring = ... # type: Callable[..., _ElementInterface]

def tostring(element: _ElementInterface, encoding: str=...) -> AnyStr: ...

class TreeBuilder:
    def __init__(self, element_factory: Callable[[AnyStr, Dict[AnyStr, AnyStr]], _ElementInterface]=...) -> None: ...
    def close(self) -> _ElementInterface: ...
    def data(self, data: AnyStr) -> None: ...
    def start(self, tag: AnyStr, attrs: Dict[AnyStr, AnyStr]) -> _ElementInterface: ...
    def end(self, tag: AnyStr) -> _ElementInterface: ...

class XMLTreeBuilder:
    # TODO-what is entity used for???
    entity = ... # type: Any
    def __init__(self, html: int=..., target: TreeBuilder=...) -> None: ...
    def doctype(self, name: str, pubid: str, system: str) -> None: ...
    def close(self) -> Any: ...  # TODO-most of the time, this will be Element, but it can be anything target.close() returns
    def feed(self, data: AnyStr)-> None: ...
