refactor: replace string concatenations with f-strings
All checks were successful
CI / test (push) Successful in 50s
All checks were successful
CI / test (push) Successful in 50s
This commit is contained in:
19
server.py
19
server.py
@@ -32,9 +32,9 @@ def youtu_be(env, start_response):
|
||||
id = env['PATH_INFO'][1:]
|
||||
env['PATH_INFO'] = '/watch'
|
||||
if not env['QUERY_STRING']:
|
||||
env['QUERY_STRING'] = 'v=' + id
|
||||
env['QUERY_STRING'] = f'v={id}'
|
||||
else:
|
||||
env['QUERY_STRING'] += '&v=' + id
|
||||
env['QUERY_STRING'] += f'&v={id}'
|
||||
yield from yt_app(env, start_response)
|
||||
|
||||
|
||||
@@ -64,12 +64,12 @@ def proxy_site(env, start_response, video=False):
|
||||
if 'HTTP_RANGE' in env:
|
||||
send_headers['Range'] = env['HTTP_RANGE']
|
||||
|
||||
url = "https://" + env['SERVER_NAME'] + env['PATH_INFO']
|
||||
url = f"https://{env['SERVER_NAME']}{env['PATH_INFO']}"
|
||||
# remove /name portion
|
||||
if video and '/videoplayback/name/' in url:
|
||||
url = url[0:url.rfind('/name/')]
|
||||
if env['QUERY_STRING']:
|
||||
url += '?' + env['QUERY_STRING']
|
||||
url += f'?{env["QUERY_STRING"]}'
|
||||
|
||||
try_num = 1
|
||||
first_attempt = True
|
||||
@@ -96,7 +96,7 @@ def proxy_site(env, start_response, video=False):
|
||||
+[('Access-Control-Allow-Origin', '*')])
|
||||
|
||||
if first_attempt:
|
||||
start_response(str(response.status) + ' ' + response.reason,
|
||||
start_response(f"{response.status} {response.reason}",
|
||||
response_headers)
|
||||
|
||||
content_length = int(dict(response_headers).get('Content-Length', 0))
|
||||
@@ -136,9 +136,8 @@ def proxy_site(env, start_response, video=False):
|
||||
fail_byte = start + total_received
|
||||
send_headers['Range'] = 'bytes=%d-%d' % (fail_byte, end)
|
||||
print(
|
||||
'Warning: YouTube closed the connection before byte',
|
||||
str(fail_byte) + '.', 'Expected', start+content_length,
|
||||
'bytes.'
|
||||
f'Warning: YouTube closed the connection before byte {fail_byte}. '
|
||||
f'Expected {start+content_length} bytes.'
|
||||
)
|
||||
|
||||
retry = True
|
||||
@@ -185,7 +184,7 @@ def split_url(url):
|
||||
# python STILL doesn't have a proper regular expression engine like grep uses built in...
|
||||
match = re.match(r'(?:https?://)?([\w-]+(?:\.[\w-]+)+?)(/.*|$)', url)
|
||||
if match is None:
|
||||
raise ValueError('Invalid or unsupported url: ' + url)
|
||||
raise ValueError(f'Invalid or unsupported url: {url}')
|
||||
|
||||
return match.group(1), match.group(2)
|
||||
|
||||
@@ -238,7 +237,7 @@ def site_dispatch(env, start_response):
|
||||
if base_name == '':
|
||||
base_name = domain
|
||||
else:
|
||||
base_name = domain + '.' + base_name
|
||||
base_name = f"{domain}.{base_name}"
|
||||
|
||||
try:
|
||||
handler = site_handlers[base_name]
|
||||
|
||||
Reference in New Issue
Block a user