jsonschema-path 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ from jsonschema_path.accessors import SchemaAccessor
2
+ from jsonschema_path.handlers import default_handlers
3
+ from jsonschema_path.paths import SchemaPath
4
+
5
+ __author__ = "Artur Maciag"
6
+ __email__ = "maciag.artur@gmail.com"
7
+ __version__ = "0.3.0"
8
+ __url__ = "https://github.com/p1c2u/jsonschema-path"
9
+ __license__ = "Apache-2.0"
10
+
11
+ __all__ = ["SchemaAccessor", "SchemaPath", "default_handlers"]
@@ -0,0 +1,94 @@
1
+ """JSONSchema spec accessors module."""
2
+ from collections import deque
3
+ from contextlib import contextmanager
4
+ from typing import Any
5
+ from typing import Deque
6
+ from typing import Hashable
7
+ from typing import Iterator
8
+ from typing import List
9
+ from typing import Optional
10
+ from typing import Union
11
+
12
+ from pathable.accessors import LookupAccessor
13
+ from referencing import Registry
14
+ from referencing import Specification
15
+ from referencing._core import Resolved
16
+ from referencing._core import Resolver
17
+ from referencing.jsonschema import DRAFT202012
18
+
19
+ from jsonschema_path.handlers import default_handlers
20
+ from jsonschema_path.retrievers import SchemaRetriever
21
+ from jsonschema_path.typing import Lookup
22
+ from jsonschema_path.typing import ResolverHandlers
23
+ from jsonschema_path.typing import Schema
24
+ from jsonschema_path.utils import is_ref
25
+
26
+
27
+ class ResolverAccessor(LookupAccessor):
28
+ def __init__(self, lookup: Lookup, resolver: Resolver[Lookup]):
29
+ super().__init__(lookup)
30
+ self.resolver = resolver
31
+
32
+
33
+ class SchemaAccessor(ResolverAccessor):
34
+ @classmethod
35
+ def from_schema(
36
+ cls,
37
+ schema: Schema,
38
+ specification: Specification[Schema] = DRAFT202012,
39
+ base_uri: str = "",
40
+ handlers: ResolverHandlers = default_handlers,
41
+ ) -> "SchemaAccessor":
42
+ retriever = SchemaRetriever(handlers, specification)
43
+ base_resource = specification.create_resource(schema)
44
+ registry: Registry[Schema] = Registry(
45
+ retrieve=retriever, # type: ignore
46
+ )
47
+ registry = registry.with_resource(base_uri, base_resource)
48
+ resolver = registry.resolver(base_uri=base_uri)
49
+ return cls(schema, resolver)
50
+
51
+ @contextmanager
52
+ def open(self, parts: List[Hashable]) -> Iterator[Union[Schema, Any]]:
53
+ parts_deque = deque(parts)
54
+ try:
55
+ resolved = self._resolve(self.lookup, parts_deque)
56
+ yield resolved.contents
57
+ finally:
58
+ pass
59
+
60
+ @contextmanager
61
+ def resolve(self, parts: List[Hashable]) -> Iterator[Resolved[Any]]:
62
+ parts_deque = deque(parts)
63
+ try:
64
+ yield self._resolve(self.lookup, parts_deque)
65
+ finally:
66
+ pass
67
+
68
+ def _resolve(
69
+ self,
70
+ contents: Schema,
71
+ parts_deque: Deque[Hashable],
72
+ resolver: Optional[Resolver[Schema]] = None,
73
+ ) -> Resolved[Any]:
74
+ resolver = resolver or self.resolver
75
+ if is_ref(contents):
76
+ ref = contents["$ref"]
77
+ resolved = resolver.lookup(ref)
78
+ self.resolver = self.resolver._evolve(
79
+ self.resolver._base_uri,
80
+ registry=resolved.resolver._registry,
81
+ )
82
+ return self._resolve(
83
+ resolved.contents,
84
+ parts_deque,
85
+ resolver=resolved.resolver,
86
+ )
87
+
88
+ try:
89
+ part = parts_deque.popleft()
90
+ except IndexError:
91
+ return Resolved(contents=contents, resolver=resolver) # type: ignore
92
+ else:
93
+ target = contents[part]
94
+ return self._resolve(target, parts_deque, resolver=resolver)
@@ -0,0 +1,25 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from jsonschema_path.handlers.file import FileHandler
4
+ from jsonschema_path.handlers.urllib import UrllibHandler
5
+
6
+ if TYPE_CHECKING:
7
+ from jsonschema_path.handlers.urllib import UrllibHandler as UrlHandler
8
+ else:
9
+ try:
10
+ from jsonschema_path.handlers.requests import (
11
+ UrlRequestsHandler as UrlHandler,
12
+ )
13
+ except ImportError:
14
+ from jsonschema_path.handlers.urllib import UrllibHandler as UrlHandler
15
+
16
+ __all__ = ["FileHandler", "UrlHandler"]
17
+
18
+ file_handler = FileHandler()
19
+ all_urls_handler = UrllibHandler("http", "https", "file")
20
+ default_handlers = {
21
+ "<all_urls>": all_urls_handler,
22
+ "http": UrlHandler("http"),
23
+ "https": UrlHandler("https"),
24
+ "file": UrllibHandler("file"),
25
+ }
@@ -0,0 +1,70 @@
1
+ """JSONSchema spec handlers file module."""
2
+ from json import dumps
3
+ from json import loads
4
+ from typing import Any
5
+ from typing import ContextManager
6
+ from typing import Optional
7
+ from typing import Tuple
8
+ from urllib.parse import urlparse
9
+
10
+ from yaml import load
11
+
12
+ from jsonschema_path.handlers.protocols import SupportsRead
13
+ from jsonschema_path.handlers.utils import uri_to_path
14
+ from jsonschema_path.loaders import JsonschemaSafeLoader
15
+
16
+
17
+ class FileHandler:
18
+ """File-like object handler."""
19
+
20
+ def __init__(self, loader: Any = JsonschemaSafeLoader):
21
+ self.loader = loader
22
+
23
+ def __call__(self, stream: SupportsRead) -> Any:
24
+ data = self._load(stream)
25
+ return loads(dumps(data))
26
+
27
+ def _load(self, stream: SupportsRead) -> Any:
28
+ return load(stream, self.loader)
29
+
30
+
31
+ class BaseFilePathHandler:
32
+ """Base file path handler."""
33
+
34
+ allowed_schemes: Tuple[str, ...] = NotImplemented
35
+
36
+ def __init__(
37
+ self, *allowed_schemes: str, file_handler: Optional[FileHandler] = None
38
+ ):
39
+ self.allowed_schemes = allowed_schemes or self.allowed_schemes
40
+ self.file_handler = file_handler or FileHandler()
41
+
42
+ def __call__(self, uri: str) -> Any:
43
+ parsed_url = urlparse(uri)
44
+ if parsed_url.scheme not in self.allowed_schemes:
45
+ raise ValueError(f"Scheme {parsed_url.scheme} not allowed")
46
+
47
+ with self._open(uri) as stream:
48
+ return self.file_handler(stream)
49
+
50
+ def _open(self, uri: str) -> ContextManager[SupportsRead]:
51
+ raise NotImplementedError
52
+
53
+
54
+ class FilePathHandler(BaseFilePathHandler):
55
+ """File path handler."""
56
+
57
+ allowed_schemes = ("file",)
58
+
59
+ def __init__(
60
+ self,
61
+ *allowed_schemes: str,
62
+ file_handler: Optional[FileHandler] = None,
63
+ encoding: str = "utf-8",
64
+ ):
65
+ super().__init__(*allowed_schemes, file_handler=file_handler)
66
+ self.encoding = encoding
67
+
68
+ def _open(self, uri: str) -> ContextManager[SupportsRead]:
69
+ filepath = uri_to_path(uri)
70
+ return open(filepath, encoding=self.encoding)
@@ -0,0 +1,7 @@
1
+ from typing import Optional
2
+ from typing import Protocol
3
+
4
+
5
+ class SupportsRead(Protocol):
6
+ def read(self, amount: Optional[int] = 0) -> str:
7
+ ...
@@ -0,0 +1,34 @@
1
+ """JSONSchema spec handlers requests module."""
2
+ from contextlib import closing
3
+ from io import StringIO
4
+ from typing import ContextManager
5
+ from typing import Optional
6
+ from typing import Union
7
+
8
+ import requests
9
+
10
+ from jsonschema_path.handlers.file import BaseFilePathHandler
11
+ from jsonschema_path.handlers.file import FileHandler
12
+ from jsonschema_path.handlers.protocols import SupportsRead
13
+
14
+
15
+ class UrlRequestsHandler(BaseFilePathHandler):
16
+ """URL (requests) scheme handler."""
17
+
18
+ def __init__(
19
+ self,
20
+ *allowed_schemes: str,
21
+ file_handler: Optional[FileHandler] = None,
22
+ timeout: int = 10,
23
+ verify: Optional[Union[bool, str]] = True,
24
+ ):
25
+ super().__init__(*allowed_schemes, file_handler=file_handler)
26
+ self.timeout = timeout
27
+ self.verify = verify
28
+
29
+ def _open(self, uri: str) -> ContextManager[SupportsRead]:
30
+ response = requests.get(uri, timeout=self.timeout, verify=self.verify)
31
+ response.raise_for_status()
32
+
33
+ data = StringIO(response.text)
34
+ return closing(data)
@@ -0,0 +1,25 @@
1
+ """JSONSchema spec handlers urllib module."""
2
+ from contextlib import closing
3
+ from typing import ContextManager
4
+ from typing import Optional
5
+ from urllib.request import urlopen
6
+
7
+ from jsonschema_path.handlers.file import BaseFilePathHandler
8
+ from jsonschema_path.handlers.file import FileHandler
9
+ from jsonschema_path.handlers.protocols import SupportsRead
10
+
11
+
12
+ class UrllibHandler(BaseFilePathHandler):
13
+ """URL (urllib) scheme handler."""
14
+
15
+ def __init__(
16
+ self,
17
+ *allowed_schemes: str,
18
+ file_handler: Optional[FileHandler] = None,
19
+ timeout: int = 10
20
+ ):
21
+ super().__init__(*allowed_schemes, file_handler=file_handler)
22
+ self.timeout = timeout
23
+
24
+ def _open(self, uri: str) -> ContextManager[SupportsRead]:
25
+ return closing(urlopen(uri, timeout=self.timeout))
@@ -0,0 +1,14 @@
1
+ import os.path
2
+ import urllib.parse
3
+ import urllib.request
4
+
5
+
6
+ def uri_to_path(uri: str) -> str:
7
+ parsed = urllib.parse.urlparse(uri)
8
+ host = "{0}{0}{mnt}{0}".format(os.path.sep, mnt=parsed.netloc)
9
+ return os.path.normpath(
10
+ os.path.join(
11
+ host,
12
+ urllib.request.url2pathname(urllib.parse.unquote(parsed.path)),
13
+ )
14
+ )
@@ -0,0 +1,54 @@
1
+ # Use CSafeFile if available
2
+ from typing import TYPE_CHECKING
3
+ from typing import Any
4
+ from typing import Dict
5
+ from typing import Iterable
6
+ from typing import Tuple
7
+ from typing import Type
8
+
9
+ if TYPE_CHECKING:
10
+ from yaml import SafeLoader
11
+ else:
12
+ try:
13
+ from yaml import CSafeLoader as SafeLoader
14
+ except ImportError:
15
+ from yaml import SafeLoader
16
+
17
+
18
+ __all__ = [
19
+ "SafeLoader",
20
+ ]
21
+
22
+
23
+ class LimitedSafeLoader(type):
24
+ """Meta YAML loader that skips the resolution of the specified YAML tags."""
25
+
26
+ def __new__(
27
+ cls,
28
+ name: str,
29
+ bases: Tuple[type, ...],
30
+ namespace: Dict[str, Any],
31
+ exclude_resolvers: Iterable[str],
32
+ ) -> "LimitedSafeLoader":
33
+ exclude_resolvers = set(exclude_resolvers)
34
+ implicit_resolvers = {
35
+ key: [
36
+ (tag, regex)
37
+ for tag, regex in mappings
38
+ if tag not in exclude_resolvers
39
+ ]
40
+ for key, mappings in SafeLoader.yaml_implicit_resolvers.items()
41
+ }
42
+ return super().__new__(
43
+ cls,
44
+ name,
45
+ (SafeLoader, *bases),
46
+ {**namespace, "yaml_implicit_resolvers": implicit_resolvers},
47
+ )
48
+
49
+
50
+ class JsonschemaSafeLoader(
51
+ metaclass=LimitedSafeLoader,
52
+ exclude_resolvers={"tag:yaml.org,2002:timestamp"},
53
+ ):
54
+ """A safe YAML loader that leaves timestamps as strings."""
@@ -0,0 +1,128 @@
1
+ """JSONSchema spec paths module."""
2
+ import warnings
3
+ from contextlib import contextmanager
4
+ from pathlib import Path
5
+ from typing import Any
6
+ from typing import Iterator
7
+ from typing import Optional
8
+ from typing import Type
9
+ from typing import TypeVar
10
+
11
+ from pathable.paths import AccessorPath
12
+ from referencing import Specification
13
+ from referencing._core import Resolved
14
+ from referencing.jsonschema import DRAFT202012
15
+
16
+ from jsonschema_path.accessors import SchemaAccessor
17
+ from jsonschema_path.handlers import default_handlers
18
+ from jsonschema_path.handlers.protocols import SupportsRead
19
+ from jsonschema_path.readers import FilePathReader
20
+ from jsonschema_path.readers import FileReader
21
+ from jsonschema_path.readers import PathReader
22
+ from jsonschema_path.typing import ResolverHandlers
23
+ from jsonschema_path.typing import Schema
24
+
25
+ TSpec = TypeVar("TSpec", bound="SchemaPath")
26
+
27
+ SPEC_SEPARATOR = "#"
28
+
29
+
30
+ class SchemaPath(AccessorPath):
31
+ def __init__(self, accessor: SchemaAccessor, *args: Any, **kwargs: Any):
32
+ super().__init__(accessor, *args, **kwargs)
33
+ self._resolved_cached: Optional[Resolved[Any]] = None
34
+
35
+ @classmethod
36
+ def from_dict(
37
+ cls: Type[TSpec],
38
+ data: Schema,
39
+ *args: Any,
40
+ separator: str = SPEC_SEPARATOR,
41
+ specification: Specification[Schema] = DRAFT202012,
42
+ base_uri: str = "",
43
+ handlers: ResolverHandlers = default_handlers,
44
+ spec_url: Optional[str] = None,
45
+ ref_resolver_handlers: Optional[ResolverHandlers] = None,
46
+ ) -> TSpec:
47
+ if spec_url is not None:
48
+ warnings.warn(
49
+ "spec_url parameter is deprecated. " "Use base_uri instead.",
50
+ DeprecationWarning,
51
+ )
52
+ base_uri = spec_url
53
+ if ref_resolver_handlers is not None:
54
+ warnings.warn(
55
+ "ref_resolver_handlers parameter is deprecated. "
56
+ "Use handlers instead.",
57
+ DeprecationWarning,
58
+ )
59
+ handlers = ref_resolver_handlers
60
+
61
+ accessor: SchemaAccessor = SchemaAccessor.from_schema(
62
+ data,
63
+ specification=specification,
64
+ base_uri=base_uri,
65
+ handlers=handlers,
66
+ )
67
+
68
+ return cls(accessor, *args, separator=separator)
69
+
70
+ @classmethod
71
+ def from_path(
72
+ cls: Type[TSpec],
73
+ path: Path,
74
+ ) -> TSpec:
75
+ reader = PathReader(path)
76
+ data, base_uri = reader.read()
77
+ return cls.from_dict(data, base_uri=base_uri)
78
+
79
+ @classmethod
80
+ def from_file_path(
81
+ cls: Type[TSpec],
82
+ file_path: str,
83
+ ) -> TSpec:
84
+ reader = FilePathReader(file_path)
85
+ data, base_uri = reader.read()
86
+ return cls.from_dict(data, base_uri=base_uri)
87
+
88
+ @classmethod
89
+ def from_file(
90
+ cls: Type[TSpec],
91
+ fileobj: SupportsRead,
92
+ base_uri: str = "",
93
+ spec_url: Optional[str] = None,
94
+ ) -> TSpec:
95
+ reader = FileReader(fileobj)
96
+ data, _ = reader.read()
97
+ return cls.from_dict(data, base_uri=base_uri, spec_url=spec_url)
98
+
99
+ def exists(self) -> bool:
100
+ try:
101
+ self.content()
102
+ except KeyError:
103
+ return False
104
+ else:
105
+ return True
106
+
107
+ def as_uri(self) -> str:
108
+ return f"#/{str(self)}"
109
+
110
+ @contextmanager
111
+ def open(self) -> Any:
112
+ """Open the path."""
113
+ # Cached path content
114
+ with self.resolve() as resolved:
115
+ yield resolved.contents
116
+
117
+ @contextmanager
118
+ def resolve(self) -> Iterator[Resolved[Any]]:
119
+ """Resolve the path."""
120
+ # Cached path content
121
+ if self._resolved_cached is None:
122
+ self._resolved_cached = self._get_resolved()
123
+ yield self._resolved_cached
124
+
125
+ def _get_resolved(self) -> Resolved[Any]:
126
+ assert isinstance(self.accessor, SchemaAccessor)
127
+ with self.accessor.resolve(self.parts) as resolved:
128
+ return resolved
File without changes
@@ -0,0 +1,41 @@
1
+ """JSONSchema spec readers module."""
2
+ from pathlib import Path
3
+ from typing import Any
4
+ from typing import Hashable
5
+ from typing import Mapping
6
+ from typing import Tuple
7
+
8
+ from jsonschema_path.handlers import all_urls_handler
9
+ from jsonschema_path.handlers import file_handler
10
+ from jsonschema_path.handlers.protocols import SupportsRead
11
+
12
+
13
+ class BaseReader:
14
+ def read(self) -> Tuple[Mapping[Hashable, Any], str]:
15
+ raise NotImplementedError
16
+
17
+
18
+ class FileReader(BaseReader):
19
+ def __init__(self, fileobj: SupportsRead):
20
+ self.fileobj = fileobj
21
+
22
+ def read(self) -> Tuple[Mapping[Hashable, Any], str]:
23
+ return file_handler(self.fileobj), ""
24
+
25
+
26
+ class PathReader(BaseReader):
27
+ def __init__(self, path: Path):
28
+ self.path = path
29
+
30
+ def read(self) -> Tuple[Mapping[Hashable, Any], str]:
31
+ if not self.path.is_file():
32
+ raise OSError(f"No such file: {self.path}")
33
+
34
+ uri = self.path.as_uri()
35
+ return all_urls_handler(uri), uri
36
+
37
+
38
+ class FilePathReader(PathReader):
39
+ def __init__(self, file_path: str):
40
+ path = Path(file_path).absolute()
41
+ super().__init__(path)
@@ -0,0 +1,46 @@
1
+ from json import loads
2
+ from urllib.parse import urlsplit
3
+ from urllib.request import urlopen
4
+
5
+ from referencing import Resource
6
+ from referencing import Specification
7
+ from referencing.typing import URI
8
+ from referencing.typing import Retrieve
9
+
10
+ from jsonschema_path.typing import ResolverHandlers
11
+ from jsonschema_path.typing import Schema
12
+
13
+ USE_REQUESTS = False
14
+ try:
15
+ import requests
16
+ except ImportError:
17
+ pass
18
+ else:
19
+ USE_REQUESTS = True
20
+
21
+
22
+ class SchemaRetriever(Retrieve[Schema]):
23
+ def __init__(
24
+ self, handlers: ResolverHandlers, specification: Specification[Schema]
25
+ ):
26
+ self.handlers = handlers
27
+ self.specification = specification
28
+
29
+ def __call__(self, uri: URI) -> Resource[Schema]:
30
+ scheme = urlsplit(uri).scheme
31
+ if scheme in self.handlers:
32
+ handler = self.handlers[scheme]
33
+ contents = handler(uri)
34
+ return self.specification.create_resource(contents)
35
+
36
+ else:
37
+ if scheme in ["http", "https"] and USE_REQUESTS:
38
+ # Requests has support for detecting the correct encoding of
39
+ # json over http
40
+ contents = requests.get(uri).json()
41
+ return self.specification.create_resource(contents)
42
+
43
+ # Otherwise, pass off to urllib and assume utf-8
44
+ with urlopen(uri) as url:
45
+ contents = loads(url.read().decode("utf-8"))
46
+ return self.specification.create_resource(contents)
@@ -0,0 +1,8 @@
1
+ from typing import Any
2
+ from typing import Hashable
3
+ from typing import Mapping
4
+
5
+ Lookup = Mapping[Hashable, Any]
6
+
7
+ ResolverHandlers = Mapping[str, Any]
8
+ Schema = Mapping[Hashable, Any]
@@ -0,0 +1,8 @@
1
+ from typing import Any
2
+ from typing import Hashable
3
+ from typing import Mapping
4
+ from typing import Optional
5
+
6
+
7
+ def is_ref(item: Optional[Mapping[Hashable, Any]]) -> bool:
8
+ return isinstance(item, dict) and "$ref" in item and item["$ref"].__hash__
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,136 @@
1
+ Metadata-Version: 2.1
2
+ Name: jsonschema-path
3
+ Version: 0.3.0
4
+ Summary: JSONSchema Spec with object-oriented paths
5
+ Home-page: https://github.com/p1c2u/jsonschema-path
6
+ License: Apache-2.0
7
+ Keywords: jsonschema,swagger,spec
8
+ Author: Artur Maciag
9
+ Author-email: maciag.artur@gmail.com
10
+ Requires-Python: >=3.8.0,<4.0.0
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Software Development :: Libraries
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Dist: PyYAML (>=5.1)
24
+ Requires-Dist: pathable (>=0.4.1,<0.5.0)
25
+ Requires-Dist: referencing (>=0.28.0,<0.31.0)
26
+ Requires-Dist: requests (>=2.31.0,<3.0.0)
27
+ Project-URL: Repository, https://github.com/p1c2u/jsonschema-path
28
+ Description-Content-Type: text/x-rst
29
+
30
+ ***************
31
+ JSONSchema Path
32
+ ***************
33
+
34
+ .. image:: https://img.shields.io/pypi/v/jsonschema-path.svg
35
+ :target: https://pypi.python.org/pypi/jsonschema-path
36
+ .. image:: https://travis-ci.org/p1c2u/jsonschema-path.svg?branch=master
37
+ :target: https://travis-ci.org/p1c2u/jsonschema-path
38
+ .. image:: https://img.shields.io/codecov/c/github/p1c2u/jsonschema-path/master.svg?style=flat
39
+ :target: https://codecov.io/github/p1c2u/jsonschema-path?branch=master
40
+ .. image:: https://img.shields.io/pypi/pyversions/jsonschema-path.svg
41
+ :target: https://pypi.python.org/pypi/jsonschema-path
42
+ .. image:: https://img.shields.io/pypi/format/jsonschema-path.svg
43
+ :target: https://pypi.python.org/pypi/jsonschema-path
44
+ .. image:: https://img.shields.io/pypi/status/jsonschema-path.svg
45
+ :target: https://pypi.python.org/pypi/jsonschema-path
46
+
47
+ About
48
+ #####
49
+
50
+ Object-oriented JSONSchema
51
+
52
+ Key features
53
+ ############
54
+
55
+ * Traverse schema like paths
56
+ * Access schema on demand with separate dereferencing accessor layer
57
+
58
+ Installation
59
+ ############
60
+
61
+ .. code-block:: console
62
+
63
+ pip install jsonschema-path
64
+
65
+ Alternatively you can download the code and install from the repository:
66
+
67
+ .. code-block:: console
68
+
69
+ pip install -e git+https://github.com/p1c2u/jsonschema-path.git#egg=jsonschema_path
70
+
71
+
72
+ Usage
73
+ #####
74
+
75
+ .. code-block:: python
76
+
77
+ >>> from jsonschema_path import SchemaPath
78
+
79
+ >>> d = {
80
+ ... "properties": {
81
+ ... "info": {
82
+ ... "$ref": "#/$defs/Info",
83
+ ... },
84
+ ... },
85
+ ... "$defs": {
86
+ ... "Info": {
87
+ ... "properties": {
88
+ ... "title": {
89
+ ... "$ref": "http://example.com",
90
+ ... },
91
+ ... "version": {
92
+ ... "type": "string",
93
+ ... "default": "1.0",
94
+ ... },
95
+ ... },
96
+ ... },
97
+ ... },
98
+ ... }
99
+
100
+ >>> path = SchemaPath.from_dict(d)
101
+
102
+ >>> # Stat keys
103
+ >>> "properties" in path
104
+ True
105
+
106
+ >>> # Concatenate paths with /
107
+ >>> info_path = path / "properties" / "info"
108
+
109
+ >>> # Stat keys with implicit dereferencing
110
+ >>> "properties" in info_path
111
+ True
112
+
113
+ >>> # Concatenate paths with implicit dereferencing
114
+ >>> version_path = info_path / "properties" / "version"
115
+
116
+ >>> # Open content with implicit dereferencing
117
+ >>> with version_path.open() as contents:
118
+ ... print(contents)
119
+ {'type': 'string', 'default': '1.0'}
120
+
121
+
122
+ Related projects
123
+ ################
124
+
125
+ * `openapi-core <https://github.com/p1c2u/openapi-core>`__
126
+ Python library that adds client-side and server-side support for the OpenAPI.
127
+ * `openapi-spec-validator <https://github.com/p1c2u/openapi-spec-validator>`__
128
+ Python library that validates OpenAPI Specs against the OpenAPI 2.0 (aka Swagger) and OpenAPI 3.0 specification
129
+ * `openapi-schema-validator <https://github.com/p1c2u/openapi-schema-validator>`__
130
+ Python library that validates schema against the OpenAPI Schema Specification v3.0.
131
+
132
+ License
133
+ #######
134
+
135
+ Copyright (c) 2017-2022, Artur Maciag, All rights reserved. Apache-2.0
136
+
@@ -0,0 +1,19 @@
1
+ jsonschema_path/__init__.py,sha256=vRtO7szlR62K9xCwiSlW76sLY_A_gVYnPgI66hL5PpI,384
2
+ jsonschema_path/accessors.py,sha256=Pjt_Ku_zfbNXOfXyyLEGJ_pl5m_OMwkxL1IgxiSVmPM,3111
3
+ jsonschema_path/handlers/__init__.py,sha256=ETY0EjxKu3Cq8MT-b2PPLj3SwZn28Fjq0_KUeb41EIU,761
4
+ jsonschema_path/handlers/file.py,sha256=KQxHd9wW5vlm0fDkg6ZA026ldQiHu9hxVynR1_fjzXM,2056
5
+ jsonschema_path/handlers/protocols.py,sha256=rWMkdbjFyk7J2G1suQqmA0vC1mtfN9o4lW53prJBw1I,154
6
+ jsonschema_path/handlers/requests.py,sha256=Bex8aum7gBJWL69rTrfq7WNQ8t3Kyb0EDIpecGSqSEQ,1053
7
+ jsonschema_path/handlers/urllib.py,sha256=JKr0e5ncD13LlktFEaJNFCoeBSSt6an_7cU71iNxrxs,807
8
+ jsonschema_path/handlers/utils.py,sha256=i_G2KK0lQH5_ZZp2x5PQp7NdTbxTn0C4-LNLYFhyXZk,361
9
+ jsonschema_path/loaders.py,sha256=1tSOoYctya0FLNXT2OU0Tam5ZtTBU6lGKO9rjhuCl8Q,1392
10
+ jsonschema_path/paths.py,sha256=I2bBv9XscuBW9ywYKNY64UPQheOzL3u-C28xEgkF5x0,3924
11
+ jsonschema_path/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ jsonschema_path/readers.py,sha256=vkASvpO0nbKHLhbrWOdglgwd42J9NndwXHfQ-WafT_c,1127
13
+ jsonschema_path/retrievers.py,sha256=ZVUkK2cUkX6nn7KSxy_4nMR0T9z8L0_DhMbMs63UJoE,1471
14
+ jsonschema_path/typing.py,sha256=fcvGdj0YgaqGEWlu2ToXBrpzjuFPWFaBPFzKOBcGEyw,181
15
+ jsonschema_path/utils.py,sha256=FA8B1DwuGSQzLJGVtR_P6_ybMj86QeikaQOKfJSgrdE,247
16
+ jsonschema_path-0.3.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
17
+ jsonschema_path-0.3.0.dist-info/METADATA,sha256=IvyrozkL66Osu8AnL9YFf8510_kBLTQ8-ArT1MPfh7Y,4318
18
+ jsonschema_path-0.3.0.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
19
+ jsonschema_path-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 1.7.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any