diff --git a/docs/conf.py b/docs/conf.py index a6723b3..2efabde 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Paste documentation build configuration file, created by # sphinx-quickstart on Tue Apr 22 22:08:49 2008. diff --git a/paste/auth/auth_tkt.py b/paste/auth/auth_tkt.py index 17d3478..284d5a0 100644 --- a/paste/auth/auth_tkt.py +++ b/paste/auth/auth_tkt.py @@ -377,14 +377,14 @@ def set_user_cookie(self, environ, userid, tokens, user_data): cookies = [] if self.no_domain_cookie: - cookies.append(('Set-Cookie', '%s=%s; Path=/%s' % ( + cookies.append(('Set-Cookie', '{}={}; Path=/{}'.format( self.cookie_name, ticket.cookie_value(), cookie_options))) if self.current_domain_cookie: - cookies.append(('Set-Cookie', '%s=%s; Path=/; Domain=%s%s' % ( + cookies.append(('Set-Cookie', '{}={}; Path=/; Domain={}{}'.format( self.cookie_name, ticket.cookie_value(), cur_domain, cookie_options))) if self.wildcard_cookie: - cookies.append(('Set-Cookie', '%s=%s; Path=/; Domain=%s%s' % ( + cookies.append(('Set-Cookie', '{}={}; Path=/; Domain={}{}'.format( self.cookie_name, ticket.cookie_value(), wild_domain, cookie_options))) @@ -395,7 +395,7 @@ def logout_user_cookie(self, environ): wild_domain = '.' + cur_domain expires = 'Sat, 01-Jan-2000 12:00:00 GMT' cookies = [ - ('Set-Cookie', '%s=""; Expires="%s"; Path=/' % (self.cookie_name, expires)), + ('Set-Cookie', '{}=""; Expires="{}"; Path=/'.format(self.cookie_name, expires)), ('Set-Cookie', '%s=""; Expires="%s"; Path=/; Domain=%s' % (self.cookie_name, expires, cur_domain)), ('Set-Cookie', '%s=""; Expires="%s"; Path=/; Domain=%s' % diff --git a/paste/auth/cookie.py b/paste/auth/cookie.py index 2c36c2d..84ff999 100644 --- a/paste/auth/cookie.py +++ b/paste/auth/cookie.py @@ -41,7 +41,11 @@ """ -import hmac, base64, random, time, warnings +import hmac +import base64 +import random +import time +import warnings from functools import reduce try: from hashlib import sha1 @@ -301,12 +305,12 @@ def response_hook(status, response_headers, exc_info=None): "The value of the environmental variable %r " "is not a str (only str is allowed; got %r)" % (k, v)) - content.append("%s=%s" % (encode(k), encode(v))) + content.append("{}={}".format(encode(k), encode(v))) if content: content = ";".join(content) content = self.signer.sign(content) content = content.decode('utf8') - cookie = '%s=%s; Path=/;' % (self.cookie_name, content) + cookie = '{}={}; Path=/;'.format(self.cookie_name, content) if 'https' == environ['wsgi.url_scheme']: cookie += ' secure;' response_headers.append(('Set-Cookie', cookie)) diff --git a/paste/auth/digest.py b/paste/auth/digest.py index 04dec15..aff9c25 100644 --- a/paste/auth/digest.py +++ b/paste/auth/digest.py @@ -42,7 +42,8 @@ from hashlib import md5 except ImportError: from md5 import md5 -import time, random +import time +import random from urllib.parse import quote as url_quote def _split_auth_string(auth_string): @@ -51,7 +52,7 @@ def _split_auth_string(auth_string): for item in auth_string.split(","): try: if prev.count('"') == 1: - prev = "%s,%s" % (prev, item) + prev = "{},{}".format(prev, item) continue except AttributeError: if prev is None: @@ -74,7 +75,7 @@ def _auth_to_kv_pairs(auth_string): def digest_password(realm, username, password): """ construct the appropriate hashcode needed for HTTP digest """ - content = "%s:%s:%s" % (username, realm, password) + content = "{}:{}:{}".format(username, realm, password) content = content.encode('utf8') return md5(content).hexdigest() @@ -87,11 +88,11 @@ def __init__(self, realm, authfunc): def build_authentication(self, stale = ''): """ builds the authentication error """ - content = "%s:%s" % (time.time(), random.random()) + content = "{}:{}".format(time.time(), random.random()) content = content.encode('utf-8') nonce = md5(content).hexdigest() - content = "%s:%s" % (time.time(), random.random()) + content = "{}:{}".format(time.time(), random.random()) content = content.encode('utf-8') opaque = md5(content).hexdigest() @@ -100,7 +101,7 @@ def build_authentication(self, stale = ''): 'nonce': nonce, 'opaque': opaque } if stale: parts['stale'] = 'true' - head = ", ".join(['%s="%s"' % (k, v) for (k, v) in parts.items()]) + head = ", ".join(['{}="{}"'.format(k, v) for (k, v) in parts.items()]) head = [("WWW-Authenticate", 'Digest %s' % head)] return HTTPUnauthorized(headers=head) @@ -109,13 +110,13 @@ def compute(self, ha1, username, response, method, """ computes the authentication, raises error if unsuccessful """ if not ha1: return self.build_authentication() - content = '%s:%s' % (method, path) + content = '{}:{}'.format(method, path) content = content.encode('utf8') ha2 = md5(content).hexdigest() if qop: - chk = "%s:%s:%s:%s:%s:%s" % (ha1, nonce, nc, cnonce, qop, ha2) + chk = "{}:{}:{}:{}:{}:{}".format(ha1, nonce, nc, cnonce, qop, ha2) else: - chk = "%s:%s:%s" % (ha1, nonce, ha2) + chk = "{}:{}:{}".format(ha1, nonce, ha2) chk = chk.encode('utf8') if response != md5(chk).hexdigest(): if nonce in self.nonce: diff --git a/paste/auth/multi.py b/paste/auth/multi.py index e3516c2..49071ea 100644 --- a/paste/auth/multi.py +++ b/paste/auth/multi.py @@ -60,7 +60,7 @@ def set_default(self, name): self.default = self.binding[name] def set_query_argument(self, name, key = '*authmeth', value = None): """ choose authentication method based on a query argument """ - lookfor = "%s=%s" % (key, value or name) + lookfor = "{}={}".format(key, value or name) self.add_predicate(name, lambda environ: lookfor in environ.get('QUERY_STRING','')) def __call__(self, environ, start_response): diff --git a/paste/auth/open_id.py b/paste/auth/open_id.py index 9889bcc..6146038 100644 --- a/paste/auth/open_id.py +++ b/paste/auth/open_id.py @@ -64,7 +64,7 @@ def quoteattr(s): qs = html.escape(s) - return '"%s"' % (qs,) + return '"{}"'.format(qs) # You may need to manually add the openid package into your # python path if you don't have it installed with your system python. @@ -314,7 +314,7 @@ def render(self, request, message=None, css_class='alert', form_contents=None, self.page_header(request, title) if message: - request['body'].append("
This example consumer uses the Python OpenID library. It just verifies that the URL that you enter is your identity URL.
-''' % (title, title)) +'''.format(title, title)) def page_footer(self, request, form_contents): """Render the page footer""" @@ -371,15 +371,15 @@ def page_footer(self, request, form_contents): request['body'].append('''\%s' % html.escape(data) - html = '%s
%s\n%s' % ( + body += '
{}\n{}'.format(
self.style, html.escape(output), html.escape(output_callers))
return [body]
finally:
@@ -206,8 +206,8 @@ def profile(self, func, *args, **kw):
def format_function(self, func, *args, **kw):
args = map(repr, args)
args.extend(
- ['%s=%r' % (k, v) for k, v in kw.items()])
- return '%s(%s)' % (func.__name__, ', '.join(args))
+ ['{}={!r}'.format(k, v) for k, v in kw.items()])
+ return '{}({})'.format(func.__name__, ', '.join(args))
def make_profile_middleware(
diff --git a/paste/debug/watchthreads.py b/paste/debug/watchthreads.py
index 95e6f3a..d484ed0 100644
--- a/paste/debug/watchthreads.py
+++ b/paste/debug/watchthreads.py
@@ -264,7 +264,7 @@ def traceback_thread(thread_id):
# Only 2.5 has support for this, with this special function
return None
frames = sys._current_frames()
- if not thread_id in frames:
+ if thread_id not in frames:
return None
frame = frames[thread_id]
out = StringIO()
@@ -315,7 +315,7 @@ def bad_app(environ, start_response):
else:
count = 0
while 1:
- print("I'm alive %s (%s)" % (count, thread.get_ident()))
+ print("I'm alive {} ({})".format(count, thread.get_ident()))
time.sleep(10)
count += 1
start_response('200 OK', [('content-type', 'text/plain')])
diff --git a/paste/evalexception/middleware.py b/paste/evalexception/middleware.py
index c62d307..cbf5234 100644
--- a/paste/evalexception/middleware.py
+++ b/paste/evalexception/middleware.py
@@ -228,7 +228,7 @@ def summary(self, environ, start_response):
exception reports
"""
start_response('200 OK', [('Content-type', 'text/x-json')])
- data = [];
+ data = []
items = self.debug_infos.values()
items.sort(lambda a, b: cmp(a.created, b.created))
data = [item.json() for item in items]
@@ -403,7 +403,7 @@ def frame(self, tbid):
if id(frame) == tbid:
return frame
else:
- raise ValueError("No frame by id %s found from %r" % (tbid, self.frames))
+ raise ValueError("No frame by id {} found from {!r}".format(tbid, self.frames))
def wsgi_application(self, environ, start_response):
start_response('200 OK', [('content-type', 'text/html')])
@@ -437,7 +437,7 @@ def eval_javascript(self):
class EvalHTMLFormatter(formatter.HTMLFormatter):
def __init__(self, base_path, counter, **kw):
- super(EvalHTMLFormatter, self).__init__(**kw)
+ super().__init__(**kw)
self.base_path = base_path
self.counter = counter
@@ -514,16 +514,16 @@ def format_eval_html(exc_data, base_path, counter):
full_traceback_html = ''
return """
- %s
- %s
+ {}
+ {}
Additionally an error occurred while sending the %s report: +
Additionally an error occurred while sending the {} report: -
%s- """ % ( +
{}
+ """.format(
html.escape(str(rep)), output.getvalue())
else:
return (
@@ -441,14 +439,14 @@ def error_template(head_html, exception, extra):