Permalink
Browse files

Standardize GET signatures with args and kwargs

  • Loading branch information...
lovett committed Jan 20, 2019
1 parent 64c7cfc commit 6bc7b159018a8e6e20e352a5bd8a793ac5de9a61
@@ -367,7 +367,7 @@ max-bool-expr=5
max-branches=12

# Maximum number of locals for function / method body
max-locals=15
max-locals=20

# Maximum number of parents for a class (see R0901).
max-parents=7
@@ -24,11 +24,15 @@ def check_wayback_availability(url):
return closest_snapshot

@cherrypy.tools.negotiable()
def GET(self, query=None, wayback=None):
def GET(self, *_args, **kwargs):
"""Display a list of recently bookmarked URLs, or URLs matching a
search.
"""

query = kwargs.get('query')
wayback = kwargs.get('wayback')

if wayback:
return {
"json": self.check_wayback_availability(wayback)
@@ -73,16 +73,17 @@ def host_to_keyword(self, host):
return "live"

@cherrypy.tools.negotiable()
def GET(self, u=None, group=None): # pylint: disable=invalid-name
def GET(self, *_args, **kwargs):
"""Display all the URLs in a group."""

host = None
bounces = None
name = None
group = None
group = kwargs.get('group')
url = kwargs.get('u')

if u:
host = self.url_to_host(u)
if url:
host = self.url_to_host(url)
record = cherrypy.engine.publish(
"registry:first_key",
value=host,
@@ -118,7 +119,7 @@ def GET(self, u=None, group=None): # pylint: disable=invalid-name
# Re-scope the current URL to each known destination.
bounces = {
bounce["rowid"]: (
u.replace(host, bounce["value"]),
url.replace(host, bounce["value"]),
bounce["key"].split(":").pop()
)
for bounce in bounces
@@ -129,7 +130,7 @@ def GET(self, u=None, group=None): # pylint: disable=invalid-name
return {
"html": ("bounce.jinja.html", {
"departing_from": departing_from,
"departing_url": u,
"departing_url": url,
"site": host,
"group": group,
"name": name,
@@ -9,9 +9,10 @@ class Controller:
name = "Calls"

@cherrypy.tools.negotiable()
def GET(self, offset=0):
def GET(self, *_args, **kwargs):
"""Display a list of recent calls"""
offset = int(offset)

offset = int(kwargs.get('offset', 0))

exclusions = cherrypy.engine.publish(
"registry:search",
@@ -9,11 +9,13 @@ class Controller:
name = "Captures"

@cherrypy.tools.negotiable()
def GET(self, path=None, cid=None, offset=0):
def GET(self, *_args, **kwargs):
"""Display a list of recent captures, or captures matching a URI path.
"""

offset = int(offset)
path = kwargs.get('path')
cid = kwargs.get('cid')
offset = int(kwargs.get('offset', 0))

if cid:
captures = cherrypy.engine.publish(
@@ -41,7 +41,7 @@ def name_and_abbrev(code):

return (name, abbrev)

def GET(self):
def GET(self, *_args, **_kwargs):
"""Request the country code list and populate the registry"""

country_codes = cherrypy.engine.publish(
@@ -11,9 +11,12 @@ class Controller:
name = "Grids"

@cherrypy.tools.negotiable()
def GET(self, name="", start=None):
def GET(self, *_args, **kwargs):
"""Display the list of available grids, or the current grid"""

name = kwargs.get('name', '')
start = kwargs.get('start')

grids = cherrypy.engine.publish(
"registry:search",
"grids:*",
@@ -9,8 +9,9 @@ class Controller:
name = "Headers"

@cherrypy.tools.negotiable()
def GET(self):
def GET(self, *_args, **_kwargs):
"""Display the headers of the current request"""

headers = sorted(
cherrypy.request.headers.items(),
key=lambda pair: pair[0]
@@ -46,11 +46,6 @@ def test_returns_text(self):
self.assertEqual(response.code, 200)
self.assertText(response)

def test_noquery(self):
"""GET takes no querystring arguments"""
response = self.request("/?test_noquery=abc123")
self.assertEqual(response.code, 404)

def test_custom_header(self):
"""GET recognizes custom headers"""
response = self.request(
@@ -12,9 +12,12 @@ class Controller:
cache_key = "headlines"

@cherrypy.tools.negotiable()
def GET(self, limit=None, offset=None):
def GET(self, *_args, **kwargs):
"""Display a list of headlines."""

limit = kwargs.get('limit')
offset = kwargs.get('offset')

try:
limit = int(limit)
except (ValueError, TypeError):
@@ -36,7 +36,7 @@ def catalog_apps(self, apps):
return catalog

@cherrypy.tools.negotiable()
def GET(self):
def GET(self, *_args, **_kwargs):
"""Display the list of applications"""

template = "homepage.jinja.html"
@@ -10,7 +10,7 @@ class Controller:
name = "HTML Head"

@cherrypy.tools.negotiable()
def GET(self):
def GET(self, *_args, **_kwargs):
"""Present a form for specifying a URL to fetch."""

app_url = cherrypy.engine.publish("url:internal").pop()
@@ -11,7 +11,7 @@ class Controller:
cache_key = "ip:external"

@cherrypy.tools.negotiable()
def GET(self):
def GET(self, *_args, **_kwargs):
"""Display the client's local IP, and the server's external IP"""

client_ip = cherrypy.request.headers.get("Remote-Addr")
@@ -10,10 +10,14 @@ class Controller:
name = "Later"

@cherrypy.tools.negotiable()
def GET(self, url=None, title=None, tags=None, comments=None):
def GET(self, *_args, **kwargs):
"""Display a form for for bookmarking a URL"""

error = None
url = kwargs.get('url')
title = kwargs.get('title')
tags = kwargs.get('tags')
comments = kwargs.get('comments')

if title:
title = cherrypy.engine.publish(
@@ -14,11 +14,14 @@ class Controller:
}

@cherrypy.tools.negotiable()
def GET(self, number=None):
def GET(self, *_args, **kwargs):
"""
Display information about the specified number, or a search form to
look up a number
"""

number = kwargs.get('number')

sanitized_number = cherrypy.engine.publish(
"formatting:phone_sanitize",
number=number
@@ -10,18 +10,20 @@ class Controller:
name = "Redirect"

@cherrypy.tools.negotiable()
def GET(self, u=None): # pylint: disable=invalid-name
def GET(self, *_args, **kwargs):
"""Perform a client-side redirect to the URL specified in the
querystring.
"""

if u is not None:
u = unquote_plus(u)
url = kwargs.get('u')

if url is not None:
url = unquote_plus(url)

return {
"html": ("redirect.jinja.html", {
"app_name": self.name,
"dest": u
"dest": url
})
}
@@ -9,11 +9,15 @@ class Controller:
name = "Registry"

@cherrypy.tools.negotiable()
def GET(self, q=None, uid=None, key=None, view="search"):
def GET(self, *_args, **kwargs):
"""Display a UI to search for entries and add new ones."""

entries = ()
glossary = None
q = kwargs.get('q')
uid = kwargs.get('uid')
key = kwargs.get('key')
view = kwargs.get('view')

if uid:
entries = cherrypy.engine.publish(
@@ -18,7 +18,7 @@ class Controller:
remove_command = "scheduler:remove"

@cherrypy.tools.negotiable()
def GET(self):
def GET(self, *_args, **_kwargs):
"""Display scheduled reminders, and a form to create new ones."""

registry_rows = cherrypy.engine.publish(
@@ -9,6 +9,6 @@ class Controller:
user_facing = False

@staticmethod
def GET():
def GET(*_args, **_kwargs):
"""Redirect requests for non-static assets"""
raise cherrypy.HTTPRedirect("/")
@@ -9,7 +9,7 @@ class Controller:
name = "Speak"

@cherrypy.tools.negotiable()
def GET(self):
def GET(self, *_args, **_kwargs):
"""Present an interface for on-demand and scheduled muting of the
application.
@@ -131,9 +131,12 @@ def render_worker():
)

@cherrypy.tools.negotiable()
def GET(self, page_name=None, action="view"):
def GET(self, *_args, **kwargs):
"""Render a page or present the edit form."""

page_name = kwargs.get('page_name')
action = kwargs.get('action')

# Require a trailing slash for the default page.
#
# This is for the benefit of the service worker, whose scope
@@ -50,7 +50,7 @@ def list_of_transforms(self):
return sorted(list(self.transforms.keys()))

@cherrypy.tools.negotiable()
def GET(self):
def GET(self, *_args, **_kwargs):
"""The default view presents the available transformation methods"""

return {
@@ -17,9 +17,11 @@ class Controller:
name = "Visitors"

@cherrypy.tools.negotiable()
def GET(self, query=None):
def GET(self, *_args, **kwargs):
"""Display a search interface, and the results of the default query"""

query = kwargs.get('query')

site_domains = cherrypy.engine.publish(
"registry:search",
"logindex:site_domain",
@@ -69,17 +71,13 @@ def GET(self, query=None):
and record["ip"] not in cookies
}

app_url = cherrypy.engine.publish("url:internal").pop()

active_date = self.get_active_date(log_records, query)

return {
"html": ("visitors.jinja.html", {
"flagless_countries": ("AP", None),
"query": query,
"query_plan": query_plan,
"reversed_ips": reversed_ips,
"active_date": active_date,
"active_date": self.get_active_date(log_records, query),
"results": log_records,
"country_names": country_names,
"deltas": deltas,
@@ -88,7 +86,7 @@ def GET(self, query=None):
"saved_queries": saved_queries,
"app_name": self.name,
"annotations": annotations,
"app_url": app_url,
"app_url": cherrypy.engine.publish("url:internal").pop(),
"cookies": cookies
})
}
@@ -13,7 +13,7 @@ class Controller:
name = "Weather"

@cherrypy.tools.negotiable()
def GET(self):
def GET(self, *_args, **_kwargs):
"""Display selected parts of the most recent Darksky API query"""

config = cherrypy.engine.publish(
@@ -13,9 +13,11 @@ class Controller:
name = "Whois"

@cherrypy.tools.negotiable()
def GET(self, address=None):
def GET(self, *_args, **kwargs):
"""Display a search form and lookup results."""

address = kwargs.get('address')

if not address:
return {
"html": ("whois.jinja.html", {
@@ -5,7 +5,7 @@
from collections import deque


class Parser(HTMLParser):
class Parser(HTMLParser): # pylint: disable=abstract-method
"""Convert an HTML document to plain text.
Can selectively ignore certain tags if the source domain of the
Oops, something went wrong.

0 comments on commit 6bc7b15

Please sign in to comment.