Improved spawn interface. Added garbage collector
This commit is contained in:
@@ -5,10 +5,25 @@ from dataclasses import dataclass
|
||||
from enum import Enum, member
|
||||
from pathlib import Path
|
||||
from typing import Self
|
||||
import urllib.request
|
||||
|
||||
|
||||
from .errors import ClanError
|
||||
|
||||
|
||||
def url_ok(url: str):
|
||||
# Create a request object with the URL and the HEAD method
|
||||
req = urllib.request.Request(url, method="HEAD")
|
||||
try:
|
||||
# Open the URL and get the response object
|
||||
res = urllib.request.urlopen(req)
|
||||
# Return True if the status code is 200 (OK)
|
||||
if not res.status_code == 200:
|
||||
raise ClanError(f"URL has status code: {res.status_code}")
|
||||
except urllib.error.URLError as ex:
|
||||
raise ClanError(f"URL error: {ex}")
|
||||
|
||||
|
||||
# Define an enum with different members that have different values
|
||||
class ClanScheme(Enum):
|
||||
# Use the dataclass decorator to add fields and methods to the members
|
||||
@@ -88,6 +103,14 @@ class ClanURI:
|
||||
case _:
|
||||
raise ClanError(f"Unsupported uri components: {comb}")
|
||||
|
||||
def check_exits(self):
|
||||
match self.scheme:
|
||||
case ClanScheme.FILE.value(path):
|
||||
if not path.exists():
|
||||
raise ClanError(f"File does not exist: {path}")
|
||||
case ClanScheme.HTTP.value(url):
|
||||
return url_ok(url)
|
||||
|
||||
def get_internal(self) -> str:
|
||||
match self.scheme:
|
||||
case ClanScheme.FILE.value(path):
|
||||
|
||||
@@ -47,6 +47,7 @@ def list_history() -> list[HistoryEntry]:
|
||||
|
||||
|
||||
def add_history(uri: ClanURI) -> list[HistoryEntry]:
|
||||
uri.check_exits()
|
||||
user_history_file().parent.mkdir(parents=True, exist_ok=True)
|
||||
logs = list_history()
|
||||
found = False
|
||||
|
||||
Reference in New Issue
Block a user