text
stringlengths
0
828
""""""
Initializes a Flask object `app`: binds the HTML prettifying with
app.after_request.
:param app: The Flask application object.
""""""
app.config.setdefault('PRETTIFY', False)
if app.config['PRETTIFY']:
app.after_request(self._prettify_response)"
990,"def _prettify_response(self, response):
""""""
Prettify the HTML response.
:param response: A Flask Response object.
""""""
if response.content_type == 'text/html; charset=utf-8':
ugly = response.get_data(as_text=True)
soup = BeautifulSoup(ugly, 'html.parser')
pretty = soup.prettify(formatter='html')
response.direct_passthrough = False
response.set_data(pretty)
return response"
991,"async def _call(self, params):
""""""Call the SABnzbd API""""""
if self._session.closed:
raise SabnzbdApiException('Session already closed')
p = {**self._default_params, **params}
try:
async with timeout(self._timeout, loop=self._session.loop):
async with self._session.get(self._api_url, params=p) as resp:
data = await resp.json()
if data.get('status', True) is False:
self._handle_error(data, params)
else:
return data
except aiohttp.ClientError:
raise SabnzbdApiException('Unable to communicate with Sabnzbd API')
except asyncio.TimeoutError:
raise SabnzbdApiException('SABnzbd API request timed out')"
992,"async def refresh_data(self):
""""""Refresh the cached SABnzbd queue data""""""
queue = await self.get_queue()
history = await self.get_history()
totals = {}
for k in history:
if k[-4:] == 'size':
totals[k] = self._convert_size(history.get(k))
self.queue = {**totals, **queue}"
993,"def _convert_size(self, size_str):
""""""Convert units to GB""""""
suffix = size_str[-1]
if suffix == 'K':
multiplier = 1.0 / (1024.0 * 1024.0)
elif suffix == 'M':
multiplier = 1.0 / 1024.0
elif suffix == 'T':
multiplier = 1024.0
else:
multiplier = 1
try:
val = float(size_str.split(' ')[0])
return val * multiplier
except ValueError:
return 0.0"
994,"def _handle_error(self, data, params):
""""""Handle an error response from the SABnzbd API""""""
error = data.get('error', 'API call failed')
mode = params.get('mode')
raise SabnzbdApiException(error, mode=mode)"
995,"def __generate_key(self, config):
""""""
Generate the ssh key, and return the ssh config location
""""""
cwd = config.get('ssh_path', self._install_directory())
if config.is_affirmative('create', default=""yes""):
if not os.path.exists(cwd):
os.makedirs(cwd)
if not os.path.exists(os.path.join(cwd, config.get('keyname'))):
command = ""ssh-keygen -t %(type)s -f %(keyname)s -N "" % config.to_dict()
lib.call(command, cwd=cwd, output_log_level=logging.DEBUG)
if not config.has('ssh_path'):
config.set('ssh_path', cwd)
config.set('ssh_key_path', os.path.join(config.get('ssh_path'), config.get('keyname')))"
996,"def __install_ssh_config(self, config):
""""""
Install the ssh configuration
""""""
if not config.is_affirmative('use_global_ssh', default=""no""):
ssh_config_injection = self._build_ssh_config(config)
if not os.path.exists(ssh_config_path):
if self.injections.in_noninjected_file(ssh_config_path, ""Host %s"" % config.get('host')):
if config.is_affirmative('override'):
self.injections.inject(ssh_config_path, ssh_config_injection)
else: