Skip to content

Commit

Permalink
Normalize string style with black.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Dec 29, 2018
1 parent 7192081 commit 5931865
Show file tree
Hide file tree
Showing 28 changed files with 959 additions and 959 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export PYTHONPATH=src

style:
isort --recursive src tests
black --skip-string-normalization src tests
black src tests
flake8 src tests

test:
Expand Down
30 changes: 15 additions & 15 deletions src/websockets/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ def print_during_input(string):
sys.stdout.write(
(
# Save cursor position
'\N{ESC}7'
"\N{ESC}7"
# Add a new line
'\N{LINE FEED}'
"\N{LINE FEED}"
# Move cursor up
'\N{ESC}[A'
"\N{ESC}[A"
# Insert blank line, scroll last line down
'\N{ESC}[L'
"\N{ESC}[L"
# Print string in the inserted blank line
'{string}\N{LINE FEED}'
"{string}\N{LINE FEED}"
# Restore cursor position
'\N{ESC}8'
"\N{ESC}8"
# Move cursor down
'\N{ESC}[B'
"\N{ESC}[B"
).format(string=string)
)
sys.stdout.flush()
Expand All @@ -78,11 +78,11 @@ def print_over_input(string):
sys.stdout.write(
(
# Move cursor to beginning of line
'\N{CARRIAGE RETURN}'
"\N{CARRIAGE RETURN}"
# Delete current line
'\N{ESC}[K'
"\N{ESC}[K"
# Print string
'{string}\N{LINE FEED}'
"{string}\N{LINE FEED}"
).format(string=string)
)
sys.stdout.flush()
Expand Down Expand Up @@ -119,7 +119,7 @@ def run_client(uri, loop, inputs, stop):
except websockets.ConnectionClosed:
break
else:
print_during_input('< ' + message)
print_during_input("< " + message)

if outgoing in done:
message = outgoing.result()
Expand All @@ -141,7 +141,7 @@ def run_client(uri, loop, inputs, stop):

def main():
# If we're on Windows, enable VT100 terminal support.
if os.name == 'nt':
if os.name == "nt":
try:
win_enable_vt100()
except RuntimeError as exc:
Expand All @@ -160,7 +160,7 @@ def main():
description="Interactive WebSocket client.",
add_help=False,
)
parser.add_argument('uri', metavar='<uri>')
parser.add_argument("uri", metavar="<uri>")
args = parser.parse_args()

# Create an event loop that will run in a background thread.
Expand All @@ -183,7 +183,7 @@ def main():
try:
while True:
# Since there's no size limit, put_nowait is identical to put.
message = input('> ')
message = input("> ")
loop.call_soon_threadsafe(inputs.put_nowait, message)
except (KeyboardInterrupt, EOFError): # ^C, ^D
loop.call_soon_threadsafe(stop.set_result, None)
Expand All @@ -192,5 +192,5 @@ def main():
thread.join()


if __name__ == '__main__':
if __name__ == "__main__":
main()
48 changes: 24 additions & 24 deletions src/websockets/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from .uri import parse_uri


__all__ = ['connect', 'WebSocketClientProtocol']
__all__ = ["connect", "WebSocketClientProtocol"]

logger = logging.getLogger(__name__)

Expand All @@ -44,7 +44,7 @@ class WebSocketClientProtocol(WebSocketCommonProtocol):
"""

is_client = True
side = 'client'
side = "client"

def __init__(
self,
Expand Down Expand Up @@ -74,7 +74,7 @@ def write_http_request(self, path, headers):

# Since the path and headers only contain ASCII characters,
# we can keep this simple.
request = 'GET {path} HTTP/1.1\r\n'.format(path=path)
request = "GET {path} HTTP/1.1\r\n".format(path=path)
request += str(headers)

self.writer.write(request.encode())
Expand Down Expand Up @@ -134,7 +134,7 @@ def process_extensions(headers, available_extensions):
"""
accepted_extensions = []

header_values = headers.get_all('Sec-WebSocket-Extensions')
header_values = headers.get_all("Sec-WebSocket-Extensions")

if header_values:

