Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up Python 2 styled code #97

Merged
merged 10 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/StyleGuide.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Python Style Guide. Some things to take particular note of:

* Docstrings are good. They should look like::

class AClass(object):
class AClass:
"""
doc string...
"""
Expand Down
20 changes: 10 additions & 10 deletions docs/do-it-yourself-framework.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ have to start with some root object, of course, which we'll pass in...

::

class ObjectPublisher(object):
class ObjectPublisher:

def __init__(self, root):
self.root = root
Expand Down Expand Up @@ -222,7 +222,7 @@ class into a module ``objectpub``::

from objectpub import ObjectPublisher

class Root(object):
class Root:

# The "index" method:
def __call__(self):
Expand Down Expand Up @@ -260,12 +260,12 @@ request is a little slim.
# insensitive keys:
from paste.response import HeaderDict

class Request(object):
class Request:
def __init__(self, environ):
self.environ = environ
self.fields = parse_formvars(environ)

class Response(object):
class Response:
def __init__(self):
self.headers = HeaderDict(
{'content-type': 'text/html'})
Expand All @@ -286,7 +286,7 @@ we'll attach the request and response objects here.
So, let's remind ourselves of what the ``__call__`` function looked
like::

class ObjectPublisher(object):
class ObjectPublisher:
...

def __call__(self, environ, start_response):
Expand All @@ -301,7 +301,7 @@ Lets's update that::
import threading
webinfo = threading.local()

class ObjectPublisher(object):
class ObjectPublisher:
...

def __call__(self, environ, start_response):
Expand Down Expand Up @@ -361,7 +361,7 @@ response).
To give an example of a really really simple middleware, here's one
that capitalizes the response::

class Capitalizer(object):
class Capitalizer:

# We generally pass in the application to be wrapped to
# the middleware constructor:
Expand Down Expand Up @@ -391,7 +391,7 @@ is a somewhat more thorough implementation of this.

from webob import Request

class Capitalizer(object):
class Capitalizer:
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
Expand All @@ -402,7 +402,7 @@ is a somewhat more thorough implementation of this.

So here's some code that does something useful, authentication::

class AuthMiddleware(object):
class AuthMiddleware:

def __init__(self, wrap_app):
self.wrap_app = wrap_app
Expand Down Expand Up @@ -450,7 +450,7 @@ So here's some code that does something useful, authentication::

from webob import Request, Response

class AuthMiddleware(object):
class AuthMiddleware:
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
Expand Down
16 changes: 8 additions & 8 deletions docs/url-parsing-with-wsgi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ request and responsibility for the response off to another object
(another actor, really). In the process we can actually retain some
control -- we can capture and transform the response, and we can
modify the request -- but that's not what the typical URL resolver will
do.
do.

Motivations
===========
Expand All @@ -80,7 +80,7 @@ Typically when a framework first supports WSGI or is integrated into
Paste, it is "monolithic" with respect to URLs. That is, you define
(in Paste, or maybe in Apache) a "root" URL, and everything under that
goes into the framework. What the framework does internally, Paste
does not know -- it probably finds internal objects to dispatch to,
does not know -- it probably finds internal objects to dispatch to,
but the framework is opaque to Paste. Not just to Paste, but to
any code that isn't in that framework.

Expand Down Expand Up @@ -171,7 +171,7 @@ in turn may delegate to yet another application.

Here's a very simple implementation of URLParser::

class URLParser(object):
class URLParser:
def __init__(self, dir):
self.dir = dir
def __call__(self, environ, start_response):
Expand Down Expand Up @@ -217,7 +217,7 @@ handle it. This "application" might be a URLParser or similar system

::

class GrabDate(object):
class GrabDate:
def __init__(self, subapp):
self.subapp = subapp
def __call__(self, environ, start_response):
Expand Down Expand Up @@ -249,12 +249,12 @@ well -- it usually just means use ``getattr`` with the popped
segments. But we'll implement a rough approximation of `Quixote's
<http://www.mems-exchange.org/software/quixote/>`_ URL parsing::

