Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
Add validation methods to _Validator and add it as XMLSchema base…
Browse files Browse the repository at this point in the history
… class (lxmlGH-50)

Clean up and replace the union of `_Element` and `_ElementTree` with a new type alias `_ElementOrTree`.
  • Loading branch information
janssenhenning authored Feb 4, 2022
1 parent bc96611 commit 17672a2
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions lxml-stubs/etree.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ _KnownEncodings = Literal[
"US-ASCII",
"us-ascii",
]
_ElementOrTree = Union[_Element, _ElementTree]

class ElementChildIterator(Iterator["_Element"]):
def __iter__(self) -> "ElementChildIterator": ...
Expand Down Expand Up @@ -406,27 +407,27 @@ class Resolver:
self, string: _AnyStr, context: Any, *, base_url: Optional[_AnyStr]
): ...

class XMLSchema:
class XMLSchema(_Validator):
def __init__(
self,
etree: Union[_Element, _ElementTree] = ...,
etree: _ElementOrTree = ...,
file: Union[_AnyStr, IO[Any]] = ...,
) -> None: ...
def assertValid(self, etree: Union[_Element, _ElementTree]) -> None: ...
def __call__(self, etree: _ElementOrTree) -> bool: ...

class XSLTAccessControl: ...

class XSLT:
def __init__(
self,
xslt_input: Union[_Element, _ElementTree],
xslt_input: _ElementOrTree,
extensions: _Dict_Tuple2AnyStr_Any = ...,
regexp: bool = ...,
access_control: XSLTAccessControl = ...,
) -> None: ...
def __call__(
self,
_input: Union[_Element, _ElementTree],
_input: _ElementOrTree,
profile_run: bool = ...,
**kwargs: Union[_AnyStr, _XSLTQuotedStringParam]
) -> _XSLTResultTree: ...
Expand Down Expand Up @@ -469,7 +470,7 @@ def XML(
base_url: Optional[_AnyStr] = ...,
) -> _Element: ...
def cleanup_namespaces(
tree_or_element: Union[_Element, _ElementTree],
tree_or_element: _ElementOrTree,
top_nsmap: Optional[_NSMap] = ...,
keep_ns_prefixes: Optional[Iterable[_AnyStr]] = ...,
) -> None: ...
Expand All @@ -481,7 +482,7 @@ def fromstring(
) -> _Element: ...
@overload
def tostring(
element_or_tree: Union[_Element, _ElementTree],
element_or_tree: _ElementOrTree,
encoding: Union[Type[str], Literal["unicode"]],
method: str = ...,
xml_declaration: bool = ...,
Expand All @@ -495,7 +496,7 @@ def tostring(
) -> str: ...
@overload
def tostring(
element_or_tree: Union[_Element, _ElementTree],
element_or_tree: _ElementOrTree,
# Should be anything but "unicode", cannot be typed
encoding: Optional[_KnownEncodings] = None,
method: str = ...,
Expand All @@ -510,7 +511,7 @@ def tostring(
) -> bytes: ...
@overload
def tostring(
element_or_tree: Union[_Element, _ElementTree],
element_or_tree: _ElementOrTree,
encoding: Union[str, type] = ...,
method: str = ...,
xml_declaration: bool = ...,
Expand All @@ -537,13 +538,18 @@ class ParseError(LxmlSyntaxError):
position: Tuple[int, int]

class XMLSyntaxError(ParseError): ...
class _Validator: ...

class _Validator:
def assert_(self, etree: _ElementOrTree) -> None: ...
def assertValid(self, etree: _ElementOrTree) -> None: ...
def validate(self, etree: _ElementOrTree) -> bool: ...
error_log = ... # type: _ErrorLog

class DTD(_Validator):
def __init__(
self, file: Union[_AnyStr, IO[Any]] = ..., *, external_id: Any = ...
) -> None: ...
def assertValid(self, etree: _Element) -> None: ...
def __call__(self, etree: _ElementOrTree) -> bool: ...

class _XPathEvaluatorBase: ...

Expand All @@ -558,9 +564,7 @@ class XPath(_XPathEvaluatorBase):
smart_strings: bool = ...
) -> None: ...
def __call__(
self,
_etree_or_element: Union[_Element, _ElementTree],
**_variables: _XPathObject
self, _etree_or_element: _ElementOrTree, **_variables: _XPathObject
) -> _XPathObject: ...
path = ... # type: str

Expand Down Expand Up @@ -617,7 +621,7 @@ def XPathEvaluator(
) -> XPathDocumentEvaluator: ...
@overload
def XPathEvaluator(
etree_or_element: Union[_Element, _ElementTree],
etree_or_element: _ElementOrTree,
namespaces: Optional[_DictAnyStr] = ...,
extensions: Any = ...,
regexp: bool = ...,
Expand Down

0 comments on commit 17672a2

Please sign in to comment.