Skip to content

Commit a99ca72

Browse files
committed
Fix formatting/syntax issues with docs
1 parent 9704c9b commit a99ca72

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

docs/quickstart.rst

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,17 @@ Also, one weird case is for Void types in Unions (and in general, but Void is re
154154

155155
bob.employment.unemployed = None
156156

157-
.. note:: One caveat for unions is having structs as union members. Let us assume `employment.school` was actually a struct with a field of type `Text` called `name`::
157+
.. note:: One caveat for unions is having structs as union members. Let us assume `employment.school` was actually a struct with a field of type `Text` called `name`
158158

159-
alice.employment.school.name = "MIT"
160-
# Raises a KjException
159+
alice.employment.school.name = "MIT"
160+
# Raises a KjException
161161

162-
The problem is that a struct within a union isn't initialized automatically. You have to do the following::
162+
The problem is that a struct within a union isn't initialized automatically. You have to do the following::
163163

164-
TODO Broken
165-
school = alice.employment.init('school')
166-
school.name = "MIT"
164+
school = alice.employment.init('school')
165+
school.name = "MIT"
167166

168-
Note that this is similar to `init` for lists, but you don't pass a size. Requiring the `init` makes it more clear that a memory allocation is occurring, and will hopefully make you mindful that you shouldn't set more than 1 field inside of a union, else you risk a memory leak
167+
Note that this is similar to `init` for lists, but you don't pass a size. Requiring the `init` makes it more clear that a memory allocation is occurring, and will hopefully make you mindful that you shouldn't set more than 1 field inside of a union, else you risk a memory leak
169168

170169

171170
Writing to a File
@@ -180,14 +179,13 @@ There is also a `write_packed` function, that writes out the message more space-
180179
Writing to a socket
181180
~~~~~~~~~~~~~~~~~~~
182181
Alternatively, you can write to a socket. This is useful if you want to send the message over the network or to another process.
183-
A full example of this is available on GitHub `examples/async_socket_message_client.py <https://github.com/capnproto/pycapnp/blob/master/examples/async_socket_message_client.py>`_.
184-
185-
.. important:: Writing to a socket is implemented using asyncio and requires a running event loop both for the python part (asyncio) and the C++ part (KJ). See :ref:`RPC <kj-event-loop>` for more information.
186-
::
182+
A full example of this is available on GitHub `examples/async_socket_message_client.py <https://github.com/capnproto/pycapnp/blob/master/examples/async_socket_message_client.py>`_.::
187183

188184
stream = await capnp.AsyncIoStream.create_connection(host="localhost", port=6000)
189185
await addresses.write_async(stream)
190186

187+
.. important:: Writing to a socket is implemented using asyncio and requires a running event loop both for the python part (asyncio) and the C++ part (KJ). See :ref:`RPC <kj-event-loop>` for more information.
188+
191189
Read a message
192190
--------------
193191

@@ -211,14 +209,13 @@ Reading from a socket
211209
~~~~~~~~~~~~~~~~~~~~~
212210

213211
The same as for writing, you can read from a socket. This is useful if you want to receive the message over the network or from another process.
214-
A full example of this is available on GitHub `examples/async_socket_message_client.py <https://github.com/capnproto/pycapnp/blob/master/examples/async_socket_message_client.py>`_.
215-
216-
.. important:: Reading from a socket is implemented using asyncio and requires a running event loop both for the python part (asyncio) and the C++ part (KJ). See :ref:`RPC <kj-event-loop>` for more information.
217-
::
212+
A full example of this is available on GitHub `examples/async_socket_message_client.py <https://github.com/capnproto/pycapnp/blob/master/examples/async_socket_message_client.py>`_.::
218213

219214
stream = await capnp.AsyncIoStream.create_connection(host="localhost", port=6000)
220215
message = await addressbook_capnp.AddressBook.read_async(stream)
221216

217+
.. important:: Reading from a socket is implemented using asyncio and requires a running event loop both for the python part (asyncio) and the C++ part (KJ). See :ref:`RPC <kj-event-loop>` for more information.
218+
222219

223220
Reading Fields
224221
~~~~~~~~~~~~~~
@@ -284,7 +281,7 @@ The above methods only guaranteed to work if your file contains a single message
284281
addresses.write(f)
285282
addresses.write(f)
286283
addresses.write(f) # write 3 messages
287-
284+
288285
with open('example.bin', 'rb') as f:
289286
for addresses in addressbook_capnp.AddressBook.read_multiple(f):
290287
print(addresses)
@@ -375,7 +372,7 @@ To ensure proper creation, usage, and cleanup of the KJ event loop, a context ma
375372
async def main():
376373
async with capnp.kj_loop():
377374
# RPC calls here
378-
375+
379376
asyncio.run(main())
380377

381378
To simplify the usage, the helper function:py:meth:`capnp.run` can execute a asyncio coroutine within the :py:meth:`capnp.kj_loop` context manager::
@@ -395,18 +392,18 @@ Client
395392

396393
Thanks to the integration into the asyncio library, most of the boiler plate code is handled by pycapnp directly. The only thing that needs to be done is to create a client object and bootstrap the server capability.
397394

398-
Starting a Client
395+
Starting a Client
399396
#################
400397

401-
The first step is to open a socket to the server. For now this needs to be done
398+
The first step is to open a socket to the server. For now this needs to be done
402399
through :py:meth:`~._AsyncIoStream.create_connection`. A thin wrapper around :py:meth:`asyncio.get_running_loop().create_connection()`
403400
that adds all required Protocol handling::
404401

405402
async def main():
406403
host = 'localhost'
407404
port = '6000'
408405
connection = await capnp.AsyncIoStream.create_connection(host=host, port=port)
409-
406+
410407
asyncio.run(capnp.run(main()))
411408

412409
.. note:: :py:meth:`~._AsyncIoStream.create_connection` forwards all calls to the underlying asyncio create_connection function.
@@ -500,7 +497,7 @@ The first argument to :py:meth:`~._AsyncIoStream.create_server` must be a callba
500497
used by the pycapnp protocol implementation. The :py:obj:`callback` parameter will be called
501498
whenever a new connection is made. It receives a py:obj:`AsyncIoStream` instance as its
502499
only argument. If the result of py:obj:`callback` is a coroutine, it will be scheduled as a
503-
task. At minimum, the callback should create a :py:class:`capnp.TwoPartyServer` for the
500+
task. At minimum, the callback should create a :py:class:`capnp.TwoPartyServer` for the
504501
passed stream. :py:class:`capnp.TwoPartyServer` also exposes a
505502
:py:meth:`~.TwoPartyServer.on_disconnect()` function, which can be used as a task to handle
506503
the lifetime properly::

0 commit comments

Comments
 (0)