-
-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathreaders.py
More file actions
23 lines (17 loc) · 679 Bytes
/
readers.py
File metadata and controls
23 lines (17 loc) · 679 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import sys
from collections.abc import Hashable
from os import path
from pathlib import Path
from typing import Any
from typing import Mapping
from typing import Tuple
from jsonschema_path.handlers import all_urls_handler
from jsonschema_path.handlers import file_handler
def read_from_stdin(filename: str) -> Tuple[Mapping[Hashable, Any], str]:
return file_handler(sys.stdin), "" # type: ignore
def read_from_filename(filename: str) -> Tuple[Mapping[Hashable, Any], str]:
if not path.isfile(filename):
raise OSError(f"No such file: {filename}")
filename = path.abspath(filename)
uri = Path(filename).as_uri()
return all_urls_handler(uri), uri