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_display_display_header(display):
display.display()
display._header_window.addstr.assert_called_with(
0, 0, castero.__title__, curses.color_pair(6) | curses.A_BOLD)
display._stdscr.reset_mock()
class DataFile:
"""Extendable class for objects with filesystem data.
Used when handling files with data that can reasonably be stored in a
dictionary. Particularly used in the Config class and the Feeds class.
Extended by classes which are based on a data file.
"""
PACKAGE = os.path.dirname(__file__)
HOME = os.path.expanduser('~')
XDG_CONFIG_HOME = os.getenv('XDG_CONFIG_HOME',
os.path.join(HOME, '.config'))
XDG_DATA_HOME = os.getenv('XDG_DATA_HOME',
os.path.join(HOME, '.local', 'share'))
CONFIG_DIR = os.path.join(XDG_CONFIG_HOME, castero.__title__)
DATA_DIR = os.path.join(XDG_DATA_HOME, castero.__title__)
DEFAULT_DOWNLOADED_DIR = os.path.join(DATA_DIR, "downloaded")
def __init__(self, path, default_path) -> None:
"""
Args:
path: the path to the data file
default_path: the path to the default data file
"""
assert os.path.exists(default_path)
self.data = collections.OrderedDict()
self._path = path
self._default_path = default_path
# if path doesn't exit, create it based on default_path
pass
# Config had a bad/unsupported value; we'll instead try all implemented
# options in order
for av_player in sorted(available_players):
try:
available_players[av_player].check_dependencies()
inst = available_players[av_player](title, path, episode)
return inst
except PlayerDependencyError:
pass
raise PlayerDependencyError("Sufficient dependencies were not met for"
" any players. If you recently downloaded"
" a player, you may need to reinstall %s"
% castero.__title__)
def redirect_stderr() -> io.TextIOWrapper:
temp_file = tempfile.TemporaryFile(prefix="%s-" % castero.__title__)
libc = ctypes.CDLL(None)
c_stderr = ctypes.c_void_p.in_dll(libc, 'stderr')
stderr_fd = sys.stderr.fileno()
libc.fflush(c_stderr)
sys.stderr.close()
# make the stderr fd point to the temp_file
os.dup2(temp_file.fileno(), stderr_fd)
# overwrite sys.stderr to use our modified fd
# - not explicitly necessary for our purposes, since curses does not
# use this field
sys.stderr = io.TextIOWrapper(os.fdopen(stderr_fd, 'wb'))
def display(self) -> None:
"""Draws all windows and sub-features, including titles and borders.
"""
# check if the screen size has changed
self.update_parent_dimensions()
# check to see if menu contents have been invalidated
if not self.menus_valid:
for perspective_id in self._perspectives:
self._perspectives[perspective_id].update_menus()
self.menus_valid = True
# add header
playing_str = castero.__title__
if self._queue.first is not None:
state = self._queue.first.state
playing_str = ["Stopped", "Playing", "Paused"][state] + \
": %s" % self._queue.first.title
if self._queue.length > 1:
playing_str += " (+%d in queue)" % (self._queue.length - 1)
if helpers.is_true(Config["right_align_time"]):
playing_str += ("[%s]" % self._queue.first.time_str).rjust(
self._header_window.getmaxyx()[1] - len(playing_str))
else:
playing_str += " [%s]" % self._queue.first.time_str
self._header_window.addstr(0, 0,
" " * self._header_window.getmaxyx()[1])
self._header_window.addstr(0, 0, playing_str,
import castero
import requests
class Net:
"""Manager for network requests.
This class provides helper methods for network requests. Generally just a
wrapper around the requests library.
"""
USER_AGENT = "%s %s <%s>" % (
castero.__title__, castero.__version__, castero.__url__)
HEADERS = {
'User-Agent': USER_AGENT
}
@staticmethod
def Get(url, **kwargs) -> requests.models.Response:
"""Send a GET request.
Args:
url: URL to retrieve from
**kwargs: optional arguments for requests.get()
Returns:
requests.models.Response: response
"""
return requests.get(url, headers=Net.HEADERS, **kwargs)
'coverage',
'codacy-coverage'
]
extras_require = {
'test': tests_require
}
def long_description():
with open("README.md") as readme:
return readme.read()
setuptools.setup(
name=castero.__title__,
version=castero.__version__,
description=castero.__description__,
long_description=long_description(),
long_description_content_type='text/markdown',
keywords=castero.__keywords__,
url=castero.__url__,
author=castero.__author__,
author_email=castero.__author_email__,
license=castero.__license__,
packages=[
'castero', 'castero.perspectives', 'castero.players', 'castero.menus'
],
package_data={
'castero': ['templates/*', 'templates/migrations/*'],
},
python_requires='>=3',
class DataFile:
"""Extendable class for objects with filesystem data.
Used when handling files with data that can reasonably be stored in a
dictionary. Particularly used in the Config class and the Feeds class.
Extended by classes which are based on a data file.
"""
PACKAGE = os.path.dirname(__file__)
HOME = os.path.expanduser('~')
XDG_CONFIG_HOME = os.getenv('XDG_CONFIG_HOME',
os.path.join(HOME, '.config'))
XDG_DATA_HOME = os.getenv('XDG_DATA_HOME',
os.path.join(HOME, '.local', 'share'))
CONFIG_DIR = os.path.join(XDG_CONFIG_HOME, castero.__title__)
DATA_DIR = os.path.join(XDG_DATA_HOME, castero.__title__)
DEFAULT_DOWNLOADED_DIR = os.path.join(DATA_DIR, "downloaded")
def __init__(self, path, default_path) -> None:
"""
Args:
path: the path to the data file
default_path: the path to the default data file
"""
assert os.path.exists(default_path)
self.data = collections.OrderedDict()
self._path = path
self._default_path = default_path
# if path doesn't exit, create it based on default_path
if not os.path.exists(self._path):