Expand Down Expand Up @@ -191,7 +191,7 @@ def process_subprotocol(headers, available_subprotocols):
"""
subprotocol = None

header_values = headers.get_all('Sec-WebSocket-Protocol')
header_values = headers.get_all("Sec-WebSocket-Protocol")

if header_values:

Expand All @@ -208,7 +208,7 @@ def process_subprotocol(headers, available_subprotocols):

if len(parsed_header_values) > 1:
raise InvalidHandshake(
"Multiple subprotocols: {}".format(', '.join(parsed_header_values))
"Multiple subprotocols: {}".format(", ".join(parsed_header_values))
)

subprotocol = parsed_header_values[0]
Expand Down Expand Up @@ -252,15 +252,15 @@ def handshake(
request_headers = Headers()

if wsuri.port == (443 if wsuri.secure else 80): # pragma: no cover
request_headers['Host'] = wsuri.host
request_headers["Host"] = wsuri.host
else:
request_headers['Host'] = '{}:{}'.format(wsuri.host, wsuri.port)
request_headers["Host"] = "{}:{}".format(wsuri.host, wsuri.port)

if wsuri.user_info:
request_headers['Authorization'] = build_basic_auth(*wsuri.user_info)
request_headers["Authorization"] = build_basic_auth(*wsuri.user_info)

if origin is not None:
request_headers['Origin'] = origin
request_headers["Origin"] = origin

key = build_request(request_headers)

Expand All @@ -271,11 +271,11 @@ def handshake(
for extension_factory in available_extensions
]
)
request_headers['Sec-WebSocket-Extensions'] = extensions_header
request_headers["Sec-WebSocket-Extensions"] = extensions_header

if available_subprotocols is not None:
protocol_header = build_subprotocol_list(available_subprotocols)
request_headers['Sec-WebSocket-Protocol'] = protocol_header
request_headers["Sec-WebSocket-Protocol"] = protocol_header

if extra_headers is not None:
if isinstance(extra_headers, Headers):
Expand All @@ -285,15 +285,15 @@ def handshake(
for name, value in extra_headers:
request_headers[name] = value

request_headers.setdefault('User-Agent', USER_AGENT)
request_headers.setdefault("User-Agent", USER_AGENT)

self.write_http_request(wsuri.resource_name, request_headers)

status_code, response_headers = yield from self.read_http_response()
if status_code in (301, 302, 303, 307, 308):
if 'Location' not in response_headers:
raise InvalidMessage('Redirect response missing Location')
raise RedirectHandshake(parse_uri(response_headers['Location']))
if "Location" not in response_headers:
raise InvalidMessage("Redirect response missing Location")
raise RedirectHandshake(parse_uri(response_headers["Location"]))
elif status_code != 101:
raise InvalidStatusCode(status_code)

Expand Down Expand Up @@ -380,7 +380,7 @@ def __init__(
legacy_recv=False,
klass=WebSocketClientProtocol,
timeout=10,
compression='deflate',
compression="deflate",
origin=None,
extensions=None,
subprotocols=None,
Expand All @@ -402,14 +402,14 @@ def __init__(

self._wsuri = parse_uri(uri)
if self._wsuri.secure:
kwds.setdefault('ssl', True)
elif kwds.get('ssl') is not None:
kwds.setdefault("ssl", True)
elif kwds.get("ssl") is not None:
raise ValueError(
"connect() received a SSL context for a ws:// URI, "
"use a wss:// URI to enable TLS"
)

if compression == 'deflate':
if compression == "deflate":
if extensions is None:
extensions = []
if not any(
Expand Down Expand Up @@ -443,7 +443,7 @@ def __init__(

def _creating_connection(self):
if self._wsuri.secure:
self._kwds.setdefault('ssl', True)
self._kwds.setdefault("ssl", True)

factory = lambda: self._create_protocol(
host=self._wsuri.host,
Expand All @@ -464,7 +464,7 @@ def _creating_connection(self):
extra_headers=self._extra_headers,
)

if self._kwds.get('sock') is None:
if self._kwds.get("sock") is None:
host, port = self._wsuri.host, self._wsuri.port
else:
# If sock is given, host and port mustn't be specified.
Expand Down Expand Up @@ -497,11 +497,11 @@ def __iter__(self): # pragma: no cover
raise
except RedirectHandshake as e:
if self._wsuri.secure and not e.wsuri.secure:
raise InvalidHandshake('Redirect dropped TLS')
raise InvalidHandshake("Redirect dropped TLS")
self._wsuri = e.wsuri
continue # redirection chain continues
else:
raise InvalidHandshake('Maximum redirects exceeded')
raise InvalidHandshake("Maximum redirects exceeded")

self.ws_client = protocol
return protocol
Expand Down
2 changes: 1 addition & 1 deletion src/websockets/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
try: # pragma: no cover
asyncio_ensure_future = asyncio.ensure_future # Python ≥ 3.5
except AttributeError: # pragma: no cover
asyncio_ensure_future = getattr(asyncio, 'async') # Python < 3.5
asyncio_ensure_future = getattr(asyncio, "async") # Python < 3.5

try: # pragma: no cover
# Python ≥ 3.5
Expand Down
42 changes: 21 additions & 21 deletions src/websockets/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
__all__ = [
'AbortHandshake',
'ConnectionClosed',
'DuplicateParameter',
'InvalidHandshake',
'InvalidHeader',
'InvalidHeaderFormat',
'InvalidHeaderValue',
'InvalidMessage',
'InvalidOrigin',
'InvalidParameterName',
'InvalidParameterValue',
'InvalidState',
'InvalidStatusCode',
'InvalidUpgrade',
'InvalidURI',
'NegotiationError',
'PayloadTooBig',
'WebSocketProtocolError',
"AbortHandshake",
"ConnectionClosed",
"DuplicateParameter",
"InvalidHandshake",
"InvalidHeader",
"InvalidHeaderFormat",
"InvalidHeaderValue",
"InvalidMessage",
"InvalidOrigin",
"InvalidParameterName",
"InvalidParameterValue",
"InvalidState",
"InvalidStatusCode",
"InvalidUpgrade",
"InvalidURI",
"NegotiationError",
"PayloadTooBig",
"WebSocketProtocolError",
]


Expand All @@ -33,7 +33,7 @@ class AbortHandshake(InvalidHandshake):
"""

def __init__(self, status, headers, body=b''):
def __init__(self, status, headers, body=b""):
self.status = status
self.headers = headers
self.body = body
Expand Down Expand Up @@ -69,7 +69,7 @@ class InvalidHeader(InvalidHandshake):
def __init__(self, name, value=None):
if value is None:
message = "Missing {} header".format(name)
elif value == '':
elif value == "":
message = "Empty {} header".format(name)
else:
message = "Invalid {} header: {}".format(name, value)
Expand Down Expand Up @@ -108,7 +108,7 @@ class InvalidOrigin(InvalidHeader):
"""

def __init__(self, origin):
super().__init__('Origin', origin)
super().__init__("Origin", origin)


class InvalidStatusCode(InvalidHandshake):
Expand Down
Loading

0 comments on commit 5931865

Please sign in to comment.