this repo has no description
8
fork

Configure Feed

Select the types of activity you want to include in your feed.

Python bits

+109
+1
py-template/.python-version
··· 1 + 3.9.6
+1
py-template/README.md
··· 1 + This is a uv project to get started with Capnproto
+34
py-template/bellairs.capnp
··· 1 + @0xa59e1c95e37fb55d; 2 + 3 + interface Directory { 4 + # Represents a directory in the filesystem 5 + 6 + list @0 () -> (entries :List(Entry)); 7 + # Lists all entries in the directory 8 + 9 + struct Entry { 10 + name @0 :Text; # Name of the entry 11 + file @1 :File; # Reference to the file object 12 + } 13 + 14 + create @1 (name :Text) -> (file :File); 15 + # Creates a new file with the given name 16 + 17 + open @2 (name :Text) -> (file :File); 18 + # Opens an existing file with the given name 19 + 20 + delete @3 (name :Text); 21 + # Deletes a file with the given name 22 + } 23 + 24 + interface File { 25 + # Represents a file in the filesystem 26 + 27 + size @0 () -> (size :UInt64); 28 + # Returns the size of the file in bytes 29 + 30 + read @1 (off :UInt64 = 0, len :UInt64 = 0xffffffffffffffff) -> (data :Data); 31 + # Reads data from the file, optionally starting at offset and reading up to len bytes 32 + # Default is to read the entire file 33 + } 34 +
+58
py-template/client-and-mock-server.py
··· 1 + import asyncio 2 + import socket 3 + 4 + import capnp 5 + 6 + capnp.remove_import_hook() 7 + 8 + bellairs_capnp = capnp.load("bellairs.capnp") 9 + 10 + """ 11 + Mock file server so I can test this. 12 + """ 13 + 14 + 15 + class TestServer(bellairs_capnp.File.Server): 16 + def __init__(self): 17 + self.data = "Voop" 18 + 19 + async def size(self, **kwargs): 20 + return len(self.data) 21 + 22 + async def read(self, offset, len, **kwargs): 23 + return self.data 24 + 25 + 26 + async def client(sock): 27 + # See https://capnproto.github.io/pycapnp/capnp.html?highlight=twopartyclient#capnp.TwoPartyClient 28 + # AP: I am a bit unsure why the only thing available here 29 + # is a two-party client, but this works as a hack. 30 + client = capnp.TwoPartyClient(sock) 31 + cap = client.bootstrap() 32 + cap = cap.cast_as(bellairs_capnp.File) 33 + result = await cap.size() 34 + size = result.size 35 + print("Got %d" % size) 36 + assert size == 4 37 + 38 + 39 + async def main(): 40 + # Create a UNIX socket pair, because the network is 41 + # more complex. 42 + client_end, server_end = socket.socketpair(socket.AF_UNIX) 43 + # Create AsyncIoStreams, which is really a wrapper around 44 + # the C++ Capnproto connection. See https://github.com/capnproto/pycapnp/blob/59a639fa977e4a2e19c6cc60b44cbc9926418710/capnp/lib/capnp.pyx#L1314 45 + client_end = await capnp.AsyncIoStream.create_connection(sock=client_end) 46 + server_end = await capnp.AsyncIoStream.create_connection(sock=server_end) 47 + # Create a TwoPartyServer. Better options 48 + # are available (e.g., see https://github.com/capnproto/pycapnp/blob/master/examples/async_ssl_server.py#L60), but 49 + # I did this for now. I think we will need to use 50 + # `AsyncIoStream.create_server` and do some amount 51 + # of indirection in there 52 + _ = capnp.TwoPartyServer(server_end, bootstrap=TestServer()) 53 + print("Started file server") 54 + await client(client_end) 55 + 56 + 57 + if __name__ == "__main__": 58 + asyncio.run(capnp.run(main()))
+7
py-template/pyproject.toml
··· 1 + [project] 2 + name = "mvp-py" 3 + version = "0.1.0" 4 + description = "Add your description here" 5 + readme = "README.md" 6 + requires-python = ">=3.9.6" 7 + dependencies = []
+8
py-template/uv.lock
··· 1 + version = 1 2 + revision = 1 3 + requires-python = ">=3.9.6" 4 + 5 + [[package]] 6 + name = "mvp-py" 7 + version = "0.1.0" 8 + source = { virtual = "." }