class ObjectApp(object):
class ObjectApp:
def __init__(self, obj):
self.obj = obj
def __call__(self, environ, start_response):
next = wsgilib.path_info_pop(environ)
if next is None:
if next is None:
# This is the object, lets serve it...
return self.publish(obj, environ, start_response)
next = next or '_q_index' # the default index method
Expand Down Expand Up @@ -288,7 +288,7 @@ Things to note:
(when ``next`` is ``None``). This means ``_q_traverse`` has to
consume extra segments of the path. In this version ``_q_traverse``
is only given the next piece of the path; Quixote gives it the
entire path (as a list of segments).
entire path (as a list of segments).

* ``publish`` is really a small and lame way to turn a Quixote object
into a WSGI application. For any serious framework you'd want to do
Expand All @@ -298,7 +298,7 @@ Things to note:
<http://www.python.org/peps/pep-0246.html>`_ to convert objects into
applications. This would include removing the explicit creation of
new ``ObjectApp`` instances, which could also be a kind of fall-back
adaptation.
adaptation.

Anyway, this example is less complete, but maybe it will get you
thinking.
4 changes: 2 additions & 2 deletions paste/auth/auth_tkt.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
DEFAULT_DIGEST = hashlib.md5


class AuthTicket(object):
class AuthTicket:

"""
This class represents an authentication token. You must pass in
Expand Down Expand Up @@ -221,7 +221,7 @@ def maybe_encode(s, encoding='utf8'):
return s


class AuthTKTMiddleware(object):
class AuthTKTMiddleware:

"""
Middleware that checks for signed cookies that match what
Expand Down
4 changes: 2 additions & 2 deletions paste/auth/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
WWW_AUTHENTICATE,
)

class AuthBasicAuthenticator(object):
class AuthBasicAuthenticator:
"""
implements ``Basic`` authentication details
"""
Expand Down Expand Up @@ -59,7 +59,7 @@ def authenticate(self, environ):

__call__ = authenticate

class AuthBasicHandler(object):
class AuthBasicHandler:
"""
HTTP/1.0 ``Basic`` authentication middleware

Expand Down
4 changes: 2 additions & 2 deletions paste/auth/cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def new_secret():
secret = secret.encode('utf8')
return secret

class AuthCookieSigner(object):
class AuthCookieSigner:
"""
save/restore ``environ`` entries via digially signed cookie

Expand Down Expand Up @@ -195,7 +195,7 @@ def append(self, value):
return
list.append(self, str(value))

class AuthCookieHandler(object):
class AuthCookieHandler:
"""
the actual handler that should be put in your middleware stack

Expand Down
8 changes: 4 additions & 4 deletions paste/auth/digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _split_auth_string(auth_string):
prev = "%s,%s" % (prev, item)
continue
except AttributeError:
if prev == None:
if prev is None:
prev = item
continue
else:
Expand All @@ -78,7 +78,7 @@ def digest_password(realm, username, password):
content = content.encode('utf8')
return md5(content).hexdigest()

class AuthDigestAuthenticator(object):
class AuthDigestAuthenticator:
""" implementation of RFC 2617 - HTTP Digest Authentication """
def __init__(self, realm, authfunc):
self.nonce = {} # list to prevent replay attacks
Expand Down Expand Up @@ -156,15 +156,15 @@ def authenticate(self, environ):
if qop:
assert 'auth' == qop
assert nonce and nc
except:
except Exception:
return self.build_authentication()
ha1 = self.authfunc(environ, realm, username)
return self.compute(ha1, username, response, method, authpath,
nonce, nc, cnonce, qop)

__call__ = authenticate

class AuthDigestHandler(object):
class AuthDigestHandler:
"""
middleware for HTTP Digest authentication (RFC 2617)

Expand Down
2 changes: 1 addition & 1 deletion paste/auth/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</html>
"""

class AuthFormHandler(object):
class AuthFormHandler:
"""
HTML-based login middleware

