Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Run Black. #5482

Merged
merged 15 commits into from
Jun 20, 2019
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ steps:

- command:
- "python -m pip install tox"
- "tox -e pep8"
label: "\U0001F9F9 PEP-8"
- "tox -e check_codestyle"
label: "\U0001F9F9 Check Style"
plugins:
- docker#v3.0.1:
image: "python:3.6"
Expand Down
1 change: 1 addition & 0 deletions changelog.d/5482.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Synapse's codebase is now formatted by `black`.
309 changes: 190 additions & 119 deletions contrib/cmdclient/console.py

Large diffs are not rendered by default.

38 changes: 15 additions & 23 deletions contrib/cmdclient/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ def __init__(self):
@defer.inlineCallbacks
def put_json(self, url, data):
response = yield self._create_put_request(
url,
data,
headers_dict={"Content-Type": ["application/json"]}
url, data, headers_dict={"Content-Type": ["application/json"]}
)
body = yield readBody(response)
defer.returnValue((response.code, body))
Expand All @@ -95,40 +93,34 @@ def _create_put_request(self, url, json_data, headers_dict={}):
"""

if "Content-Type" not in headers_dict:
raise defer.error(
RuntimeError("Must include Content-Type header for PUTs"))
raise defer.error(RuntimeError("Must include Content-Type header for PUTs"))

return self._create_request(
"PUT",
url,
producer=_JsonProducer(json_data),
headers_dict=headers_dict
"PUT", url, producer=_JsonProducer(json_data), headers_dict=headers_dict
)

def _create_get_request(self, url, headers_dict={}):
""" Wrapper of _create_request to issue a GET request
"""
return self._create_request(
"GET",
url,
headers_dict=headers_dict
)
return self._create_request("GET", url, headers_dict=headers_dict)

@defer.inlineCallbacks
def do_request(self, method, url, data=None, qparams=None, jsonreq=True, headers={}):
def do_request(
self, method, url, data=None, qparams=None, jsonreq=True, headers={}
):
if qparams:
url = "%s?%s" % (url, urllib.urlencode(qparams, True))

if jsonreq:
prod = _JsonProducer(data)
headers['Content-Type'] = ["application/json"];
headers["Content-Type"] = ["application/json"]
else:
prod = _RawProducer(data)

if method in ["POST", "PUT"]:
response = yield self._create_request(method, url,
producer=prod,
headers_dict=headers)
response = yield self._create_request(
method, url, producer=prod, headers_dict=headers
)
else:
response = yield self._create_request(method, url)

Expand All @@ -155,10 +147,7 @@ def _create_request(self, method, url, producer=None, headers_dict={}):
while True:
try:
response = yield self.agent.request(
method,
url.encode("UTF8"),
Headers(headers_dict),
producer
method, url.encode("UTF8"), Headers(headers_dict), producer
)
break
except Exception as e:
Expand All @@ -179,6 +168,7 @@ def sleep(self, seconds):
reactor.callLater(seconds, d.callback, seconds)
return d


class _RawProducer(object):
def __init__(self, data):
self.data = data
Expand All @@ -195,9 +185,11 @@ def pauseProducing(self):
def stopProducing(self):
pass


class _JsonProducer(object):
""" Used by the twisted http client to create the HTTP body from json
"""

def __init__(self, jsn):
self.data = jsn
self.body = json.dumps(jsn).encode("utf8")
Expand Down
36 changes: 17 additions & 19 deletions contrib/experiments/cursesio.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
from twisted.internet import reactor


class CursesStdIO():
class CursesStdIO:
def __init__(self, stdscr, callback=None):
self.statusText = "Synapse test app -"
self.searchText = ''
self.searchText = ""
self.stdscr = stdscr

self.logLine = ''
self.logLine = ""

self.callback = callback

Expand Down Expand Up @@ -71,8 +71,7 @@ def redraw(self):
i = 0
index = len(self.lines) - 1
while i < (self.rows - 3) and index >= 0:
self.stdscr.addstr(self.rows - 3 - i, 0, self.lines[index],
curses.A_NORMAL)
self.stdscr.addstr(self.rows - 3 - i, 0, self.lines[index], curses.A_NORMAL)
i = i + 1
index = index - 1

Expand All @@ -85,15 +84,13 @@ def paintStatus(self, text):
raise RuntimeError("TextTooLongError")

self.stdscr.addstr(
self.rows - 2, 0,
text + ' ' * (self.cols - len(text)),
curses.A_STANDOUT)
self.rows - 2, 0, text + " " * (self.cols - len(text)), curses.A_STANDOUT
)

def printLogLine(self, text):
self.stdscr.addstr(
0, 0,
text + ' ' * (self.cols - len(text)),
curses.A_STANDOUT)
0, 0, text + " " * (self.cols - len(text)), curses.A_STANDOUT
)

def doRead(self):
""" Input is ready! """
Expand All @@ -105,7 +102,7 @@ def doRead(self):

elif c == curses.KEY_ENTER or c == 10:
text = self.searchText
self.searchText = ''
self.searchText = ""

self.print_line(">> %s" % text)

Expand All @@ -122,11 +119,13 @@ def doRead(self):
return
self.searchText = self.searchText + chr(c)

self.stdscr.addstr(self.rows - 1, 0,
self.searchText + (' ' * (
self.cols - len(self.searchText) - 2)))
self.stdscr.addstr(
self.rows - 1,
0,
self.searchText + (" " * (self.cols - len(self.searchText) - 2)),
)

self.paintStatus(self.statusText + ' %d' % len(self.searchText))
self.paintStatus(self.statusText + " %d" % len(self.searchText))
self.stdscr.move(self.rows - 1, len(self.searchText))
self.stdscr.refresh()

Expand All @@ -143,7 +142,6 @@ def close(self):


class Callback(object):

def __init__(self, stdio):
self.stdio = stdio

Expand All @@ -152,7 +150,7 @@ def on_line(self, text):


def main(stdscr):
screen = CursesStdIO(stdscr) # create Screen object
screen = CursesStdIO(stdscr) # create Screen object

callback = Callback(screen)

Expand All @@ -164,5 +162,5 @@ def main(stdscr):
screen.close()


if __name__ == '__main__':
if __name__ == "__main__":
curses.wrapper(main)
Loading