Skip to content

Commit b6be5dc

Browse files
committed
[PATCH] plugin.api.validate: refactor Schema class (streamlink#4514)
Inherit from the all-schema directly to avoid having an unnecessary singledispatch type definition.
1 parent 7326a6c commit b6be5dc

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/streamlink/plugin/api/validate.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(self, *schemas):
7777
super(all, self).__init__(schemas)
7878

7979

80-
class get:
80+
class get(object):
8181
"""
8282
Get item from input.
8383
@@ -128,7 +128,7 @@ def __init__(self, *keys, **kw):
128128
self.seq = kw.get("seq", tuple)
129129

130130

131-
class xml_element:
131+
class xml_element(object):
132132
"""
133133
Validate an XML element.
134134
"""
@@ -563,19 +563,13 @@ def validate_unions(schema, value):
563563
return validate_union(schema.schema, value)
564564

565565

566-
class Schema(object):
567-
"""Wraps a validator schema into a object."""
568-
569-
def __init__(self, *schemas):
570-
self.schema = all(*schemas)
566+
class Schema(all):
567+
"""
568+
Wrapper class for :class:`all` with a validate method which raises :class:`PluginError` by default on error.
569+
"""
571570

572571
def validate(self, value, name="result", exception=PluginError):
573572
try:
574-
return validate(self.schema, value)
573+
return validate(self, value)
575574
except ValueError as err:
576575
raise exception("Unable to validate {0}: {1}".format(name, err))
577-
578-
579-
@validate.register(Schema)
580-
def validate_schema(schema, value):
581-
return schema.validate(value, exception=ValueError)

0 commit comments

Comments
 (0)