Expand Down
2 changes: 1 addition & 1 deletion paste/auth/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

"""

class MultiHandler(object):
class MultiHandler:
"""
Multiple Authentication Handler

Expand Down
2 changes: 1 addition & 1 deletion paste/cascade.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def make_cascade(loader, global_conf, catch='404', **local_conf):
apps = [app for name, app in apps]
return Cascade(apps, catch=catch)

class Cascade(object):
class Cascade:

"""
Passed a list of applications, ``Cascade`` will try each of them
Expand Down
2 changes: 1 addition & 1 deletion paste/cgiapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __call__(self, environ, start_response):
start_response(writer.status, writer.headers)
return []

class CGIWriter(object):
class CGIWriter:

def __init__(self, environ, start_response):
self.environ = environ
Expand Down
16 changes: 6 additions & 10 deletions paste/cgitb_catcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,22 @@
from io import StringIO
import sys

from paste.util import converters
from paste.util import converters, NO_DEFAULT
from paste.util.cgitb_hook import Hook


class NoDefault:
...


class CgitbMiddleware:

def __init__(self, app,
global_conf=None,
display=NoDefault,
display=NO_DEFAULT,
logdir=None,
context=5,
format="html"):
self.app = app
if global_conf is None:
global_conf = {}
if display is NoDefault:
if display is NO_DEFAULT:
display = global_conf.get('debug')
if isinstance(display, str):
display = converters.asbool(display)
Expand Down Expand Up @@ -66,7 +62,7 @@ def catching_iter(self, app_iter, environ):
if not error_on_close and hasattr(app_iter, 'close'):
try:
app_iter.close()
except:
except Exception:
close_response = self.exception_handler(
sys.exc_info(), environ)
response += (
Expand All @@ -88,7 +84,7 @@ def exception_handler(self, exc_info, environ):


def make_cgitb_middleware(app, global_conf,
display=NoDefault,
display=NO_DEFAULT,
logdir=None,
context=5,
format='html'):
Expand All @@ -108,7 +104,7 @@ def make_cgitb_middleware(app, global_conf,
source code
"""
from paste.deploy.converters import asbool
if display is not NoDefault:
if display is not NO_DEFAULT:
display = asbool(display)
if 'debug' in global_conf:
global_conf['debug'] = asbool(global_conf['debug'])
Expand Down
9 changes: 6 additions & 3 deletions paste/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
# Written for Paste (http://pythonpaste.org)
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
"""Paste Configuration Middleware and Objects"""

from paste.util import NO_DEFAULT
from paste.registry import RegistryManager, StackedObjectProxy


__all__ = ['DispatchingConfig', 'CONFIG', 'ConfigMiddleware']

class DispatchingConfig(StackedObjectProxy):
Expand Down Expand Up @@ -79,7 +82,7 @@ def _current_obj(self):

CONFIG = DispatchingConfig()

no_config = object()

class ConfigMiddleware(RegistryManager):
"""
A WSGI middleware that adds a ``paste.config`` key (by default)
Expand All @@ -96,15 +99,15 @@ def __init__(self, application, config, dispatching_config=CONFIG,
of the configuration `config`.
"""
def register_config(environ, start_response):
popped_config = environ.get(environ_key, no_config)
popped_config = environ.get(environ_key, NO_DEFAULT)
current_config = environ[environ_key] = config.copy()
environ['paste.registry'].register(dispatching_config,
current_config)

try:
app_iter = application(environ, start_response)
finally:
if popped_config is no_config:
if popped_config is NO_DEFAULT:
environ.pop(environ_key, None)
else:
environ[environ_key] = popped_config
Expand Down
2 changes: 1 addition & 1 deletion paste/cowbell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

SOUND = "http://www.c-eye.net/eyeon/WalkenWAVS/explorestudiospace.wav"

class MoreCowbell(object):
class MoreCowbell:
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
Expand Down
Loading