Applying black formatting
- Fixing flake8 configuration to agree with black - Adding black validation check to github actions
This commit is contained in:
@@ -22,12 +22,15 @@ class ExampleImpl(thread_capnp.Example.Server):
|
||||
"Implementation of the Example threading Cap'n Proto interface."
|
||||
|
||||
def subscribeStatus(self, subscriber, **kwargs):
|
||||
return capnp.getTimer().after_delay(10**9) \
|
||||
.then(lambda: subscriber.status(True)) \
|
||||
return (
|
||||
capnp.getTimer()
|
||||
.after_delay(10 ** 9)
|
||||
.then(lambda: subscriber.status(True))
|
||||
.then(lambda _: self.subscribeStatus(subscriber))
|
||||
)
|
||||
|
||||
def longRunning(self, **kwargs):
|
||||
return capnp.getTimer().after_delay(1 * 10**9)
|
||||
return capnp.getTimer().after_delay(1 * 10 ** 9)
|
||||
|
||||
def alive(self, **kwargs):
|
||||
return True
|
||||
@@ -38,10 +41,7 @@ class Server:
|
||||
while self.retry:
|
||||
try:
|
||||
# Must be a wait_for so we don't block on read()
|
||||
data = await asyncio.wait_for(
|
||||
self.reader.read(4096),
|
||||
timeout=0.1
|
||||
)
|
||||
data = await asyncio.wait_for(self.reader.read(4096), timeout=0.1)
|
||||
except asyncio.TimeoutError:
|
||||
logger.debug("myreader timeout.")
|
||||
continue
|
||||
@@ -56,10 +56,7 @@ class Server:
|
||||
while self.retry:
|
||||
try:
|
||||
# Must be a wait_for so we don't block on read()
|
||||
data = await asyncio.wait_for(
|
||||
self.server.read(4096),
|
||||
timeout=0.1
|
||||
)
|
||||
data = await asyncio.wait_for(self.server.read(4096), timeout=0.1)
|
||||
self.writer.write(data.tobytes())
|
||||
except asyncio.TimeoutError:
|
||||
logger.debug("mywriter timeout.")
|
||||
@@ -99,8 +96,10 @@ async def new_connection(reader, writer):
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(usage='''Runs the server bound to the\
|
||||
given address/port ADDRESS. ''')
|
||||
parser = argparse.ArgumentParser(
|
||||
usage="""Runs the server bound to the\
|
||||
given address/port ADDRESS. """
|
||||
)
|
||||
|
||||
parser.add_argument("address", help="ADDRESS:PORT")
|
||||
|
||||
@@ -109,20 +108,24 @@ given address/port ADDRESS. ''')
|
||||
|
||||
async def main():
|
||||
address = parse_args().address
|
||||
host = address.split(':')
|
||||
host = address.split(":")
|
||||
addr = host[0]
|
||||
port = host[1]
|
||||
|
||||
# Setup SSL context
|
||||
ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
|
||||
ctx.load_cert_chain(os.path.join(this_dir, 'selfsigned.cert'), os.path.join(this_dir, 'selfsigned.key'))
|
||||
ctx.load_cert_chain(
|
||||
os.path.join(this_dir, "selfsigned.cert"),
|
||||
os.path.join(this_dir, "selfsigned.key"),
|
||||
)
|
||||
|
||||
# Handle both IPv4 and IPv6 cases
|
||||
try:
|
||||
print("Try IPv4")
|
||||
server = await asyncio.start_server(
|
||||
new_connection,
|
||||
addr, port,
|
||||
addr,
|
||||
port,
|
||||
ssl=ctx,
|
||||
family=socket.AF_INET,
|
||||
)
|
||||
@@ -130,7 +133,8 @@ async def main():
|
||||
print("Try IPv6")
|
||||
server = await asyncio.start_server(
|
||||
new_connection,
|
||||
addr, port,
|
||||
addr,
|
||||
port,
|
||||
ssl=ctx,
|
||||
family=socket.AF_INET6,
|
||||
)
|
||||
@@ -138,5 +142,6 @@ async def main():
|
||||
async with server:
|
||||
await server.serve_forever()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
|
||||
Reference in New Issue
Block a user