Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_url(self):
"""Test the URL retreiver."""
# test webpage
webpage_url = 'http://google.com'
get_url(webpage_url) # shouldn't raise
# test file
file_url = 'https://s3.amazonaws.com/pylinac/winston_lutz.zip'
local_file = get_url(file_url)
osp.isfile(local_file)
# bad URL
with self.assertRaises(URLError):
get_url('http://asdfasdfasdfasdfasdfasdfasdfasdf.org')
def test_get_url(self):
"""Test the URL retreiver."""
# test webpage
webpage_url = 'http://google.com'
get_url(webpage_url) # shouldn't raise
# test file
file_url = 'https://s3.amazonaws.com/pylinac/winston_lutz.zip'
local_file = get_url(file_url)
osp.isfile(local_file)
# bad URL
with self.assertRaises(URLError):
get_url('http://asdfasdfasdfasdfasdfasdfasdfasdf.org')
def from_url(cls, url, check_uid=True):
"""Instantiate a CBCT object from a URL pointing to a .zip object.
Parameters
----------
url : str
URL pointing to a zip archive of CBCT images.
check_uid : bool
Whether to enforce raising an error if more than one UID is found in the dataset.
"""
filename = get_url(url)
return cls.from_zip(filename, check_uid=check_uid)
def from_url(cls, url: str, **kwargs):
"""Instantiate from a URL.
Parameters
----------
url : str
URL of the raw file.
kwargs
Passed to :func:`~pylinac.core.image.load`.
"""
filename = get_url(url)
return cls(filename, **kwargs)
def load_url(url: str, progress_bar: bool=True, **kwargs):
"""Load an image from a URL.
Parameters
----------
url : str
A string pointing to a valid URL that points to a file.
.. note:: For some images (e.g. Github), the raw binary URL must be used, not simply the basic link.
progress_bar: bool
Whether to display a progress bar of download status.
"""
filename = get_url(url, progress_bar=progress_bar)
return load(filename, **kwargs)
def from_url(cls, url):
"""
Parameters
----------
url : str
The URL to the image.
"""
image_file = get_url(url)
return cls(image_file)
def from_url(cls, url: str, filter: int=None):
"""Instantiate from a URL."""
filename = get_url(url, progress_bar=True)
return cls(filename, filter=filter)
Parameters
----------
file_or_dir : str
String pointing to a single log file or a directory that contains log files.
exclude_beam_off : bool
Whether to include snapshots where the beam was off.
recursive : bool
Whether to recursively search a directory. Irrelevant for single log files.
Returns
-------
One of :class:`~pylinac.log_analyzer.Dynalog`, :class:`~pylinac.log_analyzer.TrajectoryLog`,
:class:`~pylinac.log_analyzer.MachineLogs`.
"""
if io.is_url(file_or_dir):
file_or_dir = io.get_url(file_or_dir)
if osp.isfile(file_or_dir):
if io.is_zipfile(file_or_dir):
return MachineLogs.from_zip(file_or_dir)
if not is_log(file_or_dir):
raise NotALogError("Not a valid log")
elif is_tlog(file_or_dir):
return TrajectoryLog(file_or_dir, exclude_beam_off)
else:
return Dynalog(file_or_dir, exclude_beam_off)
elif osp.isdir(file_or_dir):
return MachineLogs(file_or_dir, recursive)
else:
raise NotALogError(f"'{file_or_dir}' did not point to a valid file, directory, or ZIP archive")
def from_url(cls, url: str, use_filenames: bool = False):
"""Instantiate from a URL.
Parameters
----------
url : str
URL that points to a zip archive of the DICOM images.
use_filenames : bool
Whether to interpret axis angles using the filenames.
Set to true for Elekta machines where the gantry/coll/couch data is not in the DICOM metadata.
"""
zfile = get_url(url)
return cls.from_zip(zfile, use_filenames=use_filenames)
def from_url(cls, url, exclude_beam_off=True):
"""Instantiate a log from a URL."""
filename = io.get_url(url)
return cls(filename, exclude_beam_off)