38 lines
738 B
Python
38 lines
738 B
Python
#!/usr/bin/env python3
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import requests
|
|
|
|
|
|
class AbstractReader:
|
|
def __init__(self, path: str):
|
|
self._path = path
|
|
|
|
def read(self) -> str:
|
|
raise NotImplementedError()
|
|
|
|
|
|
class HttpReader(AbstractReader):
|
|
def read(self) -> str:
|
|
resp = requests.get(self._path)
|
|
resp.raise_for_status()
|
|
return resp.text
|
|
|
|
|
|
class KnownReader(AbstractReader):
|
|
def read(self) -> str:
|
|
return self._path
|
|
|
|
|
|
class StdioReader(AbstractReader):
|
|
def read(self) -> str:
|
|
return sys.stdin.read()
|
|
|
|
|
|
class FileReader(AbstractReader):
|
|
def read(self) -> str:
|
|
return Path(self._path).read_text(encoding='utf-8', errors='strict')
|