Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/machinevisiontoolbox/Sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -4137,17 +4137,14 @@ class reads the JSON file and extracts the image, polygonal shapes, and associat
def __init__(self, filename: str) -> None:
self.filename = filename

try:
if str(filename).startswith(("http://", "https://")):
import urllib.request
if str(filename).startswith(("http://", "https://")):
import urllib.request

with urllib.request.urlopen(filename) as response: # noqa: S310
self.data = json.loads(response.read().decode("utf-8"))
else:
with open(self.filename, "r", encoding="utf-8") as f:
self.data = json.load(f)
except (OSError, json.JSONDecodeError, TypeError, ValueError):
return None
with urllib.request.urlopen(filename) as response: # noqa: S310
self.data = json.loads(response.read().decode("utf-8"))
else:
with open(self.filename, "r", encoding="utf-8") as f:
self.data = json.load(f)
self._nshapes = len(self.data.get("shapes", []))
self._version = self.data.get("version")

Expand Down