diff options
229 files changed, 19561 insertions, 0 deletions
diff --git a/.env.default b/.env.default new file mode 100644 index 0000000..ae53c39 --- /dev/null +++ b/.env.default @@ -0,0 +1 @@ +PYTHONPATH=. diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..452f5a3 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,3 @@ +# Contributing + +There's lots to do, and we're working hard, so any help is welcome! diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..19e1593 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,65 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + branches: + - '**' + +jobs: + tests: + name: ${{ matrix.os }} / ${{ matrix.python-version }} + runs-on: ${{ matrix.os }}-latest + strategy: + fail-fast: false + matrix: + os: [Ubuntu, MacOS, Windows] + python-version: ['3.9', '3.10', '3.11', '3.12'] + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Get full Python version + id: full-python-version + shell: bash + run: echo "version=$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")" >> "$GITHUB_OUTPUT" + + - name: Install poetry + shell: bash + run: | + python -m pip install poetry + echo "$HOME/.poetry/bin" >> $GITHUB_PATH + + - name: Configure poetry + shell: bash + run: poetry config virtualenvs.in-project true + + - name: Set up cache + uses: actions/cache@v3 + id: cache + with: + path: .venv + key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }} + + - name: Ensure cache is healthy + if: steps.cache.outputs.cache-hit == 'true' + shell: bash + run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv + + - name: Install dependencies + shell: bash + run: poetry install -E compiler + + - name: Generate code from proto files + shell: bash + run: poetry run python -m tests.generate -v + + - name: Execute test suite + shell: bash + run: poetry run python -m pytest tests/ diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml new file mode 100644 index 0000000..5199807 --- /dev/null +++ b/.github/workflows/code-quality.yml @@ -0,0 +1,18 @@ +name: Code Quality + +on: + push: + branches: + - master + pull_request: + branches: + - '**' + +jobs: + check-formatting: + name: Check code/doc formatting + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + - uses: pre-commit/action@v2.0.3 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bac28d2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +.coverage +.DS_Store +.env +.vscode/settings.json +.mypy_cache +.pytest_cache +.python-version +build/ +tests/output_* +**/__pycache__ +dist +**/*.egg-info +output +.idea +.DS_Store +.tox +.venv +.asv +venv +.devcontainer diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..4980047 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,29 @@ +ci: + autofix_prs: false + +repos: + - repo: https://github.com/pycqa/isort + rev: 5.11.5 + hooks: + - id: isort + + - repo: https://github.com/psf/black + rev: 23.1.0 + hooks: + - id: black + args: ["--target-version", "py310"] + + - repo: https://github.com/PyCQA/doc8 + rev: 0.10.1 + hooks: + - id: doc8 + additional_dependencies: + - toml + + # Removing since aristaproto don't use the java code and this breaks CI. + # - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + # rev: v2.10.0 + # hooks: + # - id: pretty-format-java + # args: [--autofix, --aosp] + # files: ^.*\.java$ diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..099fb78 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,23 @@ +MIT License + +Copyright (c) 2023 Arista Networks + +Copyright (c) 2019-2023 Daniel G. Taylor + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..31a18a9 --- /dev/null +++ b/README.md @@ -0,0 +1,463 @@ +# Arista Protobuf / Python gRPC bindings generator & library + +This was originally forked from <https://github.com/danielgtaylor/python-betterproto> @ [b8a091ae7055dd949d193695a06c9536ad51eea8](https://github.com/danielgtaylor/python-betterproto/commit/b8a091ae7055dd949d193695a06c9536ad51eea8). + +Afterwards commits up to `1f88b67eeb9871d33da154fd2c859b9d1aed62c1` on `python-betterproto` have been cherry-picked. + +Changes in this project compared with the base project: + +- Renamed to `aristaproto`. +- Cut support for Python < 3.9. +- Updating various CI actions and dependencies. +- Merged docs from multiple `rst` files to MarkDown. +- Keep nanosecond precision for `Timestamp`. + - Subclass `datetime` to store the original nano-second value when converting from `Timestamp` to `datetime`. + - On conversion from the subclass of `datetime` to `Timestamp` the original nano-second value is restored. + +## Installation + +First, install the package. Note that the `[compiler]` feature flag tells it to install extra dependencies only needed by the `protoc` plugin: + +```sh +# Install both the library and compiler +pip install "aristaproto[compiler]" + +# Install just the library (to use the generated code output) +pip install aristaproto +``` + +## Getting Started + +### Compiling proto files + +Given you installed the compiler and have a proto file, e.g `example.proto`: + +```protobuf +syntax = "proto3"; + +package hello; + +// Greeting represents a message you can tell a user. +message Greeting { + string message = 1; +} +``` + +You can run the following to invoke protoc directly: + +```sh +mkdir lib +protoc -I . --python_aristaproto_out=lib example.proto +``` + +or run the following to invoke protoc via grpcio-tools: + +```sh +pip install grpcio-tools +python -m grpc_tools.protoc -I . --python_aristaproto_out=lib example.proto +``` + +This will generate `lib/hello/__init__.py` which looks like: + +```python +# Generated by the protocol buffer compiler. DO NOT EDIT! +# sources: example.proto +# plugin: python-aristaproto +from dataclasses import dataclass + +import aristaproto + + +@dataclass +class Greeting(aristaproto.Message): + """Greeting represents a message you can tell a user.""" + + message: str = aristaproto.string_field(1) +``` + +Now you can use it! + +```python +>>> from lib.hello import Greeting +>>> test = Greeting() +>>> test +Greeting(message='') + +>>> test.message = "Hey!" +>>> test +Greeting(message="Hey!") + +>>> serialized = bytes(test) +>>> serialized +b'\n\x04Hey!' + +>>> another = Greeting().parse(serialized) +>>> another +Greeting(message="Hey!") + +>>> another.to_dict() +{"message": "Hey!"} +>>> another.to_json(indent=2) +'{\n "message": "Hey!"\n}' +``` + +### Async gRPC Support + +The generated Protobuf `Message` classes are compatible with [grpclib](https://github.com/vmagamedov/grpclib) so you are free to use it if you like. That said, this project also includes support for async gRPC stub generation with better static type checking and code completion support. It is enabled by default. + +Given an example service definition: + +```protobuf +syntax = "proto3"; + +package echo; + +message EchoRequest { + string value = 1; + // Number of extra times to echo + uint32 extra_times = 2; +} + +message EchoResponse { + repeated string values = 1; +} + +message EchoStreamResponse { + string value = 1; +} + +service Echo { + rpc Echo(EchoRequest) returns (EchoResponse); + rpc EchoStream(EchoRequest) returns (stream EchoStreamResponse); +} +``` + +Generate echo proto file: + +```sh +python -m grpc_tools.protoc -I . --python_aristaproto_out=. echo.proto +``` + +A client can be implemented as follows: + +```python +import asyncio +import echo + +from grpclib.client import Channel + + +async def main(): + channel = Channel(host="127.0.0.1", port=50051) + service = echo.EchoStub(channel) + response = await service.echo(echo.EchoRequest(value="hello", extra_times=1)) + print(response) + + async for response in service.echo_stream(echo.EchoRequest(value="hello", extra_times=1)): + print(response) + + # don't forget to close the channel when done! + channel.close() + + +if __name__ == "__main__": + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) + +``` + +which would output + +```python +EchoResponse(values=['hello', 'hello']) +EchoStreamResponse(value='hello') +EchoStreamResponse(value='hello') +``` + +This project also produces server-facing stubs that can be used to implement a Python +gRPC server. +To use them, simply subclass the base class in the generated files and override the +service methods: + +```python +import asyncio +from echo import EchoBase, EchoRequest, EchoResponse, EchoStreamResponse +from grpclib.server import Server +from typing import AsyncIterator + + +class EchoService(EchoBase): + async def echo(self, echo_request: "EchoRequest") -> "EchoResponse": + return EchoResponse([echo_request.value for _ in range(echo_request.extra_times)]) + + async def echo_stream(self, echo_request: "EchoRequest") -> AsyncIterator["EchoStreamResponse"]: + for _ in range(echo_request.extra_times): + yield EchoStreamResponse(echo_request.value) + + +async def main(): + server = Server([EchoService()]) + await server.start("127.0.0.1", 50051) + await server.wait_closed() + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) +``` + +### JSON + +Both serializing and parsing are supported to/from JSON and Python dictionaries using the following methods: + +- Dicts: `Message().to_dict()`, `Message().from_dict(...)` +- JSON: `Message().to_json()`, `Message().from_json(...)` + +For compatibility the default is to convert field names to `camelCase`. You can control this behavior by passing a casing value, e.g: + +```python +MyMessage().to_dict(casing=aristaproto.Casing.SNAKE) +``` + +### Determining if a message was sent + +Sometimes it is useful to be able to determine whether a message has been sent on the wire. This is how the Google wrapper types work to let you know whether a value is unset, set as the default (zero value), or set as something else, for example. + +Use `aristaproto.serialized_on_wire(message)` to determine if it was sent. This is a little bit different from the official Google generated Python code, and it lives outside the generated `Message` class to prevent name clashes. Note that it **only** supports Proto 3 and thus can **only** be used to check if `Message` fields are set. You cannot check if a scalar was sent on the wire. + +```py +# Old way (official Google Protobuf package) +>>> mymessage.HasField('myfield') + +# New way (this project) +>>> aristaproto.serialized_on_wire(mymessage.myfield) +``` + +### One-of Support + +Protobuf supports grouping fields in a `oneof` clause. Only one of the fields in the group may be set at a given time. For example, given the proto: + +```protobuf +syntax = "proto3"; + +message Test { + oneof foo { + bool on = 1; + int32 count = 2; + string name = 3; + } +} +``` + +On Python 3.10 and later, you can use a `match` statement to access the provided one-of field, which supports type-checking: + +```py +test = Test() +match test: + case Test(on=value): + print(value) # value: bool + case Test(count=value): + print(value) # value: int + case Test(name=value): + print(value) # value: str + case _: + print("No value provided") +``` + +You can also use `aristaproto.which_one_of(message, group_name)` to determine which of the fields was set. It returns a tuple of the field name and value, or a blank string and `None` if unset. + +```py +>>> test = Test() +>>> aristaproto.which_one_of(test, "foo") +["", None] + +>>> test.on = True +>>> aristaproto.which_one_of(test, "foo") +["on", True] + +# Setting one member of the group resets the others. +>>> test.count = 57 +>>> aristaproto.which_one_of(test, "foo") +["count", 57] + +# Default (zero) values also work. +>>> test.name = "" +>>> aristaproto.which_one_of(test, "foo") +["name", ""] +``` + +Again this is a little different than the official Google code generator: + +```py +# Old way (official Google protobuf package) +>>> message.WhichOneof("group") +"foo" + +# New way (this project) +>>> aristaproto.which_one_of(message, "group") +["foo", "foo's value"] +``` + +### Well-Known Google Types + +Google provides several well-known message types like a timestamp, duration, and several wrappers used to provide optional zero value support. Each of these has a special JSON representation and is handled a little differently from normal messages. The Python mapping for these is as follows: + +| Google Message | Python Type | Default | +| --------------------------- | ---------------------------------------- | ---------------------- | +| `google.protobuf.duration` | [`datetime.timedelta`][td] | `0` | +| `google.protobuf.timestamp` | Timezone-aware [`datetime.datetime`][dt] | `1970-01-01T00:00:00Z` | +| `google.protobuf.*Value` | `Optional[...]` | `None` | +| `google.protobuf.*` | `aristaproto.lib.google.protobuf.*` | `None` | + +[td]: https://docs.python.org/3/library/datetime.html#timedelta-objects +[dt]: https://docs.python.org/3/library/datetime.html#datetime.datetime + +For the wrapper types, the Python type corresponds to the wrapped type, e.g. `google.protobuf.BoolValue` becomes `Optional[bool]` while `google.protobuf.Int32Value` becomes `Optional[int]`. All of the optional values default to `None`, so don't forget to check for that possible state. Given: + +```protobuf +syntax = "proto3"; + +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; + +message Test { + google.protobuf.BoolValue maybe = 1; + google.protobuf.Timestamp ts = 2; + google.protobuf.Duration duration = 3; +} +``` + +You can do stuff like: + +```py +>>> t = Test().from_dict({"maybe": True, "ts": "2019-01-01T12:00:00Z", "duration": "1.200s"}) +>>> t +Test(maybe=True, ts=datetime.datetime(2019, 1, 1, 12, 0, tzinfo=datetime.timezone.utc), duration=datetime.timedelta(seconds=1, microseconds=200000)) + +>>> t.ts - t.duration +datetime.datetime(2019, 1, 1, 11, 59, 58, 800000, tzinfo=datetime.timezone.utc) + +>>> t.ts.isoformat() +'2019-01-01T12:00:00+00:00' + +>>> t.maybe = None +>>> t.to_dict() +{'ts': '2019-01-01T12:00:00Z', 'duration': '1.200s'} +``` + +## Generating Pydantic Models + +You can use python-aristaproto to generate pydantic based models, using +pydantic dataclasses. This means the results of the protobuf unmarshalling will +be typed checked. The usage is the same, but you need to add a custom option +when calling the protobuf compiler: + +```sh +protoc -I . --python_aristaproto_opt=pydantic_dataclasses --python_aristaproto_out=lib example.proto +``` + +With the important change being `--python_aristaproto_opt=pydantic_dataclasses`. This will +swap the dataclass implementation from the builtin python dataclass to the +pydantic dataclass. You must have pydantic as a dependency in your project for +this to work. + +## Development + +### Requirements + +- Python (3.9 or higher) + +- [poetry](https://python-poetry.org/docs/#installation) + *Needed to install dependencies in a virtual environment* + +- [poethepoet](https://github.com/nat-n/poethepoet) for running development tasks as defined in pyproject.toml + - Can be installed to your host environment via `pip install poethepoet` then executed as simple `poe` + - or run from the poetry venv as `poetry run poe` + +### Setup + +```sh +# Get set up with the virtual env & dependencies +poetry install -E compiler + +# Activate the poetry environment +poetry shell +``` + +### Code style + +This project enforces [black](https://github.com/psf/black) python code formatting. + +Before committing changes run: + +```sh +poe format +``` + +To avoid merge conflicts later, non-black formatted python code will fail in CI. + +### Tests + +There are two types of tests: + +1. Standard tests +2. Custom tests + +#### Standard tests + +Adding a standard test case is easy. + +- Create a new directory `aristaproto/tests/inputs/<name>` + - add `<name>.proto` with a message called `Test` + - add `<name>.json` with some test data (optional) + +It will be picked up automatically when you run the tests. + +- See also: [Standard Tests Development Guide](tests/README.md) + +#### Custom tests + +Custom tests are found in `tests/test_*.py` and are run with pytest. + +#### Running + +Here's how to run the tests. + +```sh +# Generate assets from sample .proto files required by the tests +poe generate +# Run the tests +poe test +``` + +To run tests as they are run in CI (with tox) run: + +```sh +poe full-test +``` + +### (Re)compiling Google Well-known Types + +Betterproto includes compiled versions for Google's well-known types at [src/aristaproto/lib/google](src/aristaproto/lib/google). +Be sure to regenerate these files when modifying the plugin output format, and validate by running the tests. + +Normally, the plugin does not compile any references to `google.protobuf`, since they are pre-compiled. To force compilation of `google.protobuf`, use the option `--custom_opt=INCLUDE_GOOGLE`. + +Assuming your `google.protobuf` source files (included with all releases of `protoc`) are located in `/usr/local/include`, you can regenerate them as follows: + +```sh +protoc \ + --plugin=protoc-gen-custom=src/aristaproto/plugin/main.py \ + --custom_opt=INCLUDE_GOOGLE \ + --custom_out=src/aristaproto/lib \ + -I /usr/local/include/ \ + /usr/local/include/google/protobuf/*.proto +``` + +## License + +Copyright 2023 Arista Networks + +Copyright 2019-2023 Daniel G. Taylor + +This software is free to use under the MIT license. See the [LICENSE](./LICENSE.md) file for license text. diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..d9bd096 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,1761 @@ +# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. + +[[package]] +name = "alabaster" +version = "0.7.13" +description = "A configurable sidebar-enabled Sphinx theme" +optional = false +python-versions = ">=3.6" +files = [ + {file = "alabaster-0.7.13-py3-none-any.whl", hash = "sha256:1ee19aca801bbabb5ba3f5f258e4422dfa86f82f3e9cefb0859b283cdd7f62a3"}, + {file = "alabaster-0.7.13.tar.gz", hash = "sha256:a27a4a084d5e690e16e01e03ad2b2e552c61a65469419b907243193de1a84ae2"}, +] + +[[package]] +name = "ansicon" +version = "1.89.0" +description = "Python wrapper for loading Jason Hood's ANSICON" +optional = false +python-versions = "*" +files = [ + {file = "ansicon-1.89.0-py2.py3-none-any.whl", hash = "sha256:f1def52d17f65c2c9682cf8370c03f541f410c1752d6a14029f97318e4b9dfec"}, + {file = "ansicon-1.89.0.tar.gz", hash = "sha256:e4d039def5768a47e4afec8e89e83ec3ae5a26bf00ad851f914d1240b444d2b1"}, +] + +[[package]] +name = "asv" +version = "0.4.2" +description = "Airspeed Velocity: A simple Python history benchmarking tool" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +files = [ + {file = "asv-0.4.2.tar.gz", hash = "sha256:9134f56b7a2f465420f17b5bb0dee16047a70f01029c996b7ab3f197de2d0779"}, +] + +[package.dependencies] +six = ">=1.4" + +[package.extras] +hg = ["python-hglib (>=1.5)"] + +[[package]] +name = "babel" +version = "2.14.0" +description = "Internationalization utilities" +optional = false +python-versions = ">=3.7" +files = [ + {file = "Babel-2.14.0-py3-none-any.whl", hash = "sha256:efb1a25b7118e67ce3a259bed20545c29cb68be8ad2c784c83689981b7a57287"}, + {file = "Babel-2.14.0.tar.gz", hash = "sha256:6919867db036398ba21eb5c7a0f6b28ab8cbc3ae7a73a44ebe34ae74a4e7d363"}, +] + +[package.extras] +dev = ["freezegun (>=1.0,<2.0)", "pytest (>=6.0)", "pytest-cov"] + +[[package]] +name = "betterproto-rust-codec" +version = "0.1.1" +description = "Fast conversion between betterproto messages and Protobuf wire format." +optional = true +python-versions = ">=3.7" +files = [ + {file = "betterproto_rust_codec-0.1.1-cp37-abi3-macosx_10_12_x86_64.whl", hash = "sha256:38ec2ec1743d815a04ffc020e8e3791955601b239b097e4ae0721528d4d8b608"}, + {file = "betterproto_rust_codec-0.1.1-cp37-abi3-macosx_11_0_arm64.whl", hash = "sha256:96a6deef8cda4b4d084df98b621e39a3123d8878dab551b86bbe733d885c4965"}, + {file = "betterproto_rust_codec-0.1.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:72ce9f153c83b1d0559ab40b0d6a31d8b83ac486230cefc298c8a08f4a97738b"}, + {file = "betterproto_rust_codec-0.1.1-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:b8a8485aabbe843208307a9a2c3fc8a8c09295fb22c840cebd5fa7ec6b8ddb36"}, + {file = "betterproto_rust_codec-0.1.1-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:22a395bf0c9dc86b7d3783ba43f161cd9f7a42809f38c70673cd9999d40eb4f1"}, + {file = "betterproto_rust_codec-0.1.1-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:ea99bee659b33500bb1afc4e0dbfa63530f50a7c549d0687565a10a0de63d18f"}, + {file = "betterproto_rust_codec-0.1.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:913d73365780d8f3da04cbaa1b2428ca5dc5372a5ee6f4ff2b9f30127362dff7"}, + {file = "betterproto_rust_codec-0.1.1-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:1a16dbbbc48f4a27b3b70205a2a71baa53fe0e915bc347b75d9b3864326446fa"}, + {file = "betterproto_rust_codec-0.1.1-cp37-abi3-win32.whl", hash = "sha256:06f95ac4c92aa1f28bd1be884c6db86f0bed05c9b93a1e4e3d80bbe2fc66847c"}, + {file = "betterproto_rust_codec-0.1.1-cp37-abi3-win_amd64.whl", hash = "sha256:5b70b3aea76f336cc243b966f2f7496cb6366ad2679d7a999ff521d873f9de48"}, + {file = "betterproto_rust_codec-0.1.1.tar.gz", hash = "sha256:6f7cbe80c8e3f87df992d71568771082c869ed6856521e01db833d9d3b012af5"}, +] + +[[package]] +name = "black" +version = "24.3.0" +description = "The uncompromising code formatter." +optional = true +python-versions = ">=3.8" +files = [ + {file = "black-24.3.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:7d5e026f8da0322b5662fa7a8e752b3fa2dac1c1cbc213c3d7ff9bdd0ab12395"}, + {file = "black-24.3.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9f50ea1132e2189d8dff0115ab75b65590a3e97de1e143795adb4ce317934995"}, + {file = "black-24.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e2af80566f43c85f5797365077fb64a393861a3730bd110971ab7a0c94e873e7"}, + {file = "black-24.3.0-cp310-cp310-win_amd64.whl", hash = "sha256:4be5bb28e090456adfc1255e03967fb67ca846a03be7aadf6249096100ee32d0"}, + {file = "black-24.3.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:4f1373a7808a8f135b774039f61d59e4be7eb56b2513d3d2f02a8b9365b8a8a9"}, + {file = "black-24.3.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:aadf7a02d947936ee418777e0247ea114f78aff0d0959461057cae8a04f20597"}, + {file = "black-24.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:65c02e4ea2ae09d16314d30912a58ada9a5c4fdfedf9512d23326128ac08ac3d"}, + {file = "black-24.3.0-cp311-cp311-win_amd64.whl", hash = "sha256:bf21b7b230718a5f08bd32d5e4f1db7fc8788345c8aea1d155fc17852b3410f5"}, + {file = "black-24.3.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:2818cf72dfd5d289e48f37ccfa08b460bf469e67fb7c4abb07edc2e9f16fb63f"}, + {file = "black-24.3.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:4acf672def7eb1725f41f38bf6bf425c8237248bb0804faa3965c036f7672d11"}, + {file = "black-24.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c7ed6668cbbfcd231fa0dc1b137d3e40c04c7f786e626b405c62bcd5db5857e4"}, + {file = "black-24.3.0-cp312-cp312-win_amd64.whl", hash = "sha256:56f52cfbd3dabe2798d76dbdd299faa046a901041faf2cf33288bc4e6dae57b5"}, + {file = "black-24.3.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:79dcf34b33e38ed1b17434693763301d7ccbd1c5860674a8f871bd15139e7837"}, + {file = "black-24.3.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:e19cb1c6365fd6dc38a6eae2dcb691d7d83935c10215aef8e6c38edee3f77abd"}, + {file = "black-24.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:65b76c275e4c1c5ce6e9870911384bff5ca31ab63d19c76811cb1fb162678213"}, + {file = "black-24.3.0-cp38-cp38-win_amd64.whl", hash = "sha256:b5991d523eee14756f3c8d5df5231550ae8993e2286b8014e2fdea7156ed0959"}, + {file = "black-24.3.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:c45f8dff244b3c431b36e3224b6be4a127c6aca780853574c00faf99258041eb"}, + {file = "black-24.3.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:6905238a754ceb7788a73f02b45637d820b2f5478b20fec82ea865e4f5d4d9f7"}, + {file = "black-24.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d7de8d330763c66663661a1ffd432274a2f92f07feeddd89ffd085b5744f85e7"}, + {file = "black-24.3.0-cp39-cp39-win_amd64.whl", hash = "sha256:7bb041dca0d784697af4646d3b62ba4a6b028276ae878e53f6b4f74ddd6db99f"}, + {file = "black-24.3.0-py3-none-any.whl", hash = "sha256:41622020d7120e01d377f74249e677039d20e6344ff5851de8a10f11f513bf93"}, + {file = "black-24.3.0.tar.gz", hash = "sha256:a0c9c4a0771afc6919578cec71ce82a3e31e054904e7197deacbc9382671c41f"}, +] + +[package.dependencies] +click = ">=8.0.0" +mypy-extensions = ">=0.4.3" +packaging = ">=22.0" +pathspec = ">=0.9.0" +platformdirs = ">=2" +tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} +typing-extensions = {version = ">=4.0.1", markers = "python_version < \"3.11\""} + +[package.extras] +colorama = ["colorama (>=0.4.3)"] +d = ["aiohttp (>=3.7.4)", "aiohttp (>=3.7.4,!=3.9.0)"] +jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] +uvloop = ["uvloop (>=0.15.2)"] + +[[package]] +name = "blessed" +version = "1.20.0" +description = "Easy, practical library for making terminal apps, by providing an elegant, well-documented interface to Colors, Keyboard input, and screen Positioning capabilities." +optional = false +python-versions = ">=2.7" +files = [ + {file = "blessed-1.20.0-py2.py3-none-any.whl", hash = "sha256:0c542922586a265e699188e52d5f5ac5ec0dd517e5a1041d90d2bbf23f906058"}, + {file = "blessed-1.20.0.tar.gz", hash = "sha256:2cdd67f8746e048f00df47a2880f4d6acbcdb399031b604e34ba8f71d5787680"}, +] + +[package.dependencies] +jinxed = {version = ">=1.1.0", markers = "platform_system == \"Windows\""} +six = ">=1.9.0" +wcwidth = ">=0.1.4" + +[[package]] +name = "bpython" +version = "0.19" +description = "Fancy Interface to the Python Interpreter" +optional = false +python-versions = "*" +files = [ + {file = "bpython-0.19-py2.py3-none-any.whl", hash = "sha256:95d95783bfadfa0a25300a648de5aba4423b0ee76b034022a81dde2b5e853c00"}, + {file = "bpython-0.19.tar.gz", hash = "sha256:476ce09a896c4d34bf5e56aca64650c56fdcfce45781a20dc1521221df8cc49c"}, +] + +[package.dependencies] +curtsies = ">=0.1.18" +greenlet = "*" +pygments = "*" +requests = "*" +six = ">=1.5" + +[package.extras] +jedi = ["jedi"] +urwid = ["urwid"] +watch = ["watchdog"] + +[[package]] +name = "cachelib" +version = "0.10.2" +description = "A collection of cache libraries in the same API interface." +optional = false +python-versions = ">=3.7" +files = [ + {file = "cachelib-0.10.2-py3-none-any.whl", hash = "sha256:42d49f2fad9310dd946d7be73d46776bcd4d5fde4f49ad210cfdd447fbdfc346"}, + {file = "cachelib-0.10.2.tar.gz", hash = "sha256:593faeee62a7c037d50fc835617a01b887503f972fb52b188ae7e50e9cb69740"}, +] + +[[package]] +name = "cachetools" +version = "5.3.2" +description = "Extensible memoizing collections and decorators" +optional = false +python-versions = ">=3.7" +files = [ + {file = "cachetools-5.3.2-py3-none-any.whl", hash = "sha256:861f35a13a451f94e301ce2bec7cac63e881232ccce7ed67fab9b5df4d3beaa1"}, + {file = "cachetools-5.3.2.tar.gz", hash = "sha256:086ee420196f7b2ab9ca2db2520aca326318b68fe5ba8bc4d49cca91add450f2"}, +] + +[[package]] +name = "certifi" +version = "2023.11.17" +description = "Python package for providing Mozilla's CA Bundle." +optional = false +python-versions = ">=3.6" +files = [ + {file = "certifi-2023.11.17-py3-none-any.whl", hash = "sha256:e036ab49d5b79556f99cfc2d9320b34cfbe5be05c5871b51de9329f0603b0474"}, + {file = "certifi-2023.11.17.tar.gz", hash = "sha256:9b469f3a900bf28dc19b8cfbf8019bf47f7fdd1a65a1d4ffb98fc14166beb4d1"}, +] + +[[package]] +name = "cfgv" +version = "3.4.0" +description = "Validate configuration and produce human readable error messages." +optional = false +python-versions = ">=3.8" +files = [ + {file = "cfgv-3.4.0-py2.py3-none-any.whl", hash = "sha256:b7265b1f29fd3316bfcd2b330d63d024f2bfd8bcb8b0272f8e19a504856c48f9"}, + {file = "cfgv-3.4.0.tar.gz", hash = "sha256:e52591d4c5f5dead8e0f673fb16db7949d2cfb3f7da4582893288f0ded8fe560"}, +] + +[[package]] +name = "chardet" +version = "5.2.0" +description = "Universal encoding detector for Python 3" +optional = false +python-versions = ">=3.7" +files = [ + {file = "chardet-5.2.0-py3-none-any.whl", hash = "sha256:e1cf59446890a00105fe7b7912492ea04b6e6f06d4b742b2c788469e34c82970"}, + {file = "chardet-5.2.0.tar.gz", hash = "sha256:1b3b6ff479a8c414bc3fa2c0852995695c4a026dcd6d0633b2dd092ca39c1cf7"}, +] + +[[package]] +name = "charset-normalizer" +version = "3.3.2" +description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." +optional = false +python-versions = ">=3.7.0" +files = [ + {file = "charset-normalizer-3.3.2.tar.gz", hash = "sha256:f30c3cb33b24454a82faecaf01b19c18562b1e89558fb6c56de4d9118a032fd5"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:25baf083bf6f6b341f4121c2f3c548875ee6f5339300e08be3f2b2ba1721cdd3"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:06435b539f889b1f6f4ac1758871aae42dc3a8c0e24ac9e60c2384973ad73027"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9063e24fdb1e498ab71cb7419e24622516c4a04476b17a2dab57e8baa30d6e03"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6897af51655e3691ff853668779c7bad41579facacf5fd7253b0133308cf000d"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1d3193f4a680c64b4b6a9115943538edb896edc190f0b222e73761716519268e"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:cd70574b12bb8a4d2aaa0094515df2463cb429d8536cfb6c7ce983246983e5a6"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8465322196c8b4d7ab6d1e049e4c5cb460d0394da4a27d23cc242fbf0034b6b5"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a9a8e9031d613fd2009c182b69c7b2c1ef8239a0efb1df3f7c8da66d5dd3d537"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:beb58fe5cdb101e3a055192ac291b7a21e3b7ef4f67fa1d74e331a7f2124341c"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:e06ed3eb3218bc64786f7db41917d4e686cc4856944f53d5bdf83a6884432e12"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_ppc64le.whl", hash = "sha256:2e81c7b9c8979ce92ed306c249d46894776a909505d8f5a4ba55b14206e3222f"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_s390x.whl", hash = "sha256:572c3763a264ba47b3cf708a44ce965d98555f618ca42c926a9c1616d8f34269"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:fd1abc0d89e30cc4e02e4064dc67fcc51bd941eb395c502aac3ec19fab46b519"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-win32.whl", hash = "sha256:3d47fa203a7bd9c5b6cee4736ee84ca03b8ef23193c0d1ca99b5089f72645c73"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-win_amd64.whl", hash = "sha256:10955842570876604d404661fbccbc9c7e684caf432c09c715ec38fbae45ae09"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:802fe99cca7457642125a8a88a084cef28ff0cf9407060f7b93dca5aa25480db"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:573f6eac48f4769d667c4442081b1794f52919e7edada77495aaed9236d13a96"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:549a3a73da901d5bc3ce8d24e0600d1fa85524c10287f6004fbab87672bf3e1e"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f27273b60488abe721a075bcca6d7f3964f9f6f067c8c4c605743023d7d3944f"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1ceae2f17a9c33cb48e3263960dc5fc8005351ee19db217e9b1bb15d28c02574"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:65f6f63034100ead094b8744b3b97965785388f308a64cf8d7c34f2f2e5be0c4"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:753f10e867343b4511128c6ed8c82f7bec3bd026875576dfd88483c5c73b2fd8"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:4a78b2b446bd7c934f5dcedc588903fb2f5eec172f3d29e52a9096a43722adfc"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:e537484df0d8f426ce2afb2d0f8e1c3d0b114b83f8850e5f2fbea0e797bd82ae"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:eb6904c354526e758fda7167b33005998fb68c46fbc10e013ca97f21ca5c8887"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_ppc64le.whl", hash = "sha256:deb6be0ac38ece9ba87dea880e438f25ca3eddfac8b002a2ec3d9183a454e8ae"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_s390x.whl", hash = "sha256:4ab2fe47fae9e0f9dee8c04187ce5d09f48eabe611be8259444906793ab7cbce"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:80402cd6ee291dcb72644d6eac93785fe2c8b9cb30893c1af5b8fdd753b9d40f"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-win32.whl", hash = "sha256:7cd13a2e3ddeed6913a65e66e94b51d80a041145a026c27e6bb76c31a853c6ab"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-win_amd64.whl", hash = "sha256:663946639d296df6a2bb2aa51b60a2454ca1cb29835324c640dafb5ff2131a77"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:0b2b64d2bb6d3fb9112bafa732def486049e63de9618b5843bcdd081d8144cd8"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:ddbb2551d7e0102e7252db79ba445cdab71b26640817ab1e3e3648dad515003b"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:55086ee1064215781fff39a1af09518bc9255b50d6333f2e4c74ca09fac6a8f6"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8f4a014bc36d3c57402e2977dada34f9c12300af536839dc38c0beab8878f38a"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a10af20b82360ab00827f916a6058451b723b4e65030c5a18577c8b2de5b3389"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:8d756e44e94489e49571086ef83b2bb8ce311e730092d2c34ca8f7d925cb20aa"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:90d558489962fd4918143277a773316e56c72da56ec7aa3dc3dbbe20fdfed15b"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6ac7ffc7ad6d040517be39eb591cac5ff87416c2537df6ba3cba3bae290c0fed"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:7ed9e526742851e8d5cc9e6cf41427dfc6068d4f5a3bb03659444b4cabf6bc26"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:8bdb58ff7ba23002a4c5808d608e4e6c687175724f54a5dade5fa8c67b604e4d"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_ppc64le.whl", hash = "sha256:6b3251890fff30ee142c44144871185dbe13b11bab478a88887a639655be1068"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_s390x.whl", hash = "sha256:b4a23f61ce87adf89be746c8a8974fe1c823c891d8f86eb218bb957c924bb143"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:efcb3f6676480691518c177e3b465bcddf57cea040302f9f4e6e191af91174d4"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-win32.whl", hash = "sha256:d965bba47ddeec8cd560687584e88cf699fd28f192ceb452d1d7ee807c5597b7"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-win_amd64.whl", hash = "sha256:96b02a3dc4381e5494fad39be677abcb5e6634bf7b4fa83a6dd3112607547001"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:95f2a5796329323b8f0512e09dbb7a1860c46a39da62ecb2324f116fa8fdc85c"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c002b4ffc0be611f0d9da932eb0f704fe2602a9a949d1f738e4c34c75b0863d5"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a981a536974bbc7a512cf44ed14938cf01030a99e9b3a06dd59578882f06f985"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:3287761bc4ee9e33561a7e058c72ac0938c4f57fe49a09eae428fd88aafe7bb6"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:42cb296636fcc8b0644486d15c12376cb9fa75443e00fb25de0b8602e64c1714"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:0a55554a2fa0d408816b3b5cedf0045f4b8e1a6065aec45849de2d6f3f8e9786"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:c083af607d2515612056a31f0a8d9e0fcb5876b7bfc0abad3ecd275bc4ebc2d5"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:87d1351268731db79e0f8e745d92493ee2841c974128ef629dc518b937d9194c"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-musllinux_1_1_ppc64le.whl", hash = "sha256:bd8f7df7d12c2db9fab40bdd87a7c09b1530128315d047a086fa3ae3435cb3a8"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-musllinux_1_1_s390x.whl", hash = "sha256:c180f51afb394e165eafe4ac2936a14bee3eb10debc9d9e4db8958fe36afe711"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:8c622a5fe39a48f78944a87d4fb8a53ee07344641b0562c540d840748571b811"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-win32.whl", hash = "sha256:db364eca23f876da6f9e16c9da0df51aa4f104a972735574842618b8c6d999d4"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-win_amd64.whl", hash = "sha256:86216b5cee4b06df986d214f664305142d9c76df9b6512be2738aa72a2048f99"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:6463effa3186ea09411d50efc7d85360b38d5f09b870c48e4600f63af490e56a"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6c4caeef8fa63d06bd437cd4bdcf3ffefe6738fb1b25951440d80dc7df8c03ac"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:37e55c8e51c236f95b033f6fb391d7d7970ba5fe7ff453dad675e88cf303377a"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fb69256e180cb6c8a894fee62b3afebae785babc1ee98b81cdf68bbca1987f33"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:ae5f4161f18c61806f411a13b0310bea87f987c7d2ecdbdaad0e94eb2e404238"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b2b0a0c0517616b6869869f8c581d4eb2dd83a4d79e0ebcb7d373ef9956aeb0a"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:45485e01ff4d3630ec0d9617310448a8702f70e9c01906b0d0118bdf9d124cf2"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:eb00ed941194665c332bf8e078baf037d6c35d7c4f3102ea2d4f16ca94a26dc8"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:2127566c664442652f024c837091890cb1942c30937add288223dc895793f898"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:a50aebfa173e157099939b17f18600f72f84eed3049e743b68ad15bd69b6bf99"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-musllinux_1_1_ppc64le.whl", hash = "sha256:4d0d1650369165a14e14e1e47b372cfcb31d6ab44e6e33cb2d4e57265290044d"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-musllinux_1_1_s390x.whl", hash = "sha256:923c0c831b7cfcb071580d3f46c4baf50f174be571576556269530f4bbd79d04"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:06a81e93cd441c56a9b65d8e1d043daeb97a3d0856d177d5c90ba85acb3db087"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-win32.whl", hash = "sha256:6ef1d82a3af9d3eecdba2321dc1b3c238245d890843e040e41e470ffa64c3e25"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-win_amd64.whl", hash = "sha256:eb8821e09e916165e160797a6c17edda0679379a4be5c716c260e836e122f54b"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:c235ebd9baae02f1b77bcea61bce332cb4331dc3617d254df3323aa01ab47bd4"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:5b4c145409bef602a690e7cfad0a15a55c13320ff7a3ad7ca59c13bb8ba4d45d"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:68d1f8a9e9e37c1223b656399be5d6b448dea850bed7d0f87a8311f1ff3dabb0"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:22afcb9f253dac0696b5a4be4a1c0f8762f8239e21b99680099abd9b2b1b2269"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e27ad930a842b4c5eb8ac0016b0a54f5aebbe679340c26101df33424142c143c"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:1f79682fbe303db92bc2b1136016a38a42e835d932bab5b3b1bfcfbf0640e519"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b261ccdec7821281dade748d088bb6e9b69e6d15b30652b74cbbac25e280b796"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:122c7fa62b130ed55f8f285bfd56d5f4b4a5b503609d181f9ad85e55c89f4185"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:d0eccceffcb53201b5bfebb52600a5fb483a20b61da9dbc885f8b103cbe7598c"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:9f96df6923e21816da7e0ad3fd47dd8f94b2a5ce594e00677c0013018b813458"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-musllinux_1_1_ppc64le.whl", hash = "sha256:7f04c839ed0b6b98b1a7501a002144b76c18fb1c1850c8b98d458ac269e26ed2"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-musllinux_1_1_s390x.whl", hash = "sha256:34d1c8da1e78d2e001f363791c98a272bb734000fcef47a491c1e3b0505657a8"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:ff8fa367d09b717b2a17a052544193ad76cd49979c805768879cb63d9ca50561"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-win32.whl", hash = "sha256:aed38f6e4fb3f5d6bf81bfa990a07806be9d83cf7bacef998ab1a9bd660a581f"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-win_amd64.whl", hash = "sha256:b01b88d45a6fcb69667cd6d2f7a9aeb4bf53760d7fc536bf679ec94fe9f3ff3d"}, + {file = "charset_normalizer-3.3.2-py3-none-any.whl", hash = "sha256:3e4d1f6587322d2788836a99c69062fbb091331ec940e02d12d179c1d53e25fc"}, +] + +[[package]] +name = "click" +version = "8.1.7" +description = "Composable command line interface toolkit" +optional = true +python-versions = ">=3.7" +files = [ + {file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"}, + {file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + +[[package]] +name = "coverage" +version = "7.4.0" +description = "Code coverage measurement for Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "coverage-7.4.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:36b0ea8ab20d6a7564e89cb6135920bc9188fb5f1f7152e94e8300b7b189441a"}, + {file = "coverage-7.4.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:0676cd0ba581e514b7f726495ea75aba3eb20899d824636c6f59b0ed2f88c471"}, + {file = "coverage-7.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d0ca5c71a5a1765a0f8f88022c52b6b8be740e512980362f7fdbb03725a0d6b9"}, + {file = "coverage-7.4.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a7c97726520f784239f6c62506bc70e48d01ae71e9da128259d61ca5e9788516"}, + {file = "coverage-7.4.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:815ac2d0f3398a14286dc2cea223a6f338109f9ecf39a71160cd1628786bc6f5"}, + {file = "coverage-7.4.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:80b5ee39b7f0131ebec7968baa9b2309eddb35b8403d1869e08f024efd883566"}, + {file = "coverage-7.4.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:5b2ccb7548a0b65974860a78c9ffe1173cfb5877460e5a229238d985565574ae"}, + {file = "coverage-7.4.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:995ea5c48c4ebfd898eacb098164b3cc826ba273b3049e4a889658548e321b43"}, + {file = "coverage-7.4.0-cp310-cp310-win32.whl", hash = "sha256:79287fd95585ed36e83182794a57a46aeae0b64ca53929d1176db56aacc83451"}, + {file = "coverage-7.4.0-cp310-cp310-win_amd64.whl", hash = "sha256:5b14b4f8760006bfdb6e08667af7bc2d8d9bfdb648351915315ea17645347137"}, + {file = "coverage-7.4.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:04387a4a6ecb330c1878907ce0dc04078ea72a869263e53c72a1ba5bbdf380ca"}, + {file = "coverage-7.4.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:ea81d8f9691bb53f4fb4db603203029643caffc82bf998ab5b59ca05560f4c06"}, + {file = "coverage-7.4.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:74775198b702868ec2d058cb92720a3c5a9177296f75bd97317c787daf711505"}, + {file = "coverage-7.4.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:76f03940f9973bfaee8cfba70ac991825611b9aac047e5c80d499a44079ec0bc"}, + {file = "coverage-7.4.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:485e9f897cf4856a65a57c7f6ea3dc0d4e6c076c87311d4bc003f82cfe199d25"}, + {file = "coverage-7.4.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:6ae8c9d301207e6856865867d762a4b6fd379c714fcc0607a84b92ee63feff70"}, + {file = "coverage-7.4.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:bf477c355274a72435ceb140dc42de0dc1e1e0bf6e97195be30487d8eaaf1a09"}, + {file = "coverage-7.4.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:83c2dda2666fe32332f8e87481eed056c8b4d163fe18ecc690b02802d36a4d26"}, + {file = "coverage-7.4.0-cp311-cp311-win32.whl", hash = "sha256:697d1317e5290a313ef0d369650cfee1a114abb6021fa239ca12b4849ebbd614"}, + {file = "coverage-7.4.0-cp311-cp311-win_amd64.whl", hash = "sha256:26776ff6c711d9d835557ee453082025d871e30b3fd6c27fcef14733f67f0590"}, + {file = "coverage-7.4.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:13eaf476ec3e883fe3e5fe3707caeb88268a06284484a3daf8250259ef1ba143"}, + {file = "coverage-7.4.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:846f52f46e212affb5bcf131c952fb4075b55aae6b61adc9856222df89cbe3e2"}, + {file = "coverage-7.4.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:26f66da8695719ccf90e794ed567a1549bb2644a706b41e9f6eae6816b398c4a"}, + {file = "coverage-7.4.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:164fdcc3246c69a6526a59b744b62e303039a81e42cfbbdc171c91a8cc2f9446"}, + {file = "coverage-7.4.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:316543f71025a6565677d84bc4df2114e9b6a615aa39fb165d697dba06a54af9"}, + {file = "coverage-7.4.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:bb1de682da0b824411e00a0d4da5a784ec6496b6850fdf8c865c1d68c0e318dd"}, + {file = "coverage-7.4.0-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:0e8d06778e8fbffccfe96331a3946237f87b1e1d359d7fbe8b06b96c95a5407a"}, + {file = "coverage-7.4.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a56de34db7b7ff77056a37aedded01b2b98b508227d2d0979d373a9b5d353daa"}, + {file = "coverage-7.4.0-cp312-cp312-win32.whl", hash = "sha256:51456e6fa099a8d9d91497202d9563a320513fcf59f33991b0661a4a6f2ad450"}, + {file = "coverage-7.4.0-cp312-cp312-win_amd64.whl", hash = "sha256:cd3c1e4cb2ff0083758f09be0f77402e1bdf704adb7f89108007300a6da587d0"}, + {file = "coverage-7.4.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:e9d1bf53c4c8de58d22e0e956a79a5b37f754ed1ffdbf1a260d9dcfa2d8a325e"}, + {file = "coverage-7.4.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:109f5985182b6b81fe33323ab4707011875198c41964f014579cf82cebf2bb85"}, + {file = "coverage-7.4.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3cc9d4bc55de8003663ec94c2f215d12d42ceea128da8f0f4036235a119c88ac"}, + {file = "coverage-7.4.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:cc6d65b21c219ec2072c1293c505cf36e4e913a3f936d80028993dd73c7906b1"}, + {file = "coverage-7.4.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5a10a4920def78bbfff4eff8a05c51be03e42f1c3735be42d851f199144897ba"}, + {file = "coverage-7.4.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:b8e99f06160602bc64da35158bb76c73522a4010f0649be44a4e167ff8555952"}, + {file = "coverage-7.4.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:7d360587e64d006402b7116623cebf9d48893329ef035278969fa3bbf75b697e"}, + {file = "coverage-7.4.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:29f3abe810930311c0b5d1a7140f6395369c3db1be68345638c33eec07535105"}, + {file = "coverage-7.4.0-cp38-cp38-win32.whl", hash = "sha256:5040148f4ec43644702e7b16ca864c5314ccb8ee0751ef617d49aa0e2d6bf4f2"}, + {file = "coverage-7.4.0-cp38-cp38-win_amd64.whl", hash = "sha256:9864463c1c2f9cb3b5db2cf1ff475eed2f0b4285c2aaf4d357b69959941aa555"}, + {file = "coverage-7.4.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:936d38794044b26c99d3dd004d8af0035ac535b92090f7f2bb5aa9c8e2f5cd42"}, + {file = "coverage-7.4.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:799c8f873794a08cdf216aa5d0531c6a3747793b70c53f70e98259720a6fe2d7"}, + {file = "coverage-7.4.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e7defbb9737274023e2d7af02cac77043c86ce88a907c58f42b580a97d5bcca9"}, + {file = "coverage-7.4.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a1526d265743fb49363974b7aa8d5899ff64ee07df47dd8d3e37dcc0818f09ed"}, + {file = "coverage-7.4.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bf635a52fc1ea401baf88843ae8708591aa4adff875e5c23220de43b1ccf575c"}, + {file = "coverage-7.4.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:756ded44f47f330666843b5781be126ab57bb57c22adbb07d83f6b519783b870"}, + {file = "coverage-7.4.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:0eb3c2f32dabe3a4aaf6441dde94f35687224dfd7eb2a7f47f3fd9428e421058"}, + {file = "coverage-7.4.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:bfd5db349d15c08311702611f3dccbef4b4e2ec148fcc636cf8739519b4a5c0f"}, + {file = "coverage-7.4.0-cp39-cp39-win32.whl", hash = "sha256:53d7d9158ee03956e0eadac38dfa1ec8068431ef8058fe6447043db1fb40d932"}, + {file = "coverage-7.4.0-cp39-cp39-win_amd64.whl", hash = "sha256:cfd2a8b6b0d8e66e944d47cdec2f47c48fef2ba2f2dff5a9a75757f64172857e"}, + {file = "coverage-7.4.0-pp38.pp39.pp310-none-any.whl", hash = "sha256:c530833afc4707fe48524a44844493f36d8727f04dcce91fb978c414a8556cc6"}, + {file = "coverage-7.4.0.tar.gz", hash = "sha256:707c0f58cb1712b8809ece32b68996ee1e609f71bd14615bd8f87a1293cb610e"}, +] + +[package.extras] +toml = ["tomli"] + +[[package]] +name = "curtsies" +version = "0.4.2" +description = "Curses-like terminal wrapper, with colored strings!" +optional = false +python-versions = ">=3.7" +files = [ + {file = "curtsies-0.4.2-py3-none-any.whl", hash = "sha256:f24d676a8c4711fb9edba1ab7e6134bc52305a222980b3b717bb303f5e94cec6"}, + {file = "curtsies-0.4.2.tar.gz", hash = "sha256:6ebe33215bd7c92851a506049c720cca4cf5c192c1665c1d7a98a04c4702760e"}, +] + +[package.dependencies] +blessed = ">=1.5" +cwcwidth = "*" + +[[package]] +name = "cwcwidth" +version = "0.1.9" +description = "Python bindings for wc(s)width" +optional = false +python-versions = ">=3.8" +files = [ + {file = "cwcwidth-0.1.9-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:704f0d6888aa5e81e76d9f76709385f9f55aca8c450ee82cc722054814a7791f"}, + {file = "cwcwidth-0.1.9-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:0633158205b50f253ad04e301156807e309a9fb9479a520418e010da6df13604"}, + {file = "cwcwidth-0.1.9-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6a5407d0933c3aab8ee92cffd9e4f09010f25af10ebdfa19776748402bba9261"}, + {file = "cwcwidth-0.1.9-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:72490e07dfbc599fdf6efe26a13cfbf725f0513b181c3386d65bfd84f6175924"}, + {file = "cwcwidth-0.1.9-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:bf71151ae06e95f266bef91392c1562539b2eed847fd1f00f7b5b4ca3fd41a67"}, + {file = "cwcwidth-0.1.9-cp310-cp310-win32.whl", hash = "sha256:3e3c186b5c171d85f2b7f093e7efb33fd9b6e55b791ff75a0f101b18ec0433cd"}, + {file = "cwcwidth-0.1.9-cp310-cp310-win_amd64.whl", hash = "sha256:ae17e493ffc18497c2602f8f42a0d8e490ea42ab3ccfbe5e4a6069a6d24f3b36"}, + {file = "cwcwidth-0.1.9-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:b1c3eb0a8c1b25c4a17b6b9bbf7d25ce9df3ea43b6f87903c51bc12434a2cc29"}, + {file = "cwcwidth-0.1.9-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6c8752815ce4e40e7b34b7fe039276a5fbfb1b077131614381b13ef3b7bb21ff"}, + {file = "cwcwidth-0.1.9-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:368ace13080dbaacdc247370d8a965a749b124aa50d0b1b6eb87601826db870f"}, + {file = "cwcwidth-0.1.9-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:ca9a653661e152a426bdb51a272f36bc79f9830e6a7169abe8110ec367c3518c"}, + {file = "cwcwidth-0.1.9-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:f96386cc29e6eef8ef066d7dd3c767c5119d66506dabea20dd344dabb3f2d225"}, + {file = "cwcwidth-0.1.9-cp311-cp311-win32.whl", hash = "sha256:f6ba88970ec12fdbed5554beb1b9a25d8271fc3d0d9e60639db700a79bed1863"}, + {file = "cwcwidth-0.1.9-cp311-cp311-win_amd64.whl", hash = "sha256:aa6725e7b3571fdf6ce7c02d1dd2d69e00d166bb6df44e46ab215067028b3a03"}, + {file = "cwcwidth-0.1.9-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:42de102d5191fc68ef3ff6530f60c4895148ddc21aa0acaaf4612e5f7f0c38c4"}, + {file = "cwcwidth-0.1.9-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:877e48c615b3fec88b7e640f9cf9d96704497657fb5aad2b7c0b0c59ecabff69"}, + {file = "cwcwidth-0.1.9-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fdbaf0a8dad20eb685df11a195a2449fe230b08a5b356d036c8d7e59d4128a88"}, + {file = "cwcwidth-0.1.9-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:f6e0e023c4b127c47fd4c44cf537be209b9a28d8725f4f576f4d63744a23aa38"}, + {file = "cwcwidth-0.1.9-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:b4f7d24236ce3c9d3b5e07fd75d232452f19bdddb6ae8bbfdcb97b6cb02835e8"}, + {file = "cwcwidth-0.1.9-cp312-cp312-win32.whl", hash = "sha256:ba9da6c911bf108334426890bc9f57b839a38e1afc4383a41bd70adbce470db3"}, + {file = "cwcwidth-0.1.9-cp312-cp312-win_amd64.whl", hash = "sha256:40466f16e85c338e8fc3eee87a8c9ca23416cc68b3049f68cb4cead5fb8b71b3"}, + {file = "cwcwidth-0.1.9-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:167f59c3c1e1d8e231a1abd666af4e73dd8a94917efb6522e9b610ac4587903a"}, + {file = "cwcwidth-0.1.9-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:afc745f18c9e3c38851a931c0c0a7e479d6494911ba1353f998d707f95a895b4"}, + {file = "cwcwidth-0.1.9-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f8d55c47cbec4796e89cfedc89c52e6c4c2faeb77489a763415b9f76d8fc14db"}, + {file = "cwcwidth-0.1.9-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:c858842849ce2cfdf207095253da83831d9407771c8073f6b75f24d3faf1a1eb"}, + {file = "cwcwidth-0.1.9-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:cc049ce273f32b632f5ead649b2120f8b2b78035d7b069fdc460c4be9affddb5"}, + {file = "cwcwidth-0.1.9-cp38-cp38-win32.whl", hash = "sha256:1bafe978a5b7915848244a952829e3f8757c0cebef581c8250da6064c906c38c"}, + {file = "cwcwidth-0.1.9-cp38-cp38-win_amd64.whl", hash = "sha256:024d1b21e6123bf30a849e60eea3482f556bbd00d39215f86c904e5bd81fc1b6"}, + {file = "cwcwidth-0.1.9-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:7d367da5e6fb538388817bf5b2d6dd4db90e5e631d99c34055589d007b5c94bc"}, + {file = "cwcwidth-0.1.9-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ad721d9dbc14eafd06176e4f5594942336b1e813de2a5ab7bd64254393c5713f"}, + {file = "cwcwidth-0.1.9-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:711ace9796cb6767ff29095ff5b0ec4619e7297854eb4b91ba99154590eddcc9"}, + {file = "cwcwidth-0.1.9-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:945615a7b8cdcbcd8e06d399f96a2b09440c3a4c5cb3c2d0109f00d80da27a12"}, + {file = "cwcwidth-0.1.9-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:ffaf706abe400282f299463594d8887566e2a280cd0255110bd4397cc7be2910"}, + {file = "cwcwidth-0.1.9-cp39-cp39-win32.whl", hash = "sha256:03093cac6f8e4326b1c30169e024fe2894f76c6ffddf6464e489bb33cb3a2897"}, + {file = "cwcwidth-0.1.9-cp39-cp39-win_amd64.whl", hash = "sha256:0ddef2c504e6f4fd6122b46d55061f487add1ebb86596ae70ffc2a8b8955c8bc"}, + {file = "cwcwidth-0.1.9.tar.gz", hash = "sha256:f19d11a0148d4a8cacd064c96e93bca8ce3415a186ae8204038f45e108db76b8"}, +] + +[[package]] +name = "distlib" +version = "0.3.8" +description = "Distribution utilities" +optional = false +python-versions = "*" +files = [ + {file = "distlib-0.3.8-py2.py3-none-any.whl", hash = "sha256:034db59a0b96f8ca18035f36290806a9a6e6bd9d1ff91e45a7f172eb17e51784"}, + {file = "distlib-0.3.8.tar.gz", hash = "sha256:1530ea13e350031b6312d8580ddb6b27a104275a31106523b8f123787f494f64"}, +] + +[[package]] +name = "docutils" +version = "0.20.1" +description = "Docutils -- Python Documentation Utilities" +optional = false +python-versions = ">=3.7" +files = [ + {file = "docutils-0.20.1-py3-none-any.whl", hash = "sha256:96f387a2c5562db4476f09f13bbab2192e764cac08ebbf3a34a95d9b1e4a59d6"}, + {file = "docutils-0.20.1.tar.gz", hash = "sha256:f08a4e276c3a1583a86dce3e34aba3fe04d02bba2dd51ed16106244e8a923e3b"}, +] + +[[package]] +name = "exceptiongroup" +version = "1.2.0" +description = "Backport of PEP 654 (exception groups)" +optional = false +python-versions = ">=3.7" +files = [ + {file = "exceptiongroup-1.2.0-py3-none-any.whl", hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"}, + {file = "exceptiongroup-1.2.0.tar.gz", hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"}, +] + +[package.extras] +test = ["pytest (>=6)"] + +[[package]] +name = "filelock" +version = "3.13.1" +description = "A platform independent file lock." +optional = false +python-versions = ">=3.8" +files = [ + {file = "filelock-3.13.1-py3-none-any.whl", hash = "sha256:57dbda9b35157b05fb3e58ee91448612eb674172fab98ee235ccb0b5bee19a1c"}, + {file = "filelock-3.13.1.tar.gz", hash = "sha256:521f5f56c50f8426f5e03ad3b281b490a87ef15bc6c526f168290f0c7148d44e"}, +] + +[package.extras] +docs = ["furo (>=2023.9.10)", "sphinx (>=7.2.6)", "sphinx-autodoc-typehints (>=1.24)"] +testing = ["covdefaults (>=2.3)", "coverage (>=7.3.2)", "diff-cover (>=8)", "pytest (>=7.4.3)", "pytest-cov (>=4.1)", "pytest-mock (>=3.12)", "pytest-timeout (>=2.2)"] +typing = ["typing-extensions (>=4.8)"] + +[[package]] +name = "greenlet" +version = "3.0.3" +description = "Lightweight in-process concurrent programming" +optional = false +python-versions = ">=3.7" +files = [ + {file = "greenlet-3.0.3-cp310-cp310-macosx_11_0_universal2.whl", hash = "sha256:9da2bd29ed9e4f15955dd1595ad7bc9320308a3b766ef7f837e23ad4b4aac31a"}, + {file = "greenlet-3.0.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d353cadd6083fdb056bb46ed07e4340b0869c305c8ca54ef9da3421acbdf6881"}, + {file = "greenlet-3.0.3-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:dca1e2f3ca00b84a396bc1bce13dd21f680f035314d2379c4160c98153b2059b"}, + {file = "greenlet-3.0.3-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:3ed7fb269f15dc662787f4119ec300ad0702fa1b19d2135a37c2c4de6fadfd4a"}, + {file = "greenlet-3.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dd4f49ae60e10adbc94b45c0b5e6a179acc1736cf7a90160b404076ee283cf83"}, + {file = "greenlet-3.0.3-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:73a411ef564e0e097dbe7e866bb2dda0f027e072b04da387282b02c308807405"}, + {file = "greenlet-3.0.3-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:7f362975f2d179f9e26928c5b517524e89dd48530a0202570d55ad6ca5d8a56f"}, + {file = "greenlet-3.0.3-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:649dde7de1a5eceb258f9cb00bdf50e978c9db1b996964cd80703614c86495eb"}, + {file = "greenlet-3.0.3-cp310-cp310-win_amd64.whl", hash = "sha256:68834da854554926fbedd38c76e60c4a2e3198c6fbed520b106a8986445caaf9"}, + {file = "greenlet-3.0.3-cp311-cp311-macosx_11_0_universal2.whl", hash = "sha256:b1b5667cced97081bf57b8fa1d6bfca67814b0afd38208d52538316e9422fc61"}, + {file = "greenlet-3.0.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:52f59dd9c96ad2fc0d5724107444f76eb20aaccb675bf825df6435acb7703559"}, + {file = "greenlet-3.0.3-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:afaff6cf5200befd5cec055b07d1c0a5a06c040fe5ad148abcd11ba6ab9b114e"}, + {file = "greenlet-3.0.3-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:fe754d231288e1e64323cfad462fcee8f0288654c10bdf4f603a39ed923bef33"}, + {file = "greenlet-3.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2797aa5aedac23af156bbb5a6aa2cd3427ada2972c828244eb7d1b9255846379"}, + {file = "greenlet-3.0.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b7f009caad047246ed379e1c4dbcb8b020f0a390667ea74d2387be2998f58a22"}, + {file = "greenlet-3.0.3-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:c5e1536de2aad7bf62e27baf79225d0d64360d4168cf2e6becb91baf1ed074f3"}, + {file = "greenlet-3.0.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:894393ce10ceac937e56ec00bb71c4c2f8209ad516e96033e4b3b1de270e200d"}, + {file = "greenlet-3.0.3-cp311-cp311-win_amd64.whl", hash = "sha256:1ea188d4f49089fc6fb283845ab18a2518d279c7cd9da1065d7a84e991748728"}, + {file = "greenlet-3.0.3-cp312-cp312-macosx_11_0_universal2.whl", hash = "sha256:70fb482fdf2c707765ab5f0b6655e9cfcf3780d8d87355a063547b41177599be"}, + {file = "greenlet-3.0.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d4d1ac74f5c0c0524e4a24335350edad7e5f03b9532da7ea4d3c54d527784f2e"}, + {file = "greenlet-3.0.3-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:149e94a2dd82d19838fe4b2259f1b6b9957d5ba1b25640d2380bea9c5df37676"}, + {file = "greenlet-3.0.3-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:15d79dd26056573940fcb8c7413d84118086f2ec1a8acdfa854631084393efcc"}, + {file = "greenlet-3.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:881b7db1ebff4ba09aaaeae6aa491daeb226c8150fc20e836ad00041bcb11230"}, + {file = "greenlet-3.0.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:fcd2469d6a2cf298f198f0487e0a5b1a47a42ca0fa4dfd1b6862c999f018ebbf"}, + {file = "greenlet-3.0.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:1f672519db1796ca0d8753f9e78ec02355e862d0998193038c7073045899f305"}, + {file = "greenlet-3.0.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:2516a9957eed41dd8f1ec0c604f1cdc86758b587d964668b5b196a9db5bfcde6"}, + {file = "greenlet-3.0.3-cp312-cp312-win_amd64.whl", hash = "sha256:bba5387a6975598857d86de9eac14210a49d554a77eb8261cc68b7d082f78ce2"}, + {file = "greenlet-3.0.3-cp37-cp37m-macosx_11_0_universal2.whl", hash = "sha256:5b51e85cb5ceda94e79d019ed36b35386e8c37d22f07d6a751cb659b180d5274"}, + {file = "greenlet-3.0.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:daf3cb43b7cf2ba96d614252ce1684c1bccee6b2183a01328c98d36fcd7d5cb0"}, + {file = "greenlet-3.0.3-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:99bf650dc5d69546e076f413a87481ee1d2d09aaaaaca058c9251b6d8c14783f"}, + {file = "greenlet-3.0.3-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2dd6e660effd852586b6a8478a1d244b8dc90ab5b1321751d2ea15deb49ed414"}, + {file = "greenlet-3.0.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e3391d1e16e2a5a1507d83e4a8b100f4ee626e8eca43cf2cadb543de69827c4c"}, + {file = "greenlet-3.0.3-cp37-cp37m-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e1f145462f1fa6e4a4ae3c0f782e580ce44d57c8f2c7aae1b6fa88c0b2efdb41"}, + {file = "greenlet-3.0.3-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:1a7191e42732df52cb5f39d3527217e7ab73cae2cb3694d241e18f53d84ea9a7"}, + {file = "greenlet-3.0.3-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:0448abc479fab28b00cb472d278828b3ccca164531daab4e970a0458786055d6"}, + {file = "greenlet-3.0.3-cp37-cp37m-win32.whl", hash = "sha256:b542be2440edc2d48547b5923c408cbe0fc94afb9f18741faa6ae970dbcb9b6d"}, + {file = "greenlet-3.0.3-cp37-cp37m-win_amd64.whl", hash = "sha256:01bc7ea167cf943b4c802068e178bbf70ae2e8c080467070d01bfa02f337ee67"}, + {file = "greenlet-3.0.3-cp38-cp38-macosx_11_0_universal2.whl", hash = "sha256:1996cb9306c8595335bb157d133daf5cf9f693ef413e7673cb07e3e5871379ca"}, + {file = "greenlet-3.0.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3ddc0f794e6ad661e321caa8d2f0a55ce01213c74722587256fb6566049a8b04"}, + {file = "greenlet-3.0.3-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c9db1c18f0eaad2f804728c67d6c610778456e3e1cc4ab4bbd5eeb8e6053c6fc"}, + {file = "greenlet-3.0.3-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7170375bcc99f1a2fbd9c306f5be8764eaf3ac6b5cb968862cad4c7057756506"}, + {file = "greenlet-3.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6b66c9c1e7ccabad3a7d037b2bcb740122a7b17a53734b7d72a344ce39882a1b"}, + {file = "greenlet-3.0.3-cp38-cp38-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:098d86f528c855ead3479afe84b49242e174ed262456c342d70fc7f972bc13c4"}, + {file = "greenlet-3.0.3-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:81bb9c6d52e8321f09c3d165b2a78c680506d9af285bfccbad9fb7ad5a5da3e5"}, + {file = "greenlet-3.0.3-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:fd096eb7ffef17c456cfa587523c5f92321ae02427ff955bebe9e3c63bc9f0da"}, + {file = "greenlet-3.0.3-cp38-cp38-win32.whl", hash = "sha256:d46677c85c5ba00a9cb6f7a00b2bfa6f812192d2c9f7d9c4f6a55b60216712f3"}, + {file = "greenlet-3.0.3-cp38-cp38-win_amd64.whl", hash = "sha256:419b386f84949bf0e7c73e6032e3457b82a787c1ab4a0e43732898a761cc9dbf"}, + {file = "greenlet-3.0.3-cp39-cp39-macosx_11_0_universal2.whl", hash = "sha256:da70d4d51c8b306bb7a031d5cff6cc25ad253affe89b70352af5f1cb68e74b53"}, + {file = "greenlet-3.0.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:086152f8fbc5955df88382e8a75984e2bb1c892ad2e3c80a2508954e52295257"}, + {file = "greenlet-3.0.3-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d73a9fe764d77f87f8ec26a0c85144d6a951a6c438dfe50487df5595c6373eac"}, + {file = "greenlet-3.0.3-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b7dcbe92cc99f08c8dd11f930de4d99ef756c3591a5377d1d9cd7dd5e896da71"}, + {file = "greenlet-3.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1551a8195c0d4a68fac7a4325efac0d541b48def35feb49d803674ac32582f61"}, + {file = "greenlet-3.0.3-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:64d7675ad83578e3fc149b617a444fab8efdafc9385471f868eb5ff83e446b8b"}, + {file = "greenlet-3.0.3-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:b37eef18ea55f2ffd8f00ff8fe7c8d3818abd3e25fb73fae2ca3b672e333a7a6"}, + {file = "greenlet-3.0.3-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:77457465d89b8263bca14759d7c1684df840b6811b2499838cc5b040a8b5b113"}, + {file = "greenlet-3.0.3-cp39-cp39-win32.whl", hash = "sha256:57e8974f23e47dac22b83436bdcf23080ade568ce77df33159e019d161ce1d1e"}, + {file = "greenlet-3.0.3-cp39-cp39-win_amd64.whl", hash = "sha256:c5ee858cfe08f34712f548c3c363e807e7186f03ad7a5039ebadb29e8c6be067"}, + {file = "greenlet-3.0.3.tar.gz", hash = "sha256:43374442353259554ce33599da8b692d5aa96f8976d567d4badf263371fbe491"}, +] + +[package.extras] +docs = ["Sphinx", "furo"] +test = ["objgraph", "psutil"] + +[[package]] +name = "grpcio" +version = "1.60.0" +description = "HTTP/2-based RPC framework" +optional = false +python-versions = ">=3.7" +files = [ + {file = "grpcio-1.60.0-cp310-cp310-linux_armv7l.whl", hash = "sha256:d020cfa595d1f8f5c6b343530cd3ca16ae5aefdd1e832b777f9f0eb105f5b139"}, + {file = "grpcio-1.60.0-cp310-cp310-macosx_12_0_universal2.whl", hash = "sha256:b98f43fcdb16172dec5f4b49f2fece4b16a99fd284d81c6bbac1b3b69fcbe0ff"}, + {file = "grpcio-1.60.0-cp310-cp310-manylinux_2_17_aarch64.whl", hash = "sha256:20e7a4f7ded59097c84059d28230907cd97130fa74f4a8bfd1d8e5ba18c81491"}, + {file = "grpcio-1.60.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:452ca5b4afed30e7274445dd9b441a35ece656ec1600b77fff8c216fdf07df43"}, + {file = "grpcio-1.60.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:43e636dc2ce9ece583b3e2ca41df5c983f4302eabc6d5f9cd04f0562ee8ec1ae"}, + {file = "grpcio-1.60.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:6e306b97966369b889985a562ede9d99180def39ad42c8014628dd3cc343f508"}, + {file = "grpcio-1.60.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:f897c3b127532e6befdcf961c415c97f320d45614daf84deba0a54e64ea2457b"}, + {file = "grpcio-1.60.0-cp310-cp310-win32.whl", hash = "sha256:b87efe4a380887425bb15f220079aa8336276398dc33fce38c64d278164f963d"}, + {file = "grpcio-1.60.0-cp310-cp310-win_amd64.whl", hash = "sha256:a9c7b71211f066908e518a2ef7a5e211670761651039f0d6a80d8d40054047df"}, + {file = "grpcio-1.60.0-cp311-cp311-linux_armv7l.whl", hash = "sha256:fb464479934778d7cc5baf463d959d361954d6533ad34c3a4f1d267e86ee25fd"}, + {file = "grpcio-1.60.0-cp311-cp311-macosx_10_10_universal2.whl", hash = "sha256:4b44d7e39964e808b071714666a812049765b26b3ea48c4434a3b317bac82f14"}, + {file = "grpcio-1.60.0-cp311-cp311-manylinux_2_17_aarch64.whl", hash = "sha256:90bdd76b3f04bdb21de5398b8a7c629676c81dfac290f5f19883857e9371d28c"}, + {file = "grpcio-1.60.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:91229d7203f1ef0ab420c9b53fe2ca5c1fbeb34f69b3bc1b5089466237a4a134"}, + {file = "grpcio-1.60.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3b36a2c6d4920ba88fa98075fdd58ff94ebeb8acc1215ae07d01a418af4c0253"}, + {file = "grpcio-1.60.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:297eef542156d6b15174a1231c2493ea9ea54af8d016b8ca7d5d9cc65cfcc444"}, + {file = "grpcio-1.60.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:87c9224acba0ad8bacddf427a1c2772e17ce50b3042a789547af27099c5f751d"}, + {file = "grpcio-1.60.0-cp311-cp311-win32.whl", hash = "sha256:95ae3e8e2c1b9bf671817f86f155c5da7d49a2289c5cf27a319458c3e025c320"}, + {file = "grpcio-1.60.0-cp311-cp311-win_amd64.whl", hash = "sha256:467a7d31554892eed2aa6c2d47ded1079fc40ea0b9601d9f79204afa8902274b"}, + {file = "grpcio-1.60.0-cp312-cp312-linux_armv7l.whl", hash = "sha256:a7152fa6e597c20cb97923407cf0934e14224af42c2b8d915f48bc3ad2d9ac18"}, + {file = "grpcio-1.60.0-cp312-cp312-macosx_10_10_universal2.whl", hash = "sha256:7db16dd4ea1b05ada504f08d0dca1cd9b926bed3770f50e715d087c6f00ad748"}, + {file = "grpcio-1.60.0-cp312-cp312-manylinux_2_17_aarch64.whl", hash = "sha256:b0571a5aef36ba9177e262dc88a9240c866d903a62799e44fd4aae3f9a2ec17e"}, + {file = "grpcio-1.60.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6fd9584bf1bccdfff1512719316efa77be235469e1e3295dce64538c4773840b"}, + {file = "grpcio-1.60.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d6a478581b1a1a8fdf3318ecb5f4d0cda41cacdffe2b527c23707c9c1b8fdb55"}, + {file = "grpcio-1.60.0-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:77c8a317f0fd5a0a2be8ed5cbe5341537d5c00bb79b3bb27ba7c5378ba77dbca"}, + {file = "grpcio-1.60.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:1c30bb23a41df95109db130a6cc1b974844300ae2e5d68dd4947aacba5985aa5"}, + {file = "grpcio-1.60.0-cp312-cp312-win32.whl", hash = "sha256:2aef56e85901c2397bd557c5ba514f84de1f0ae5dd132f5d5fed042858115951"}, + {file = "grpcio-1.60.0-cp312-cp312-win_amd64.whl", hash = "sha256:e381fe0c2aa6c03b056ad8f52f8efca7be29fb4d9ae2f8873520843b6039612a"}, + {file = "grpcio-1.60.0-cp37-cp37m-linux_armv7l.whl", hash = "sha256:92f88ca1b956eb8427a11bb8b4a0c0b2b03377235fc5102cb05e533b8693a415"}, + {file = "grpcio-1.60.0-cp37-cp37m-macosx_10_10_universal2.whl", hash = "sha256:e278eafb406f7e1b1b637c2cf51d3ad45883bb5bd1ca56bc05e4fc135dfdaa65"}, + {file = "grpcio-1.60.0-cp37-cp37m-manylinux_2_17_aarch64.whl", hash = "sha256:a48edde788b99214613e440fce495bbe2b1e142a7f214cce9e0832146c41e324"}, + {file = "grpcio-1.60.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:de2ad69c9a094bf37c1102b5744c9aec6cf74d2b635558b779085d0263166454"}, + {file = "grpcio-1.60.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:073f959c6f570797272f4ee9464a9997eaf1e98c27cb680225b82b53390d61e6"}, + {file = "grpcio-1.60.0-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:c826f93050c73e7769806f92e601e0efdb83ec8d7c76ddf45d514fee54e8e619"}, + {file = "grpcio-1.60.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:9e30be89a75ee66aec7f9e60086fadb37ff8c0ba49a022887c28c134341f7179"}, + {file = "grpcio-1.60.0-cp37-cp37m-win_amd64.whl", hash = "sha256:b0fb2d4801546598ac5cd18e3ec79c1a9af8b8f2a86283c55a5337c5aeca4b1b"}, + {file = "grpcio-1.60.0-cp38-cp38-linux_armv7l.whl", hash = "sha256:9073513ec380434eb8d21970e1ab3161041de121f4018bbed3146839451a6d8e"}, + {file = "grpcio-1.60.0-cp38-cp38-macosx_10_10_universal2.whl", hash = "sha256:74d7d9fa97809c5b892449b28a65ec2bfa458a4735ddad46074f9f7d9550ad13"}, + {file = "grpcio-1.60.0-cp38-cp38-manylinux_2_17_aarch64.whl", hash = "sha256:1434ca77d6fed4ea312901122dc8da6c4389738bf5788f43efb19a838ac03ead"}, + {file = "grpcio-1.60.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e61e76020e0c332a98290323ecfec721c9544f5b739fab925b6e8cbe1944cf19"}, + {file = "grpcio-1.60.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:675997222f2e2f22928fbba640824aebd43791116034f62006e19730715166c0"}, + {file = "grpcio-1.60.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:5208a57eae445ae84a219dfd8b56e04313445d146873117b5fa75f3245bc1390"}, + {file = "grpcio-1.60.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:428d699c8553c27e98f4d29fdc0f0edc50e9a8a7590bfd294d2edb0da7be3629"}, + {file = "grpcio-1.60.0-cp38-cp38-win32.whl", hash = "sha256:83f2292ae292ed5a47cdcb9821039ca8e88902923198f2193f13959360c01860"}, + {file = "grpcio-1.60.0-cp38-cp38-win_amd64.whl", hash = "sha256:705a68a973c4c76db5d369ed573fec3367d7d196673fa86614b33d8c8e9ebb08"}, + {file = "grpcio-1.60.0-cp39-cp39-linux_armv7l.whl", hash = "sha256:c193109ca4070cdcaa6eff00fdb5a56233dc7610216d58fb81638f89f02e4968"}, + {file = "grpcio-1.60.0-cp39-cp39-macosx_10_10_universal2.whl", hash = "sha256:676e4a44e740deaba0f4d95ba1d8c5c89a2fcc43d02c39f69450b1fa19d39590"}, + {file = "grpcio-1.60.0-cp39-cp39-manylinux_2_17_aarch64.whl", hash = "sha256:5ff21e000ff2f658430bde5288cb1ac440ff15c0d7d18b5fb222f941b46cb0d2"}, + {file = "grpcio-1.60.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:4c86343cf9ff7b2514dd229bdd88ebba760bd8973dac192ae687ff75e39ebfab"}, + {file = "grpcio-1.60.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0fd3b3968ffe7643144580f260f04d39d869fcc2cddb745deef078b09fd2b328"}, + {file = "grpcio-1.60.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:30943b9530fe3620e3b195c03130396cd0ee3a0d10a66c1bee715d1819001eaf"}, + {file = "grpcio-1.60.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:b10241250cb77657ab315270b064a6c7f1add58af94befa20687e7c8d8603ae6"}, + {file = "grpcio-1.60.0-cp39-cp39-win32.whl", hash = "sha256:79a050889eb8d57a93ed21d9585bb63fca881666fc709f5d9f7f9372f5e7fd03"}, + {file = "grpcio-1.60.0-cp39-cp39-win_amd64.whl", hash = "sha256:8a97a681e82bc11a42d4372fe57898d270a2707f36c45c6676e49ce0d5c41353"}, + {file = "grpcio-1.60.0.tar.gz", hash = "sha256:2199165a1affb666aa24adf0c97436686d0a61bc5fc113c037701fb7c7fceb96"}, +] + +[package.extras] +protobuf = ["grpcio-tools (>=1.60.0)"] + +[[package]] +name = "grpcio-tools" +version = "1.60.0" +description = "Protobuf code generator for gRPC" +optional = false +python-versions = ">=3.7" +files = [ + {file = "grpcio-tools-1.60.0.tar.gz", hash = "sha256:ed30499340228d733ff69fcf4a66590ed7921f94eb5a2bf692258b1280b9dac7"}, + {file = "grpcio_tools-1.60.0-cp310-cp310-linux_armv7l.whl", hash = "sha256:6807b7a3f3e6e594566100bd7fe04a2c42ce6d5792652677f1aaf5aa5adaef3d"}, + {file = "grpcio_tools-1.60.0-cp310-cp310-macosx_12_0_universal2.whl", hash = "sha256:857c5351e9dc33a019700e171163f94fcc7e3ae0f6d2b026b10fda1e3c008ef1"}, + {file = "grpcio_tools-1.60.0-cp310-cp310-manylinux_2_17_aarch64.whl", hash = "sha256:ec0e401e9a43d927d216d5169b03c61163fb52b665c5af2fed851357b15aef88"}, + {file = "grpcio_tools-1.60.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e68dc4474f30cad11a965f0eb5d37720a032b4720afa0ec19dbcea2de73b5aae"}, + {file = "grpcio_tools-1.60.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bbf0ed772d2ae7e8e5d7281fcc00123923ab130b94f7a843eee9af405918f924"}, + {file = "grpcio_tools-1.60.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:c771b19dce2bfe06899247168c077d7ab4e273f6655d8174834f9a6034415096"}, + {file = "grpcio_tools-1.60.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:e5614cf0960456d21d8a0f4902e3e5e3bcacc4e400bf22f196e5dd8aabb978b7"}, + {file = "grpcio_tools-1.60.0-cp310-cp310-win32.whl", hash = "sha256:87cf439178f3eb45c1a889b2e4a17cbb4c450230d92c18d9c57e11271e239c55"}, + {file = "grpcio_tools-1.60.0-cp310-cp310-win_amd64.whl", hash = "sha256:687f576d7ff6ce483bc9a196d1ceac45144e8733b953620a026daed8e450bc38"}, + {file = "grpcio_tools-1.60.0-cp311-cp311-linux_armv7l.whl", hash = "sha256:2a8a758701f3ac07ed85f5a4284c6a9ddefcab7913a8e552497f919349e72438"}, + {file = "grpcio_tools-1.60.0-cp311-cp311-macosx_10_10_universal2.whl", hash = "sha256:7c1cde49631732356cb916ee1710507967f19913565ed5f9991e6c9cb37e3887"}, + {file = "grpcio_tools-1.60.0-cp311-cp311-manylinux_2_17_aarch64.whl", hash = "sha256:d941749bd8dc3f8be58fe37183143412a27bec3df8482d5abd6b4ec3f1ac2924"}, + {file = "grpcio_tools-1.60.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9ee35234f1da8fba7ddbc544856ff588243f1128ea778d7a1da3039be829a134"}, + {file = "grpcio_tools-1.60.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b8f7a5094adb49e85db13ea3df5d99a976c2bdfd83b0ba26af20ebb742ac6786"}, + {file = "grpcio_tools-1.60.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:24c4ead4a03037beaeb8ef2c90d13d70101e35c9fae057337ed1a9144ef10b53"}, + {file = "grpcio_tools-1.60.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:811abb9c4fb6679e0058dfa123fb065d97b158b71959c0e048e7972bbb82ba0f"}, + {file = "grpcio_tools-1.60.0-cp311-cp311-win32.whl", hash = "sha256:bd2a17b0193fbe4793c215d63ce1e01ae00a8183d81d7c04e77e1dfafc4b2b8a"}, + {file = "grpcio_tools-1.60.0-cp311-cp311-win_amd64.whl", hash = "sha256:b22b1299b666eebd5752ba7719da536075eae3053abcf2898b65f763c314d9da"}, + {file = "grpcio_tools-1.60.0-cp312-cp312-linux_armv7l.whl", hash = "sha256:74025fdd6d1cb7ba4b5d087995339e9a09f0c16cf15dfe56368b23e41ffeaf7a"}, + {file = "grpcio_tools-1.60.0-cp312-cp312-macosx_10_10_universal2.whl", hash = "sha256:5a907a4f1ffba86501b2cdb8682346249ea032b922fc69a92f082ba045cca548"}, + {file = "grpcio_tools-1.60.0-cp312-cp312-manylinux_2_17_aarch64.whl", hash = "sha256:1fbb9554466d560472f07d906bfc8dcaf52f365c2a407015185993e30372a886"}, + {file = "grpcio_tools-1.60.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f10ef47460ce3c6fd400f05fe757b90df63486c9b84d1ecad42dcc5f80c8ac14"}, + {file = "grpcio_tools-1.60.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:321b18f42a70813545e416ddcb8bf20defa407a8114906711c9710a69596ceda"}, + {file = "grpcio_tools-1.60.0-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:081336d8258f1a56542aa8a7a5dec99a2b38d902e19fbdd744594783301b0210"}, + {file = "grpcio_tools-1.60.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:addc9b23d6ff729d9f83d4a2846292d4c84f5eb2ec38f08489a6a0d66ac2b91e"}, + {file = "grpcio_tools-1.60.0-cp312-cp312-win32.whl", hash = "sha256:e87cabac7969bdde309575edc2456357667a1b28262b2c1f12580ef48315b19d"}, + {file = "grpcio_tools-1.60.0-cp312-cp312-win_amd64.whl", hash = "sha256:e70d867c120d9849093b0ac24d861e378bc88af2552e743d83b9f642d2caa7c2"}, + {file = "grpcio_tools-1.60.0-cp37-cp37m-linux_armv7l.whl", hash = "sha256:559ce714fe212aaf4abbe1493c5bb8920def00cc77ce0d45266f4fd9d8b3166f"}, + {file = "grpcio_tools-1.60.0-cp37-cp37m-macosx_10_10_universal2.whl", hash = "sha256:7a5263a0f2ddb7b1cfb2349e392cfc4f318722e0f48f886393e06946875d40f3"}, + {file = "grpcio_tools-1.60.0-cp37-cp37m-manylinux_2_17_aarch64.whl", hash = "sha256:18976684a931ca4bcba65c78afa778683aefaae310f353e198b1823bf09775a0"}, + {file = "grpcio_tools-1.60.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e5c519a0d4ba1ab44a004fa144089738c59278233e2010b2cf4527dc667ff297"}, + {file = "grpcio_tools-1.60.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6170873b1e5b6580ebb99e87fb6e4ea4c48785b910bd7af838cc6e44b2bccb04"}, + {file = "grpcio_tools-1.60.0-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:fb4df80868b3e397d5fbccc004c789d2668b622b51a9d2387b4c89c80d31e2c5"}, + {file = "grpcio_tools-1.60.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:dba6e32c87b4af29b5f475fb2f470f7ee3140bfc128644f17c6c59ddeb670680"}, + {file = "grpcio_tools-1.60.0-cp37-cp37m-win_amd64.whl", hash = "sha256:f610384dee4b1ca705e8da66c5b5fe89a2de3d165c5282c3d1ddf40cb18924e4"}, + {file = "grpcio_tools-1.60.0-cp38-cp38-linux_armv7l.whl", hash = "sha256:4041538f55aad5b3ae7e25ab314d7995d689e968bfc8aa169d939a3160b1e4c6"}, + {file = "grpcio_tools-1.60.0-cp38-cp38-macosx_10_10_universal2.whl", hash = "sha256:2fb4cf74bfe1e707cf10bc9dd38a1ebaa145179453d150febb121c7e9cd749bf"}, + {file = "grpcio_tools-1.60.0-cp38-cp38-manylinux_2_17_aarch64.whl", hash = "sha256:2fd1671c52f96e79a2302c8b1c1f78b8a561664b8b3d6946f20d8f1cc6b4225a"}, + {file = "grpcio_tools-1.60.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:dd1e68c232fe01dd5312a8dbe52c50ecd2b5991d517d7f7446af4ba6334ba872"}, + {file = "grpcio_tools-1.60.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:17a32b3da4fc0798cdcec0a9c974ac2a1e98298f151517bf9148294a3b1a5742"}, + {file = "grpcio_tools-1.60.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:9970d384fb0c084b00945ef57d98d57a8d32be106d8f0bd31387f7cbfe411b5b"}, + {file = "grpcio_tools-1.60.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:5ce6bbd4936977ec1114f2903eb4342781960d521b0d82f73afedb9335251f6f"}, + {file = "grpcio_tools-1.60.0-cp38-cp38-win32.whl", hash = "sha256:2e00de389729ca8d8d1a63c2038703078a887ff738dc31be640b7da9c26d0d4f"}, + {file = "grpcio_tools-1.60.0-cp38-cp38-win_amd64.whl", hash = "sha256:6192184b1f99372ff1d9594bd4b12264e3ff26440daba7eb043726785200ff77"}, + {file = "grpcio_tools-1.60.0-cp39-cp39-linux_armv7l.whl", hash = "sha256:eae27f9b16238e2aaee84c77b5923c6924d6dccb0bdd18435bf42acc8473ae1a"}, + {file = "grpcio_tools-1.60.0-cp39-cp39-macosx_10_10_universal2.whl", hash = "sha256:b96981f3a31b85074b73d97c8234a5ed9053d65a36b18f4a9c45a2120a5b7a0a"}, + {file = "grpcio_tools-1.60.0-cp39-cp39-manylinux_2_17_aarch64.whl", hash = "sha256:1748893efd05cf4a59a175d7fa1e4fbb652f4d84ccaa2109f7869a2be48ed25e"}, + {file = "grpcio_tools-1.60.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7a6fe752205caae534f29fba907e2f59ff79aa42c6205ce9a467e9406cbac68c"}, + {file = "grpcio_tools-1.60.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3456df087ea61a0972a5bc165aed132ed6ddcc63f5749e572f9fff84540bdbad"}, + {file = "grpcio_tools-1.60.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:f3d916606dcf5610d4367918245b3d9d8cd0d2ec0b7043d1bbb8c50fe9815c3a"}, + {file = "grpcio_tools-1.60.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:fc01bc1079279ec342f0f1b6a107b3f5dc3169c33369cf96ada6e2e171f74e86"}, + {file = "grpcio_tools-1.60.0-cp39-cp39-win32.whl", hash = "sha256:2dd01257e4feff986d256fa0bac9f56de59dc735eceeeb83de1c126e2e91f653"}, + {file = "grpcio_tools-1.60.0-cp39-cp39-win_amd64.whl", hash = "sha256:1b93ae8ffd18e9af9a965ebca5fa521e89066267de7abdde20721edc04e42721"}, +] + +[package.dependencies] +grpcio = ">=1.60.0" +protobuf = ">=4.21.6,<5.0dev" +setuptools = "*" + +[[package]] +name = "grpclib" +version = "0.4.7" +description = "Pure-Python gRPC implementation for asyncio" +optional = false +python-versions = ">=3.7" +files = [ + {file = "grpclib-0.4.7.tar.gz", hash = "sha256:2988ef57c02b22b7a2e8e961792c41ccf97efc2ace91ae7a5b0de03c363823c3"}, +] + +[package.dependencies] +h2 = ">=3.1.0,<5" +multidict = "*" + +[package.extras] +protobuf = ["protobuf (>=3.20.0)"] + +[[package]] +name = "h2" +version = "4.1.0" +description = "HTTP/2 State-Machine based protocol implementation" +optional = false +python-versions = ">=3.6.1" +files = [ + {file = "h2-4.1.0-py3-none-any.whl", hash = "sha256:03a46bcf682256c95b5fd9e9a99c1323584c3eec6440d379b9903d709476bc6d"}, + {file = "h2-4.1.0.tar.gz", hash = "sha256:a83aca08fbe7aacb79fec788c9c0bac936343560ed9ec18b82a13a12c28d2abb"}, +] + +[package.dependencies] +hpack = ">=4.0,<5" +hyperframe = ">=6.0,<7" + +[[package]] +name = "hpack" +version = "4.0.0" +description = "Pure-Python HPACK header compression" +optional = false +python-versions = ">=3.6.1" +files = [ + {file = "hpack-4.0.0-py3-none-any.whl", hash = "sha256:84a076fad3dc9a9f8063ccb8041ef100867b1878b25ef0ee63847a5d53818a6c"}, + {file = "hpack-4.0.0.tar.gz", hash = "sha256:fc41de0c63e687ebffde81187a948221294896f6bdc0ae2312708df339430095"}, +] + +[[package]] +name = "hyperframe" +version = "6.0.1" +description = "HTTP/2 framing layer for Python" +optional = false +python-versions = ">=3.6.1" +files = [ + {file = "hyperframe-6.0.1-py3-none-any.whl", hash = "sha256:0ec6bafd80d8ad2195c4f03aacba3a8265e57bc4cff261e802bf39970ed02a15"}, + {file = "hyperframe-6.0.1.tar.gz", hash = "sha256:ae510046231dc8e9ecb1a6586f63d2347bf4c8905914aa84ba585ae85f28a914"}, +] + +[[package]] +name = "identify" +version = "2.5.33" +description = "File identification library for Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "identify-2.5.33-py2.py3-none-any.whl", hash = "sha256:d40ce5fcd762817627670da8a7d8d8e65f24342d14539c59488dc603bf662e34"}, + {file = "identify-2.5.33.tar.gz", hash = "sha256:161558f9fe4559e1557e1bff323e8631f6a0e4837f7497767c1782832f16b62d"}, +] + +[package.extras] +license = ["ukkonen"] + +[[package]] +name = "idna" +version = "3.7" +description = "Internationalized Domain Names in Applications (IDNA)" +optional = false +python-versions = ">=3.5" +files = [ + {file = "idna-3.7-py3-none-any.whl", hash = "sha256:82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0"}, + {file = "idna-3.7.tar.gz", hash = "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc"}, +] + +[[package]] +name = "imagesize" +version = "1.4.1" +description = "Getting image size from png/jpeg/jpeg2000/gif file" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +files = [ + {file = "imagesize-1.4.1-py2.py3-none-any.whl", hash = "sha256:0d8d18d08f840c19d0ee7ca1fd82490fdc3729b7ac93f49870406ddde8ef8d8b"}, + {file = "imagesize-1.4.1.tar.gz", hash = "sha256:69150444affb9cb0d5cc5a92b3676f0b2fb7cd9ae39e947a5e11a36b4497cd4a"}, +] + +[[package]] +name = "iniconfig" +version = "2.0.0" +description = "brain-dead simple config-ini parsing" +optional = false +python-versions = ">=3.7" +files = [ + {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, + {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, +] + +[[package]] +name = "isort" +version = "5.13.2" +description = "A Python utility / library to sort Python imports." +optional = true +python-versions = ">=3.8.0" +files = [ + {file = "isort-5.13.2-py3-none-any.whl", hash = "sha256:8ca5e72a8d85860d5a3fa69b8745237f2939afe12dbf656afbcb47fe72d947a6"}, + {file = "isort-5.13.2.tar.gz", hash = "sha256:48fdfcb9face5d58a4f6dde2e72a1fb8dcaf8ab26f95ab49fab84c2ddefb0109"}, +] + +[package.extras] +colors = ["colorama (>=0.4.6)"] + +[[package]] +name = "jinja2" +version = "3.1.3" +description = "A very fast and expressive template engine." +optional = false +python-versions = ">=3.7" +files = [ + {file = "Jinja2-3.1.3-py3-none-any.whl", hash = "sha256:7d6d50dd97d52cbc355597bd845fabfbac3f551e1f99619e39a35ce8c370b5fa"}, + {file = "Jinja2-3.1.3.tar.gz", hash = "sha256:ac8bd6544d4bb2c9792bf3a159e80bba8fda7f07e81bc3aed565432d5925ba90"}, +] + +[package.dependencies] +MarkupSafe = ">=2.0" + +[package.extras] +i18n = ["Babel (>=2.7)"] + +[[package]] +name = "jinxed" +version = "1.2.1" +description = "Jinxed Terminal Library" +optional = false +python-versions = "*" +files = [ + {file = "jinxed-1.2.1-py2.py3-none-any.whl", hash = "sha256:37422659c4925969c66148c5e64979f553386a4226b9484d910d3094ced37d30"}, + {file = "jinxed-1.2.1.tar.gz", hash = "sha256:30c3f861b73279fea1ed928cfd4dfb1f273e16cd62c8a32acfac362da0f78f3f"}, +] + +[package.dependencies] +ansicon = {version = "*", markers = "platform_system == \"Windows\""} + +[[package]] +name = "markupsafe" +version = "2.1.3" +description = "Safely add untrusted strings to HTML/XML markup." +optional = false +python-versions = ">=3.7" +files = [ + {file = "MarkupSafe-2.1.3-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:cd0f502fe016460680cd20aaa5a76d241d6f35a1c3350c474bac1273803893fa"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:e09031c87a1e51556fdcb46e5bd4f59dfb743061cf93c4d6831bf894f125eb57"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:68e78619a61ecf91e76aa3e6e8e33fc4894a2bebe93410754bd28fce0a8a4f9f"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:65c1a9bcdadc6c28eecee2c119465aebff8f7a584dd719facdd9e825ec61ab52"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:525808b8019e36eb524b8c68acdd63a37e75714eac50e988180b169d64480a00"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:962f82a3086483f5e5f64dbad880d31038b698494799b097bc59c2edf392fce6"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:aa7bd130efab1c280bed0f45501b7c8795f9fdbeb02e965371bbef3523627779"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:c9c804664ebe8f83a211cace637506669e7890fec1b4195b505c214e50dd4eb7"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-win32.whl", hash = "sha256:10bbfe99883db80bdbaff2dcf681dfc6533a614f700da1287707e8a5d78a8431"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-win_amd64.whl", hash = "sha256:1577735524cdad32f9f694208aa75e422adba74f1baee7551620e43a3141f559"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:ad9e82fb8f09ade1c3e1b996a6337afac2b8b9e365f926f5a61aacc71adc5b3c"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:3c0fae6c3be832a0a0473ac912810b2877c8cb9d76ca48de1ed31e1c68386575"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b076b6226fb84157e3f7c971a47ff3a679d837cf338547532ab866c57930dbee"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bfce63a9e7834b12b87c64d6b155fdd9b3b96191b6bd334bf37db7ff1fe457f2"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:338ae27d6b8745585f87218a3f23f1512dbf52c26c28e322dbe54bcede54ccb9"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:e4dd52d80b8c83fdce44e12478ad2e85c64ea965e75d66dbeafb0a3e77308fcc"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:df0be2b576a7abbf737b1575f048c23fb1d769f267ec4358296f31c2479db8f9"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:5bbe06f8eeafd38e5d0a4894ffec89378b6c6a625ff57e3028921f8ff59318ac"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-win32.whl", hash = "sha256:dd15ff04ffd7e05ffcb7fe79f1b98041b8ea30ae9234aed2a9168b5797c3effb"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-win_amd64.whl", hash = "sha256:134da1eca9ec0ae528110ccc9e48041e0828d79f24121a1a146161103c76e686"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:f698de3fd0c4e6972b92290a45bd9b1536bffe8c6759c62471efaa8acb4c37bc"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aa57bd9cf8ae831a362185ee444e15a93ecb2e344c8e52e4d721ea3ab6ef1823"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ffcc3f7c66b5f5b7931a5aa68fc9cecc51e685ef90282f4a82f0f5e9b704ad11"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:47d4f1c5f80fc62fdd7777d0d40a2e9dda0a05883ab11374334f6c4de38adffd"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1f67c7038d560d92149c060157d623c542173016c4babc0c1913cca0564b9939"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:9aad3c1755095ce347e26488214ef77e0485a3c34a50c5a5e2471dff60b9dd9c"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:14ff806850827afd6b07a5f32bd917fb7f45b046ba40c57abdb636674a8b559c"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8f9293864fe09b8149f0cc42ce56e3f0e54de883a9de90cd427f191c346eb2e1"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-win32.whl", hash = "sha256:715d3562f79d540f251b99ebd6d8baa547118974341db04f5ad06d5ea3eb8007"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-win_amd64.whl", hash = "sha256:1b8dd8c3fd14349433c79fa8abeb573a55fc0fdd769133baac1f5e07abf54aeb"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8e254ae696c88d98da6555f5ace2279cf7cd5b3f52be2b5cf97feafe883b58d2"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cb0932dc158471523c9637e807d9bfb93e06a95cbf010f1a38b98623b929ef2b"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9402b03f1a1b4dc4c19845e5c749e3ab82d5078d16a2a4c2cd2df62d57bb0707"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ca379055a47383d02a5400cb0d110cef0a776fc644cda797db0c5696cfd7e18e"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:b7ff0f54cb4ff66dd38bebd335a38e2c22c41a8ee45aa608efc890ac3e3931bc"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:c011a4149cfbcf9f03994ec2edffcb8b1dc2d2aede7ca243746df97a5d41ce48"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:56d9f2ecac662ca1611d183feb03a3fa4406469dafe241673d521dd5ae92a155"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-win32.whl", hash = "sha256:8758846a7e80910096950b67071243da3e5a20ed2546e6392603c096778d48e0"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-win_amd64.whl", hash = "sha256:787003c0ddb00500e49a10f2844fac87aa6ce977b90b0feaaf9de23c22508b24"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:2ef12179d3a291be237280175b542c07a36e7f60718296278d8593d21ca937d4"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:2c1b19b3aaacc6e57b7e25710ff571c24d6c3613a45e905b1fde04d691b98ee0"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8afafd99945ead6e075b973fefa56379c5b5c53fd8937dad92c662da5d8fd5ee"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8c41976a29d078bb235fea9b2ecd3da465df42a562910f9022f1a03107bd02be"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d080e0a5eb2529460b30190fcfcc4199bd7f827663f858a226a81bc27beaa97e"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:69c0f17e9f5a7afdf2cc9fb2d1ce6aabdb3bafb7f38017c0b77862bcec2bbad8"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:504b320cd4b7eff6f968eddf81127112db685e81f7e36e75f9f84f0df46041c3"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:42de32b22b6b804f42c5d98be4f7e5e977ecdd9ee9b660fda1a3edf03b11792d"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-win32.whl", hash = "sha256:ceb01949af7121f9fc39f7d27f91be8546f3fb112c608bc4029aef0bab86a2a5"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-win_amd64.whl", hash = "sha256:1b40069d487e7edb2676d3fbdb2b0829ffa2cd63a2ec26c4938b2d34391b4ecc"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:8023faf4e01efadfa183e863fefde0046de576c6f14659e8782065bcece22198"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:6b2b56950d93e41f33b4223ead100ea0fe11f8e6ee5f641eb753ce4b77a7042b"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9dcdfd0eaf283af041973bff14a2e143b8bd64e069f4c383416ecd79a81aab58"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:05fb21170423db021895e1ea1e1f3ab3adb85d1c2333cbc2310f2a26bc77272e"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:282c2cb35b5b673bbcadb33a585408104df04f14b2d9b01d4c345a3b92861c2c"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:ab4a0df41e7c16a1392727727e7998a467472d0ad65f3ad5e6e765015df08636"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:7ef3cb2ebbf91e330e3bb937efada0edd9003683db6b57bb108c4001f37a02ea"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:0a4e4a1aff6c7ac4cd55792abf96c915634c2b97e3cc1c7129578aa68ebd754e"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-win32.whl", hash = "sha256:fec21693218efe39aa7f8599346e90c705afa52c5b31ae019b2e57e8f6542bb2"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-win_amd64.whl", hash = "sha256:3fd4abcb888d15a94f32b75d8fd18ee162ca0c064f35b11134be77050296d6ba"}, + {file = "MarkupSafe-2.1.3.tar.gz", hash = "sha256:af598ed32d6ae86f1b747b82783958b1a4ab8f617b06fe68795c7f026abbdcad"}, +] + +[[package]] +name = "multidict" +version = "6.0.4" +description = "multidict implementation" +optional = false +python-versions = ">=3.7" +files = [ + {file = "multidict-6.0.4-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:0b1a97283e0c85772d613878028fec909f003993e1007eafa715b24b377cb9b8"}, + {file = "multidict-6.0.4-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:eeb6dcc05e911516ae3d1f207d4b0520d07f54484c49dfc294d6e7d63b734171"}, + {file = "multidict-6.0.4-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d6d635d5209b82a3492508cf5b365f3446afb65ae7ebd755e70e18f287b0adf7"}, + {file = "multidict-6.0.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c048099e4c9e9d615545e2001d3d8a4380bd403e1a0578734e0d31703d1b0c0b"}, + {file = "multidict-6.0.4-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:ea20853c6dbbb53ed34cb4d080382169b6f4554d394015f1bef35e881bf83547"}, + {file = "multidict-6.0.4-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:16d232d4e5396c2efbbf4f6d4df89bfa905eb0d4dc5b3549d872ab898451f569"}, + {file = "multidict-6.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:36c63aaa167f6c6b04ef2c85704e93af16c11d20de1d133e39de6a0e84582a93"}, + {file = "multidict-6.0.4-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:64bdf1086b6043bf519869678f5f2757f473dee970d7abf6da91ec00acb9cb98"}, + {file = "multidict-6.0.4-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:43644e38f42e3af682690876cff722d301ac585c5b9e1eacc013b7a3f7b696a0"}, + {file = "multidict-6.0.4-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:7582a1d1030e15422262de9f58711774e02fa80df0d1578995c76214f6954988"}, + {file = "multidict-6.0.4-cp310-cp310-musllinux_1_1_ppc64le.whl", hash = "sha256:ddff9c4e225a63a5afab9dd15590432c22e8057e1a9a13d28ed128ecf047bbdc"}, + {file = "multidict-6.0.4-cp310-cp310-musllinux_1_1_s390x.whl", hash = "sha256:ee2a1ece51b9b9e7752e742cfb661d2a29e7bcdba2d27e66e28a99f1890e4fa0"}, + {file = "multidict-6.0.4-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:a2e4369eb3d47d2034032a26c7a80fcb21a2cb22e1173d761a162f11e562caa5"}, + {file = "multidict-6.0.4-cp310-cp310-win32.whl", hash = "sha256:574b7eae1ab267e5f8285f0fe881f17efe4b98c39a40858247720935b893bba8"}, + {file = "multidict-6.0.4-cp310-cp310-win_amd64.whl", hash = "sha256:4dcbb0906e38440fa3e325df2359ac6cb043df8e58c965bb45f4e406ecb162cc"}, + {file = "multidict-6.0.4-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:0dfad7a5a1e39c53ed00d2dd0c2e36aed4650936dc18fd9a1826a5ae1cad6f03"}, + {file = "multidict-6.0.4-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:64da238a09d6039e3bd39bb3aee9c21a5e34f28bfa5aa22518581f910ff94af3"}, + {file = "multidict-6.0.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:ff959bee35038c4624250473988b24f846cbeb2c6639de3602c073f10410ceba"}, + {file = "multidict-6.0.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:01a3a55bd90018c9c080fbb0b9f4891db37d148a0a18722b42f94694f8b6d4c9"}, + {file = "multidict-6.0.4-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c5cb09abb18c1ea940fb99360ea0396f34d46566f157122c92dfa069d3e0e982"}, + {file = "multidict-6.0.4-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:666daae833559deb2d609afa4490b85830ab0dfca811a98b70a205621a6109fe"}, + {file = "multidict-6.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:11bdf3f5e1518b24530b8241529d2050014c884cf18b6fc69c0c2b30ca248710"}, + {file = "multidict-6.0.4-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7d18748f2d30f94f498e852c67d61261c643b349b9d2a581131725595c45ec6c"}, + {file = "multidict-6.0.4-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:458f37be2d9e4c95e2d8866a851663cbc76e865b78395090786f6cd9b3bbf4f4"}, + {file = "multidict-6.0.4-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:b1a2eeedcead3a41694130495593a559a668f382eee0727352b9a41e1c45759a"}, + {file = "multidict-6.0.4-cp311-cp311-musllinux_1_1_ppc64le.whl", hash = "sha256:7d6ae9d593ef8641544d6263c7fa6408cc90370c8cb2bbb65f8d43e5b0351d9c"}, + {file = "multidict-6.0.4-cp311-cp311-musllinux_1_1_s390x.whl", hash = "sha256:5979b5632c3e3534e42ca6ff856bb24b2e3071b37861c2c727ce220d80eee9ed"}, + {file = "multidict-6.0.4-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:dcfe792765fab89c365123c81046ad4103fcabbc4f56d1c1997e6715e8015461"}, + {file = "multidict-6.0.4-cp311-cp311-win32.whl", hash = "sha256:3601a3cece3819534b11d4efc1eb76047488fddd0c85a3948099d5da4d504636"}, + {file = "multidict-6.0.4-cp311-cp311-win_amd64.whl", hash = "sha256:81a4f0b34bd92df3da93315c6a59034df95866014ac08535fc819f043bfd51f0"}, + {file = "multidict-6.0.4-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:67040058f37a2a51ed8ea8f6b0e6ee5bd78ca67f169ce6122f3e2ec80dfe9b78"}, + {file = "multidict-6.0.4-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:853888594621e6604c978ce2a0444a1e6e70c8d253ab65ba11657659dcc9100f"}, + {file = "multidict-6.0.4-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:39ff62e7d0f26c248b15e364517a72932a611a9b75f35b45be078d81bdb86603"}, + {file = "multidict-6.0.4-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:af048912e045a2dc732847d33821a9d84ba553f5c5f028adbd364dd4765092ac"}, + {file = "multidict-6.0.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b1e8b901e607795ec06c9e42530788c45ac21ef3aaa11dbd0c69de543bfb79a9"}, + {file = "multidict-6.0.4-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:62501642008a8b9871ddfccbf83e4222cf8ac0d5aeedf73da36153ef2ec222d2"}, + {file = "multidict-6.0.4-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:99b76c052e9f1bc0721f7541e5e8c05db3941eb9ebe7b8553c625ef88d6eefde"}, + {file = "multidict-6.0.4-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:509eac6cf09c794aa27bcacfd4d62c885cce62bef7b2c3e8b2e49d365b5003fe"}, + {file = "multidict-6.0.4-cp37-cp37m-musllinux_1_1_ppc64le.whl", hash = "sha256:21a12c4eb6ddc9952c415f24eef97e3e55ba3af61f67c7bc388dcdec1404a067"}, + {file = "multidict-6.0.4-cp37-cp37m-musllinux_1_1_s390x.whl", hash = "sha256:5cad9430ab3e2e4fa4a2ef4450f548768400a2ac635841bc2a56a2052cdbeb87"}, + {file = "multidict-6.0.4-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:ab55edc2e84460694295f401215f4a58597f8f7c9466faec545093045476327d"}, + {file = "multidict-6.0.4-cp37-cp37m-win32.whl", hash = "sha256:5a4dcf02b908c3b8b17a45fb0f15b695bf117a67b76b7ad18b73cf8e92608775"}, + {file = "multidict-6.0.4-cp37-cp37m-win_amd64.whl", hash = "sha256:6ed5f161328b7df384d71b07317f4d8656434e34591f20552c7bcef27b0ab88e"}, + {file = "multidict-6.0.4-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:5fc1b16f586f049820c5c5b17bb4ee7583092fa0d1c4e28b5239181ff9532e0c"}, + {file = "multidict-6.0.4-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1502e24330eb681bdaa3eb70d6358e818e8e8f908a22a1851dfd4e15bc2f8161"}, + {file = "multidict-6.0.4-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:b692f419760c0e65d060959df05f2a531945af31fda0c8a3b3195d4efd06de11"}, + {file = "multidict-6.0.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:45e1ecb0379bfaab5eef059f50115b54571acfbe422a14f668fc8c27ba410e7e"}, + {file = "multidict-6.0.4-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:ddd3915998d93fbcd2566ddf9cf62cdb35c9e093075f862935573d265cf8f65d"}, + {file = "multidict-6.0.4-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:59d43b61c59d82f2effb39a93c48b845efe23a3852d201ed2d24ba830d0b4cf2"}, + {file = "multidict-6.0.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:cc8e1d0c705233c5dd0c5e6460fbad7827d5d36f310a0fadfd45cc3029762258"}, + {file = "multidict-6.0.4-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d6aa0418fcc838522256761b3415822626f866758ee0bc6632c9486b179d0b52"}, + {file = "multidict-6.0.4-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:6748717bb10339c4760c1e63da040f5f29f5ed6e59d76daee30305894069a660"}, + {file = "multidict-6.0.4-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:4d1a3d7ef5e96b1c9e92f973e43aa5e5b96c659c9bc3124acbbd81b0b9c8a951"}, + {file = "multidict-6.0.4-cp38-cp38-musllinux_1_1_ppc64le.whl", hash = "sha256:4372381634485bec7e46718edc71528024fcdc6f835baefe517b34a33c731d60"}, + {file = "multidict-6.0.4-cp38-cp38-musllinux_1_1_s390x.whl", hash = "sha256:fc35cb4676846ef752816d5be2193a1e8367b4c1397b74a565a9d0389c433a1d"}, + {file = "multidict-6.0.4-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:4b9d9e4e2b37daddb5c23ea33a3417901fa7c7b3dee2d855f63ee67a0b21e5b1"}, + {file = "multidict-6.0.4-cp38-cp38-win32.whl", hash = "sha256:e41b7e2b59679edfa309e8db64fdf22399eec4b0b24694e1b2104fb789207779"}, + {file = "multidict-6.0.4-cp38-cp38-win_amd64.whl", hash = "sha256:d6c254ba6e45d8e72739281ebc46ea5eb5f101234f3ce171f0e9f5cc86991480"}, + {file = "multidict-6.0.4-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:16ab77bbeb596e14212e7bab8429f24c1579234a3a462105cda4a66904998664"}, + {file = "multidict-6.0.4-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:bc779e9e6f7fda81b3f9aa58e3a6091d49ad528b11ed19f6621408806204ad35"}, + {file = "multidict-6.0.4-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:4ceef517eca3e03c1cceb22030a3e39cb399ac86bff4e426d4fc6ae49052cc60"}, + {file = "multidict-6.0.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:281af09f488903fde97923c7744bb001a9b23b039a909460d0f14edc7bf59706"}, + {file = "multidict-6.0.4-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:52f2dffc8acaba9a2f27174c41c9e57f60b907bb9f096b36b1a1f3be71c6284d"}, + {file = "multidict-6.0.4-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b41156839806aecb3641f3208c0dafd3ac7775b9c4c422d82ee2a45c34ba81ca"}, + {file = "multidict-6.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d5e3fc56f88cc98ef8139255cf8cd63eb2c586531e43310ff859d6bb3a6b51f1"}, + {file = "multidict-6.0.4-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8316a77808c501004802f9beebde51c9f857054a0c871bd6da8280e718444449"}, + {file = "multidict-6.0.4-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:f70b98cd94886b49d91170ef23ec5c0e8ebb6f242d734ed7ed677b24d50c82cf"}, + {file = "multidict-6.0.4-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:bf6774e60d67a9efe02b3616fee22441d86fab4c6d335f9d2051d19d90a40063"}, + {file = "multidict-6.0.4-cp39-cp39-musllinux_1_1_ppc64le.whl", hash = "sha256:e69924bfcdda39b722ef4d9aa762b2dd38e4632b3641b1d9a57ca9cd18f2f83a"}, + {file = "multidict-6.0.4-cp39-cp39-musllinux_1_1_s390x.whl", hash = "sha256:6b181d8c23da913d4ff585afd1155a0e1194c0b50c54fcfe286f70cdaf2b7176"}, + {file = "multidict-6.0.4-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:52509b5be062d9eafc8170e53026fbc54cf3b32759a23d07fd935fb04fc22d95"}, + {file = "multidict-6.0.4-cp39-cp39-win32.whl", hash = "sha256:27c523fbfbdfd19c6867af7346332b62b586eed663887392cff78d614f9ec313"}, + {file = "multidict-6.0.4-cp39-cp39-win_amd64.whl", hash = "sha256:33029f5734336aa0d4c0384525da0387ef89148dc7191aae00ca5fb23d7aafc2"}, + {file = "multidict-6.0.4.tar.gz", hash = "sha256:3666906492efb76453c0e7b97f2cf459b0682e7402c0489a95484965dbc1da49"}, +] + +[[package]] +name = "mypy" +version = "0.930" +description = "Optional static typing for Python" +optional = false +python-versions = ">=3.6" +files = [ + {file = "mypy-0.930-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:221cc94dc6a801ccc2be7c0c9fd791c5e08d1fa2c5e1c12dec4eab15b2469871"}, + {file = "mypy-0.930-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:db3a87376a1380f396d465bed462e76ea89f838f4c5e967d68ff6ee34b785c31"}, + {file = "mypy-0.930-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:1d2296f35aae9802eeb1327058b550371ee382d71374b3e7d2804035ef0b830b"}, + {file = "mypy-0.930-cp310-cp310-win_amd64.whl", hash = "sha256:959319b9a3cafc33a8185f440a433ba520239c72e733bf91f9efd67b0a8e9b30"}, + {file = "mypy-0.930-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:45a4dc21c789cfd09b8ccafe114d6de66f0b341ad761338de717192f19397a8c"}, + {file = "mypy-0.930-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:1e689e92cdebd87607a041585f1dc7339aa2e8a9f9bad9ba7e6ece619431b20c"}, + {file = "mypy-0.930-cp36-cp36m-win_amd64.whl", hash = "sha256:ed4e0ea066bb12f56b2812a15ff223c57c0a44eca817ceb96b214bb055c7051f"}, + {file = "mypy-0.930-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:a9d8dffefba634b27d650e0de2564379a1a367e2e08d6617d8f89261a3bf63b2"}, + {file = "mypy-0.930-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:b419e9721260161e70d054a15abbd50603c16f159860cfd0daeab647d828fc29"}, + {file = "mypy-0.930-cp37-cp37m-win_amd64.whl", hash = "sha256:601f46593f627f8a9b944f74fd387c9b5f4266b39abad77471947069c2fc7651"}, + {file = "mypy-0.930-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1ea7199780c1d7940b82dbc0a4e37722b4e3851264dbba81e01abecc9052d8a7"}, + {file = "mypy-0.930-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:70b197dd8c78fc5d2daf84bd093e8466a2b2e007eedaa85e792e513a820adbf7"}, + {file = "mypy-0.930-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:5feb56f8bb280468fe5fc8e6f56f48f99aa0df9eed3c507a11505ee4657b5380"}, + {file = "mypy-0.930-cp38-cp38-win_amd64.whl", hash = "sha256:2e9c5409e9cb81049bb03fa1009b573dea87976713e3898561567a86c4eaee01"}, + {file = "mypy-0.930-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:554873e45c1ca20f31ddf873deb67fa5d2e87b76b97db50669f0468ccded8fae"}, + {file = "mypy-0.930-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:0feb82e9fa849affca7edd24713dbe809dce780ced9f3feca5ed3d80e40b777f"}, + {file = "mypy-0.930-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:bc1a0607ea03c30225347334af66b0af12eefba018a89a88c209e02b7065ea95"}, + {file = "mypy-0.930-cp39-cp39-win_amd64.whl", hash = "sha256:f9f665d69034b1fcfdbcd4197480d26298bbfb5d2dfe206245b6498addb34999"}, + {file = "mypy-0.930-py3-none-any.whl", hash = "sha256:bf4a44e03040206f7c058d1f5ba02ef2d1820720c88bc4285c7d9a4269f54173"}, + {file = "mypy-0.930.tar.gz", hash = "sha256:51426262ae4714cc7dd5439814676e0992b55bcc0f6514eccb4cf8e0678962c2"}, +] + +[package.dependencies] +mypy-extensions = ">=0.4.3" +tomli = ">=1.1.0" +typing-extensions = ">=3.10" + +[package.extras] +dmypy = ["psutil (>=4.0)"] +python2 = ["typed-ast (>=1.4.0,<2)"] + +[[package]] +name = "mypy-extensions" +version = "1.0.0" +description = "Type system extensions for programs checked with the mypy type checker." +optional = false +python-versions = ">=3.5" +files = [ + {file = "mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d"}, + {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, +] + +[[package]] +name = "nodeenv" +version = "1.8.0" +description = "Node.js virtual environment builder" +optional = false +python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*" +files = [ + {file = "nodeenv-1.8.0-py2.py3-none-any.whl", hash = "sha256:df865724bb3c3adc86b3876fa209771517b0cfe596beff01a92700e0e8be4cec"}, + {file = "nodeenv-1.8.0.tar.gz", hash = "sha256:d51e0c37e64fbf47d017feac3145cdbb58836d7eee8c6f6d3b6880c5456227d2"}, +] + +[package.dependencies] +setuptools = "*" + +[[package]] +name = "packaging" +version = "23.2" +description = "Core utilities for Python packages" +optional = false +python-versions = ">=3.7" +files = [ + {file = "packaging-23.2-py3-none-any.whl", hash = "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7"}, + {file = "packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5"}, +] + +[[package]] +name = "pastel" +version = "0.2.1" +description = "Bring colors to your terminal." +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +files = [ + {file = "pastel-0.2.1-py2.py3-none-any.whl", hash = "sha256:4349225fcdf6c2bb34d483e523475de5bb04a5c10ef711263452cb37d7dd4364"}, + {file = "pastel-0.2.1.tar.gz", hash = "sha256:e6581ac04e973cac858828c6202c1e1e81fee1dc7de7683f3e1ffe0bfd8a573d"}, +] + +[[package]] +name = "pathspec" +version = "0.12.1" +description = "Utility library for gitignore style pattern matching of file paths." +optional = true +python-versions = ">=3.8" +files = [ + {file = "pathspec-0.12.1-py3-none-any.whl", hash = "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08"}, + {file = "pathspec-0.12.1.tar.gz", hash = "sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712"}, +] + +[[package]] +name = "platformdirs" +version = "4.1.0" +description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." +optional = false +python-versions = ">=3.8" +files = [ + {file = "platformdirs-4.1.0-py3-none-any.whl", hash = "sha256:11c8f37bcca40db96d8144522d925583bdb7a31f7b0e37e3ed4318400a8e2380"}, + {file = "platformdirs-4.1.0.tar.gz", hash = "sha256:906d548203468492d432bcb294d4bc2fff751bf84971fbb2c10918cc206ee420"}, +] + +[package.extras] +docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.1)", "sphinx-autodoc-typehints (>=1.24)"] +test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4)", "pytest-cov (>=4.1)", "pytest-mock (>=3.11.1)"] + +[[package]] +name = "pluggy" +version = "1.3.0" +description = "plugin and hook calling mechanisms for python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pluggy-1.3.0-py3-none-any.whl", hash = "sha256:d89c696a773f8bd377d18e5ecda92b7a3793cbe66c87060a6fb58c7b6e1061f7"}, + {file = "pluggy-1.3.0.tar.gz", hash = "sha256:cf61ae8f126ac6f7c451172cf30e3e43d3ca77615509771b3a984a0730651e12"}, +] + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + +[[package]] +name = "poethepoet" +version = "0.24.4" +description = "A task runner that works well with poetry." +optional = false +python-versions = ">=3.8" +files = [ + {file = "poethepoet-0.24.4-py3-none-any.whl", hash = "sha256:fb4ea35d7f40fe2081ea917d2e4102e2310fda2cde78974050ca83896e229075"}, + {file = "poethepoet-0.24.4.tar.gz", hash = "sha256:ff4220843a87c888cbcb5312c8905214701d0af60ac7271795baa8369b428fef"}, +] + +[package.dependencies] +pastel = ">=0.2.1,<0.3.0" +tomli = ">=1.2.2" + +[package.extras] +poetry-plugin = ["poetry (>=1.0,<2.0)"] + +[[package]] +name = "pre-commit" +version = "2.21.0" +description = "A framework for managing and maintaining multi-language pre-commit hooks." +optional = false +python-versions = ">=3.7" +files = [ + {file = "pre_commit-2.21.0-py2.py3-none-any.whl", hash = "sha256:e2f91727039fc39a92f58a588a25b87f936de6567eed4f0e673e0507edc75bad"}, + {file = "pre_commit-2.21.0.tar.gz", hash = "sha256:31ef31af7e474a8d8995027fefdfcf509b5c913ff31f2015b4ec4beb26a6f658"}, +] + +[package.dependencies] +cfgv = ">=2.0.0" +identify = ">=1.0.0" +nodeenv = ">=0.11.1" +pyyaml = ">=5.1" +virtualenv = ">=20.10.0" + +[[package]] +name = "protobuf" +version = "4.25.1" +description = "" +optional = false +python-versions = ">=3.8" +files = [ + {file = "protobuf-4.25.1-cp310-abi3-win32.whl", hash = "sha256:193f50a6ab78a970c9b4f148e7c750cfde64f59815e86f686c22e26b4fe01ce7"}, + {file = "protobuf-4.25.1-cp310-abi3-win_amd64.whl", hash = "sha256:3497c1af9f2526962f09329fd61a36566305e6c72da2590ae0d7d1322818843b"}, + {file = "protobuf-4.25.1-cp37-abi3-macosx_10_9_universal2.whl", hash = "sha256:0bf384e75b92c42830c0a679b0cd4d6e2b36ae0cf3dbb1e1dfdda48a244f4bcd"}, + {file = "protobuf-4.25.1-cp37-abi3-manylinux2014_aarch64.whl", hash = "sha256:0f881b589ff449bf0b931a711926e9ddaad3b35089cc039ce1af50b21a4ae8cb"}, + {file = "protobuf-4.25.1-cp37-abi3-manylinux2014_x86_64.whl", hash = "sha256:ca37bf6a6d0046272c152eea90d2e4ef34593aaa32e8873fc14c16440f22d4b7"}, + {file = "protobuf-4.25.1-cp38-cp38-win32.whl", hash = "sha256:abc0525ae2689a8000837729eef7883b9391cd6aa7950249dcf5a4ede230d5dd"}, + {file = "protobuf-4.25.1-cp38-cp38-win_amd64.whl", hash = "sha256:1484f9e692091450e7edf418c939e15bfc8fc68856e36ce399aed6889dae8bb0"}, + {file = "protobuf-4.25.1-cp39-cp39-win32.whl", hash = "sha256:8bdbeaddaac52d15c6dce38c71b03038ef7772b977847eb6d374fc86636fa510"}, + {file = "protobuf-4.25.1-cp39-cp39-win_amd64.whl", hash = "sha256:becc576b7e6b553d22cbdf418686ee4daa443d7217999125c045ad56322dda10"}, + {file = "protobuf-4.25.1-py3-none-any.whl", hash = "sha256:a19731d5e83ae4737bb2a089605e636077ac001d18781b3cf489b9546c7c80d6"}, + {file = "protobuf-4.25.1.tar.gz", hash = "sha256:57d65074b4f5baa4ab5da1605c02be90ac20c8b40fb137d6a8df9f416b0d0ce2"}, +] + +[[package]] +name = "pydantic" +version = "1.10.13" +description = "Data validation and settings management using python type hints" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pydantic-1.10.13-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:efff03cc7a4f29d9009d1c96ceb1e7a70a65cfe86e89d34e4a5f2ab1e5693737"}, + {file = "pydantic-1.10.13-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:3ecea2b9d80e5333303eeb77e180b90e95eea8f765d08c3d278cd56b00345d01"}, + {file = "pydantic-1.10.13-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1740068fd8e2ef6eb27a20e5651df000978edce6da6803c2bef0bc74540f9548"}, + {file = "pydantic-1.10.13-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:84bafe2e60b5e78bc64a2941b4c071a4b7404c5c907f5f5a99b0139781e69ed8"}, + {file = "pydantic-1.10.13-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:bc0898c12f8e9c97f6cd44c0ed70d55749eaf783716896960b4ecce2edfd2d69"}, + {file = "pydantic-1.10.13-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:654db58ae399fe6434e55325a2c3e959836bd17a6f6a0b6ca8107ea0571d2e17"}, + {file = "pydantic-1.10.13-cp310-cp310-win_amd64.whl", hash = "sha256:75ac15385a3534d887a99c713aa3da88a30fbd6204a5cd0dc4dab3d770b9bd2f"}, + {file = "pydantic-1.10.13-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:c553f6a156deb868ba38a23cf0df886c63492e9257f60a79c0fd8e7173537653"}, + {file = "pydantic-1.10.13-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:5e08865bc6464df8c7d61439ef4439829e3ab62ab1669cddea8dd00cd74b9ffe"}, + {file = "pydantic-1.10.13-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e31647d85a2013d926ce60b84f9dd5300d44535a9941fe825dc349ae1f760df9"}, + {file = "pydantic-1.10.13-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:210ce042e8f6f7c01168b2d84d4c9eb2b009fe7bf572c2266e235edf14bacd80"}, + {file = "pydantic-1.10.13-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:8ae5dd6b721459bfa30805f4c25880e0dd78fc5b5879f9f7a692196ddcb5a580"}, + {file = "pydantic-1.10.13-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:f8e81fc5fb17dae698f52bdd1c4f18b6ca674d7068242b2aff075f588301bbb0"}, + {file = "pydantic-1.10.13-cp311-cp311-win_amd64.whl", hash = "sha256:61d9dce220447fb74f45e73d7ff3b530e25db30192ad8d425166d43c5deb6df0"}, + {file = "pydantic-1.10.13-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:4b03e42ec20286f052490423682016fd80fda830d8e4119f8ab13ec7464c0132"}, + {file = "pydantic-1.10.13-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f59ef915cac80275245824e9d771ee939133be38215555e9dc90c6cb148aaeb5"}, + {file = "pydantic-1.10.13-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:5a1f9f747851338933942db7af7b6ee8268568ef2ed86c4185c6ef4402e80ba8"}, + {file = "pydantic-1.10.13-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:97cce3ae7341f7620a0ba5ef6cf043975cd9d2b81f3aa5f4ea37928269bc1b87"}, + {file = "pydantic-1.10.13-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:854223752ba81e3abf663d685f105c64150873cc6f5d0c01d3e3220bcff7d36f"}, + {file = "pydantic-1.10.13-cp37-cp37m-win_amd64.whl", hash = "sha256:b97c1fac8c49be29486df85968682b0afa77e1b809aff74b83081cc115e52f33"}, + {file = "pydantic-1.10.13-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:c958d053453a1c4b1c2062b05cd42d9d5c8eb67537b8d5a7e3c3032943ecd261"}, + {file = "pydantic-1.10.13-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:4c5370a7edaac06daee3af1c8b1192e305bc102abcbf2a92374b5bc793818599"}, + {file = "pydantic-1.10.13-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7d6f6e7305244bddb4414ba7094ce910560c907bdfa3501e9db1a7fd7eaea127"}, + {file = "pydantic-1.10.13-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d3a3c792a58e1622667a2837512099eac62490cdfd63bd407993aaf200a4cf1f"}, + {file = "pydantic-1.10.13-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:c636925f38b8db208e09d344c7aa4f29a86bb9947495dd6b6d376ad10334fb78"}, + {file = "pydantic-1.10.13-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:678bcf5591b63cc917100dc50ab6caebe597ac67e8c9ccb75e698f66038ea953"}, + {file = "pydantic-1.10.13-cp38-cp38-win_amd64.whl", hash = "sha256:6cf25c1a65c27923a17b3da28a0bdb99f62ee04230c931d83e888012851f4e7f"}, + {file = "pydantic-1.10.13-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:8ef467901d7a41fa0ca6db9ae3ec0021e3f657ce2c208e98cd511f3161c762c6"}, + {file = "pydantic-1.10.13-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:968ac42970f57b8344ee08837b62f6ee6f53c33f603547a55571c954a4225691"}, + {file = "pydantic-1.10.13-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9849f031cf8a2f0a928fe885e5a04b08006d6d41876b8bbd2fc68a18f9f2e3fd"}, + {file = "pydantic-1.10.13-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:56e3ff861c3b9c6857579de282ce8baabf443f42ffba355bf070770ed63e11e1"}, + {file = "pydantic-1.10.13-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:9f00790179497767aae6bcdc36355792c79e7bbb20b145ff449700eb076c5f96"}, + {file = "pydantic-1.10.13-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:75b297827b59bc229cac1a23a2f7a4ac0031068e5be0ce385be1462e7e17a35d"}, + {file = "pydantic-1.10.13-cp39-cp39-win_amd64.whl", hash = "sha256:e70ca129d2053fb8b728ee7d1af8e553a928d7e301a311094b8a0501adc8763d"}, + {file = "pydantic-1.10.13-py3-none-any.whl", hash = "sha256:b87326822e71bd5f313e7d3bfdc77ac3247035ac10b0c0618bd99dcf95b1e687"}, + {file = "pydantic-1.10.13.tar.gz", hash = "sha256:32c8b48dcd3b2ac4e78b0ba4af3a2c2eb6048cb75202f0ea7b34feb740efc340"}, +] + +[package.dependencies] +typing-extensions = ">=4.2.0" + +[package.extras] +dotenv = ["python-dotenv (>=0.10.4)"] +email = ["email-validator (>=1.0.3)"] + +[[package]] +name = "pygments" +version = "2.17.2" +description = "Pygments is a syntax highlighting package written in Python." +optional = false +python-versions = ">=3.7" +files = [ + {file = "pygments-2.17.2-py3-none-any.whl", hash = "sha256:b27c2826c47d0f3219f29554824c30c5e8945175d888647acd804ddd04af846c"}, + {file = "pygments-2.17.2.tar.gz", hash = "sha256:da46cec9fd2de5be3a8a784f434e4c4ab670b4ff54d605c4c2717e9d49c4c367"}, +] + +[package.extras] +plugins = ["importlib-metadata"] +windows-terminal = ["colorama (>=0.4.6)"] + +[[package]] +name = "pyproject-api" +version = "1.6.1" +description = "API to interact with the python pyproject.toml based projects" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pyproject_api-1.6.1-py3-none-any.whl", hash = "sha256:4c0116d60476b0786c88692cf4e325a9814965e2469c5998b830bba16b183675"}, + {file = "pyproject_api-1.6.1.tar.gz", hash = "sha256:1817dc018adc0d1ff9ca1ed8c60e1623d5aaca40814b953af14a9cf9a5cae538"}, +] + +[package.dependencies] +packaging = ">=23.1" +tomli = {version = ">=2.0.1", markers = "python_version < \"3.11\""} + +[package.extras] +docs = ["furo (>=2023.8.19)", "sphinx (<7.2)", "sphinx-autodoc-typehints (>=1.24)"] +testing = ["covdefaults (>=2.3)", "pytest (>=7.4)", "pytest-cov (>=4.1)", "pytest-mock (>=3.11.1)", "setuptools (>=68.1.2)", "wheel (>=0.41.2)"] + +[[package]] +name = "pytest" +version = "7.4.4" +description = "pytest: simple powerful testing with Python" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pytest-7.4.4-py3-none-any.whl", hash = "sha256:b090cdf5ed60bf4c45261be03239c2c1c22df034fbffe691abe93cd80cea01d8"}, + {file = "pytest-7.4.4.tar.gz", hash = "sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "sys_platform == \"win32\""} +exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=0.12,<2.0" +tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} + +[package.extras] +testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] + +[[package]] +name = "pytest-asyncio" +version = "0.23.3" +description = "Pytest support for asyncio" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pytest-asyncio-0.23.3.tar.gz", hash = "sha256:af313ce900a62fbe2b1aed18e37ad757f1ef9940c6b6a88e2954de38d6b1fb9f"}, + {file = "pytest_asyncio-0.23.3-py3-none-any.whl", hash = "sha256:37a9d912e8338ee7b4a3e917381d1c95bfc8682048cb0fbc35baba316ec1faba"}, +] + +[package.dependencies] +pytest = ">=7.0.0" + +[package.extras] +docs = ["sphinx (>=5.3)", "sphinx-rtd-theme (>=1.0)"] +testing = ["coverage (>=6.2)", "hypothesis (>=5.7.1)"] + +[[package]] +name = "pytest-cov" +version = "2.12.1" +description = "Pytest plugin for measuring coverage." +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +files = [ + {file = "pytest-cov-2.12.1.tar.gz", hash = "sha256:261ceeb8c227b726249b376b8526b600f38667ee314f910353fa318caa01f4d7"}, + {file = "pytest_cov-2.12.1-py2.py3-none-any.whl", hash = "sha256:261bb9e47e65bd099c89c3edf92972865210c36813f80ede5277dceb77a4a62a"}, +] + +[package.dependencies] +coverage = ">=5.2.1" +pytest = ">=4.6" +toml = "*" + +[package.extras] +testing = ["fields", "hunter", "process-tests", "pytest-xdist", "six", "virtualenv"] + +[[package]] +name = "pytest-mock" +version = "3.12.0" +description = "Thin-wrapper around the mock package for easier use with pytest" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pytest-mock-3.12.0.tar.gz", hash = "sha256:31a40f038c22cad32287bb43932054451ff5583ff094bca6f675df2f8bc1a6e9"}, + {file = "pytest_mock-3.12.0-py3-none-any.whl", hash = "sha256:0972719a7263072da3a21c7f4773069bcc7486027d7e8e1f81d98a47e701bc4f"}, +] + +[package.dependencies] +pytest = ">=5.0" + +[package.extras] +dev = ["pre-commit", "pytest-asyncio", "tox"] + +[[package]] +name = "python-dateutil" +version = "2.8.2" +description = "Extensions to the standard Python datetime module" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" +files = [ + {file = "python-dateutil-2.8.2.tar.gz", hash = "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86"}, + {file = "python_dateutil-2.8.2-py2.py3-none-any.whl", hash = "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9"}, +] + +[package.dependencies] +six = ">=1.5" + +[[package]] +name = "pyyaml" +version = "6.0.1" +description = "YAML parser and emitter for Python" +optional = false +python-versions = ">=3.6" +files = [ + {file = "PyYAML-6.0.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d858aa552c999bc8a8d57426ed01e40bef403cd8ccdd0fc5f6f04a00414cac2a"}, + {file = "PyYAML-6.0.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f"}, + {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, + {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, + {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, + {file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"}, + {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, + {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, + {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, + {file = "PyYAML-6.0.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:f003ed9ad21d6a4713f0a9b5a7a0a79e08dd0f221aff4525a2be4c346ee60aab"}, + {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, + {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, + {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, + {file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"}, + {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, + {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, + {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, + {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, + {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, + {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, + {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, + {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, + {file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"}, + {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, + {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, + {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, + {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:afd7e57eddb1a54f0f1a974bc4391af8bcce0b444685d936840f125cf046d5bd"}, + {file = "PyYAML-6.0.1-cp36-cp36m-win32.whl", hash = "sha256:fca0e3a251908a499833aa292323f32437106001d436eca0e6e7833256674585"}, + {file = "PyYAML-6.0.1-cp36-cp36m-win_amd64.whl", hash = "sha256:f22ac1c3cac4dbc50079e965eba2c1058622631e526bd9afd45fedd49ba781fa"}, + {file = "PyYAML-6.0.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:b1275ad35a5d18c62a7220633c913e1b42d44b46ee12554e5fd39c70a243d6a3"}, + {file = "PyYAML-6.0.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:18aeb1bf9a78867dc38b259769503436b7c72f7a1f1f4c93ff9a17de54319b27"}, + {file = "PyYAML-6.0.1-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:596106435fa6ad000c2991a98fa58eeb8656ef2325d7e158344fb33864ed87e3"}, + {file = "PyYAML-6.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:baa90d3f661d43131ca170712d903e6295d1f7a0f595074f151c0aed377c9b9c"}, + {file = "PyYAML-6.0.1-cp37-cp37m-win32.whl", hash = "sha256:9046c58c4395dff28dd494285c82ba00b546adfc7ef001486fbf0324bc174fba"}, + {file = "PyYAML-6.0.1-cp37-cp37m-win_amd64.whl", hash = "sha256:4fb147e7a67ef577a588a0e2c17b6db51dda102c71de36f8549b6816a96e1867"}, + {file = "PyYAML-6.0.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1d4c7e777c441b20e32f52bd377e0c409713e8bb1386e1099c2415f26e479595"}, + {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, + {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, + {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, + {file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"}, + {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, + {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, + {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, + {file = "PyYAML-6.0.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:c8098ddcc2a85b61647b2590f825f3db38891662cfc2fc776415143f599bb859"}, + {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, + {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, + {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, + {file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"}, + {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, + {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, + {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, +] + +[[package]] +name = "requests" +version = "2.32.0" +description = "Python HTTP for Humans." +optional = false +python-versions = ">=3.8" +files = [ + {file = "requests-2.32.0-py3-none-any.whl", hash = "sha256:f2c3881dddb70d056c5bd7600a4fae312b2a300e39be6a118d30b90bd27262b5"}, + {file = "requests-2.32.0.tar.gz", hash = "sha256:fa5490319474c82ef1d2c9bc459d3652e3ae4ef4c4ebdd18a21145a47ca4b6b8"}, +] + +[package.dependencies] +certifi = ">=2017.4.17" +charset-normalizer = ">=2,<4" +idna = ">=2.5,<4" +urllib3 = ">=1.21.1,<3" + +[package.extras] +socks = ["PySocks (>=1.5.6,!=1.5.7)"] +use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] + +[[package]] +name = "setuptools" +version = "69.0.3" +description = "Easily download, build, install, upgrade, and uninstall Python packages" +optional = false +python-versions = ">=3.8" +files = [ + {file = "setuptools-69.0.3-py3-none-any.whl", hash = "sha256:385eb4edd9c9d5c17540511303e39a147ce2fc04bc55289c322b9e5904fe2c05"}, + {file = "setuptools-69.0.3.tar.gz", hash = "sha256:be1af57fc409f93647f2e8e4573a142ed38724b8cdd389706a867bb4efcf1e78"}, +] + +[package.extras] +docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (<7.2.5)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier"] +testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-ruff", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] +testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.1)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] + +[[package]] +name = "six" +version = "1.16.0" +description = "Python 2 and 3 compatibility utilities" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" +files = [ + {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, + {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, +] + +[[package]] +name = "snowballstemmer" +version = "2.2.0" +description = "This package provides 29 stemmers for 28 languages generated from Snowball algorithms." +optional = false +python-versions = "*" +files = [ + {file = "snowballstemmer-2.2.0-py2.py3-none-any.whl", hash = "sha256:c8e1716e83cc398ae16824e5572ae04e0d9fc2c6b985fb0f900f5f0c96ecba1a"}, + {file = "snowballstemmer-2.2.0.tar.gz", hash = "sha256:09b16deb8547d3412ad7b590689584cd0fe25ec8db3be37788be3810cbf19cb1"}, +] + +[[package]] +name = "sphinx" +version = "3.1.2" +description = "Python documentation generator" +optional = false +python-versions = ">=3.5" +files = [ + {file = "Sphinx-3.1.2-py3-none-any.whl", hash = "sha256:97dbf2e31fc5684bb805104b8ad34434ed70e6c588f6896991b2fdfd2bef8c00"}, + {file = "Sphinx-3.1.2.tar.gz", hash = "sha256:b9daeb9b39aa1ffefc2809b43604109825300300b987a24f45976c001ba1a8fd"}, +] + +[package.dependencies] +alabaster = ">=0.7,<0.8" +babel = ">=1.3" +colorama = {version = ">=0.3.5", markers = "sys_platform == \"win32\""} +docutils = ">=0.12" +imagesize = "*" +Jinja2 = ">=2.3" +packaging = "*" +Pygments = ">=2.0" +requests = ">=2.5.0" +setuptools = "*" +snowballstemmer = ">=1.1" +sphinxcontrib-applehelp = "*" +sphinxcontrib-devhelp = "*" +sphinxcontrib-htmlhelp = "*" +sphinxcontrib-jsmath = "*" +sphinxcontrib-qthelp = "*" +sphinxcontrib-serializinghtml = "*" + +[package.extras] +docs = ["sphinxcontrib-websupport"] +lint = ["docutils-stubs", "flake8 (>=3.5.0)", "flake8-import-order", "mypy (>=0.780)"] +test = ["cython", "html5lib", "pytest", "pytest-cov", "typed-ast"] + +[[package]] +name = "sphinx-rtd-theme" +version = "0.5.0" +description = "Read the Docs theme for Sphinx" +optional = false +python-versions = "*" +files = [ + {file = "sphinx_rtd_theme-0.5.0-py2.py3-none-any.whl", hash = "sha256:373413d0f82425aaa28fb288009bf0d0964711d347763af2f1b65cafcb028c82"}, + {file = "sphinx_rtd_theme-0.5.0.tar.gz", hash = "sha256:22c795ba2832a169ca301cd0a083f7a434e09c538c70beb42782c073651b707d"}, +] + +[package.dependencies] +sphinx = "*" + +[package.extras] +dev = ["bump2version", "sphinxcontrib-httpdomain", "transifex-client"] + +[[package]] +name = "sphinxcontrib-applehelp" +version = "1.0.4" +description = "sphinxcontrib-applehelp is a Sphinx extension which outputs Apple help books" +optional = false +python-versions = ">=3.8" +files = [ + {file = "sphinxcontrib-applehelp-1.0.4.tar.gz", hash = "sha256:828f867945bbe39817c210a1abfd1bc4895c8b73fcaade56d45357a348a07d7e"}, + {file = "sphinxcontrib_applehelp-1.0.4-py3-none-any.whl", hash = "sha256:29d341f67fb0f6f586b23ad80e072c8e6ad0b48417db2bde114a4c9746feb228"}, +] + +[package.extras] +lint = ["docutils-stubs", "flake8", "mypy"] +test = ["pytest"] + +[[package]] +name = "sphinxcontrib-devhelp" +version = "1.0.2" +description = "sphinxcontrib-devhelp is a sphinx extension which outputs Devhelp document." +optional = false +python-versions = ">=3.5" +files = [ + {file = "sphinxcontrib-devhelp-1.0.2.tar.gz", hash = "sha256:ff7f1afa7b9642e7060379360a67e9c41e8f3121f2ce9164266f61b9f4b338e4"}, + {file = "sphinxcontrib_devhelp-1.0.2-py2.py3-none-any.whl", hash = "sha256:8165223f9a335cc1af7ffe1ed31d2871f325254c0423bc0c4c7cd1c1e4734a2e"}, +] + +[package.extras] +lint = ["docutils-stubs", "flake8", "mypy"] +test = ["pytest"] + +[[package]] +name = "sphinxcontrib-htmlhelp" +version = "2.0.1" +description = "sphinxcontrib-htmlhelp is a sphinx extension which renders HTML help files" +optional = false +python-versions = ">=3.8" +files = [ + {file = "sphinxcontrib-htmlhelp-2.0.1.tar.gz", hash = "sha256:0cbdd302815330058422b98a113195c9249825d681e18f11e8b1f78a2f11efff"}, + {file = "sphinxcontrib_htmlhelp-2.0.1-py3-none-any.whl", hash = "sha256:c38cb46dccf316c79de6e5515e1770414b797162b23cd3d06e67020e1d2a6903"}, +] + +[package.extras] +lint = ["docutils-stubs", "flake8", "mypy"] +test = ["html5lib", "pytest"] + +[[package]] +name = "sphinxcontrib-jsmath" +version = "1.0.1" +description = "A sphinx extension which renders display math in HTML via JavaScript" +optional = false +python-versions = ">=3.5" +files = [ + {file = "sphinxcontrib-jsmath-1.0.1.tar.gz", hash = "sha256:a9925e4a4587247ed2191a22df5f6970656cb8ca2bd6284309578f2153e0c4b8"}, + {file = "sphinxcontrib_jsmath-1.0.1-py2.py3-none-any.whl", hash = "sha256:2ec2eaebfb78f3f2078e73666b1415417a116cc848b72e5172e596c871103178"}, +] + +[package.extras] +test = ["flake8", "mypy", "pytest"] + +[[package]] +name = "sphinxcontrib-qthelp" +version = "1.0.3" +description = "sphinxcontrib-qthelp is a sphinx extension which outputs QtHelp document." +optional = false +python-versions = ">=3.5" +files = [ + {file = "sphinxcontrib-qthelp-1.0.3.tar.gz", hash = "sha256:4c33767ee058b70dba89a6fc5c1892c0d57a54be67ddd3e7875a18d14cba5a72"}, + {file = "sphinxcontrib_qthelp-1.0.3-py2.py3-none-any.whl", hash = "sha256:bd9fc24bcb748a8d51fd4ecaade681350aa63009a347a8c14e637895444dfab6"}, +] + +[package.extras] +lint = ["docutils-stubs", "flake8", "mypy"] +test = ["pytest"] + +[[package]] +name = "sphinxcontrib-serializinghtml" +version = "1.1.5" +description = "sphinxcontrib-serializinghtml is a sphinx extension which outputs \"serialized\" HTML files (json and pickle)." +optional = false +python-versions = ">=3.5" +files = [ + {file = "sphinxcontrib-serializinghtml-1.1.5.tar.gz", hash = "sha256:aa5f6de5dfdf809ef505c4895e51ef5c9eac17d0f287933eb49ec495280b6952"}, + {file = "sphinxcontrib_serializinghtml-1.1.5-py2.py3-none-any.whl", hash = "sha256:352a9a00ae864471d3a7ead8d7d79f5fc0b57e8b3f95e9867eb9eb28999b92fd"}, +] + +[package.extras] +lint = ["docutils-stubs", "flake8", "mypy"] +test = ["pytest"] + +[[package]] +name = "toml" +version = "0.10.2" +description = "Python Library for Tom's Obvious, Minimal Language" +optional = false +python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" +files = [ + {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, + {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, +] + +[[package]] +name = "tomli" +version = "2.0.1" +description = "A lil' TOML parser" +optional = false +python-versions = ">=3.7" +files = [ + {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, + {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, +] + +[[package]] +name = "tomlkit" +version = "0.12.3" +description = "Style preserving TOML library" +optional = false +python-versions = ">=3.7" +files = [ + {file = "tomlkit-0.12.3-py3-none-any.whl", hash = "sha256:b0a645a9156dc7cb5d3a1f0d4bab66db287fcb8e0430bdd4664a095ea16414ba"}, + {file = "tomlkit-0.12.3.tar.gz", hash = "sha256:75baf5012d06501f07bee5bf8e801b9f343e7aac5a92581f20f80ce632e6b5a4"}, +] + +[[package]] +name = "tox" +version = "4.11.4" +description = "tox is a generic virtualenv management and test command line tool" +optional = false +python-versions = ">=3.8" +files = [ + {file = "tox-4.11.4-py3-none-any.whl", hash = "sha256:2adb83d68f27116812b69aa36676a8d6a52249cb0d173649de0e7d0c2e3e7229"}, + {file = "tox-4.11.4.tar.gz", hash = "sha256:73a7240778fabf305aeb05ab8ea26e575e042ab5a18d71d0ed13e343a51d6ce1"}, +] + +[package.dependencies] +cachetools = ">=5.3.1" +chardet = ">=5.2" +colorama = ">=0.4.6" +filelock = ">=3.12.3" +packaging = ">=23.1" +platformdirs = ">=3.10" +pluggy = ">=1.3" +pyproject-api = ">=1.6.1" +tomli = {version = ">=2.0.1", markers = "python_version < \"3.11\""} +virtualenv = ">=20.24.3" + +[package.extras] +docs = ["furo (>=2023.8.19)", "sphinx (>=7.2.4)", "sphinx-argparse-cli (>=1.11.1)", "sphinx-autodoc-typehints (>=1.24)", "sphinx-copybutton (>=0.5.2)", "sphinx-inline-tabs (>=2023.4.21)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"] +testing = ["build[virtualenv] (>=0.10)", "covdefaults (>=2.3)", "detect-test-pollution (>=1.1.1)", "devpi-process (>=1)", "diff-cover (>=7.7)", "distlib (>=0.3.7)", "flaky (>=3.7)", "hatch-vcs (>=0.3)", "hatchling (>=1.18)", "psutil (>=5.9.5)", "pytest (>=7.4)", "pytest-cov (>=4.1)", "pytest-mock (>=3.11.1)", "pytest-xdist (>=3.3.1)", "re-assert (>=1.1)", "time-machine (>=2.12)", "wheel (>=0.41.2)"] + +[[package]] +name = "typing-extensions" +version = "4.9.0" +description = "Backported and Experimental Type Hints for Python 3.8+" +optional = false +python-versions = ">=3.8" +files = [ + {file = "typing_extensions-4.9.0-py3-none-any.whl", hash = "sha256:af72aea155e91adfc61c3ae9e0e342dbc0cba726d6cba4b6c72c1f34e47291cd"}, + {file = "typing_extensions-4.9.0.tar.gz", hash = "sha256:23478f88c37f27d76ac8aee6c905017a143b0b1b886c3c9f66bc2fd94f9f5783"}, +] + +[[package]] +name = "urllib3" +version = "2.1.0" +description = "HTTP library with thread-safe connection pooling, file post, and more." +optional = false +python-versions = ">=3.8" +files = [ + {file = "urllib3-2.1.0-py3-none-any.whl", hash = "sha256:55901e917a5896a349ff771be919f8bd99aff50b79fe58fec595eb37bbc56bb3"}, + {file = "urllib3-2.1.0.tar.gz", hash = "sha256:df7aa8afb0148fa78488e7899b2c59b5f4ffcfa82e6c54ccb9dd37c1d7b52d54"}, +] + +[package.extras] +brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)"] +socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"] +zstd = ["zstandard (>=0.18.0)"] + +[[package]] +name = "virtualenv" +version = "20.25.0" +description = "Virtual Python Environment builder" +optional = false +python-versions = ">=3.7" +files = [ + {file = "virtualenv-20.25.0-py3-none-any.whl", hash = "sha256:4238949c5ffe6876362d9c0180fc6c3a824a7b12b80604eeb8085f2ed7460de3"}, + {file = "virtualenv-20.25.0.tar.gz", hash = "sha256:bf51c0d9c7dd63ea8e44086fa1e4fb1093a31e963b86959257378aef020e1f1b"}, +] + +[package.dependencies] +distlib = ">=0.3.7,<1" +filelock = ">=3.12.2,<4" +platformdirs = ">=3.9.1,<5" + +[package.extras] +docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.2)", "sphinx-argparse (>=0.4)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"] +test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23.1)", "pytest (>=7.4)", "pytest-env (>=0.8.2)", "pytest-freezer (>=0.4.8)", "pytest-mock (>=3.11.1)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", "setuptools (>=68)", "time-machine (>=2.10)"] + +[[package]] +name = "wcwidth" +version = "0.2.12" +description = "Measures the displayed width of unicode strings in a terminal" +optional = false +python-versions = "*" +files = [ + {file = "wcwidth-0.2.12-py2.py3-none-any.whl", hash = "sha256:f26ec43d96c8cbfed76a5075dac87680124fa84e0855195a6184da9c187f133c"}, + {file = "wcwidth-0.2.12.tar.gz", hash = "sha256:f01c104efdf57971bcb756f054dd58ddec5204dd15fa31d6503ea57947d97c02"}, +] + +[extras] +compiler = ["black", "isort", "jinja2"] +rust-codec = ["betterproto-rust-codec"] + +[metadata] +lock-version = "2.0" +python-versions = "^3.9" +content-hash = "220432db3c5f79d611514dcc019773c7d7ef3bed9b2dc6b1bc96e77585b559d2" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..6e737ab --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,159 @@ +[tool.poetry] +name = "aristaproto" +version = "0.1.2" +description = "Arista Protobuf / Python gRPC bindings generator & library" +authors = ["Arista Networks <ansible@arista.com>"] +readme = "README.md" +repository = "https://github.com/aristanetworks/python-aristaproto" +keywords = ["protobuf", "gRPC", "aristanetworks", "arista"] +license = "MIT" +packages = [ + { include = "aristaproto", from = "src" } +] + +[tool.poetry.dependencies] +python = "^3.9" +black = { version = ">=23.1.0", optional = true } +grpclib = "^0.4.1" +jinja2 = { version = ">=3.0.3", optional = true } +python-dateutil = "^2.8" +isort = {version = "^5.11.5", optional = true} +typing-extensions = "^4.7.1" +betterproto-rust-codec = { version = "0.1.1", optional = true } + +[tool.poetry.group.dev.dependencies] +asv = "^0.4.2" +bpython = "^0.19" +jinja2 = ">=3.0.3" +mypy = "^0.930" +sphinx = "3.1.2" +sphinx-rtd-theme = "0.5.0" +pre-commit = "^2.17.0" +grpcio-tools = "^1.54.2" +tox = "^4.0.0" + +[tool.poetry.group.test.dependencies] +poethepoet = ">=0.9.0" +pytest = "^7.3.2" +pytest-asyncio = "^0.23.0" +pytest-cov = "^2.9.0" +pytest-mock = "^3.12.0" +pydantic = ">=1.8.0,<2" +protobuf = "^4" +cachelib = "^0.10.2" +tomlkit = ">=0.7.0" + +[tool.poetry.scripts] +protoc-gen-python_aristaproto = "aristaproto.plugin:main" + +[tool.poetry.extras] +compiler = ["black", "isort", "jinja2"] +rust-codec = ["betterproto-rust-codec"] + + +# Dev workflow tasks + +[tool.poe.tasks.generate] +script = "tests.generate:main" +help = "Generate test cases (do this once before running test)" + +[tool.poe.tasks.test] +cmd = "pytest" +help = "Run tests" + +[tool.poe.tasks.types] +cmd = "mypy src --ignore-missing-imports" +help = "Check types with mypy" + +[tool.poe.tasks] +_black = "black . --exclude tests/output_ --target-version py310" +_isort = "isort . --extend-skip-glob 'tests/output_*/**/*'" + +[tool.poe.tasks.format] +sequence = ["_black", "_isort"] +help = "Apply black and isort formatting to source code" + +[tool.poe.tasks.docs] +cmd = "sphinx-build docs docs/build" +help = "Build the sphinx docs" + +[tool.poe.tasks.bench] +shell = "asv run master^! && asv run HEAD^! && asv compare master HEAD" +help = "Benchmark current commit vs. master branch" + +[tool.poe.tasks.clean] +cmd = """ +rm -rf .asv .coverage .mypy_cache .pytest_cache + dist aristaproto.egg-info **/__pycache__ + testsoutput_* +""" +help = "Clean out generated files from the workspace" + +[tool.poe.tasks.generate_lib] +cmd = """ +protoc + --plugin=protoc-gen-custom=src/aristaproto/plugin/main.py + --custom_opt=INCLUDE_GOOGLE + --custom_out=src/aristaproto/lib/std + -I /usr/local/include/ + /usr/local/include/google/protobuf/**/*.proto +""" +help = "Regenerate the types in aristaproto.lib.std.google" + +# CI tasks + +[tool.poe.tasks.full-test] +shell = "poe generate && tox" +help = "Run tests with multiple pythons" + +[tool.poe.tasks.check-style] +cmd = "black . --check --diff" +help = "Check if code style is correct" + +[tool.isort] +py_version = 37 +profile = "black" +force_single_line = false +combine_as_imports = true +lines_after_imports = 2 +include_trailing_comma = true +force_grid_wrap = 2 +src_paths = ["src", "tests"] + +[tool.black] +target-version = ['py37'] + +[tool.doc8] +paths = ["docs"] +max_line_length = 88 + +[tool.doc8.ignore_path_errors] +"docs/migrating.rst" = [ + "D001", # contains table which is longer than 88 characters long +] + +[tool.coverage.run] +omit = ["aristaproto/tests/*"] + +[tool.tox] +legacy_tox_ini = """ +[tox] +requires = + tox>=4.2 + tox-poetry-installer[poetry]==1.0.0b1 +env_list = + py311 + py39 + +[testenv] +commands = + pytest {posargs: --cov aristaproto} +poetry_dep_groups = + test +require_locked_deps = true +require_poetry = true +""" + +[build-system] +requires = ["poetry-core>=1.0.0,<2"] +build-backend = "poetry.core.masonry.api" diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..bec2b96 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,5 @@ +[pytest] +python_files = test_*.py +python_classes = +norecursedirs = **/output_* +addopts = -p no:warnings
\ No newline at end of file diff --git a/src/aristaproto/__init__.py b/src/aristaproto/__init__.py new file mode 100644 index 0000000..79d71c5 --- /dev/null +++ b/src/aristaproto/__init__.py @@ -0,0 +1,2038 @@ +from __future__ import annotations + +import dataclasses +import enum as builtin_enum +import json +import math +import struct +import sys +import typing +import warnings +from abc import ABC +from base64 import ( + b64decode, + b64encode, +) +from copy import deepcopy +from datetime import ( + datetime, + timedelta, + timezone, +) +from io import BytesIO +from itertools import count +from typing import ( + TYPE_CHECKING, + Any, + Callable, + ClassVar, + Dict, + Generator, + Iterable, + Mapping, + Optional, + Set, + Tuple, + Type, + Union, + get_type_hints, +) + +from dateutil.parser import isoparse +from typing_extensions import Self + +from ._types import T +from ._version import __version__ +from .casing import ( + camel_case, + safe_snake_case, + snake_case, +) +from .enum import Enum as Enum +from .grpc.grpclib_client import ServiceStub as ServiceStub +from .utils import ( + classproperty, + hybridmethod, +) + + +if TYPE_CHECKING: + from _typeshed import ( + SupportsRead, + SupportsWrite, + ) + + +# Proto 3 data types +TYPE_ENUM = "enum" +TYPE_BOOL = "bool" +TYPE_INT32 = "int32" +TYPE_INT64 = "int64" +TYPE_UINT32 = "uint32" +TYPE_UINT64 = "uint64" +TYPE_SINT32 = "sint32" +TYPE_SINT64 = "sint64" +TYPE_FLOAT = "float" +TYPE_DOUBLE = "double" +TYPE_FIXED32 = "fixed32" +TYPE_SFIXED32 = "sfixed32" +TYPE_FIXED64 = "fixed64" +TYPE_SFIXED64 = "sfixed64" +TYPE_STRING = "string" +TYPE_BYTES = "bytes" +TYPE_MESSAGE = "message" +TYPE_MAP = "map" + +# Fields that use a fixed amount of space (4 or 8 bytes) +FIXED_TYPES = [ + TYPE_FLOAT, + TYPE_DOUBLE, + TYPE_FIXED32, + TYPE_SFIXED32, + TYPE_FIXED64, + TYPE_SFIXED64, +] + +# Fields that are numerical 64-bit types +INT_64_TYPES = [TYPE_INT64, TYPE_UINT64, TYPE_SINT64, TYPE_FIXED64, TYPE_SFIXED64] + +# Fields that are efficiently packed when +PACKED_TYPES = [ + TYPE_ENUM, + TYPE_BOOL, + TYPE_INT32, + TYPE_INT64, + TYPE_UINT32, + TYPE_UINT64, + TYPE_SINT32, + TYPE_SINT64, + TYPE_FLOAT, + TYPE_DOUBLE, + TYPE_FIXED32, + TYPE_SFIXED32, + TYPE_FIXED64, + TYPE_SFIXED64, +] + +# Wire types +# https://developers.google.com/protocol-buffers/docs/encoding#structure +WIRE_VARINT = 0 +WIRE_FIXED_64 = 1 +WIRE_LEN_DELIM = 2 +WIRE_FIXED_32 = 5 + +# Mappings of which Proto 3 types correspond to which wire types. +WIRE_VARINT_TYPES = [ + TYPE_ENUM, + TYPE_BOOL, + TYPE_INT32, + TYPE_INT64, + TYPE_UINT32, + TYPE_UINT64, + TYPE_SINT32, + TYPE_SINT64, +] + +WIRE_FIXED_32_TYPES = [TYPE_FLOAT, TYPE_FIXED32, TYPE_SFIXED32] +WIRE_FIXED_64_TYPES = [TYPE_DOUBLE, TYPE_FIXED64, TYPE_SFIXED64] +WIRE_LEN_DELIM_TYPES = [TYPE_STRING, TYPE_BYTES, TYPE_MESSAGE, TYPE_MAP] + +# Indicator of message delimitation in streams +SIZE_DELIMITED = -1 + + +class _DateTime(datetime): + """Subclass of datetime with an attribute to store the original nanos value from a Timestamp field""" + + __slots__ = "_nanos" + + @property + def nanos(self): + return self._nanos + + +# Protobuf datetimes start at the Unix Epoch in 1970 in UTC. +def datetime_default_gen() -> _DateTime: + return _DateTime(1970, 1, 1, tzinfo=timezone.utc) + + +DATETIME_ZERO = datetime_default_gen() + +# Special protobuf json doubles +INFINITY = "Infinity" +NEG_INFINITY = "-Infinity" +NAN = "NaN" + + +class Casing(builtin_enum.Enum): + """Casing constants for serialization.""" + + CAMEL = camel_case #: A camelCase sterilization function. + SNAKE = snake_case #: A snake_case sterilization function. + + +PLACEHOLDER: Any = object() + + +@dataclasses.dataclass(frozen=True) +class FieldMetadata: + """Stores internal metadata used for parsing & serialization.""" + + # Protobuf field number + number: int + # Protobuf type name + proto_type: str + # Map information if the proto_type is a map + map_types: Optional[Tuple[str, str]] = None + # Groups several "one-of" fields together + group: Optional[str] = None + # Describes the wrapped type (e.g. when using google.protobuf.BoolValue) + wraps: Optional[str] = None + # Is the field optional + optional: Optional[bool] = False + + @staticmethod + def get(field: dataclasses.Field) -> "FieldMetadata": + """Returns the field metadata for a dataclass field.""" + return field.metadata["aristaproto"] + + +def dataclass_field( + number: int, + proto_type: str, + *, + map_types: Optional[Tuple[str, str]] = None, + group: Optional[str] = None, + wraps: Optional[str] = None, + optional: bool = False, +) -> dataclasses.Field: + """Creates a dataclass field with attached protobuf metadata.""" + return dataclasses.field( + default=None if optional else PLACEHOLDER, + metadata={ + "aristaproto": FieldMetadata( + number, proto_type, map_types, group, wraps, optional + ) + }, + ) + + +# Note: the fields below return `Any` to prevent type errors in the generated +# data classes since the types won't match with `Field` and they get swapped +# out at runtime. The generated dataclass variables are still typed correctly. + + +def enum_field(number: int, group: Optional[str] = None, optional: bool = False) -> Any: + return dataclass_field(number, TYPE_ENUM, group=group, optional=optional) + + +def bool_field(number: int, group: Optional[str] = None, optional: bool = False) -> Any: + return dataclass_field(number, TYPE_BOOL, group=group, optional=optional) + + +def int32_field( + number: int, group: Optional[str] = None, optional: bool = False +) -> Any: + return dataclass_field(number, TYPE_INT32, group=group, optional=optional) + + +def int64_field( + number: int, group: Optional[str] = None, optional: bool = False +) -> Any: + return dataclass_field(number, TYPE_INT64, group=group, optional=optional) + + +def uint32_field( + number: int, group: Optional[str] = None, optional: bool = False +) -> Any: + return dataclass_field(number, TYPE_UINT32, group=group, optional=optional) + + +def uint64_field( + number: int, group: Optional[str] = None, optional: bool = False +) -> Any: + return dataclass_field(number, TYPE_UINT64, group=group, optional=optional) + + +def sint32_field( + number: int, group: Optional[str] = None, optional: bool = False +) -> Any: + return dataclass_field(number, TYPE_SINT32, group=group, optional=optional) + + +def sint64_field( + number: int, group: Optional[str] = None, optional: bool = False +) -> Any: + return dataclass_field(number, TYPE_SINT64, group=group, optional=optional) + + +def float_field( + number: int, group: Optional[str] = None, optional: bool = False +) -> Any: + return dataclass_field(number, TYPE_FLOAT, group=group, optional=optional) + + +def double_field( + number: int, group: Optional[str] = None, optional: bool = False +) -> Any: + return dataclass_field(number, TYPE_DOUBLE, group=group, optional=optional) + + +def fixed32_field( + number: int, group: Optional[str] = None, optional: bool = False +) -> Any: + return dataclass_field(number, TYPE_FIXED32, group=group, optional=optional) + + +def fixed64_field( + number: int, group: Optional[str] = None, optional: bool = False +) -> Any: + return dataclass_field(number, TYPE_FIXED64, group=group, optional=optional) + + +def sfixed32_field( + number: int, group: Optional[str] = None, optional: bool = False +) -> Any: + return dataclass_field(number, TYPE_SFIXED32, group=group, optional=optional) + + +def sfixed64_field( + number: int, group: Optional[str] = None, optional: bool = False +) -> Any: + return dataclass_field(number, TYPE_SFIXED64, group=group, optional=optional) + + +def string_field( + number: int, group: Optional[str] = None, optional: bool = False +) -> Any: + return dataclass_field(number, TYPE_STRING, group=group, optional=optional) + + +def bytes_field( + number: int, group: Optional[str] = None, optional: bool = False +) -> Any: + return dataclass_field(number, TYPE_BYTES, group=group, optional=optional) + + +def message_field( + number: int, + group: Optional[str] = None, + wraps: Optional[str] = None, + optional: bool = False, +) -> Any: + return dataclass_field( + number, TYPE_MESSAGE, group=group, wraps=wraps, optional=optional + ) + + +def map_field( + number: int, key_type: str, value_type: str, group: Optional[str] = None +) -> Any: + return dataclass_field( + number, TYPE_MAP, map_types=(key_type, value_type), group=group + ) + + +def _pack_fmt(proto_type: str) -> str: + """Returns a little-endian format string for reading/writing binary.""" + return { + TYPE_DOUBLE: "<d", + TYPE_FLOAT: "<f", + TYPE_FIXED32: "<I", + TYPE_FIXED64: "<Q", + TYPE_SFIXED32: "<i", + TYPE_SFIXED64: "<q", + }[proto_type] + + +def dump_varint(value: int, stream: "SupportsWrite[bytes]") -> None: + """Encodes a single varint and dumps it into the provided stream.""" + if value < -(1 << 63): + raise ValueError( + "Negative value is not representable as a 64-bit integer - unable to encode a varint within 10 bytes." + ) + elif value < 0: + value += 1 << 64 + + bits = value & 0x7F + value >>= 7 + while value: + stream.write((0x80 | bits).to_bytes(1, "little")) + bits = value & 0x7F + value >>= 7 + stream.write(bits.to_bytes(1, "little")) + + +def encode_varint(value: int) -> bytes: + """Encodes a single varint value for serialization.""" + with BytesIO() as stream: + dump_varint(value, stream) + return stream.getvalue() + + +def size_varint(value: int) -> int: + """Calculates the size in bytes that a value would take as a varint.""" + if value < -(1 << 63): + raise ValueError( + "Negative value is not representable as a 64-bit integer - unable to encode a varint within 10 bytes." + ) + elif value < 0: + return 10 + elif value == 0: + return 1 + else: + return math.ceil(value.bit_length() / 7) + + +def _preprocess_single(proto_type: str, wraps: str, value: Any) -> bytes: + """Adjusts values before serialization.""" + if proto_type in ( + TYPE_ENUM, + TYPE_BOOL, + TYPE_INT32, + TYPE_INT64, + TYPE_UINT32, + TYPE_UINT64, + ): + return encode_varint(value) + elif proto_type in (TYPE_SINT32, TYPE_SINT64): + # Handle zig-zag encoding. + return encode_varint(value << 1 if value >= 0 else (value << 1) ^ (~0)) + elif proto_type in FIXED_TYPES: + return struct.pack(_pack_fmt(proto_type), value) + elif proto_type == TYPE_STRING: + return value.encode("utf-8") + elif proto_type == TYPE_MESSAGE: + if isinstance(value, datetime): + # Convert the `datetime` to a timestamp message. + value = _Timestamp.from_datetime(value) + elif isinstance(value, timedelta): + # Convert the `timedelta` to a duration message. + value = _Duration.from_timedelta(value) + elif wraps: + if value is None: + return b"" + value = _get_wrapper(wraps)(value=value) + + return bytes(value) + + return value + + +def _len_preprocessed_single(proto_type: str, wraps: str, value: Any) -> int: + """Calculate the size of adjusted values for serialization without fully serializing them.""" + if proto_type in ( + TYPE_ENUM, + TYPE_BOOL, + TYPE_INT32, + TYPE_INT64, + TYPE_UINT32, + TYPE_UINT64, + ): + return size_varint(value) + elif proto_type in (TYPE_SINT32, TYPE_SINT64): + # Handle zig-zag encoding. + return size_varint(value << 1 if value >= 0 else (value << 1) ^ (~0)) + elif proto_type in FIXED_TYPES: + return len(struct.pack(_pack_fmt(proto_type), value)) + elif proto_type == TYPE_STRING: + return len(value.encode("utf-8")) + elif proto_type == TYPE_MESSAGE: + if isinstance(value, datetime): + # Convert the `datetime` to a timestamp message. + value = _Timestamp.from_datetime(value) + elif isinstance(value, timedelta): + # Convert the `timedelta` to a duration message. + value = _Duration.from_timedelta(value) + elif wraps: + if value is None: + return 0 + value = _get_wrapper(wraps)(value=value) + + return len(bytes(value)) + + return len(value) + + +def _serialize_single( + field_number: int, + proto_type: str, + value: Any, + *, + serialize_empty: bool = False, + wraps: str = "", +) -> bytes: + """Serializes a single field and value.""" + value = _preprocess_single(proto_type, wraps, value) + + output = bytearray() + if proto_type in WIRE_VARINT_TYPES: + key = encode_varint(field_number << 3) + output += key + value + elif proto_type in WIRE_FIXED_32_TYPES: + key = encode_varint((field_number << 3) | 5) + output += key + value + elif proto_type in WIRE_FIXED_64_TYPES: + key = encode_varint((field_number << 3) | 1) + output += key + value + elif proto_type in WIRE_LEN_DELIM_TYPES: + if len(value) or serialize_empty or wraps: + key = encode_varint((field_number << 3) | 2) + output += key + encode_varint(len(value)) + value + else: + raise NotImplementedError(proto_type) + + return bytes(output) + + +def _len_single( + field_number: int, + proto_type: str, + value: Any, + *, + serialize_empty: bool = False, + wraps: str = "", +) -> int: + """Calculates the size of a serialized single field and value.""" + size = _len_preprocessed_single(proto_type, wraps, value) + if proto_type in WIRE_VARINT_TYPES: + size += size_varint(field_number << 3) + elif proto_type in WIRE_FIXED_32_TYPES: + size += size_varint((field_number << 3) | 5) + elif proto_type in WIRE_FIXED_64_TYPES: + size += size_varint((field_number << 3) | 1) + elif proto_type in WIRE_LEN_DELIM_TYPES: + if size or serialize_empty or wraps: + size += size_varint((field_number << 3) | 2) + size_varint(size) + else: + raise NotImplementedError(proto_type) + + return size + + +def _parse_float(value: Any) -> float: + """Parse the given value to a float + + Parameters + ---------- + value: Any + Value to parse + + Returns + ------- + float + Parsed value + """ + if value == INFINITY: + return float("inf") + if value == NEG_INFINITY: + return -float("inf") + if value == NAN: + return float("nan") + return float(value) + + +def _dump_float(value: float) -> Union[float, str]: + """Dump the given float to JSON + + Parameters + ---------- + value: float + Value to dump + + Returns + ------- + Union[float, str] + Dumped value, either a float or the strings + """ + if value == float("inf"): + return INFINITY + if value == -float("inf"): + return NEG_INFINITY + if isinstance(value, float) and math.isnan(value): + return NAN + return value + + +def load_varint(stream: "SupportsRead[bytes]") -> Tuple[int, bytes]: + """ + Load a single varint value from a stream. Returns the value and the raw bytes read. + """ + result = 0 + raw = b"" + for shift in count(0, 7): + if shift >= 64: + raise ValueError("Too many bytes when decoding varint.") + b = stream.read(1) + if not b: + raise EOFError("Stream ended unexpectedly while attempting to load varint.") + raw += b + b_int = int.from_bytes(b, byteorder="little") + result |= (b_int & 0x7F) << shift + if not (b_int & 0x80): + return result, raw + + +def decode_varint(buffer: bytes, pos: int) -> Tuple[int, int]: + """ + Decode a single varint value from a byte buffer. Returns the value and the + new position in the buffer. + """ + with BytesIO(buffer) as stream: + stream.seek(pos) + value, raw = load_varint(stream) + return value, pos + len(raw) + + +@dataclasses.dataclass(frozen=True) +class ParsedField: + number: int + wire_type: int + value: Any + raw: bytes + + +def load_fields(stream: "SupportsRead[bytes]") -> Generator[ParsedField, None, None]: + while True: + try: + num_wire, raw = load_varint(stream) + except EOFError: + return + number = num_wire >> 3 + wire_type = num_wire & 0x7 + + decoded: Any = None + if wire_type == WIRE_VARINT: + decoded, r = load_varint(stream) + raw += r + elif wire_type == WIRE_FIXED_64: + decoded = stream.read(8) + raw += decoded + elif wire_type == WIRE_LEN_DELIM: + length, r = load_varint(stream) + decoded = stream.read(length) + raw += r + raw += decoded + elif wire_type == WIRE_FIXED_32: + decoded = stream.read(4) + raw += decoded + + yield ParsedField(number=number, wire_type=wire_type, value=decoded, raw=raw) + + +def parse_fields(value: bytes) -> Generator[ParsedField, None, None]: + i = 0 + while i < len(value): + start = i + num_wire, i = decode_varint(value, i) + number = num_wire >> 3 + wire_type = num_wire & 0x7 + + decoded: Any = None + if wire_type == WIRE_VARINT: + decoded, i = decode_varint(value, i) + elif wire_type == WIRE_FIXED_64: + decoded, i = value[i : i + 8], i + 8 + elif wire_type == WIRE_LEN_DELIM: + length, i = decode_varint(value, i) + decoded = value[i : i + length] + i += length + elif wire_type == WIRE_FIXED_32: + decoded, i = value[i : i + 4], i + 4 + + yield ParsedField( + number=number, wire_type=wire_type, value=decoded, raw=value[start:i] + ) + + +class ProtoClassMetadata: + __slots__ = ( + "oneof_group_by_field", + "oneof_field_by_group", + "default_gen", + "cls_by_field", + "field_name_by_number", + "meta_by_field_name", + "sorted_field_names", + ) + + oneof_group_by_field: Dict[str, str] + oneof_field_by_group: Dict[str, Set[dataclasses.Field]] + field_name_by_number: Dict[int, str] + meta_by_field_name: Dict[str, FieldMetadata] + sorted_field_names: Tuple[str, ...] + default_gen: Dict[str, Callable[[], Any]] + cls_by_field: Dict[str, Type] + + def __init__(self, cls: Type["Message"]): + by_field = {} + by_group: Dict[str, Set] = {} + by_field_name = {} + by_field_number = {} + + fields = dataclasses.fields(cls) + for field in fields: + meta = FieldMetadata.get(field) + + if meta.group: + # This is part of a one-of group. + by_field[field.name] = meta.group + + by_group.setdefault(meta.group, set()).add(field) + + by_field_name[field.name] = meta + by_field_number[meta.number] = field.name + + self.oneof_group_by_field = by_field + self.oneof_field_by_group = by_group + self.field_name_by_number = by_field_number + self.meta_by_field_name = by_field_name + self.sorted_field_names = tuple( + by_field_number[number] for number in sorted(by_field_number) + ) + self.default_gen = self._get_default_gen(cls, fields) + self.cls_by_field = self._get_cls_by_field(cls, fields) + + @staticmethod + def _get_default_gen( + cls: Type["Message"], fields: Iterable[dataclasses.Field] + ) -> Dict[str, Callable[[], Any]]: + return {field.name: cls._get_field_default_gen(field) for field in fields} + + @staticmethod + def _get_cls_by_field( + cls: Type["Message"], fields: Iterable[dataclasses.Field] + ) -> Dict[str, Type]: + field_cls = {} + + for field in fields: + meta = FieldMetadata.get(field) + if meta.proto_type == TYPE_MAP: + assert meta.map_types + kt = cls._cls_for(field, index=0) + vt = cls._cls_for(field, index=1) + field_cls[field.name] = dataclasses.make_dataclass( + "Entry", + [ + ("key", kt, dataclass_field(1, meta.map_types[0])), + ("value", vt, dataclass_field(2, meta.map_types[1])), + ], + bases=(Message,), + ) + field_cls[f"{field.name}.value"] = vt + else: + field_cls[field.name] = cls._cls_for(field) + + return field_cls + + +class Message(ABC): + """ + The base class for protobuf messages, all generated messages will inherit from + this. This class registers the message fields which are used by the serializers and + parsers to go between the Python, binary and JSON representations of the message. + + .. container:: operations + + .. describe:: bytes(x) + + Calls :meth:`__bytes__`. + + .. describe:: bool(x) + + Calls :meth:`__bool__`. + """ + + _serialized_on_wire: bool + _unknown_fields: bytes + _group_current: Dict[str, str] + _aristaproto_meta: ClassVar[ProtoClassMetadata] + + def __post_init__(self) -> None: + # Keep track of whether every field was default + all_sentinel = True + + # Set current field of each group after `__init__` has already been run. + group_current: Dict[str, Optional[str]] = {} + for field_name, meta in self._aristaproto.meta_by_field_name.items(): + if meta.group: + group_current.setdefault(meta.group) + + value = self.__raw_get(field_name) + if value is not PLACEHOLDER and not (meta.optional and value is None): + # Found a non-sentinel value + all_sentinel = False + + if meta.group: + # This was set, so make it the selected value of the one-of. + group_current[meta.group] = field_name + + # Now that all the defaults are set, reset it! + self.__dict__["_serialized_on_wire"] = not all_sentinel + self.__dict__["_unknown_fields"] = b"" + self.__dict__["_group_current"] = group_current + + def __raw_get(self, name: str) -> Any: + return super().__getattribute__(name) + + def __eq__(self, other) -> bool: + if type(self) is not type(other): + return NotImplemented + + for field_name in self._aristaproto.meta_by_field_name: + self_val = self.__raw_get(field_name) + other_val = other.__raw_get(field_name) + if self_val is PLACEHOLDER: + if other_val is PLACEHOLDER: + continue + self_val = self._get_field_default(field_name) + elif other_val is PLACEHOLDER: + other_val = other._get_field_default(field_name) + + if self_val != other_val: + # We consider two nan values to be the same for the + # purposes of comparing messages (otherwise a message + # is not equal to itself) + if ( + isinstance(self_val, float) + and isinstance(other_val, float) + and math.isnan(self_val) + and math.isnan(other_val) + ): + continue + else: + return False + + return True + + def __repr__(self) -> str: + parts = [ + f"{field_name}={value!r}" + for field_name in self._aristaproto.sorted_field_names + for value in (self.__raw_get(field_name),) + if value is not PLACEHOLDER + ] + return f"{self.__class__.__name__}({', '.join(parts)})" + + def __rich_repr__(self) -> Iterable[Tuple[str, Any, Any]]: + for field_name in self._aristaproto.sorted_field_names: + yield field_name, self.__raw_get(field_name), PLACEHOLDER + + if not TYPE_CHECKING: + + def __getattribute__(self, name: str) -> Any: + """ + Lazily initialize default values to avoid infinite recursion for recursive + message types. + Raise :class:`AttributeError` on attempts to access unset ``oneof`` fields. + """ + try: + group_current = super().__getattribute__("_group_current") + except AttributeError: + pass + else: + if name not in {"__class__", "_aristaproto"}: + group = self._aristaproto.oneof_group_by_field.get(name) + if group is not None and group_current[group] != name: + if sys.version_info < (3, 10): + raise AttributeError( + f"{group!r} is set to {group_current[group]!r}, not {name!r}" + ) + else: + raise AttributeError( + f"{group!r} is set to {group_current[group]!r}, not {name!r}", + name=name, + obj=self, + ) + + value = super().__getattribute__(name) + if value is not PLACEHOLDER: + return value + + value = self._get_field_default(name) + super().__setattr__(name, value) + return value + + def __setattr__(self, attr: str, value: Any) -> None: + if ( + isinstance(value, Message) + and hasattr(value, "_aristaproto") + and not value._aristaproto.meta_by_field_name + ): + value._serialized_on_wire = True + + if attr != "_serialized_on_wire": + # Track when a field has been set. + self.__dict__["_serialized_on_wire"] = True + + if hasattr(self, "_group_current"): # __post_init__ had already run + if attr in self._aristaproto.oneof_group_by_field: + group = self._aristaproto.oneof_group_by_field[attr] + for field in self._aristaproto.oneof_field_by_group[group]: + if field.name == attr: + self._group_current[group] = field.name + else: + super().__setattr__(field.name, PLACEHOLDER) + + super().__setattr__(attr, value) + + def __bool__(self) -> bool: + """True if the Message has any fields with non-default values.""" + return any( + self.__raw_get(field_name) + not in (PLACEHOLDER, self._get_field_default(field_name)) + for field_name in self._aristaproto.meta_by_field_name + ) + + def __deepcopy__(self: T, _: Any = {}) -> T: + kwargs = {} + for name in self._aristaproto.sorted_field_names: + value = self.__raw_get(name) + if value is not PLACEHOLDER: + kwargs[name] = deepcopy(value) + return self.__class__(**kwargs) # type: ignore + + def __copy__(self: T, _: Any = {}) -> T: + kwargs = {} + for name in self._aristaproto.sorted_field_names: + value = self.__raw_get(name) + if value is not PLACEHOLDER: + kwargs[name] = value + return self.__class__(**kwargs) # type: ignore + + @classproperty + def _aristaproto(cls: type[Self]) -> ProtoClassMetadata: # type: ignore + """ + Lazy initialize metadata for each protobuf class. + It may be initialized multiple times in a multi-threaded environment, + but that won't affect the correctness. + """ + try: + return cls._aristaproto_meta + except AttributeError: + cls._aristaproto_meta = meta = ProtoClassMetadata(cls) + return meta + + def dump(self, stream: "SupportsWrite[bytes]", delimit: bool = False) -> None: + """ + Dumps the binary encoded Protobuf message to the stream. + + Parameters + ----------- + stream: :class:`BinaryIO` + The stream to dump the message to. + delimit: + Whether to prefix the message with a varint declaring its size. + """ + if delimit == SIZE_DELIMITED: + dump_varint(len(self), stream) + + for field_name, meta in self._aristaproto.meta_by_field_name.items(): + try: + value = getattr(self, field_name) + except AttributeError: + continue + + if value is None: + # Optional items should be skipped. This is used for the Google + # wrapper types and proto3 field presence/optional fields. + continue + + # Being selected in a a group means this field is the one that is + # currently set in a `oneof` group, so it must be serialized even + # if the value is the default zero value. + # + # Note that proto3 field presence/optional fields are put in a + # synthetic single-item oneof by protoc, which helps us ensure we + # send the value even if the value is the default zero value. + selected_in_group = bool(meta.group) or meta.optional + + # Empty messages can still be sent on the wire if they were + # set (or received empty). + serialize_empty = isinstance(value, Message) and value._serialized_on_wire + + include_default_value_for_oneof = self._include_default_value_for_oneof( + field_name=field_name, meta=meta + ) + + if value == self._get_field_default(field_name) and not ( + selected_in_group or serialize_empty or include_default_value_for_oneof + ): + # Default (zero) values are not serialized. Two exceptions are + # if this is the selected oneof item or if we know we have to + # serialize an empty message (i.e. zero value was explicitly + # set by the user). + continue + + if isinstance(value, list): + if meta.proto_type in PACKED_TYPES: + # Packed lists look like a length-delimited field. First, + # preprocess/encode each value into a buffer and then + # treat it like a field of raw bytes. + buf = bytearray() + for item in value: + buf += _preprocess_single(meta.proto_type, "", item) + stream.write(_serialize_single(meta.number, TYPE_BYTES, buf)) + else: + for item in value: + stream.write( + _serialize_single( + meta.number, + meta.proto_type, + item, + wraps=meta.wraps or "", + serialize_empty=True, + ) + # if it's an empty message it still needs to be represented + # as an item in the repeated list + or b"\n\x00" + ) + + elif isinstance(value, dict): + for k, v in value.items(): + assert meta.map_types + sk = _serialize_single(1, meta.map_types[0], k) + sv = _serialize_single(2, meta.map_types[1], v) + stream.write( + _serialize_single(meta.number, meta.proto_type, sk + sv) + ) + else: + # If we have an empty string and we're including the default value for + # a oneof, make sure we serialize it. This ensures that the byte string + # output isn't simply an empty string. This also ensures that round trip + # serialization will keep `which_one_of` calls consistent. + if ( + isinstance(value, str) + and value == "" + and include_default_value_for_oneof + ): + serialize_empty = True + + stream.write( + _serialize_single( + meta.number, + meta.proto_type, + value, + serialize_empty=serialize_empty or bool(selected_in_group), + wraps=meta.wraps or "", + ) + ) + + stream.write(self._unknown_fields) + + def __bytes__(self) -> bytes: + """ + Get the binary encoded Protobuf representation of this message instance. + """ + with BytesIO() as stream: + self.dump(stream) + return stream.getvalue() + + def __len__(self) -> int: + """ + Get the size of the encoded Protobuf representation of this message instance. + """ + size = 0 + for field_name, meta in self._aristaproto.meta_by_field_name.items(): + try: + value = getattr(self, field_name) + except AttributeError: + continue + + if value is None: + # Optional items should be skipped. This is used for the Google + # wrapper types and proto3 field presence/optional fields. + continue + + # Being selected in a group means this field is the one that is + # currently set in a `oneof` group, so it must be serialized even + # if the value is the default zero value. + # + # Note that proto3 field presence/optional fields are put in a + # synthetic single-item oneof by protoc, which helps us ensure we + # send the value even if the value is the default zero value. + selected_in_group = bool(meta.group) + + # Empty messages can still be sent on the wire if they were + # set (or received empty). + serialize_empty = isinstance(value, Message) and value._serialized_on_wire + + include_default_value_for_oneof = self._include_default_value_for_oneof( + field_name=field_name, meta=meta + ) + + if value == self._get_field_default(field_name) and not ( + selected_in_group or serialize_empty or include_default_value_for_oneof + ): + # Default (zero) values are not serialized. Two exceptions are + # if this is the selected oneof item or if we know we have to + # serialize an empty message (i.e. zero value was explicitly + # set by the user). + continue + + if isinstance(value, list): + if meta.proto_type in PACKED_TYPES: + # Packed lists look like a length-delimited field. First, + # preprocess/encode each value into a buffer and then + # treat it like a field of raw bytes. + buf = bytearray() + for item in value: + buf += _preprocess_single(meta.proto_type, "", item) + size += _len_single(meta.number, TYPE_BYTES, buf) + else: + for item in value: + size += ( + _len_single( + meta.number, + meta.proto_type, + item, + wraps=meta.wraps or "", + serialize_empty=True, + ) + # if it's an empty message it still needs to be represented + # as an item in the repeated list + or 2 + ) + + elif isinstance(value, dict): + for k, v in value.items(): + assert meta.map_types + sk = _serialize_single(1, meta.map_types[0], k) + sv = _serialize_single(2, meta.map_types[1], v) + size += _len_single(meta.number, meta.proto_type, sk + sv) + else: + # If we have an empty string and we're including the default value for + # a oneof, make sure we serialize it. This ensures that the byte string + # output isn't simply an empty string. This also ensures that round trip + # serialization will keep `which_one_of` calls consistent. + if ( + isinstance(value, str) + and value == "" + and include_default_value_for_oneof + ): + serialize_empty = True + + size += _len_single( + meta.number, + meta.proto_type, + value, + serialize_empty=serialize_empty or bool(selected_in_group), + wraps=meta.wraps or "", + ) + + size += len(self._unknown_fields) + return size + + # For compatibility with other libraries + def SerializeToString(self: T) -> bytes: + """ + Get the binary encoded Protobuf representation of this message instance. + + .. note:: + This is a method for compatibility with other libraries, + you should really use ``bytes(x)``. + + Returns + -------- + :class:`bytes` + The binary encoded Protobuf representation of this message instance + """ + return bytes(self) + + def __getstate__(self) -> bytes: + return bytes(self) + + def __setstate__(self: T, pickled_bytes: bytes) -> T: + return self.parse(pickled_bytes) + + def __reduce__(self) -> Tuple[Any, ...]: + return (self.__class__.FromString, (bytes(self),)) + + @classmethod + def _type_hint(cls, field_name: str) -> Type: + return cls._type_hints()[field_name] + + @classmethod + def _type_hints(cls) -> Dict[str, Type]: + module = sys.modules[cls.__module__] + return get_type_hints(cls, module.__dict__, {}) + + @classmethod + def _cls_for(cls, field: dataclasses.Field, index: int = 0) -> Type: + """Get the message class for a field from the type hints.""" + field_cls = cls._type_hint(field.name) + if hasattr(field_cls, "__args__") and index >= 0: + if field_cls.__args__ is not None: + field_cls = field_cls.__args__[index] + return field_cls + + def _get_field_default(self, field_name: str) -> Any: + with warnings.catch_warnings(): + # ignore warnings when initialising deprecated field defaults + warnings.filterwarnings("ignore", category=DeprecationWarning) + return self._aristaproto.default_gen[field_name]() + + @classmethod + def _get_field_default_gen(cls, field: dataclasses.Field) -> Any: + t = cls._type_hint(field.name) + + if hasattr(t, "__origin__"): + if t.__origin__ is dict: + # This is some kind of map (dict in Python). + return dict + elif t.__origin__ is list: + # This is some kind of list (repeated) field. + return list + elif t.__origin__ is Union and t.__args__[1] is type(None): + # This is an optional field (either wrapped, or using proto3 + # field presence). For setting the default we really don't care + # what kind of field it is. + return type(None) + else: + return t + elif issubclass(t, Enum): + # Enums always default to zero. + return t.try_value + elif t is datetime: + # Offsets are relative to 1970-01-01T00:00:00Z + return datetime_default_gen + else: + # This is either a primitive scalar or another message type. Calling + # it should result in its zero value. + return t + + def _postprocess_single( + self, wire_type: int, meta: FieldMetadata, field_name: str, value: Any + ) -> Any: + """Adjusts values after parsing.""" + if wire_type == WIRE_VARINT: + if meta.proto_type in (TYPE_INT32, TYPE_INT64): + bits = int(meta.proto_type[3:]) + value = value & ((1 << bits) - 1) + signbit = 1 << (bits - 1) + value = int((value ^ signbit) - signbit) + elif meta.proto_type in (TYPE_SINT32, TYPE_SINT64): + # Undo zig-zag encoding + value = (value >> 1) ^ (-(value & 1)) + elif meta.proto_type == TYPE_BOOL: + # Booleans use a varint encoding, so convert it to true/false. + value = value > 0 + elif meta.proto_type == TYPE_ENUM: + # Convert enum ints to python enum instances + value = self._aristaproto.cls_by_field[field_name].try_value(value) + elif wire_type in (WIRE_FIXED_32, WIRE_FIXED_64): + fmt = _pack_fmt(meta.proto_type) + value = struct.unpack(fmt, value)[0] + elif wire_type == WIRE_LEN_DELIM: + if meta.proto_type == TYPE_STRING: + value = str(value, "utf-8") + elif meta.proto_type == TYPE_MESSAGE: + cls = self._aristaproto.cls_by_field[field_name] + + if cls == datetime: + value = _Timestamp().parse(value).to_datetime() + elif cls == timedelta: + value = _Duration().parse(value).to_timedelta() + elif meta.wraps: + # This is a Google wrapper value message around a single + # scalar type. + value = _get_wrapper(meta.wraps)().parse(value).value + else: + value = cls().parse(value) + value._serialized_on_wire = True + elif meta.proto_type == TYPE_MAP: + value = self._aristaproto.cls_by_field[field_name]().parse(value) + + return value + + def _include_default_value_for_oneof( + self, field_name: str, meta: FieldMetadata + ) -> bool: + return ( + meta.group is not None and self._group_current.get(meta.group) == field_name + ) + + def load( + self: T, + stream: "SupportsRead[bytes]", + size: Optional[int] = None, + ) -> T: + """ + Load the binary encoded Protobuf from a stream into this message instance. This + returns the instance itself and is therefore assignable and chainable. + + Parameters + ----------- + stream: :class:`bytes` + The stream to load the message from. + size: :class:`Optional[int]` + The size of the message in the stream. + Reads stream until EOF if ``None`` is given. + Reads based on a size delimiter prefix varint if SIZE_DELIMITED is given. + + Returns + -------- + :class:`Message` + The initialized message. + """ + # If the message is delimited, parse the message delimiter + if size == SIZE_DELIMITED: + size, _ = load_varint(stream) + + # Got some data over the wire + self._serialized_on_wire = True + proto_meta = self._aristaproto + read = 0 + for parsed in load_fields(stream): + field_name = proto_meta.field_name_by_number.get(parsed.number) + if not field_name: + self._unknown_fields += parsed.raw + continue + + meta = proto_meta.meta_by_field_name[field_name] + + value: Any + if parsed.wire_type == WIRE_LEN_DELIM and meta.proto_type in PACKED_TYPES: + # This is a packed repeated field. + pos = 0 + value = [] + while pos < len(parsed.value): + if meta.proto_type in (TYPE_FLOAT, TYPE_FIXED32, TYPE_SFIXED32): + decoded, pos = parsed.value[pos : pos + 4], pos + 4 + wire_type = WIRE_FIXED_32 + elif meta.proto_type in (TYPE_DOUBLE, TYPE_FIXED64, TYPE_SFIXED64): + decoded, pos = parsed.value[pos : pos + 8], pos + 8 + wire_type = WIRE_FIXED_64 + else: + decoded, pos = decode_varint(parsed.value, pos) + wire_type = WIRE_VARINT + decoded = self._postprocess_single( + wire_type, meta, field_name, decoded + ) + value.append(decoded) + else: + value = self._postprocess_single( + parsed.wire_type, meta, field_name, parsed.value + ) + + try: + current = getattr(self, field_name) + except AttributeError: + current = self._get_field_default(field_name) + setattr(self, field_name, current) + + if meta.proto_type == TYPE_MAP: + # Value represents a single key/value pair entry in the map. + current[value.key] = value.value + elif isinstance(current, list) and not isinstance(value, list): + current.append(value) + else: + setattr(self, field_name, value) + + # If we have now loaded the expected length of the message, stop + if size is not None: + prev = read + read += len(parsed.raw) + if read == size: + break + elif read > size: + raise ValueError( + f"Expected message of size {size}, can only read " + f"either {prev} or {read} bytes - there is no " + "message of the expected size in the stream." + ) + + if size is not None and read < size: + raise ValueError( + f"Expected message of size {size}, but was only able to " + f"read {read} bytes - the stream may have ended too soon," + " or the expected size may have been incorrect." + ) + + return self + + def parse(self: T, data: bytes) -> T: + """ + Parse the binary encoded Protobuf into this message instance. This + returns the instance itself and is therefore assignable and chainable. + + Parameters + ----------- + data: :class:`bytes` + The data to parse the message from. + + Returns + -------- + :class:`Message` + The initialized message. + """ + with BytesIO(data) as stream: + return self.load(stream) + + # For compatibility with other libraries. + @classmethod + def FromString(cls: Type[T], data: bytes) -> T: + """ + Parse the binary encoded Protobuf into this message instance. This + returns the instance itself and is therefore assignable and chainable. + + .. note:: + This is a method for compatibility with other libraries, + you should really use :meth:`parse`. + + + Parameters + ----------- + data: :class:`bytes` + The data to parse the protobuf from. + + Returns + -------- + :class:`Message` + The initialized message. + """ + return cls().parse(data) + + def to_dict( + self, casing: Casing = Casing.CAMEL, include_default_values: bool = False + ) -> Dict[str, Any]: + """ + Returns a JSON serializable dict representation of this object. + + Parameters + ----------- + casing: :class:`Casing` + The casing to use for key values. Default is :attr:`Casing.CAMEL` for + compatibility purposes. + include_default_values: :class:`bool` + If ``True`` will include the default values of fields. Default is ``False``. + E.g. an ``int32`` field will be included with a value of ``0`` if this is + set to ``True``, otherwise this would be ignored. + + Returns + -------- + Dict[:class:`str`, Any] + The JSON serializable dict representation of this object. + """ + output: Dict[str, Any] = {} + field_types = self._type_hints() + defaults = self._aristaproto.default_gen + for field_name, meta in self._aristaproto.meta_by_field_name.items(): + field_is_repeated = defaults[field_name] is list + try: + value = getattr(self, field_name) + except AttributeError: + value = self._get_field_default(field_name) + cased_name = casing(field_name).rstrip("_") # type: ignore + if meta.proto_type == TYPE_MESSAGE: + if isinstance(value, datetime): + if ( + value != DATETIME_ZERO + or include_default_values + or self._include_default_value_for_oneof( + field_name=field_name, meta=meta + ) + ): + output[cased_name] = _Timestamp.timestamp_to_json(value) + elif isinstance(value, timedelta): + if ( + value != timedelta(0) + or include_default_values + or self._include_default_value_for_oneof( + field_name=field_name, meta=meta + ) + ): + output[cased_name] = _Duration.delta_to_json(value) + elif meta.wraps: + if value is not None or include_default_values: + output[cased_name] = value + elif field_is_repeated: + # Convert each item. + cls = self._aristaproto.cls_by_field[field_name] + if cls == datetime: + value = [_Timestamp.timestamp_to_json(i) for i in value] + elif cls == timedelta: + value = [_Duration.delta_to_json(i) for i in value] + else: + value = [ + i.to_dict(casing, include_default_values) for i in value + ] + if value or include_default_values: + output[cased_name] = value + elif value is None: + if include_default_values: + output[cased_name] = value + elif ( + value._serialized_on_wire + or include_default_values + or self._include_default_value_for_oneof( + field_name=field_name, meta=meta + ) + ): + output[cased_name] = value.to_dict(casing, include_default_values) + elif meta.proto_type == TYPE_MAP: + output_map = {**value} + for k in value: + if hasattr(value[k], "to_dict"): + output_map[k] = value[k].to_dict(casing, include_default_values) + + if value or include_default_values: + output[cased_name] = output_map + elif ( + value != self._get_field_default(field_name) + or include_default_values + or self._include_default_value_for_oneof( + field_name=field_name, meta=meta + ) + ): + if meta.proto_type in INT_64_TYPES: + if field_is_repeated: + output[cased_name] = [str(n) for n in value] + elif value is None: + if include_default_values: + output[cased_name] = value + else: + output[cased_name] = str(value) + elif meta.proto_type == TYPE_BYTES: + if field_is_repeated: + output[cased_name] = [ + b64encode(b).decode("utf8") for b in value + ] + elif value is None and include_default_values: + output[cased_name] = value + else: + output[cased_name] = b64encode(value).decode("utf8") + elif meta.proto_type == TYPE_ENUM: + if field_is_repeated: + enum_class = field_types[field_name].__args__[0] + if isinstance(value, typing.Iterable) and not isinstance( + value, str + ): + output[cased_name] = [enum_class(el).name for el in value] + else: + # transparently upgrade single value to repeated + output[cased_name] = [enum_class(value).name] + elif value is None: + if include_default_values: + output[cased_name] = value + elif meta.optional: + enum_class = field_types[field_name].__args__[0] + output[cased_name] = enum_class(value).name + else: + enum_class = field_types[field_name] # noqa + output[cased_name] = enum_class(value).name + elif meta.proto_type in (TYPE_FLOAT, TYPE_DOUBLE): + if field_is_repeated: + output[cased_name] = [_dump_float(n) for n in value] + else: + output[cased_name] = _dump_float(value) + else: + output[cased_name] = value + return output + + @classmethod + def _from_dict_init(cls, mapping: Mapping[str, Any]) -> Mapping[str, Any]: + init_kwargs: Dict[str, Any] = {} + for key, value in mapping.items(): + field_name = safe_snake_case(key) + try: + meta = cls._aristaproto.meta_by_field_name[field_name] + except KeyError: + continue + if value is None: + continue + + if meta.proto_type == TYPE_MESSAGE: + sub_cls = cls._aristaproto.cls_by_field[field_name] + if sub_cls == datetime: + value = ( + [isoparse(item) for item in value] + if isinstance(value, list) + else isoparse(value) + ) + elif sub_cls == timedelta: + value = ( + [timedelta(seconds=float(item[:-1])) for item in value] + if isinstance(value, list) + else timedelta(seconds=float(value[:-1])) + ) + elif not meta.wraps: + value = ( + [sub_cls.from_dict(item) for item in value] + if isinstance(value, list) + else sub_cls.from_dict(value) + ) + elif meta.map_types and meta.map_types[1] == TYPE_MESSAGE: + sub_cls = cls._aristaproto.cls_by_field[f"{field_name}.value"] + value = {k: sub_cls.from_dict(v) for k, v in value.items()} + else: + if meta.proto_type in INT_64_TYPES: + value = ( + [int(n) for n in value] + if isinstance(value, list) + else int(value) + ) + elif meta.proto_type == TYPE_BYTES: + value = ( + [b64decode(n) for n in value] + if isinstance(value, list) + else b64decode(value) + ) + elif meta.proto_type == TYPE_ENUM: + enum_cls = cls._aristaproto.cls_by_field[field_name] + if isinstance(value, list): + value = [enum_cls.from_string(e) for e in value] + elif isinstance(value, str): + value = enum_cls.from_string(value) + elif meta.proto_type in (TYPE_FLOAT, TYPE_DOUBLE): + value = ( + [_parse_float(n) for n in value] + if isinstance(value, list) + else _parse_float(value) + ) + + init_kwargs[field_name] = value + return init_kwargs + + @hybridmethod + def from_dict(cls: type[Self], value: Mapping[str, Any]) -> Self: # type: ignore + """ + Parse the key/value pairs into the a new message instance. + + Parameters + ----------- + value: Dict[:class:`str`, Any] + The dictionary to parse from. + + Returns + -------- + :class:`Message` + The initialized message. + """ + self = cls(**cls._from_dict_init(value)) + self._serialized_on_wire = True + return self + + @from_dict.instancemethod + def from_dict(self, value: Mapping[str, Any]) -> Self: + """ + Parse the key/value pairs into the current message instance. This returns the + instance itself and is therefore assignable and chainable. + + Parameters + ----------- + value: Dict[:class:`str`, Any] + The dictionary to parse from. + + Returns + -------- + :class:`Message` + The initialized message. + """ + self._serialized_on_wire = True + for field, value in self._from_dict_init(value).items(): + setattr(self, field, value) + return self + + def to_json( + self, + indent: Union[None, int, str] = None, + include_default_values: bool = False, + casing: Casing = Casing.CAMEL, + ) -> str: + """A helper function to parse the message instance into its JSON + representation. + + This is equivalent to:: + + json.dumps(message.to_dict(), indent=indent) + + Parameters + ----------- + indent: Optional[Union[:class:`int`, :class:`str`]] + The indent to pass to :func:`json.dumps`. + + include_default_values: :class:`bool` + If ``True`` will include the default values of fields. Default is ``False``. + E.g. an ``int32`` field will be included with a value of ``0`` if this is + set to ``True``, otherwise this would be ignored. + + casing: :class:`Casing` + The casing to use for key values. Default is :attr:`Casing.CAMEL` for + compatibility purposes. + + Returns + -------- + :class:`str` + The JSON representation of the message. + """ + return json.dumps( + self.to_dict(include_default_values=include_default_values, casing=casing), + indent=indent, + ) + + def from_json(self: T, value: Union[str, bytes]) -> T: + """A helper function to return the message instance from its JSON + representation. This returns the instance itself and is therefore assignable + and chainable. + + This is equivalent to:: + + return message.from_dict(json.loads(value)) + + Parameters + ----------- + value: Union[:class:`str`, :class:`bytes`] + The value to pass to :func:`json.loads`. + + Returns + -------- + :class:`Message` + The initialized message. + """ + return self.from_dict(json.loads(value)) + + def to_pydict( + self, casing: Casing = Casing.CAMEL, include_default_values: bool = False + ) -> Dict[str, Any]: + """ + Returns a python dict representation of this object. + + Parameters + ----------- + casing: :class:`Casing` + The casing to use for key values. Default is :attr:`Casing.CAMEL` for + compatibility purposes. + include_default_values: :class:`bool` + If ``True`` will include the default values of fields. Default is ``False``. + E.g. an ``int32`` field will be included with a value of ``0`` if this is + set to ``True``, otherwise this would be ignored. + + Returns + -------- + Dict[:class:`str`, Any] + The python dict representation of this object. + """ + output: Dict[str, Any] = {} + defaults = self._aristaproto.default_gen + for field_name, meta in self._aristaproto.meta_by_field_name.items(): + field_is_repeated = defaults[field_name] is list + value = getattr(self, field_name) + cased_name = casing(field_name).rstrip("_") # type: ignore + if meta.proto_type == TYPE_MESSAGE: + if isinstance(value, datetime): + if ( + value != DATETIME_ZERO + or include_default_values + or self._include_default_value_for_oneof( + field_name=field_name, meta=meta + ) + ): + output[cased_name] = value + elif isinstance(value, timedelta): + if ( + value != timedelta(0) + or include_default_values + or self._include_default_value_for_oneof( + field_name=field_name, meta=meta + ) + ): + output[cased_name] = value + elif meta.wraps: + if value is not None or include_default_values: + output[cased_name] = value + elif field_is_repeated: + # Convert each item. + value = [i.to_pydict(casing, include_default_values) for i in value] + if value or include_default_values: + output[cased_name] = value + elif value is None: + if include_default_values: + output[cased_name] = None + elif ( + value._serialized_on_wire + or include_default_values + or self._include_default_value_for_oneof( + field_name=field_name, meta=meta + ) + ): + output[cased_name] = value.to_pydict(casing, include_default_values) + elif meta.proto_type == TYPE_MAP: + for k in value: + if hasattr(value[k], "to_pydict"): + value[k] = value[k].to_pydict(casing, include_default_values) + + if value or include_default_values: + output[cased_name] = value + elif ( + value != self._get_field_default(field_name) + or include_default_values + or self._include_default_value_for_oneof( + field_name=field_name, meta=meta + ) + ): + output[cased_name] = value + return output + + def from_pydict(self: T, value: Mapping[str, Any]) -> T: + """ + Parse the key/value pairs into the current message instance. This returns the + instance itself and is therefore assignable and chainable. + + Parameters + ----------- + value: Dict[:class:`str`, Any] + The dictionary to parse from. + + Returns + -------- + :class:`Message` + The initialized message. + """ + self._serialized_on_wire = True + for key in value: + field_name = safe_snake_case(key) + meta = self._aristaproto.meta_by_field_name.get(field_name) + if not meta: + continue + + if value[key] is not None: + if meta.proto_type == TYPE_MESSAGE: + v = getattr(self, field_name) + if isinstance(v, list): + cls = self._aristaproto.cls_by_field[field_name] + for item in value[key]: + v.append(cls().from_pydict(item)) + elif isinstance(v, datetime): + v = value[key] + elif isinstance(v, timedelta): + v = value[key] + elif meta.wraps: + v = value[key] + else: + # NOTE: `from_pydict` mutates the underlying message, so no + # assignment here is necessary. + v.from_pydict(value[key]) + elif meta.map_types and meta.map_types[1] == TYPE_MESSAGE: + v = getattr(self, field_name) + cls = self._aristaproto.cls_by_field[f"{field_name}.value"] + for k in value[key]: + v[k] = cls().from_pydict(value[key][k]) + else: + v = value[key] + + if v is not None: + setattr(self, field_name, v) + return self + + def is_set(self, name: str) -> bool: + """ + Check if field with the given name has been set. + + Parameters + ----------- + name: :class:`str` + The name of the field to check for. + + Returns + -------- + :class:`bool` + `True` if field has been set, otherwise `False`. + """ + default = ( + PLACEHOLDER + if not self._aristaproto.meta_by_field_name[name].optional + else None + ) + return self.__raw_get(name) is not default + + @classmethod + def _validate_field_groups(cls, values): + group_to_one_ofs = cls._aristaproto.oneof_field_by_group + field_name_to_meta = cls._aristaproto.meta_by_field_name + + for group, field_set in group_to_one_ofs.items(): + if len(field_set) == 1: + (field,) = field_set + field_name = field.name + meta = field_name_to_meta[field_name] + + # This is a synthetic oneof; we should ignore it's presence and not consider it as a oneof. + if meta.optional: + continue + + set_fields = [ + field.name for field in field_set if values[field.name] is not None + ] + + if not set_fields: + raise ValueError(f"Group {group} has no value; all fields are None") + elif len(set_fields) > 1: + set_fields_str = ", ".join(set_fields) + raise ValueError( + f"Group {group} has more than one value; fields {set_fields_str} are not None" + ) + + return values + + +Message.__annotations__ = {} # HACK to avoid typing.get_type_hints breaking :) + +# monkey patch (de-)serialization functions of class `Message` +# with functions from `betterproto-rust-codec` if available +try: + import betterproto_rust_codec + + def __parse_patch(self: T, data: bytes) -> T: + betterproto_rust_codec.deserialize(self, data) + return self + + def __bytes_patch(self) -> bytes: + return betterproto_rust_codec.serialize(self) + + Message.parse = __parse_patch + Message.__bytes__ = __bytes_patch +except ModuleNotFoundError: + pass + + +def serialized_on_wire(message: Message) -> bool: + """ + If this message was or should be serialized on the wire. This can be used to detect + presence (e.g. optional wrapper message) and is used internally during + parsing/serialization. + + Returns + -------- + :class:`bool` + Whether this message was or should be serialized on the wire. + """ + return message._serialized_on_wire + + +def which_one_of(message: Message, group_name: str) -> Tuple[str, Optional[Any]]: + """ + Return the name and value of a message's one-of field group. + + Returns + -------- + Tuple[:class:`str`, Any] + The field name and the value for that field. + """ + field_name = message._group_current.get(group_name) + if not field_name: + return "", None + return field_name, getattr(message, field_name) + + +# Circular import workaround: google.protobuf depends on base classes defined above. +from .lib.google.protobuf import ( # noqa + BoolValue, + BytesValue, + DoubleValue, + Duration, + EnumValue, + FloatValue, + Int32Value, + Int64Value, + StringValue, + Timestamp, + UInt32Value, + UInt64Value, +) + + +class _Duration(Duration): + @classmethod + def from_timedelta( + cls, delta: timedelta, *, _1_microsecond: timedelta = timedelta(microseconds=1) + ) -> "_Duration": + total_ms = delta // _1_microsecond + seconds = int(total_ms / 1e6) + nanos = int((total_ms % 1e6) * 1e3) + return cls(seconds, nanos) + + def to_timedelta(self) -> timedelta: + return timedelta(seconds=self.seconds, microseconds=self.nanos / 1e3) + + @staticmethod + def delta_to_json(delta: timedelta) -> str: + parts = str(delta.total_seconds()).split(".") + if len(parts) > 1: + while len(parts[1]) not in (3, 6, 9): + parts[1] = f"{parts[1]}0" + return f"{'.'.join(parts)}s" + + +class _Timestamp(Timestamp): + @classmethod + def from_datetime(cls, dt: datetime) -> "_Timestamp": + # manual epoch offset calulation to avoid rounding errors, + # to support negative timestamps (before 1970) and skirt + # around datetime bugs (apparently 0 isn't a year in [0, 9999]??) + offset = dt - DATETIME_ZERO + # below is the same as timedelta.total_seconds() but without dividing by 1e6 + # so we end up with microseconds as integers instead of seconds as float + offset_us = ( + offset.days * 24 * 60 * 60 + offset.seconds + ) * 10**6 + offset.microseconds + seconds, us = divmod(offset_us, 10**6) + # If ths given datetime is our subclass containing nanos from the original Timestamp + # We will prefer those nanos over the datetime micros. + if isinstance(dt, _DateTime) and dt.nanos: + return cls(seconds, dt.nanos) + return cls(seconds, us * 1000) + + def to_datetime(self) -> _DateTime: + # datetime.fromtimestamp() expects a timestamp in seconds, not microseconds + # if we pass it as a floating point number, we will run into rounding errors + # see also #407 + offset = timedelta(seconds=self.seconds, microseconds=self.nanos // 1000) + dt = DATETIME_ZERO + offset + # Store the original nanos in our subclass of datetime. + setattr(dt, "_nanos", self.nanos) + return dt + + @staticmethod + def timestamp_to_json(dt: datetime) -> str: + # If ths given datetime is our subclass containing nanos from the original Timestamp + # We will prefer those nanos over the datetime micros. + if isinstance(dt, _DateTime) and dt.nanos: + nanos = dt.nanos + else: + nanos = dt.microsecond * 1e3 + if dt.tzinfo is not None: + # change timezone aware datetime objects to utc + dt = dt.astimezone(timezone.utc) + copy = dt.replace(microsecond=0, tzinfo=None) + result = copy.isoformat() + if (nanos % 1e9) == 0: + # If there are 0 fractional digits, the fractional + # point '.' should be omitted when serializing. + return f"{result}Z" + if (nanos % 1e6) == 0: + # Serialize 3 fractional digits. + return f"{result}.{int(nanos // 1e6) :03d}Z" + if (nanos % 1e3) == 0: + # Serialize 6 fractional digits. + return f"{result}.{int(nanos // 1e3) :06d}Z" + # Serialize 9 fractional digits. + return f"{result}.{nanos:09d}" + + +def _get_wrapper(proto_type: str) -> Type: + """Get the wrapper message class for a wrapped type.""" + + # TODO: include ListValue and NullValue? + return { + TYPE_BOOL: BoolValue, + TYPE_BYTES: BytesValue, + TYPE_DOUBLE: DoubleValue, + TYPE_FLOAT: FloatValue, + TYPE_ENUM: EnumValue, + TYPE_INT32: Int32Value, + TYPE_INT64: Int64Value, + TYPE_STRING: StringValue, + TYPE_UINT32: UInt32Value, + TYPE_UINT64: UInt64Value, + }[proto_type] diff --git a/src/aristaproto/_types.py b/src/aristaproto/_types.py new file mode 100644 index 0000000..616d550 --- /dev/null +++ b/src/aristaproto/_types.py @@ -0,0 +1,14 @@ +from typing import ( + TYPE_CHECKING, + TypeVar, +) + + +if TYPE_CHECKING: + from grpclib._typing import IProtoMessage + + from . import Message + +# Bound type variable to allow methods to return `self` of subclasses +T = TypeVar("T", bound="Message") +ST = TypeVar("ST", bound="IProtoMessage") diff --git a/src/aristaproto/_version.py b/src/aristaproto/_version.py new file mode 100644 index 0000000..347a391 --- /dev/null +++ b/src/aristaproto/_version.py @@ -0,0 +1,4 @@ +from importlib import metadata + + +__version__ = metadata.version("aristaproto") diff --git a/src/aristaproto/casing.py b/src/aristaproto/casing.py new file mode 100644 index 0000000..f7d0832 --- /dev/null +++ b/src/aristaproto/casing.py @@ -0,0 +1,143 @@ +import keyword +import re + + +# Word delimiters and symbols that will not be preserved when re-casing. +# language=PythonRegExp +SYMBOLS = "[^a-zA-Z0-9]*" + +# Optionally capitalized word. +# language=PythonRegExp +WORD = "[A-Z]*[a-z]*[0-9]*" + +# Uppercase word, not followed by lowercase letters. +# language=PythonRegExp +WORD_UPPER = "[A-Z]+(?![a-z])[0-9]*" + + +def safe_snake_case(value: str) -> str: + """Snake case a value taking into account Python keywords.""" + value = snake_case(value) + value = sanitize_name(value) + return value + + +def snake_case(value: str, strict: bool = True) -> str: + """ + Join words with an underscore into lowercase and remove symbols. + + Parameters + ----------- + value: :class:`str` + The value to convert. + strict: :class:`bool` + Whether or not to force single underscores. + + Returns + -------- + :class:`str` + The value in snake_case. + """ + + def substitute_word(symbols: str, word: str, is_start: bool) -> str: + if not word: + return "" + if strict: + delimiter_count = 0 if is_start else 1 # Single underscore if strict. + elif is_start: + delimiter_count = len(symbols) + elif word.isupper() or word.islower(): + delimiter_count = max( + 1, len(symbols) + ) # Preserve all delimiters if not strict. + else: + delimiter_count = len(symbols) + 1 # Extra underscore for leading capital. + + return ("_" * delimiter_count) + word.lower() + + snake = re.sub( + f"(^)?({SYMBOLS})({WORD_UPPER}|{WORD})", + lambda groups: substitute_word(groups[2], groups[3], groups[1] is not None), + value, + ) + return snake + + +def pascal_case(value: str, strict: bool = True) -> str: + """ + Capitalize each word and remove symbols. + + Parameters + ----------- + value: :class:`str` + The value to convert. + strict: :class:`bool` + Whether or not to output only alphanumeric characters. + + Returns + -------- + :class:`str` + The value in PascalCase. + """ + + def substitute_word(symbols, word): + if strict: + return word.capitalize() # Remove all delimiters + + if word.islower(): + delimiter_length = len(symbols[:-1]) # Lose one delimiter + else: + delimiter_length = len(symbols) # Preserve all delimiters + + return ("_" * delimiter_length) + word.capitalize() + + return re.sub( + f"({SYMBOLS})({WORD_UPPER}|{WORD})", + lambda groups: substitute_word(groups[1], groups[2]), + value, + ) + + +def camel_case(value: str, strict: bool = True) -> str: + """ + Capitalize all words except first and remove symbols. + + Parameters + ----------- + value: :class:`str` + The value to convert. + strict: :class:`bool` + Whether or not to output only alphanumeric characters. + + Returns + -------- + :class:`str` + The value in camelCase. + """ + return lowercase_first(pascal_case(value, strict=strict)) + + +def lowercase_first(value: str) -> str: + """ + Lower cases the first character of the value. + + Parameters + ---------- + value: :class:`str` + The value to lower case. + + Returns + ------- + :class:`str` + The lower cased string. + """ + return value[0:1].lower() + value[1:] + + +def sanitize_name(value: str) -> str: + # https://www.python.org/dev/peps/pep-0008/#descriptive-naming-styles + if keyword.iskeyword(value): + return f"{value}_" + if not value.isidentifier(): + return f"_{value}" + return value diff --git a/src/aristaproto/compile/__init__.py b/src/aristaproto/compile/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/aristaproto/compile/__init__.py diff --git a/src/aristaproto/compile/importing.py b/src/aristaproto/compile/importing.py new file mode 100644 index 0000000..8486ddd --- /dev/null +++ b/src/aristaproto/compile/importing.py @@ -0,0 +1,176 @@ +import os +import re +from typing import ( + Dict, + List, + Set, + Tuple, + Type, +) + +from ..casing import safe_snake_case +from ..lib.google import protobuf as google_protobuf +from .naming import pythonize_class_name + + +WRAPPER_TYPES: Dict[str, Type] = { + ".google.protobuf.DoubleValue": google_protobuf.DoubleValue, + ".google.protobuf.FloatValue": google_protobuf.FloatValue, + ".google.protobuf.Int32Value": google_protobuf.Int32Value, + ".google.protobuf.Int64Value": google_protobuf.Int64Value, + ".google.protobuf.UInt32Value": google_protobuf.UInt32Value, + ".google.protobuf.UInt64Value": google_protobuf.UInt64Value, + ".google.protobuf.BoolValue": google_protobuf.BoolValue, + ".google.protobuf.StringValue": google_protobuf.StringValue, + ".google.protobuf.BytesValue": google_protobuf.BytesValue, +} + + +def parse_source_type_name(field_type_name: str) -> Tuple[str, str]: + """ + Split full source type name into package and type name. + E.g. 'root.package.Message' -> ('root.package', 'Message') + 'root.Message.SomeEnum' -> ('root', 'Message.SomeEnum') + """ + package_match = re.match(r"^\.?([^A-Z]+)\.(.+)", field_type_name) + if package_match: + package = package_match.group(1) + name = package_match.group(2) + else: + package = "" + name = field_type_name.lstrip(".") + return package, name + + +def get_type_reference( + *, + package: str, + imports: set, + source_type: str, + unwrap: bool = True, + pydantic: bool = False, +) -> str: + """ + Return a Python type name for a proto type reference. Adds the import if + necessary. Unwraps well known type if required. + """ + if unwrap: + if source_type in WRAPPER_TYPES: + wrapped_type = type(WRAPPER_TYPES[source_type]().value) + return f"Optional[{wrapped_type.__name__}]" + + if source_type == ".google.protobuf.Duration": + return "timedelta" + + elif source_type == ".google.protobuf.Timestamp": + return "datetime" + + source_package, source_type = parse_source_type_name(source_type) + + current_package: List[str] = package.split(".") if package else [] + py_package: List[str] = source_package.split(".") if source_package else [] + py_type: str = pythonize_class_name(source_type) + + compiling_google_protobuf = current_package == ["google", "protobuf"] + importing_google_protobuf = py_package == ["google", "protobuf"] + if importing_google_protobuf and not compiling_google_protobuf: + py_package = ( + ["aristaproto", "lib"] + (["pydantic"] if pydantic else []) + py_package + ) + + if py_package[:1] == ["aristaproto"]: + return reference_absolute(imports, py_package, py_type) + + if py_package == current_package: + return reference_sibling(py_type) + + if py_package[: len(current_package)] == current_package: + return reference_descendent(current_package, imports, py_package, py_type) + + if current_package[: len(py_package)] == py_package: + return reference_ancestor(current_package, imports, py_package, py_type) + + return reference_cousin(current_package, imports, py_package, py_type) + + +def reference_absolute(imports: Set[str], py_package: List[str], py_type: str) -> str: + """ + Returns a reference to a python type located in the root, i.e. sys.path. + """ + string_import = ".".join(py_package) + string_alias = safe_snake_case(string_import) + imports.add(f"import {string_import} as {string_alias}") + return f'"{string_alias}.{py_type}"' + + +def reference_sibling(py_type: str) -> str: + """ + Returns a reference to a python type within the same package as the current package. + """ + return f'"{py_type}"' + + +def reference_descendent( + current_package: List[str], imports: Set[str], py_package: List[str], py_type: str +) -> str: + """ + Returns a reference to a python type in a package that is a descendent of the + current package, and adds the required import that is aliased to avoid name + conflicts. + """ + importing_descendent = py_package[len(current_package) :] + string_from = ".".join(importing_descendent[:-1]) + string_import = importing_descendent[-1] + if string_from: + string_alias = "_".join(importing_descendent) + imports.add(f"from .{string_from} import {string_import} as {string_alias}") + return f'"{string_alias}.{py_type}"' + else: + imports.add(f"from . import {string_import}") + return f'"{string_import}.{py_type}"' + + +def reference_ancestor( + current_package: List[str], imports: Set[str], py_package: List[str], py_type: str +) -> str: + """ + Returns a reference to a python type in a package which is an ancestor to the + current package, and adds the required import that is aliased (if possible) to avoid + name conflicts. + + Adds trailing __ to avoid name mangling (python.org/dev/peps/pep-0008/#id34). + """ + distance_up = len(current_package) - len(py_package) + if py_package: + string_import = py_package[-1] + string_alias = f"_{'_' * distance_up}{string_import}__" + string_from = f"..{'.' * distance_up}" + imports.add(f"from {string_from} import {string_import} as {string_alias}") + return f'"{string_alias}.{py_type}"' + else: + string_alias = f"{'_' * distance_up}{py_type}__" + imports.add(f"from .{'.' * distance_up} import {py_type} as {string_alias}") + return f'"{string_alias}"' + + +def reference_cousin( + current_package: List[str], imports: Set[str], py_package: List[str], py_type: str +) -> str: + """ + Returns a reference to a python type in a package that is not descendent, ancestor + or sibling, and adds the required import that is aliased to avoid name conflicts. + """ + shared_ancestry = os.path.commonprefix([current_package, py_package]) # type: ignore + distance_up = len(current_package) - len(shared_ancestry) + string_from = f".{'.' * distance_up}" + ".".join( + py_package[len(shared_ancestry) : -1] + ) + string_import = py_package[-1] + # Add trailing __ to avoid name mangling (python.org/dev/peps/pep-0008/#id34) + string_alias = ( + f"{'_' * distance_up}" + + safe_snake_case(".".join(py_package[len(shared_ancestry) :])) + + "__" + ) + imports.add(f"from {string_from} import {string_import} as {string_alias}") + return f'"{string_alias}.{py_type}"' diff --git a/src/aristaproto/compile/naming.py b/src/aristaproto/compile/naming.py new file mode 100644 index 0000000..0c45dde --- /dev/null +++ b/src/aristaproto/compile/naming.py @@ -0,0 +1,21 @@ +from aristaproto import casing + + +def pythonize_class_name(name: str) -> str: + return casing.pascal_case(name) + + +def pythonize_field_name(name: str) -> str: + return casing.safe_snake_case(name) + + +def pythonize_method_name(name: str) -> str: + return casing.safe_snake_case(name) + + +def pythonize_enum_member_name(name: str, enum_name: str) -> str: + enum_name = casing.snake_case(enum_name).upper() + find = name.find(enum_name) + if find != -1: + name = name[find + len(enum_name) :].strip("_") + return casing.sanitize_name(name) diff --git a/src/aristaproto/enum.py b/src/aristaproto/enum.py new file mode 100644 index 0000000..8535e86 --- /dev/null +++ b/src/aristaproto/enum.py @@ -0,0 +1,195 @@ +from __future__ import annotations + +import sys +from enum import ( + EnumMeta, + IntEnum, +) +from types import MappingProxyType +from typing import ( + TYPE_CHECKING, + Any, + Dict, + Optional, + Tuple, +) + + +if TYPE_CHECKING: + from collections.abc import ( + Generator, + Mapping, + ) + + from typing_extensions import ( + Never, + Self, + ) + + +def _is_descriptor(obj: object) -> bool: + return ( + hasattr(obj, "__get__") or hasattr(obj, "__set__") or hasattr(obj, "__delete__") + ) + + +class EnumType(EnumMeta if TYPE_CHECKING else type): + _value_map_: Mapping[int, Enum] + _member_map_: Mapping[str, Enum] + + def __new__( + mcs, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any] + ) -> Self: + value_map = {} + member_map = {} + + new_mcs = type( + f"{name}Type", + tuple( + dict.fromkeys( + [base.__class__ for base in bases if base.__class__ is not type] + + [EnumType, type] + ) + ), # reorder the bases so EnumType and type are last to avoid conflicts + {"_value_map_": value_map, "_member_map_": member_map}, + ) + + members = { + name: value + for name, value in namespace.items() + if not _is_descriptor(value) and not name.startswith("__") + } + + cls = type.__new__( + new_mcs, + name, + bases, + {key: value for key, value in namespace.items() if key not in members}, + ) + # this allows us to disallow member access from other members as + # members become proper class variables + + for name, value in members.items(): + member = value_map.get(value) + if member is None: + member = cls.__new__(cls, name=name, value=value) # type: ignore + value_map[value] = member + member_map[name] = member + type.__setattr__(new_mcs, name, member) + + return cls + + if not TYPE_CHECKING: + + def __call__(cls, value: int) -> Enum: + try: + return cls._value_map_[value] + except (KeyError, TypeError): + raise ValueError(f"{value!r} is not a valid {cls.__name__}") from None + + def __iter__(cls) -> Generator[Enum, None, None]: + yield from cls._member_map_.values() + + def __reversed__(cls) -> Generator[Enum, None, None]: + yield from reversed(cls._member_map_.values()) + + def __getitem__(cls, key: str) -> Enum: + return cls._member_map_[key] + + @property + def __members__(cls) -> MappingProxyType[str, Enum]: + return MappingProxyType(cls._member_map_) + + def __repr__(cls) -> str: + return f"<enum {cls.__name__!r}>" + + def __len__(cls) -> int: + return len(cls._member_map_) + + def __setattr__(cls, name: str, value: Any) -> Never: + raise AttributeError(f"{cls.__name__}: cannot reassign Enum members.") + + def __delattr__(cls, name: str) -> Never: + raise AttributeError(f"{cls.__name__}: cannot delete Enum members.") + + def __contains__(cls, member: object) -> bool: + return isinstance(member, cls) and member.name in cls._member_map_ + + +class Enum(IntEnum if TYPE_CHECKING else int, metaclass=EnumType): + """ + The base class for protobuf enumerations, all generated enumerations will + inherit from this. Emulates `enum.IntEnum`. + """ + + name: Optional[str] + value: int + + if not TYPE_CHECKING: + + def __new__(cls, *, name: Optional[str], value: int) -> Self: + self = super().__new__(cls, value) + super().__setattr__(self, "name", name) + super().__setattr__(self, "value", value) + return self + + def __str__(self) -> str: + return self.name or "None" + + def __repr__(self) -> str: + return f"{self.__class__.__name__}.{self.name}" + + def __setattr__(self, key: str, value: Any) -> Never: + raise AttributeError( + f"{self.__class__.__name__} Cannot reassign a member's attributes." + ) + + def __delattr__(self, item: Any) -> Never: + raise AttributeError( + f"{self.__class__.__name__} Cannot delete a member's attributes." + ) + + def __copy__(self) -> Self: + return self + + def __deepcopy__(self, memo: Any) -> Self: + return self + + @classmethod + def try_value(cls, value: int = 0) -> Self: + """Return the value which corresponds to the value. + + Parameters + ----------- + value: :class:`int` + The value of the enum member to get. + + Returns + ------- + :class:`Enum` + The corresponding member or a new instance of the enum if + ``value`` isn't actually a member. + """ + try: + return cls._value_map_[value] + except (KeyError, TypeError): + return cls.__new__(cls, name=None, value=value) + + @classmethod + def from_string(cls, name: str) -> Self: + """Return the value which corresponds to the string name. + + Parameters + ----------- + name: :class:`str` + The name of the enum member to get. + + Raises + ------- + :exc:`ValueError` + The member was not found in the Enum. + """ + try: + return cls._member_map_[name] + except KeyError as e: + raise ValueError(f"Unknown value {name} for enum {cls.__name__}") from e diff --git a/src/aristaproto/grpc/__init__.py b/src/aristaproto/grpc/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/aristaproto/grpc/__init__.py diff --git a/src/aristaproto/grpc/grpclib_client.py b/src/aristaproto/grpc/grpclib_client.py new file mode 100644 index 0000000..b19e806 --- /dev/null +++ b/src/aristaproto/grpc/grpclib_client.py @@ -0,0 +1,177 @@ +import asyncio +from abc import ABC +from typing import ( + TYPE_CHECKING, + AsyncIterable, + AsyncIterator, + Collection, + Iterable, + Mapping, + Optional, + Tuple, + Type, + Union, +) + +import grpclib.const + + +if TYPE_CHECKING: + from grpclib.client import Channel + from grpclib.metadata import Deadline + + from .._types import ( + ST, + IProtoMessage, + Message, + T, + ) + + +Value = Union[str, bytes] +MetadataLike = Union[Mapping[str, Value], Collection[Tuple[str, Value]]] +MessageSource = Union[Iterable["IProtoMessage"], AsyncIterable["IProtoMessage"]] + + +class ServiceStub(ABC): + """ + Base class for async gRPC clients. + """ + + def __init__( + self, + channel: "Channel", + *, + timeout: Optional[float] = None, + deadline: Optional["Deadline"] = None, + metadata: Optional[MetadataLike] = None, + ) -> None: + self.channel = channel + self.timeout = timeout + self.deadline = deadline + self.metadata = metadata + + def __resolve_request_kwargs( + self, + timeout: Optional[float], + deadline: Optional["Deadline"], + metadata: Optional[MetadataLike], + ): + return { + "timeout": self.timeout if timeout is None else timeout, + "deadline": self.deadline if deadline is None else deadline, + "metadata": self.metadata if metadata is None else metadata, + } + + async def _unary_unary( + self, + route: str, + request: "IProtoMessage", + response_type: Type["T"], + *, + timeout: Optional[float] = None, + deadline: Optional["Deadline"] = None, + metadata: Optional[MetadataLike] = None, + ) -> "T": + """Make a unary request and return the response.""" + async with self.channel.request( + route, + grpclib.const.Cardinality.UNARY_UNARY, + type(request), + response_type, + **self.__resolve_request_kwargs(timeout, deadline, metadata), + ) as stream: + await stream.send_message(request, end=True) + response = await stream.recv_message() + assert response is not None + return response + + async def _unary_stream( + self, + route: str, + request: "IProtoMessage", + response_type: Type["T"], + *, + timeout: Optional[float] = None, + deadline: Optional["Deadline"] = None, + metadata: Optional[MetadataLike] = None, + ) -> AsyncIterator["T"]: + """Make a unary request and return the stream response iterator.""" + async with self.channel.request( + route, + grpclib.const.Cardinality.UNARY_STREAM, + type(request), + response_type, + **self.__resolve_request_kwargs(timeout, deadline, metadata), + ) as stream: + await stream.send_message(request, end=True) + async for message in stream: + yield message + + async def _stream_unary( + self, + route: str, + request_iterator: MessageSource, + request_type: Type["IProtoMessage"], + response_type: Type["T"], + *, + timeout: Optional[float] = None, + deadline: Optional["Deadline"] = None, + metadata: Optional[MetadataLike] = None, + ) -> "T": + """Make a stream request and return the response.""" + async with self.channel.request( + route, + grpclib.const.Cardinality.STREAM_UNARY, + request_type, + response_type, + **self.__resolve_request_kwargs(timeout, deadline, metadata), + ) as stream: + await stream.send_request() + await self._send_messages(stream, request_iterator) + response = await stream.recv_message() + assert response is not None + return response + + async def _stream_stream( + self, + route: str, + request_iterator: MessageSource, + request_type: Type["IProtoMessage"], + response_type: Type["T"], + *, + timeout: Optional[float] = None, + deadline: Optional["Deadline"] = None, + metadata: Optional[MetadataLike] = None, + ) -> AsyncIterator["T"]: + """ + Make a stream request and return an AsyncIterator to iterate over response + messages. + """ + async with self.channel.request( + route, + grpclib.const.Cardinality.STREAM_STREAM, + request_type, + response_type, + **self.__resolve_request_kwargs(timeout, deadline, metadata), + ) as stream: + await stream.send_request() + sending_task = asyncio.ensure_future( + self._send_messages(stream, request_iterator) + ) + try: + async for response in stream: + yield response + except: + sending_task.cancel() + raise + + @staticmethod + async def _send_messages(stream, messages: MessageSource): + if isinstance(messages, AsyncIterable): + async for message in messages: + await stream.send_message(message) + else: + for message in messages: + await stream.send_message(message) + await stream.end() diff --git a/src/aristaproto/grpc/grpclib_server.py b/src/aristaproto/grpc/grpclib_server.py new file mode 100644 index 0000000..3e28031 --- /dev/null +++ b/src/aristaproto/grpc/grpclib_server.py @@ -0,0 +1,33 @@ +from abc import ABC +from collections.abc import AsyncIterable +from typing import ( + Any, + Callable, + Dict, +) + +import grpclib +import grpclib.server + + +class ServiceBase(ABC): + """ + Base class for async gRPC servers. + """ + + async def _call_rpc_handler_server_stream( + self, + handler: Callable, + stream: grpclib.server.Stream, + request: Any, + ) -> None: + response_iter = handler(request) + # check if response is actually an AsyncIterator + # this might be false if the method just returns without + # yielding at least once + # in that case, we just interpret it as an empty iterator + if isinstance(response_iter, AsyncIterable): + async for response_message in response_iter: + await stream.send_message(response_message) + else: + response_iter.close() diff --git a/src/aristaproto/grpc/util/__init__.py b/src/aristaproto/grpc/util/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/aristaproto/grpc/util/__init__.py diff --git a/src/aristaproto/grpc/util/async_channel.py b/src/aristaproto/grpc/util/async_channel.py new file mode 100644 index 0000000..9f18dbf --- /dev/null +++ b/src/aristaproto/grpc/util/async_channel.py @@ -0,0 +1,193 @@ +import asyncio +from typing import ( + AsyncIterable, + AsyncIterator, + Iterable, + Optional, + TypeVar, + Union, +) + + +T = TypeVar("T") + + +class ChannelClosed(Exception): + """ + An exception raised on an attempt to send through a closed channel + """ + + +class ChannelDone(Exception): + """ + An exception raised on an attempt to send receive from a channel that is both closed + and empty. + """ + + +class AsyncChannel(AsyncIterable[T]): + """ + A buffered async channel for sending items between coroutines with FIFO ordering. + + This makes decoupled bidirectional steaming gRPC requests easy if used like: + + .. code-block:: python + client = GeneratedStub(grpclib_chan) + request_channel = await AsyncChannel() + # We can start be sending all the requests we already have + await request_channel.send_from([RequestObject(...), RequestObject(...)]) + async for response in client.rpc_call(request_channel): + # The response iterator will remain active until the connection is closed + ... + # More items can be sent at any time + await request_channel.send(RequestObject(...)) + ... + # The channel must be closed to complete the gRPC connection + request_channel.close() + + Items can be sent through the channel by either: + - providing an iterable to the send_from method + - passing them to the send method one at a time + + Items can be received from the channel by either: + - iterating over the channel with a for loop to get all items + - calling the receive method to get one item at a time + + If the channel is empty then receivers will wait until either an item appears or the + channel is closed. + + Once the channel is closed then subsequent attempt to send through the channel will + fail with a ChannelClosed exception. + + When th channel is closed and empty then it is done, and further attempts to receive + from it will fail with a ChannelDone exception + + If multiple coroutines receive from the channel concurrently, each item sent will be + received by only one of the receivers. + + :param source: + An optional iterable will items that should be sent through the channel + immediately. + :param buffer_limit: + Limit the number of items that can be buffered in the channel, A value less than + 1 implies no limit. If the channel is full then attempts to send more items will + result in the sender waiting until an item is received from the channel. + :param close: + If set to True then the channel will automatically close after exhausting source + or immediately if no source is provided. + """ + + def __init__(self, *, buffer_limit: int = 0, close: bool = False): + self._queue: asyncio.Queue[T] = asyncio.Queue(buffer_limit) + self._closed = False + self._waiting_receivers: int = 0 + # Track whether flush has been invoked so it can only happen once + self._flushed = False + + def __aiter__(self) -> AsyncIterator[T]: + return self + + async def __anext__(self) -> T: + if self.done(): + raise StopAsyncIteration + self._waiting_receivers += 1 + try: + result = await self._queue.get() + if result is self.__flush: + raise StopAsyncIteration + return result + finally: + self._waiting_receivers -= 1 + self._queue.task_done() + + def closed(self) -> bool: + """ + Returns True if this channel is closed and no-longer accepting new items + """ + return self._closed + + def done(self) -> bool: + """ + Check if this channel is done. + + :return: True if this channel is closed and and has been drained of items in + which case any further attempts to receive an item from this channel will raise + a ChannelDone exception. + """ + # After close the channel is not yet done until there is at least one waiting + # receiver per enqueued item. + return self._closed and self._queue.qsize() <= self._waiting_receivers + + async def send_from( + self, source: Union[Iterable[T], AsyncIterable[T]], close: bool = False + ) -> "AsyncChannel[T]": + """ + Iterates the given [Async]Iterable and sends all the resulting items. + If close is set to True then subsequent send calls will be rejected with a + ChannelClosed exception. + :param source: an iterable of items to send + :param close: + if True then the channel will be closed after the source has been exhausted + + """ + if self._closed: + raise ChannelClosed("Cannot send through a closed channel") + if isinstance(source, AsyncIterable): + async for item in source: + await self._queue.put(item) + else: + for item in source: + await self._queue.put(item) + if close: + # Complete the closing process + self.close() + return self + + async def send(self, item: T) -> "AsyncChannel[T]": + """ + Send a single item over this channel. + :param item: The item to send + """ + if self._closed: + raise ChannelClosed("Cannot send through a closed channel") + await self._queue.put(item) + return self + + async def receive(self) -> Optional[T]: + """ + Returns the next item from this channel when it becomes available, + or None if the channel is closed before another item is sent. + :return: An item from the channel + """ + if self.done(): + raise ChannelDone("Cannot receive from a closed channel") + self._waiting_receivers += 1 + try: + result = await self._queue.get() + if result is self.__flush: + return None + return result + finally: + self._waiting_receivers -= 1 + self._queue.task_done() + + def close(self): + """ + Close this channel to new items + """ + self._closed = True + asyncio.ensure_future(self._flush_queue()) + + async def _flush_queue(self): + """ + To be called after the channel is closed. Pushes a number of self.__flush + objects to the queue to ensure no waiting consumers get deadlocked. + """ + if not self._flushed: + self._flushed = True + deadlocked_receivers = max(0, self._waiting_receivers - self._queue.qsize()) + for _ in range(deadlocked_receivers): + await self._queue.put(self.__flush) + + # A special signal object for flushing the queue when the channel is closed + __flush = object() diff --git a/src/aristaproto/lib/__init__.py b/src/aristaproto/lib/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/aristaproto/lib/__init__.py diff --git a/src/aristaproto/lib/google/__init__.py b/src/aristaproto/lib/google/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/aristaproto/lib/google/__init__.py diff --git a/src/aristaproto/lib/google/protobuf/__init__.py b/src/aristaproto/lib/google/protobuf/__init__.py new file mode 100644 index 0000000..f8aad1e --- /dev/null +++ b/src/aristaproto/lib/google/protobuf/__init__.py @@ -0,0 +1 @@ +from aristaproto.lib.std.google.protobuf import * diff --git a/src/aristaproto/lib/google/protobuf/compiler/__init__.py b/src/aristaproto/lib/google/protobuf/compiler/__init__.py new file mode 100644 index 0000000..cfa3855 --- /dev/null +++ b/src/aristaproto/lib/google/protobuf/compiler/__init__.py @@ -0,0 +1 @@ +from aristaproto.lib.std.google.protobuf.compiler import * diff --git a/src/aristaproto/lib/pydantic/__init__.py b/src/aristaproto/lib/pydantic/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/aristaproto/lib/pydantic/__init__.py diff --git a/src/aristaproto/lib/pydantic/google/__init__.py b/src/aristaproto/lib/pydantic/google/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/aristaproto/lib/pydantic/google/__init__.py diff --git a/src/aristaproto/lib/pydantic/google/protobuf/__init__.py b/src/aristaproto/lib/pydantic/google/protobuf/__init__.py new file mode 100644 index 0000000..3a7e8ac --- /dev/null +++ b/src/aristaproto/lib/pydantic/google/protobuf/__init__.py @@ -0,0 +1,2589 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# sources: google/protobuf/any.proto, google/protobuf/api.proto, google/protobuf/descriptor.proto, google/protobuf/duration.proto, google/protobuf/empty.proto, google/protobuf/field_mask.proto, google/protobuf/source_context.proto, google/protobuf/struct.proto, google/protobuf/timestamp.proto, google/protobuf/type.proto, google/protobuf/wrappers.proto +# plugin: python-aristaproto + +import warnings +from typing import TYPE_CHECKING + + +if TYPE_CHECKING: + from dataclasses import dataclass +else: + from pydantic.dataclasses import dataclass + +from typing import ( + Dict, + List, + Mapping, + Optional, +) + +from pydantic import root_validator +from typing_extensions import Self + +import aristaproto +from aristaproto.utils import hybridmethod + + +class Syntax(aristaproto.Enum): + """The syntax in which a protocol buffer element is defined.""" + + PROTO2 = 0 + """Syntax `proto2`.""" + + PROTO3 = 1 + """Syntax `proto3`.""" + + EDITIONS = 2 + """Syntax `editions`.""" + + +class FieldKind(aristaproto.Enum): + """Basic field types.""" + + TYPE_UNKNOWN = 0 + """Field type unknown.""" + + TYPE_DOUBLE = 1 + """Field type double.""" + + TYPE_FLOAT = 2 + """Field type float.""" + + TYPE_INT64 = 3 + """Field type int64.""" + + TYPE_UINT64 = 4 + """Field type uint64.""" + + TYPE_INT32 = 5 + """Field type int32.""" + + TYPE_FIXED64 = 6 + """Field type fixed64.""" + + TYPE_FIXED32 = 7 + """Field type fixed32.""" + + TYPE_BOOL = 8 + """Field type bool.""" + + TYPE_STRING = 9 + """Field type string.""" + + TYPE_GROUP = 10 + """Field type group. Proto2 syntax only, and deprecated.""" + + TYPE_MESSAGE = 11 + """Field type message.""" + + TYPE_BYTES = 12 + """Field type bytes.""" + + TYPE_UINT32 = 13 + """Field type uint32.""" + + TYPE_ENUM = 14 + """Field type enum.""" + + TYPE_SFIXED32 = 15 + """Field type sfixed32.""" + + TYPE_SFIXED64 = 16 + """Field type sfixed64.""" + + TYPE_SINT32 = 17 + """Field type sint32.""" + + TYPE_SINT64 = 18 + """Field type sint64.""" + + +class FieldCardinality(aristaproto.Enum): + """Whether a field is optional, required, or repeated.""" + + CARDINALITY_UNKNOWN = 0 + """For fields with unknown cardinality.""" + + CARDINALITY_OPTIONAL = 1 + """For optional fields.""" + + CARDINALITY_REQUIRED = 2 + """For required fields. Proto2 syntax only.""" + + CARDINALITY_REPEATED = 3 + """For repeated fields.""" + + +class Edition(aristaproto.Enum): + """The full set of known editions.""" + + UNKNOWN = 0 + """A placeholder for an unknown edition value.""" + + PROTO2 = 998 + """ + Legacy syntax "editions". These pre-date editions, but behave much like + distinct editions. These can't be used to specify the edition of proto + files, but feature definitions must supply proto2/proto3 defaults for + backwards compatibility. + """ + + PROTO3 = 999 + _2023 = 1000 + """ + Editions that have been released. The specific values are arbitrary and + should not be depended on, but they will always be time-ordered for easy + comparison. + """ + + _2024 = 1001 + _1_TEST_ONLY = 1 + """ + Placeholder editions for testing feature resolution. These should not be + used or relyed on outside of tests. + """ + + _2_TEST_ONLY = 2 + _99997_TEST_ONLY = 99997 + _99998_TEST_ONLY = 99998 + _99999_TEST_ONLY = 99999 + MAX = 2147483647 + """ + Placeholder for specifying unbounded edition support. This should only + ever be used by plugins that can expect to never require any changes to + support a new edition. + """ + + +class ExtensionRangeOptionsVerificationState(aristaproto.Enum): + """The verification state of the extension range.""" + + DECLARATION = 0 + """All the extensions of the range must be declared.""" + + UNVERIFIED = 1 + + +class FieldDescriptorProtoType(aristaproto.Enum): + TYPE_DOUBLE = 1 + """ + 0 is reserved for errors. + Order is weird for historical reasons. + """ + + TYPE_FLOAT = 2 + TYPE_INT64 = 3 + """ + Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if + negative values are likely. + """ + + TYPE_UINT64 = 4 + TYPE_INT32 = 5 + """ + Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if + negative values are likely. + """ + + TYPE_FIXED64 = 6 + TYPE_FIXED32 = 7 + TYPE_BOOL = 8 + TYPE_STRING = 9 + TYPE_GROUP = 10 + """ + Tag-delimited aggregate. + Group type is deprecated and not supported after google.protobuf. However, Proto3 + implementations should still be able to parse the group wire format and + treat group fields as unknown fields. In Editions, the group wire format + can be enabled via the `message_encoding` feature. + """ + + TYPE_MESSAGE = 11 + TYPE_BYTES = 12 + """New in version 2.""" + + TYPE_UINT32 = 13 + TYPE_ENUM = 14 + TYPE_SFIXED32 = 15 + TYPE_SFIXED64 = 16 + TYPE_SINT32 = 17 + TYPE_SINT64 = 18 + + +class FieldDescriptorProtoLabel(aristaproto.Enum): + LABEL_OPTIONAL = 1 + """0 is reserved for errors""" + + LABEL_REPEATED = 3 + LABEL_REQUIRED = 2 + """ + The required label is only allowed in google.protobuf. In proto3 and Editions + it's explicitly prohibited. In Editions, the `field_presence` feature + can be used to get this behavior. + """ + + +class FileOptionsOptimizeMode(aristaproto.Enum): + """Generated classes can be optimized for speed or code size.""" + + SPEED = 1 + CODE_SIZE = 2 + """etc.""" + + LITE_RUNTIME = 3 + + +class FieldOptionsCType(aristaproto.Enum): + STRING = 0 + """Default mode.""" + + CORD = 1 + """ + The option [ctype=CORD] may be applied to a non-repeated field of type + "bytes". It indicates that in C++, the data should be stored in a Cord + instead of a string. For very large strings, this may reduce memory + fragmentation. It may also allow better performance when parsing from a + Cord, or when parsing with aliasing enabled, as the parsed Cord may then + alias the original buffer. + """ + + STRING_PIECE = 2 + + +class FieldOptionsJsType(aristaproto.Enum): + JS_NORMAL = 0 + """Use the default type.""" + + JS_STRING = 1 + """Use JavaScript strings.""" + + JS_NUMBER = 2 + """Use JavaScript numbers.""" + + +class FieldOptionsOptionRetention(aristaproto.Enum): + """ + If set to RETENTION_SOURCE, the option will be omitted from the binary. + Note: as of January 2023, support for this is in progress and does not yet + have an effect (b/264593489). + """ + + RETENTION_UNKNOWN = 0 + RETENTION_RUNTIME = 1 + RETENTION_SOURCE = 2 + + +class FieldOptionsOptionTargetType(aristaproto.Enum): + """ + This indicates the types of entities that the field may apply to when used + as an option. If it is unset, then the field may be freely used as an + option on any kind of entity. Note: as of January 2023, support for this is + in progress and does not yet have an effect (b/264593489). + """ + + TARGET_TYPE_UNKNOWN = 0 + TARGET_TYPE_FILE = 1 + TARGET_TYPE_EXTENSION_RANGE = 2 + TARGET_TYPE_MESSAGE = 3 + TARGET_TYPE_FIELD = 4 + TARGET_TYPE_ONEOF = 5 + TARGET_TYPE_ENUM = 6 + TARGET_TYPE_ENUM_ENTRY = 7 + TARGET_TYPE_SERVICE = 8 + TARGET_TYPE_METHOD = 9 + + +class MethodOptionsIdempotencyLevel(aristaproto.Enum): + """ + Is this method side-effect-free (or safe in HTTP parlance), or idempotent, + or neither? HTTP based RPC implementation may choose GET verb for safe + methods, and PUT verb for idempotent methods instead of the default POST. + """ + + IDEMPOTENCY_UNKNOWN = 0 + NO_SIDE_EFFECTS = 1 + IDEMPOTENT = 2 + + +class FeatureSetFieldPresence(aristaproto.Enum): + FIELD_PRESENCE_UNKNOWN = 0 + EXPLICIT = 1 + IMPLICIT = 2 + LEGACY_REQUIRED = 3 + + +class FeatureSetEnumType(aristaproto.Enum): + ENUM_TYPE_UNKNOWN = 0 + OPEN = 1 + CLOSED = 2 + + +class FeatureSetRepeatedFieldEncoding(aristaproto.Enum): + REPEATED_FIELD_ENCODING_UNKNOWN = 0 + PACKED = 1 + EXPANDED = 2 + + +class FeatureSetUtf8Validation(aristaproto.Enum): + UTF8_VALIDATION_UNKNOWN = 0 + VERIFY = 2 + NONE = 3 + + +class FeatureSetMessageEncoding(aristaproto.Enum): + MESSAGE_ENCODING_UNKNOWN = 0 + LENGTH_PREFIXED = 1 + DELIMITED = 2 + + +class FeatureSetJsonFormat(aristaproto.Enum): + JSON_FORMAT_UNKNOWN = 0 + ALLOW = 1 + LEGACY_BEST_EFFORT = 2 + + +class GeneratedCodeInfoAnnotationSemantic(aristaproto.Enum): + """ + Represents the identified object's effect on the element in the original + .proto file. + """ + + NONE = 0 + """There is no effect or the effect is indescribable.""" + + SET = 1 + """The element is set or otherwise mutated.""" + + ALIAS = 2 + """An alias to the element is returned.""" + + +class NullValue(aristaproto.Enum): + """ + `NullValue` is a singleton enumeration to represent the null value for the + `Value` type union. + + The JSON representation for `NullValue` is JSON `null`. + """ + + _ = 0 + """Null value.""" + + +@dataclass(eq=False, repr=False) +class Any(aristaproto.Message): + """ + `Any` contains an arbitrary serialized protocol buffer message along with a + URL that describes the type of the serialized message. + + Protobuf library provides support to pack/unpack Any values in the form + of utility functions or additional generated methods of the Any type. + + Example 1: Pack and unpack a message in C++. + + Foo foo = ...; + Any any; + any.PackFrom(foo); + ... + if (any.UnpackTo(&foo)) { + ... + } + + Example 2: Pack and unpack a message in Java. + + Foo foo = ...; + Any any = Any.pack(foo); + ... + if (any.is(Foo.class)) { + foo = any.unpack(Foo.class); + } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } + + Example 3: Pack and unpack a message in Python. + + foo = Foo(...) + any = Any() + any.Pack(foo) + ... + if any.Is(Foo.DESCRIPTOR): + any.Unpack(foo) + ... + + Example 4: Pack and unpack a message in Go + + foo := &pb.Foo{...} + any, err := anypb.New(foo) + if err != nil { + ... + } + ... + foo := &pb.Foo{} + if err := any.UnmarshalTo(foo); err != nil { + ... + } + + The pack methods provided by protobuf library will by default use + 'type.googleapis.com/full.type.name' as the type URL and the unpack + methods only use the fully qualified type name after the last '/' + in the type URL, for example "foo.bar.com/x/y.z" will yield type + name "y.z". + + JSON + ==== + The JSON representation of an `Any` value uses the regular + representation of the deserialized, embedded message, with an + additional field `@type` which contains the type URL. Example: + + package google.profile; + message Person { + string first_name = 1; + string last_name = 2; + } + + { + "@type": "type.googleapis.com/google.profile.Person", + "firstName": <string>, + "lastName": <string> + } + + If the embedded message type is well-known and has a custom JSON + representation, that representation will be embedded adding a field + `value` which holds the custom JSON in addition to the `@type` + field. Example (for message [google.protobuf.Duration][]): + + { + "@type": "type.googleapis.com/google.protobuf.Duration", + "value": "1.212s" + } + """ + + type_url: str = aristaproto.string_field(1) + """ + A URL/resource name that uniquely identifies the type of the serialized + protocol buffer message. This string must contain at least + one "/" character. The last segment of the URL's path must represent + the fully qualified name of the type (as in + `path/google.protobuf.Duration`). The name should be in a canonical form + (e.g., leading "." is not accepted). + + In practice, teams usually precompile into the binary all types that they + expect it to use in the context of Any. However, for URLs which use the + scheme `http`, `https`, or no scheme, one can optionally set up a type + server that maps type URLs to message definitions as follows: + + * If no scheme is provided, `https` is assumed. + * An HTTP GET on the URL must yield a [google.protobuf.Type][] + value in binary format, or produce an error. + * Applications are allowed to cache lookup results based on the + URL, or have them precompiled into a binary to avoid any + lookup. Therefore, binary compatibility needs to be preserved + on changes to types. (Use versioned type names to manage + breaking changes.) + + Note: this functionality is not currently available in the official + protobuf release, and it is not used for type URLs beginning with + type.googleapis.com. As of May 2023, there are no widely used type server + implementations and no plans to implement one. + + Schemes other than `http`, `https` (or the empty scheme) might be + used with implementation specific semantics. + """ + + value: bytes = aristaproto.bytes_field(2) + """ + Must be a valid serialized protocol buffer of the above specified type. + """ + + +@dataclass(eq=False, repr=False) +class SourceContext(aristaproto.Message): + """ + `SourceContext` represents information about the source of a + protobuf element, like the file in which it is defined. + """ + + file_name: str = aristaproto.string_field(1) + """ + The path-qualified name of the .proto file that contained the associated + protobuf element. For example: `"google/protobuf/source_context.proto"`. + """ + + +@dataclass(eq=False, repr=False) +class Type(aristaproto.Message): + """A protocol buffer message type.""" + + name: str = aristaproto.string_field(1) + """The fully qualified message name.""" + + fields: List["Field"] = aristaproto.message_field(2) + """The list of fields.""" + + oneofs: List[str] = aristaproto.string_field(3) + """The list of types appearing in `oneof` definitions in this type.""" + + options: List["Option"] = aristaproto.message_field(4) + """The protocol buffer options.""" + + source_context: "SourceContext" = aristaproto.message_field(5) + """The source context.""" + + syntax: "Syntax" = aristaproto.enum_field(6) + """The source syntax.""" + + edition: str = aristaproto.string_field(7) + """ + The source edition string, only valid when syntax is SYNTAX_EDITIONS. + """ + + +@dataclass(eq=False, repr=False) +class Field(aristaproto.Message): + """A single field of a message type.""" + + kind: "FieldKind" = aristaproto.enum_field(1) + """The field type.""" + + cardinality: "FieldCardinality" = aristaproto.enum_field(2) + """The field cardinality.""" + + number: int = aristaproto.int32_field(3) + """The field number.""" + + name: str = aristaproto.string_field(4) + """The field name.""" + + type_url: str = aristaproto.string_field(6) + """ + The field type URL, without the scheme, for message or enumeration + types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`. + """ + + oneof_index: int = aristaproto.int32_field(7) + """ + The index of the field type in `Type.oneofs`, for message or enumeration + types. The first type has index 1; zero means the type is not in the list. + """ + + packed: bool = aristaproto.bool_field(8) + """Whether to use alternative packed wire representation.""" + + options: List["Option"] = aristaproto.message_field(9) + """The protocol buffer options.""" + + json_name: str = aristaproto.string_field(10) + """The field JSON name.""" + + default_value: str = aristaproto.string_field(11) + """ + The string value of the default value of this field. Proto2 syntax only. + """ + + +@dataclass(eq=False, repr=False) +class Enum(aristaproto.Message): + """Enum type definition.""" + + name: str = aristaproto.string_field(1) + """Enum type name.""" + + enumvalue: List["EnumValue"] = aristaproto.message_field( + 2, wraps=aristaproto.TYPE_ENUM + ) + """Enum value definitions.""" + + options: List["Option"] = aristaproto.message_field(3) + """Protocol buffer options.""" + + source_context: "SourceContext" = aristaproto.message_field(4) + """The source context.""" + + syntax: "Syntax" = aristaproto.enum_field(5) + """The source syntax.""" + + edition: str = aristaproto.string_field(6) + """ + The source edition string, only valid when syntax is SYNTAX_EDITIONS. + """ + + +@dataclass(eq=False, repr=False) +class EnumValue(aristaproto.Message): + """Enum value definition.""" + + name: str = aristaproto.string_field(1) + """Enum value name.""" + + number: int = aristaproto.int32_field(2) + """Enum value number.""" + + options: List["Option"] = aristaproto.message_field(3) + """Protocol buffer options.""" + + +@dataclass(eq=False, repr=False) +class Option(aristaproto.Message): + """ + A protocol buffer option, which can be attached to a message, field, + enumeration, etc. + """ + + name: str = aristaproto.string_field(1) + """ + The option's name. For protobuf built-in options (options defined in + descriptor.proto), this is the short name. For example, `"map_entry"`. + For custom options, it should be the fully-qualified name. For example, + `"google.api.http"`. + """ + + value: "Any" = aristaproto.message_field(2) + """ + The option's value packed in an Any message. If the value is a primitive, + the corresponding wrapper type defined in google/protobuf/wrappers.proto + should be used. If the value is an enum, it should be stored as an int32 + value using the google.protobuf.Int32Value type. + """ + + +@dataclass(eq=False, repr=False) +class Api(aristaproto.Message): + """ + Api is a light-weight descriptor for an API Interface. + + Interfaces are also described as "protocol buffer services" in some contexts, + such as by the "service" keyword in a .proto file, but they are different + from API Services, which represent a concrete implementation of an interface + as opposed to simply a description of methods and bindings. They are also + sometimes simply referred to as "APIs" in other contexts, such as the name of + this message itself. See https://cloud.google.com/apis/design/glossary for + detailed terminology. + """ + + name: str = aristaproto.string_field(1) + """ + The fully qualified name of this interface, including package name + followed by the interface's simple name. + """ + + methods: List["Method"] = aristaproto.message_field(2) + """The methods of this interface, in unspecified order.""" + + options: List["Option"] = aristaproto.message_field(3) + """Any metadata attached to the interface.""" + + version: str = aristaproto.string_field(4) + """ + A version string for this interface. If specified, must have the form + `major-version.minor-version`, as in `1.10`. If the minor version is + omitted, it defaults to zero. If the entire version field is empty, the + major version is derived from the package name, as outlined below. If the + field is not empty, the version in the package name will be verified to be + consistent with what is provided here. + + The versioning schema uses [semantic + versioning](http://semver.org) where the major version number + indicates a breaking change and the minor version an additive, + non-breaking change. Both version numbers are signals to users + what to expect from different versions, and should be carefully + chosen based on the product plan. + + The major version is also reflected in the package name of the + interface, which must end in `v<major-version>`, as in + `google.feature.v1`. For major versions 0 and 1, the suffix can + be omitted. Zero major versions must only be used for + experimental, non-GA interfaces. + """ + + source_context: "SourceContext" = aristaproto.message_field(5) + """ + Source context for the protocol buffer service represented by this + message. + """ + + mixins: List["Mixin"] = aristaproto.message_field(6) + """Included interfaces. See [Mixin][].""" + + syntax: "Syntax" = aristaproto.enum_field(7) + """The source syntax of the service.""" + + +@dataclass(eq=False, repr=False) +class Method(aristaproto.Message): + """Method represents a method of an API interface.""" + + name: str = aristaproto.string_field(1) + """The simple name of this method.""" + + request_type_url: str = aristaproto.string_field(2) + """A URL of the input message type.""" + + request_streaming: bool = aristaproto.bool_field(3) + """If true, the request is streamed.""" + + response_type_url: str = aristaproto.string_field(4) + """The URL of the output message type.""" + + response_streaming: bool = aristaproto.bool_field(5) + """If true, the response is streamed.""" + + options: List["Option"] = aristaproto.message_field(6) + """Any metadata attached to the method.""" + + syntax: "Syntax" = aristaproto.enum_field(7) + """The source syntax of this method.""" + + +@dataclass(eq=False, repr=False) +class Mixin(aristaproto.Message): + """ + Declares an API Interface to be included in this interface. The including + interface must redeclare all the methods from the included interface, but + documentation and options are inherited as follows: + + - If after comment and whitespace stripping, the documentation + string of the redeclared method is empty, it will be inherited + from the original method. + + - Each annotation belonging to the service config (http, + visibility) which is not set in the redeclared method will be + inherited. + + - If an http annotation is inherited, the path pattern will be + modified as follows. Any version prefix will be replaced by the + version of the including interface plus the [root][] path if + specified. + + Example of a simple mixin: + + package google.acl.v1; + service AccessControl { + // Get the underlying ACL object. + rpc GetAcl(GetAclRequest) returns (Acl) { + option (google.api.http).get = "/v1/{resource=**}:getAcl"; + } + } + + package google.storage.v2; + service Storage { + rpc GetAcl(GetAclRequest) returns (Acl); + + // Get a data record. + rpc GetData(GetDataRequest) returns (Data) { + option (google.api.http).get = "/v2/{resource=**}"; + } + } + + Example of a mixin configuration: + + apis: + - name: google.storage.v2.Storage + mixins: + - name: google.acl.v1.AccessControl + + The mixin construct implies that all methods in `AccessControl` are + also declared with same name and request/response types in + `Storage`. A documentation generator or annotation processor will + see the effective `Storage.GetAcl` method after inherting + documentation and annotations as follows: + + service Storage { + // Get the underlying ACL object. + rpc GetAcl(GetAclRequest) returns (Acl) { + option (google.api.http).get = "/v2/{resource=**}:getAcl"; + } + ... + } + + Note how the version in the path pattern changed from `v1` to `v2`. + + If the `root` field in the mixin is specified, it should be a + relative path under which inherited HTTP paths are placed. Example: + + apis: + - name: google.storage.v2.Storage + mixins: + - name: google.acl.v1.AccessControl + root: acls + + This implies the following inherited HTTP annotation: + + service Storage { + // Get the underlying ACL object. + rpc GetAcl(GetAclRequest) returns (Acl) { + option (google.api.http).get = "/v2/acls/{resource=**}:getAcl"; + } + ... + } + """ + + name: str = aristaproto.string_field(1) + """The fully qualified name of the interface which is included.""" + + root: str = aristaproto.string_field(2) + """ + If non-empty specifies a path under which inherited HTTP paths + are rooted. + """ + + +@dataclass(eq=False, repr=False) +class FileDescriptorSet(aristaproto.Message): + """ + The protocol compiler can output a FileDescriptorSet containing the .proto + files it parses. + """ + + file: List["FileDescriptorProto"] = aristaproto.message_field(1) + + +@dataclass(eq=False, repr=False) +class FileDescriptorProto(aristaproto.Message): + """Describes a complete .proto file.""" + + name: str = aristaproto.string_field(1) + package: str = aristaproto.string_field(2) + dependency: List[str] = aristaproto.string_field(3) + """Names of files imported by this file.""" + + public_dependency: List[int] = aristaproto.int32_field(10) + """Indexes of the public imported files in the dependency list above.""" + + weak_dependency: List[int] = aristaproto.int32_field(11) + """ + Indexes of the weak imported files in the dependency list. + For Google-internal migration only. Do not use. + """ + + message_type: List["DescriptorProto"] = aristaproto.message_field(4) + """All top-level definitions in this file.""" + + enum_type: List["EnumDescriptorProto"] = aristaproto.message_field(5) + service: List["ServiceDescriptorProto"] = aristaproto.message_field(6) + extension: List["FieldDescriptorProto"] = aristaproto.message_field(7) + options: "FileOptions" = aristaproto.message_field(8) + source_code_info: "SourceCodeInfo" = aristaproto.message_field(9) + """ + This field contains optional information about the original source code. + You may safely remove this entire field without harming runtime + functionality of the descriptors -- the information is needed only by + development tools. + """ + + syntax: str = aristaproto.string_field(12) + """ + The syntax of the proto file. + The supported values are "proto2", "proto3", and "editions". + + If `edition` is present, this value must be "editions". + """ + + edition: "Edition" = aristaproto.enum_field(14) + """The edition of the proto file.""" + + +@dataclass(eq=False, repr=False) +class DescriptorProto(aristaproto.Message): + """Describes a message type.""" + + name: str = aristaproto.string_field(1) + field: List["FieldDescriptorProto"] = aristaproto.message_field(2) + extension: List["FieldDescriptorProto"] = aristaproto.message_field(6) + nested_type: List["DescriptorProto"] = aristaproto.message_field(3) + enum_type: List["EnumDescriptorProto"] = aristaproto.message_field(4) + extension_range: List["DescriptorProtoExtensionRange"] = aristaproto.message_field( + 5 + ) + oneof_decl: List["OneofDescriptorProto"] = aristaproto.message_field(8) + options: "MessageOptions" = aristaproto.message_field(7) + reserved_range: List["DescriptorProtoReservedRange"] = aristaproto.message_field(9) + reserved_name: List[str] = aristaproto.string_field(10) + """ + Reserved field names, which may not be used by fields in the same message. + A given name may only be reserved once. + """ + + +@dataclass(eq=False, repr=False) +class DescriptorProtoExtensionRange(aristaproto.Message): + start: int = aristaproto.int32_field(1) + end: int = aristaproto.int32_field(2) + options: "ExtensionRangeOptions" = aristaproto.message_field(3) + + +@dataclass(eq=False, repr=False) +class DescriptorProtoReservedRange(aristaproto.Message): + """ + Range of reserved tag numbers. Reserved tag numbers may not be used by + fields or extension ranges in the same message. Reserved ranges may + not overlap. + """ + + start: int = aristaproto.int32_field(1) + end: int = aristaproto.int32_field(2) + + +@dataclass(eq=False, repr=False) +class ExtensionRangeOptions(aristaproto.Message): + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """The parser stores options it doesn't recognize here. See above.""" + + declaration: List["ExtensionRangeOptionsDeclaration"] = aristaproto.message_field(2) + """ + For external users: DO NOT USE. We are in the process of open sourcing + extension declaration and executing internal cleanups before it can be + used externally. + """ + + features: "FeatureSet" = aristaproto.message_field(50) + """Any features defined in the specific edition.""" + + verification: "ExtensionRangeOptionsVerificationState" = aristaproto.enum_field(3) + """ + The verification state of the range. + TODO: flip the default to DECLARATION once all empty ranges + are marked as UNVERIFIED. + """ + + +@dataclass(eq=False, repr=False) +class ExtensionRangeOptionsDeclaration(aristaproto.Message): + number: int = aristaproto.int32_field(1) + """The extension number declared within the extension range.""" + + full_name: str = aristaproto.string_field(2) + """ + The fully-qualified name of the extension field. There must be a leading + dot in front of the full name. + """ + + type: str = aristaproto.string_field(3) + """ + The fully-qualified type name of the extension field. Unlike + Metadata.type, Declaration.type must have a leading dot for messages + and enums. + """ + + reserved: bool = aristaproto.bool_field(5) + """ + If true, indicates that the number is reserved in the extension range, + and any extension field with the number will fail to compile. Set this + when a declared extension field is deleted. + """ + + repeated: bool = aristaproto.bool_field(6) + """ + If true, indicates that the extension must be defined as repeated. + Otherwise the extension must be defined as optional. + """ + + +@dataclass(eq=False, repr=False) +class FieldDescriptorProto(aristaproto.Message): + """Describes a field within a message.""" + + name: str = aristaproto.string_field(1) + number: int = aristaproto.int32_field(3) + label: "FieldDescriptorProtoLabel" = aristaproto.enum_field(4) + type: "FieldDescriptorProtoType" = aristaproto.enum_field(5) + """ + If type_name is set, this need not be set. If both this and type_name + are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP. + """ + + type_name: str = aristaproto.string_field(6) + """ + For message and enum types, this is the name of the type. If the name + starts with a '.', it is fully-qualified. Otherwise, C++-like scoping + rules are used to find the type (i.e. first the nested types within this + message are searched, then within the parent, on up to the root + namespace). + """ + + extendee: str = aristaproto.string_field(2) + """ + For extensions, this is the name of the type being extended. It is + resolved in the same manner as type_name. + """ + + default_value: str = aristaproto.string_field(7) + """ + For numeric types, contains the original text representation of the value. + For booleans, "true" or "false". + For strings, contains the default text contents (not escaped in any way). + For bytes, contains the C escaped value. All bytes >= 128 are escaped. + """ + + oneof_index: int = aristaproto.int32_field(9) + """ + If set, gives the index of a oneof in the containing type's oneof_decl + list. This field is a member of that oneof. + """ + + json_name: str = aristaproto.string_field(10) + """ + JSON name of this field. The value is set by protocol compiler. If the + user has set a "json_name" option on this field, that option's value + will be used. Otherwise, it's deduced from the field's name by converting + it to camelCase. + """ + + options: "FieldOptions" = aristaproto.message_field(8) + proto3_optional: bool = aristaproto.bool_field(17) + """ + If true, this is a proto3 "optional". When a proto3 field is optional, it + tracks presence regardless of field type. + + When proto3_optional is true, this field must belong to a oneof to signal + to old proto3 clients that presence is tracked for this field. This oneof + is known as a "synthetic" oneof, and this field must be its sole member + (each proto3 optional field gets its own synthetic oneof). Synthetic oneofs + exist in the descriptor only, and do not generate any API. Synthetic oneofs + must be ordered after all "real" oneofs. + + For message fields, proto3_optional doesn't create any semantic change, + since non-repeated message fields always track presence. However it still + indicates the semantic detail of whether the user wrote "optional" or not. + This can be useful for round-tripping the .proto file. For consistency we + give message fields a synthetic oneof also, even though it is not required + to track presence. This is especially important because the parser can't + tell if a field is a message or an enum, so it must always create a + synthetic oneof. + + Proto2 optional fields do not set this flag, because they already indicate + optional with `LABEL_OPTIONAL`. + """ + + +@dataclass(eq=False, repr=False) +class OneofDescriptorProto(aristaproto.Message): + """Describes a oneof.""" + + name: str = aristaproto.string_field(1) + options: "OneofOptions" = aristaproto.message_field(2) + + +@dataclass(eq=False, repr=False) +class EnumDescriptorProto(aristaproto.Message): + """Describes an enum type.""" + + name: str = aristaproto.string_field(1) + value: List["EnumValueDescriptorProto"] = aristaproto.message_field(2) + options: "EnumOptions" = aristaproto.message_field(3) + reserved_range: List[ + "EnumDescriptorProtoEnumReservedRange" + ] = aristaproto.message_field(4) + """ + Range of reserved numeric values. Reserved numeric values may not be used + by enum values in the same enum declaration. Reserved ranges may not + overlap. + """ + + reserved_name: List[str] = aristaproto.string_field(5) + """ + Reserved enum value names, which may not be reused. A given name may only + be reserved once. + """ + + +@dataclass(eq=False, repr=False) +class EnumDescriptorProtoEnumReservedRange(aristaproto.Message): + """ + Range of reserved numeric values. Reserved values may not be used by + entries in the same enum. Reserved ranges may not overlap. + + Note that this is distinct from DescriptorProto.ReservedRange in that it + is inclusive such that it can appropriately represent the entire int32 + domain. + """ + + start: int = aristaproto.int32_field(1) + end: int = aristaproto.int32_field(2) + + +@dataclass(eq=False, repr=False) +class EnumValueDescriptorProto(aristaproto.Message): + """Describes a value within an enum.""" + + name: str = aristaproto.string_field(1) + number: int = aristaproto.int32_field(2) + options: "EnumValueOptions" = aristaproto.message_field(3) + + +@dataclass(eq=False, repr=False) +class ServiceDescriptorProto(aristaproto.Message): + """Describes a service.""" + + name: str = aristaproto.string_field(1) + method: List["MethodDescriptorProto"] = aristaproto.message_field(2) + options: "ServiceOptions" = aristaproto.message_field(3) + + +@dataclass(eq=False, repr=False) +class MethodDescriptorProto(aristaproto.Message): + """Describes a method of a service.""" + + name: str = aristaproto.string_field(1) + input_type: str = aristaproto.string_field(2) + """ + Input and output type names. These are resolved in the same way as + FieldDescriptorProto.type_name, but must refer to a message type. + """ + + output_type: str = aristaproto.string_field(3) + options: "MethodOptions" = aristaproto.message_field(4) + client_streaming: bool = aristaproto.bool_field(5) + """Identifies if client streams multiple client messages""" + + server_streaming: bool = aristaproto.bool_field(6) + """Identifies if server streams multiple server messages""" + + +@dataclass(eq=False, repr=False) +class FileOptions(aristaproto.Message): + java_package: str = aristaproto.string_field(1) + """ + Sets the Java package where classes generated from this .proto will be + placed. By default, the proto package is used, but this is often + inappropriate because proto packages do not normally start with backwards + domain names. + """ + + java_outer_classname: str = aristaproto.string_field(8) + """ + Controls the name of the wrapper Java class generated for the .proto file. + That class will always contain the .proto file's getDescriptor() method as + well as any top-level extensions defined in the .proto file. + If java_multiple_files is disabled, then all the other classes from the + .proto file will be nested inside the single wrapper outer class. + """ + + java_multiple_files: bool = aristaproto.bool_field(10) + """ + If enabled, then the Java code generator will generate a separate .java + file for each top-level message, enum, and service defined in the .proto + file. Thus, these types will *not* be nested inside the wrapper class + named by java_outer_classname. However, the wrapper class will still be + generated to contain the file's getDescriptor() method as well as any + top-level extensions defined in the file. + """ + + java_generate_equals_and_hash: bool = aristaproto.bool_field(20) + """This option does nothing.""" + + java_string_check_utf8: bool = aristaproto.bool_field(27) + """ + A proto2 file can set this to true to opt in to UTF-8 checking for Java, + which will throw an exception if invalid UTF-8 is parsed from the wire or + assigned to a string field. + + TODO: clarify exactly what kinds of field types this option + applies to, and update these docs accordingly. + + Proto3 files already perform these checks. Setting the option explicitly to + false has no effect: it cannot be used to opt proto3 files out of UTF-8 + checks. + """ + + optimize_for: "FileOptionsOptimizeMode" = aristaproto.enum_field(9) + go_package: str = aristaproto.string_field(11) + """ + Sets the Go package where structs generated from this .proto will be + placed. If omitted, the Go package will be derived from the following: + - The basename of the package import path, if provided. + - Otherwise, the package statement in the .proto file, if present. + - Otherwise, the basename of the .proto file, without extension. + """ + + cc_generic_services: bool = aristaproto.bool_field(16) + """ + Should generic services be generated in each language? "Generic" services + are not specific to any particular RPC system. They are generated by the + main code generators in each language (without additional plugins). + Generic services were the only kind of service generation supported by + early versions of google.protobuf. + + Generic services are now considered deprecated in favor of using plugins + that generate code specific to your particular RPC system. Therefore, + these default to false. Old code which depends on generic services should + explicitly set them to true. + """ + + java_generic_services: bool = aristaproto.bool_field(17) + py_generic_services: bool = aristaproto.bool_field(18) + deprecated: bool = aristaproto.bool_field(23) + """ + Is this file deprecated? + Depending on the target platform, this can emit Deprecated annotations + for everything in the file, or it will be completely ignored; in the very + least, this is a formalization for deprecating files. + """ + + cc_enable_arenas: bool = aristaproto.bool_field(31) + """ + Enables the use of arenas for the proto messages in this file. This applies + only to generated classes for C++. + """ + + objc_class_prefix: str = aristaproto.string_field(36) + """ + Sets the objective c class prefix which is prepended to all objective c + generated classes from this .proto. There is no default. + """ + + csharp_namespace: str = aristaproto.string_field(37) + """Namespace for generated classes; defaults to the package.""" + + swift_prefix: str = aristaproto.string_field(39) + """ + By default Swift generators will take the proto package and CamelCase it + replacing '.' with underscore and use that to prefix the types/symbols + defined. When this options is provided, they will use this value instead + to prefix the types/symbols defined. + """ + + php_class_prefix: str = aristaproto.string_field(40) + """ + Sets the php class prefix which is prepended to all php generated classes + from this .proto. Default is empty. + """ + + php_namespace: str = aristaproto.string_field(41) + """ + Use this option to change the namespace of php generated classes. Default + is empty. When this option is empty, the package name will be used for + determining the namespace. + """ + + php_metadata_namespace: str = aristaproto.string_field(44) + """ + Use this option to change the namespace of php generated metadata classes. + Default is empty. When this option is empty, the proto file name will be + used for determining the namespace. + """ + + ruby_package: str = aristaproto.string_field(45) + """ + Use this option to change the package of ruby generated classes. Default + is empty. When this option is not set, the package name will be used for + determining the ruby package. + """ + + features: "FeatureSet" = aristaproto.message_field(50) + """Any features defined in the specific edition.""" + + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """ + The parser stores options it doesn't recognize here. + See the documentation for the "Options" section above. + """ + + def __post_init__(self) -> None: + super().__post_init__() + if self.is_set("java_generate_equals_and_hash"): + warnings.warn( + "FileOptions.java_generate_equals_and_hash is deprecated", + DeprecationWarning, + ) + + +@dataclass(eq=False, repr=False) +class MessageOptions(aristaproto.Message): + message_set_wire_format: bool = aristaproto.bool_field(1) + """ + Set true to use the old proto1 MessageSet wire format for extensions. + This is provided for backwards-compatibility with the MessageSet wire + format. You should not use this for any other reason: It's less + efficient, has fewer features, and is more complicated. + + The message must be defined exactly as follows: + message Foo { + option message_set_wire_format = true; + extensions 4 to max; + } + Note that the message cannot have any defined fields; MessageSets only + have extensions. + + All extensions of your type must be singular messages; e.g. they cannot + be int32s, enums, or repeated messages. + + Because this is an option, the above two restrictions are not enforced by + the protocol compiler. + """ + + no_standard_descriptor_accessor: bool = aristaproto.bool_field(2) + """ + Disables the generation of the standard "descriptor()" accessor, which can + conflict with a field of the same name. This is meant to make migration + from proto1 easier; new code should avoid fields named "descriptor". + """ + + deprecated: bool = aristaproto.bool_field(3) + """ + Is this message deprecated? + Depending on the target platform, this can emit Deprecated annotations + for the message, or it will be completely ignored; in the very least, + this is a formalization for deprecating messages. + """ + + map_entry: bool = aristaproto.bool_field(7) + """ + Whether the message is an automatically generated map entry type for the + maps field. + + For maps fields: + map<KeyType, ValueType> map_field = 1; + The parsed descriptor looks like: + message MapFieldEntry { + option map_entry = true; + optional KeyType key = 1; + optional ValueType value = 2; + } + repeated MapFieldEntry map_field = 1; + + Implementations may choose not to generate the map_entry=true message, but + use a native map in the target language to hold the keys and values. + The reflection APIs in such implementations still need to work as + if the field is a repeated message field. + + NOTE: Do not set the option in .proto files. Always use the maps syntax + instead. The option should only be implicitly set by the proto compiler + parser. + """ + + deprecated_legacy_json_field_conflicts: bool = aristaproto.bool_field(11) + """ + Enable the legacy handling of JSON field name conflicts. This lowercases + and strips underscored from the fields before comparison in proto3 only. + The new behavior takes `json_name` into account and applies to proto2 as + well. + + This should only be used as a temporary measure against broken builds due + to the change in behavior for JSON field name conflicts. + + TODO This is legacy behavior we plan to remove once downstream + teams have had time to migrate. + """ + + features: "FeatureSet" = aristaproto.message_field(12) + """Any features defined in the specific edition.""" + + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """The parser stores options it doesn't recognize here. See above.""" + + def __post_init__(self) -> None: + super().__post_init__() + if self.is_set("deprecated_legacy_json_field_conflicts"): + warnings.warn( + "MessageOptions.deprecated_legacy_json_field_conflicts is deprecated", + DeprecationWarning, + ) + + +@dataclass(eq=False, repr=False) +class FieldOptions(aristaproto.Message): + ctype: "FieldOptionsCType" = aristaproto.enum_field(1) + """ + The ctype option instructs the C++ code generator to use a different + representation of the field than it normally would. See the specific + options below. This option is only implemented to support use of + [ctype=CORD] and [ctype=STRING] (the default) on non-repeated fields of + type "bytes" in the open source release -- sorry, we'll try to include + other types in a future version! + """ + + packed: bool = aristaproto.bool_field(2) + """ + The packed option can be enabled for repeated primitive fields to enable + a more efficient representation on the wire. Rather than repeatedly + writing the tag and type for each element, the entire array is encoded as + a single length-delimited blob. In proto3, only explicit setting it to + false will avoid using packed encoding. This option is prohibited in + Editions, but the `repeated_field_encoding` feature can be used to control + the behavior. + """ + + jstype: "FieldOptionsJsType" = aristaproto.enum_field(6) + """ + The jstype option determines the JavaScript type used for values of the + field. The option is permitted only for 64 bit integral and fixed types + (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING + is represented as JavaScript string, which avoids loss of precision that + can happen when a large value is converted to a floating point JavaScript. + Specifying JS_NUMBER for the jstype causes the generated JavaScript code to + use the JavaScript "number" type. The behavior of the default option + JS_NORMAL is implementation dependent. + + This option is an enum to permit additional types to be added, e.g. + goog.math.Integer. + """ + + lazy: bool = aristaproto.bool_field(5) + """ + Should this field be parsed lazily? Lazy applies only to message-type + fields. It means that when the outer message is initially parsed, the + inner message's contents will not be parsed but instead stored in encoded + form. The inner message will actually be parsed when it is first accessed. + + This is only a hint. Implementations are free to choose whether to use + eager or lazy parsing regardless of the value of this option. However, + setting this option true suggests that the protocol author believes that + using lazy parsing on this field is worth the additional bookkeeping + overhead typically needed to implement it. + + This option does not affect the public interface of any generated code; + all method signatures remain the same. Furthermore, thread-safety of the + interface is not affected by this option; const methods remain safe to + call from multiple threads concurrently, while non-const methods continue + to require exclusive access. + + Note that lazy message fields are still eagerly verified to check + ill-formed wireformat or missing required fields. Calling IsInitialized() + on the outer message would fail if the inner message has missing required + fields. Failed verification would result in parsing failure (except when + uninitialized messages are acceptable). + """ + + unverified_lazy: bool = aristaproto.bool_field(15) + """ + unverified_lazy does no correctness checks on the byte stream. This should + only be used where lazy with verification is prohibitive for performance + reasons. + """ + + deprecated: bool = aristaproto.bool_field(3) + """ + Is this field deprecated? + Depending on the target platform, this can emit Deprecated annotations + for accessors, or it will be completely ignored; in the very least, this + is a formalization for deprecating fields. + """ + + weak: bool = aristaproto.bool_field(10) + """For Google-internal migration only. Do not use.""" + + debug_redact: bool = aristaproto.bool_field(16) + """ + Indicate that the field value should not be printed out when using debug + formats, e.g. when the field contains sensitive credentials. + """ + + retention: "FieldOptionsOptionRetention" = aristaproto.enum_field(17) + targets: List["FieldOptionsOptionTargetType"] = aristaproto.enum_field(19) + edition_defaults: List["FieldOptionsEditionDefault"] = aristaproto.message_field(20) + features: "FeatureSet" = aristaproto.message_field(21) + """Any features defined in the specific edition.""" + + feature_support: "FieldOptionsFeatureSupport" = aristaproto.message_field(22) + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """The parser stores options it doesn't recognize here. See above.""" + + +@dataclass(eq=False, repr=False) +class FieldOptionsEditionDefault(aristaproto.Message): + edition: "Edition" = aristaproto.enum_field(3) + value: str = aristaproto.string_field(2) + + +@dataclass(eq=False, repr=False) +class FieldOptionsFeatureSupport(aristaproto.Message): + """Information about the support window of a feature.""" + + edition_introduced: "Edition" = aristaproto.enum_field(1) + """ + The edition that this feature was first available in. In editions + earlier than this one, the default assigned to EDITION_LEGACY will be + used, and proto files will not be able to override it. + """ + + edition_deprecated: "Edition" = aristaproto.enum_field(2) + """ + The edition this feature becomes deprecated in. Using this after this + edition may trigger warnings. + """ + + deprecation_warning: str = aristaproto.string_field(3) + """ + The deprecation warning text if this feature is used after the edition it + was marked deprecated in. + """ + + edition_removed: "Edition" = aristaproto.enum_field(4) + """ + The edition this feature is no longer available in. In editions after + this one, the last default assigned will be used, and proto files will + not be able to override it. + """ + + +@dataclass(eq=False, repr=False) +class OneofOptions(aristaproto.Message): + features: "FeatureSet" = aristaproto.message_field(1) + """Any features defined in the specific edition.""" + + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """The parser stores options it doesn't recognize here. See above.""" + + +@dataclass(eq=False, repr=False) +class EnumOptions(aristaproto.Message): + allow_alias: bool = aristaproto.bool_field(2) + """ + Set this option to true to allow mapping different tag names to the same + value. + """ + + deprecated: bool = aristaproto.bool_field(3) + """ + Is this enum deprecated? + Depending on the target platform, this can emit Deprecated annotations + for the enum, or it will be completely ignored; in the very least, this + is a formalization for deprecating enums. + """ + + deprecated_legacy_json_field_conflicts: bool = aristaproto.bool_field(6) + """ + Enable the legacy handling of JSON field name conflicts. This lowercases + and strips underscored from the fields before comparison in proto3 only. + The new behavior takes `json_name` into account and applies to proto2 as + well. + TODO Remove this legacy behavior once downstream teams have + had time to migrate. + """ + + features: "FeatureSet" = aristaproto.message_field(7) + """Any features defined in the specific edition.""" + + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """The parser stores options it doesn't recognize here. See above.""" + + def __post_init__(self) -> None: + super().__post_init__() + if self.is_set("deprecated_legacy_json_field_conflicts"): + warnings.warn( + "EnumOptions.deprecated_legacy_json_field_conflicts is deprecated", + DeprecationWarning, + ) + + +@dataclass(eq=False, repr=False) +class EnumValueOptions(aristaproto.Message): + deprecated: bool = aristaproto.bool_field(1) + """ + Is this enum value deprecated? + Depending on the target platform, this can emit Deprecated annotations + for the enum value, or it will be completely ignored; in the very least, + this is a formalization for deprecating enum values. + """ + + features: "FeatureSet" = aristaproto.message_field(2) + """Any features defined in the specific edition.""" + + debug_redact: bool = aristaproto.bool_field(3) + """ + Indicate that fields annotated with this enum value should not be printed + out when using debug formats, e.g. when the field contains sensitive + credentials. + """ + + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """The parser stores options it doesn't recognize here. See above.""" + + +@dataclass(eq=False, repr=False) +class ServiceOptions(aristaproto.Message): + features: "FeatureSet" = aristaproto.message_field(34) + """Any features defined in the specific edition.""" + + deprecated: bool = aristaproto.bool_field(33) + """ + Is this service deprecated? + Depending on the target platform, this can emit Deprecated annotations + for the service, or it will be completely ignored; in the very least, + this is a formalization for deprecating services. + """ + + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """The parser stores options it doesn't recognize here. See above.""" + + +@dataclass(eq=False, repr=False) +class MethodOptions(aristaproto.Message): + deprecated: bool = aristaproto.bool_field(33) + """ + Is this method deprecated? + Depending on the target platform, this can emit Deprecated annotations + for the method, or it will be completely ignored; in the very least, + this is a formalization for deprecating methods. + """ + + idempotency_level: "MethodOptionsIdempotencyLevel" = aristaproto.enum_field(34) + features: "FeatureSet" = aristaproto.message_field(35) + """Any features defined in the specific edition.""" + + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """The parser stores options it doesn't recognize here. See above.""" + + +@dataclass(eq=False, repr=False) +class UninterpretedOption(aristaproto.Message): + """ + A message representing a option the parser does not recognize. This only + appears in options protos created by the compiler::Parser class. + DescriptorPool resolves these when building Descriptor objects. Therefore, + options protos in descriptor objects (e.g. returned by Descriptor::options(), + or produced by Descriptor::CopyTo()) will never have UninterpretedOptions + in them. + """ + + name: List["UninterpretedOptionNamePart"] = aristaproto.message_field(2) + identifier_value: str = aristaproto.string_field(3) + """ + The value of the uninterpreted option, in whatever type the tokenizer + identified it as during parsing. Exactly one of these should be set. + """ + + positive_int_value: int = aristaproto.uint64_field(4) + negative_int_value: int = aristaproto.int64_field(5) + double_value: float = aristaproto.double_field(6) + string_value: bytes = aristaproto.bytes_field(7) + aggregate_value: str = aristaproto.string_field(8) + + +@dataclass(eq=False, repr=False) +class UninterpretedOptionNamePart(aristaproto.Message): + """ + The name of the uninterpreted option. Each string represents a segment in + a dot-separated name. is_extension is true iff a segment represents an + extension (denoted with parentheses in options specs in .proto files). + E.g.,{ ["foo", false], ["bar.baz", true], ["moo", false] } represents + "foo.(bar.baz).moo". + """ + + name_part: str = aristaproto.string_field(1) + is_extension: bool = aristaproto.bool_field(2) + + +@dataclass(eq=False, repr=False) +class FeatureSet(aristaproto.Message): + """ + TODO Enums in C++ gencode (and potentially other languages) are + not well scoped. This means that each of the feature enums below can clash + with each other. The short names we've chosen maximize call-site + readability, but leave us very open to this scenario. A future feature will + be designed and implemented to handle this, hopefully before we ever hit a + conflict here. + """ + + field_presence: "FeatureSetFieldPresence" = aristaproto.enum_field(1) + enum_type: "FeatureSetEnumType" = aristaproto.enum_field(2) + repeated_field_encoding: "FeatureSetRepeatedFieldEncoding" = aristaproto.enum_field( + 3 + ) + utf8_validation: "FeatureSetUtf8Validation" = aristaproto.enum_field(4) + message_encoding: "FeatureSetMessageEncoding" = aristaproto.enum_field(5) + json_format: "FeatureSetJsonFormat" = aristaproto.enum_field(6) + + +@dataclass(eq=False, repr=False) +class FeatureSetDefaults(aristaproto.Message): + """ + A compiled specification for the defaults of a set of features. These + messages are generated from FeatureSet extensions and can be used to seed + feature resolution. The resolution with this object becomes a simple search + for the closest matching edition, followed by proto merges. + """ + + defaults: List[ + "FeatureSetDefaultsFeatureSetEditionDefault" + ] = aristaproto.message_field(1) + minimum_edition: "Edition" = aristaproto.enum_field(4) + """ + The minimum supported edition (inclusive) when this was constructed. + Editions before this will not have defaults. + """ + + maximum_edition: "Edition" = aristaproto.enum_field(5) + """ + The maximum known edition (inclusive) when this was constructed. Editions + after this will not have reliable defaults. + """ + + +@dataclass(eq=False, repr=False) +class FeatureSetDefaultsFeatureSetEditionDefault(aristaproto.Message): + """ + A map from every known edition with a unique set of defaults to its + defaults. Not all editions may be contained here. For a given edition, + the defaults at the closest matching edition ordered at or before it should + be used. This field must be in strict ascending order by edition. + """ + + edition: "Edition" = aristaproto.enum_field(3) + overridable_features: "FeatureSet" = aristaproto.message_field(4) + """Defaults of features that can be overridden in this edition.""" + + fixed_features: "FeatureSet" = aristaproto.message_field(5) + """Defaults of features that can't be overridden in this edition.""" + + features: "FeatureSet" = aristaproto.message_field(2) + """ + TODO Deprecate and remove this field, which is just the + above two merged. + """ + + +@dataclass(eq=False, repr=False) +class SourceCodeInfo(aristaproto.Message): + """ + Encapsulates information about the original source file from which a + FileDescriptorProto was generated. + """ + + location: List["SourceCodeInfoLocation"] = aristaproto.message_field(1) + """ + A Location identifies a piece of source code in a .proto file which + corresponds to a particular definition. This information is intended + to be useful to IDEs, code indexers, documentation generators, and similar + tools. + + For example, say we have a file like: + message Foo { + optional string foo = 1; + } + Let's look at just the field definition: + optional string foo = 1; + ^ ^^ ^^ ^ ^^^ + a bc de f ghi + We have the following locations: + span path represents + [a,i) [ 4, 0, 2, 0 ] The whole field definition. + [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). + [c,d) [ 4, 0, 2, 0, 5 ] The type (string). + [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). + [g,h) [ 4, 0, 2, 0, 3 ] The number (1). + + Notes: + - A location may refer to a repeated field itself (i.e. not to any + particular index within it). This is used whenever a set of elements are + logically enclosed in a single code segment. For example, an entire + extend block (possibly containing multiple extension definitions) will + have an outer location whose path refers to the "extensions" repeated + field without an index. + - Multiple locations may have the same path. This happens when a single + logical declaration is spread out across multiple places. The most + obvious example is the "extend" block again -- there may be multiple + extend blocks in the same scope, each of which will have the same path. + - A location's span is not always a subset of its parent's span. For + example, the "extendee" of an extension declaration appears at the + beginning of the "extend" block and is shared by all extensions within + the block. + - Just because a location's span is a subset of some other location's span + does not mean that it is a descendant. For example, a "group" defines + both a type and a field in a single declaration. Thus, the locations + corresponding to the type and field and their components will overlap. + - Code which tries to interpret locations should probably be designed to + ignore those that it doesn't understand, as more types of locations could + be recorded in the future. + """ + + +@dataclass(eq=False, repr=False) +class SourceCodeInfoLocation(aristaproto.Message): + path: List[int] = aristaproto.int32_field(1) + """ + Identifies which part of the FileDescriptorProto was defined at this + location. + + Each element is a field number or an index. They form a path from + the root FileDescriptorProto to the place where the definition appears. + For example, this path: + [ 4, 3, 2, 7, 1 ] + refers to: + file.message_type(3) // 4, 3 + .field(7) // 2, 7 + .name() // 1 + This is because FileDescriptorProto.message_type has field number 4: + repeated DescriptorProto message_type = 4; + and DescriptorProto.field has field number 2: + repeated FieldDescriptorProto field = 2; + and FieldDescriptorProto.name has field number 1: + optional string name = 1; + + Thus, the above path gives the location of a field name. If we removed + the last element: + [ 4, 3, 2, 7 ] + this path refers to the whole field declaration (from the beginning + of the label to the terminating semicolon). + """ + + span: List[int] = aristaproto.int32_field(2) + """ + Always has exactly three or four elements: start line, start column, + end line (optional, otherwise assumed same as start line), end column. + These are packed into a single field for efficiency. Note that line + and column numbers are zero-based -- typically you will want to add + 1 to each before displaying to a user. + """ + + leading_comments: str = aristaproto.string_field(3) + """ + If this SourceCodeInfo represents a complete declaration, these are any + comments appearing before and after the declaration which appear to be + attached to the declaration. + + A series of line comments appearing on consecutive lines, with no other + tokens appearing on those lines, will be treated as a single comment. + + leading_detached_comments will keep paragraphs of comments that appear + before (but not connected to) the current element. Each paragraph, + separated by empty lines, will be one comment element in the repeated + field. + + Only the comment content is provided; comment markers (e.g. //) are + stripped out. For block comments, leading whitespace and an asterisk + will be stripped from the beginning of each line other than the first. + Newlines are included in the output. + + Examples: + + optional int32 foo = 1; // Comment attached to foo. + // Comment attached to bar. + optional int32 bar = 2; + + optional string baz = 3; + // Comment attached to baz. + // Another line attached to baz. + + // Comment attached to moo. + // + // Another line attached to moo. + optional double moo = 4; + + // Detached comment for corge. This is not leading or trailing comments + // to moo or corge because there are blank lines separating it from + // both. + + // Detached comment for corge paragraph 2. + + optional string corge = 5; + /* Block comment attached + * to corge. Leading asterisks + * will be removed. */ + /* Block comment attached to + * grault. */ + optional int32 grault = 6; + + // ignored detached comments. + """ + + trailing_comments: str = aristaproto.string_field(4) + leading_detached_comments: List[str] = aristaproto.string_field(6) + + +@dataclass(eq=False, repr=False) +class GeneratedCodeInfo(aristaproto.Message): + """ + Describes the relationship between generated code and its original source + file. A GeneratedCodeInfo message is associated with only one generated + source file, but may contain references to different source .proto files. + """ + + annotation: List["GeneratedCodeInfoAnnotation"] = aristaproto.message_field(1) + """ + An Annotation connects some span of text in generated code to an element + of its generating .proto file. + """ + + +@dataclass(eq=False, repr=False) +class GeneratedCodeInfoAnnotation(aristaproto.Message): + path: List[int] = aristaproto.int32_field(1) + """ + Identifies the element in the original source .proto file. This field + is formatted the same as SourceCodeInfo.Location.path. + """ + + source_file: str = aristaproto.string_field(2) + """Identifies the filesystem path to the original source .proto.""" + + begin: int = aristaproto.int32_field(3) + """ + Identifies the starting offset in bytes in the generated code + that relates to the identified object. + """ + + end: int = aristaproto.int32_field(4) + """ + Identifies the ending offset in bytes in the generated code that + relates to the identified object. The end offset should be one past + the last relevant byte (so the length of the text = end - begin). + """ + + semantic: "GeneratedCodeInfoAnnotationSemantic" = aristaproto.enum_field(5) + + +@dataclass(eq=False, repr=False) +class Duration(aristaproto.Message): + """ + A Duration represents a signed, fixed-length span of time represented + as a count of seconds and fractions of seconds at nanosecond + resolution. It is independent of any calendar and concepts like "day" + or "month". It is related to Timestamp in that the difference between + two Timestamp values is a Duration and it can be added or subtracted + from a Timestamp. Range is approximately +-10,000 years. + + # Examples + + Example 1: Compute Duration from two Timestamps in pseudo code. + + Timestamp start = ...; + Timestamp end = ...; + Duration duration = ...; + + duration.seconds = end.seconds - start.seconds; + duration.nanos = end.nanos - start.nanos; + + if (duration.seconds < 0 && duration.nanos > 0) { + duration.seconds += 1; + duration.nanos -= 1000000000; + } else if (duration.seconds > 0 && duration.nanos < 0) { + duration.seconds -= 1; + duration.nanos += 1000000000; + } + + Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. + + Timestamp start = ...; + Duration duration = ...; + Timestamp end = ...; + + end.seconds = start.seconds + duration.seconds; + end.nanos = start.nanos + duration.nanos; + + if (end.nanos < 0) { + end.seconds -= 1; + end.nanos += 1000000000; + } else if (end.nanos >= 1000000000) { + end.seconds += 1; + end.nanos -= 1000000000; + } + + Example 3: Compute Duration from datetime.timedelta in Python. + + td = datetime.timedelta(days=3, minutes=10) + duration = Duration() + duration.FromTimedelta(td) + + # JSON Mapping + + In JSON format, the Duration type is encoded as a string rather than an + object, where the string ends in the suffix "s" (indicating seconds) and + is preceded by the number of seconds, with nanoseconds expressed as + fractional seconds. For example, 3 seconds with 0 nanoseconds should be + encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should + be expressed in JSON format as "3.000000001s", and 3 seconds and 1 + microsecond should be expressed in JSON format as "3.000001s". + """ + + seconds: int = aristaproto.int64_field(1) + """ + Signed seconds of the span of time. Must be from -315,576,000,000 + to +315,576,000,000 inclusive. Note: these bounds are computed from: + 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years + """ + + nanos: int = aristaproto.int32_field(2) + """ + Signed fractions of a second at nanosecond resolution of the span + of time. Durations less than one second are represented with a 0 + `seconds` field and a positive or negative `nanos` field. For durations + of one second or more, a non-zero value for the `nanos` field must be + of the same sign as the `seconds` field. Must be from -999,999,999 + to +999,999,999 inclusive. + """ + + +@dataclass(eq=False, repr=False) +class Empty(aristaproto.Message): + """ + A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to use it as the request + or the response type of an API method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); + } + """ + + pass + + +@dataclass(eq=False, repr=False) +class FieldMask(aristaproto.Message): + """ + `FieldMask` represents a set of symbolic field paths, for example: + + paths: "f.a" + paths: "f.b.d" + + Here `f` represents a field in some root message, `a` and `b` + fields in the message found in `f`, and `d` a field found in the + message in `f.b`. + + Field masks are used to specify a subset of fields that should be + returned by a get operation or modified by an update operation. + Field masks also have a custom JSON encoding (see below). + + # Field Masks in Projections + + When used in the context of a projection, a response message or + sub-message is filtered by the API to only contain those fields as + specified in the mask. For example, if the mask in the previous + example is applied to a response message as follows: + + f { + a : 22 + b { + d : 1 + x : 2 + } + y : 13 + } + z: 8 + + The result will not contain specific values for fields x,y and z + (their value will be set to the default, and omitted in proto text + output): + + + f { + a : 22 + b { + d : 1 + } + } + + A repeated field is not allowed except at the last position of a + paths string. + + If a FieldMask object is not present in a get operation, the + operation applies to all fields (as if a FieldMask of all fields + had been specified). + + Note that a field mask does not necessarily apply to the + top-level response message. In case of a REST get operation, the + field mask applies directly to the response, but in case of a REST + list operation, the mask instead applies to each individual message + in the returned resource list. In case of a REST custom method, + other definitions may be used. Where the mask applies will be + clearly documented together with its declaration in the API. In + any case, the effect on the returned resource/resources is required + behavior for APIs. + + # Field Masks in Update Operations + + A field mask in update operations specifies which fields of the + targeted resource are going to be updated. The API is required + to only change the values of the fields as specified in the mask + and leave the others untouched. If a resource is passed in to + describe the updated values, the API ignores the values of all + fields not covered by the mask. + + If a repeated field is specified for an update operation, new values will + be appended to the existing repeated field in the target resource. Note that + a repeated field is only allowed in the last position of a `paths` string. + + If a sub-message is specified in the last position of the field mask for an + update operation, then new value will be merged into the existing sub-message + in the target resource. + + For example, given the target message: + + f { + b { + d: 1 + x: 2 + } + c: [1] + } + + And an update message: + + f { + b { + d: 10 + } + c: [2] + } + + then if the field mask is: + + paths: ["f.b", "f.c"] + + then the result will be: + + f { + b { + d: 10 + x: 2 + } + c: [1, 2] + } + + An implementation may provide options to override this default behavior for + repeated and message fields. + + In order to reset a field's value to the default, the field must + be in the mask and set to the default value in the provided resource. + Hence, in order to reset all fields of a resource, provide a default + instance of the resource and set all fields in the mask, or do + not provide a mask as described below. + + If a field mask is not present on update, the operation applies to + all fields (as if a field mask of all fields has been specified). + Note that in the presence of schema evolution, this may mean that + fields the client does not know and has therefore not filled into + the request will be reset to their default. If this is unwanted + behavior, a specific service may require a client to always specify + a field mask, producing an error if not. + + As with get operations, the location of the resource which + describes the updated values in the request message depends on the + operation kind. In any case, the effect of the field mask is + required to be honored by the API. + + ## Considerations for HTTP REST + + The HTTP kind of an update operation which uses a field mask must + be set to PATCH instead of PUT in order to satisfy HTTP semantics + (PUT must only be used for full updates). + + # JSON Encoding of Field Masks + + In JSON, a field mask is encoded as a single string where paths are + separated by a comma. Fields name in each path are converted + to/from lower-camel naming conventions. + + As an example, consider the following message declarations: + + message Profile { + User user = 1; + Photo photo = 2; + } + message User { + string display_name = 1; + string address = 2; + } + + In proto a field mask for `Profile` may look as such: + + mask { + paths: "user.display_name" + paths: "photo" + } + + In JSON, the same mask is represented as below: + + { + mask: "user.displayName,photo" + } + + # Field Masks and Oneof Fields + + Field masks treat fields in oneofs just as regular fields. Consider the + following message: + + message SampleMessage { + oneof test_oneof { + string name = 4; + SubMessage sub_message = 9; + } + } + + The field mask can be: + + mask { + paths: "name" + } + + Or: + + mask { + paths: "sub_message" + } + + Note that oneof type names ("test_oneof" in this case) cannot be used in + paths. + + ## Field Mask Verification + + The implementation of any API method which has a FieldMask type field in the + request should verify the included field paths, and return an + `INVALID_ARGUMENT` error if any path is unmappable. + """ + + paths: List[str] = aristaproto.string_field(1) + """The set of field mask paths.""" + + +@dataclass(eq=False, repr=False) +class Struct(aristaproto.Message): + """ + `Struct` represents a structured data value, consisting of fields + which map to dynamically typed values. In some languages, `Struct` + might be supported by a native representation. For example, in + scripting languages like JS a struct is represented as an + object. The details of that representation are described together + with the proto support for the language. + + The JSON representation for `Struct` is JSON object. + """ + + fields: Dict[str, "Value"] = aristaproto.map_field( + 1, aristaproto.TYPE_STRING, aristaproto.TYPE_MESSAGE + ) + """Unordered map of dynamically typed values.""" + + @hybridmethod + def from_dict(cls: "type[Self]", value: Mapping[str, Any]) -> Self: # type: ignore + self = cls() + return self.from_dict(value) + + @from_dict.instancemethod + def from_dict(self, value: Mapping[str, Any]) -> Self: + fields = {**value} + for k in fields: + if hasattr(fields[k], "from_dict"): + fields[k] = fields[k].from_dict() + + self.fields = fields + return self + + def to_dict( + self, + casing: aristaproto.Casing = aristaproto.Casing.CAMEL, + include_default_values: bool = False, + ) -> Dict[str, Any]: + output = {**self.fields} + for k in self.fields: + if hasattr(self.fields[k], "to_dict"): + output[k] = self.fields[k].to_dict(casing, include_default_values) + return output + + +@dataclass(eq=False, repr=False) +class Value(aristaproto.Message): + """ + `Value` represents a dynamically typed value which can be either + null, a number, a string, a boolean, a recursive struct value, or a + list of values. A producer of value is expected to set one of these + variants. Absence of any variant indicates an error. + + The JSON representation for `Value` is JSON value. + """ + + null_value: Optional["NullValue"] = aristaproto.enum_field( + 1, optional=True, group="kind" + ) + """Represents a null value.""" + + number_value: Optional[float] = aristaproto.double_field( + 2, optional=True, group="kind" + ) + """Represents a double value.""" + + string_value: Optional[str] = aristaproto.string_field( + 3, optional=True, group="kind" + ) + """Represents a string value.""" + + bool_value: Optional[bool] = aristaproto.bool_field(4, optional=True, group="kind") + """Represents a boolean value.""" + + struct_value: Optional["Struct"] = aristaproto.message_field( + 5, optional=True, group="kind" + ) + """Represents a structured value.""" + + list_value: Optional["ListValue"] = aristaproto.message_field( + 6, optional=True, group="kind" + ) + """Represents a repeated `Value`.""" + + @root_validator() + def check_oneof(cls, values): + return cls._validate_field_groups(values) + + +@dataclass(eq=False, repr=False) +class ListValue(aristaproto.Message): + """ + `ListValue` is a wrapper around a repeated field of values. + + The JSON representation for `ListValue` is JSON array. + """ + + values: List["Value"] = aristaproto.message_field(1) + """Repeated field of dynamically typed values.""" + + +@dataclass(eq=False, repr=False) +class Timestamp(aristaproto.Message): + """ + A Timestamp represents a point in time independent of any time zone or local + calendar, encoded as a count of seconds and fractions of seconds at + nanosecond resolution. The count is relative to an epoch at UTC midnight on + January 1, 1970, in the proleptic Gregorian calendar which extends the + Gregorian calendar backwards to year one. + + All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap + second table is needed for interpretation, using a [24-hour linear + smear](https://developers.google.com/time/smear). + + The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By + restricting to that range, we ensure that we can convert to and from [RFC + 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. + + # Examples + + Example 1: Compute Timestamp from POSIX `time()`. + + Timestamp timestamp; + timestamp.set_seconds(time(NULL)); + timestamp.set_nanos(0); + + Example 2: Compute Timestamp from POSIX `gettimeofday()`. + + struct timeval tv; + gettimeofday(&tv, NULL); + + Timestamp timestamp; + timestamp.set_seconds(tv.tv_sec); + timestamp.set_nanos(tv.tv_usec * 1000); + + Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. + + FILETIME ft; + GetSystemTimeAsFileTime(&ft); + UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + + // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z + // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. + Timestamp timestamp; + timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); + timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); + + Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. + + long millis = System.currentTimeMillis(); + + Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) + .setNanos((int) ((millis % 1000) * 1000000)).build(); + + Example 5: Compute Timestamp from Java `Instant.now()`. + + Instant now = Instant.now(); + + Timestamp timestamp = + Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + .setNanos(now.getNano()).build(); + + Example 6: Compute Timestamp from current time in Python. + + timestamp = Timestamp() + timestamp.GetCurrentTime() + + # JSON Mapping + + In JSON format, the Timestamp type is encoded as a string in the + [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the + format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" + where {year} is always expressed using four digits while {month}, {day}, + {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional + seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), + are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone + is required. A proto3 JSON serializer should always use UTC (as indicated by + "Z") when printing the Timestamp type and a proto3 JSON parser should be + able to accept both UTC and other timezones (as indicated by an offset). + + For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past + 01:30 UTC on January 15, 2017. + + In JavaScript, one can convert a Date object to this format using the + standard + [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) + method. In Python, a standard `datetime.datetime` object can be converted + to this format using + [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with + the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use + the Joda Time's [`ISODateTimeFormat.dateTime()`]( + http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime() + ) to obtain a formatter capable of generating timestamps in this format. + """ + + seconds: int = aristaproto.int64_field(1) + """ + Represents seconds of UTC time since Unix epoch + 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + 9999-12-31T23:59:59Z inclusive. + """ + + nanos: int = aristaproto.int32_field(2) + """ + Non-negative fractions of a second at nanosecond resolution. Negative + second values with fractions must still have non-negative nanos values + that count forward in time. Must be from 0 to 999,999,999 + inclusive. + """ + + +@dataclass(eq=False, repr=False) +class DoubleValue(aristaproto.Message): + """ + Wrapper message for `double`. + + The JSON representation for `DoubleValue` is JSON number. + """ + + value: float = aristaproto.double_field(1) + """The double value.""" + + +@dataclass(eq=False, repr=False) +class FloatValue(aristaproto.Message): + """ + Wrapper message for `float`. + + The JSON representation for `FloatValue` is JSON number. + """ + + value: float = aristaproto.float_field(1) + """The float value.""" + + +@dataclass(eq=False, repr=False) +class Int64Value(aristaproto.Message): + """ + Wrapper message for `int64`. + + The JSON representation for `Int64Value` is JSON string. + """ + + value: int = aristaproto.int64_field(1) + """The int64 value.""" + + +@dataclass(eq=False, repr=False) +class UInt64Value(aristaproto.Message): + """ + Wrapper message for `uint64`. + + The JSON representation for `UInt64Value` is JSON string. + """ + + value: int = aristaproto.uint64_field(1) + """The uint64 value.""" + + +@dataclass(eq=False, repr=False) +class Int32Value(aristaproto.Message): + """ + Wrapper message for `int32`. + + The JSON representation for `Int32Value` is JSON number. + """ + + value: int = aristaproto.int32_field(1) + """The int32 value.""" + + +@dataclass(eq=False, repr=False) +class UInt32Value(aristaproto.Message): + """ + Wrapper message for `uint32`. + + The JSON representation for `UInt32Value` is JSON number. + """ + + value: int = aristaproto.uint32_field(1) + """The uint32 value.""" + + +@dataclass(eq=False, repr=False) +class BoolValue(aristaproto.Message): + """ + Wrapper message for `bool`. + + The JSON representation for `BoolValue` is JSON `true` and `false`. + """ + + value: bool = aristaproto.bool_field(1) + """The bool value.""" + + +@dataclass(eq=False, repr=False) +class StringValue(aristaproto.Message): + """ + Wrapper message for `string`. + + The JSON representation for `StringValue` is JSON string. + """ + + value: str = aristaproto.string_field(1) + """The string value.""" + + +@dataclass(eq=False, repr=False) +class BytesValue(aristaproto.Message): + """ + Wrapper message for `bytes`. + + The JSON representation for `BytesValue` is JSON string. + """ + + value: bytes = aristaproto.bytes_field(1) + """The bytes value.""" + + +Type.__pydantic_model__.update_forward_refs() # type: ignore +Field.__pydantic_model__.update_forward_refs() # type: ignore +Enum.__pydantic_model__.update_forward_refs() # type: ignore +EnumValue.__pydantic_model__.update_forward_refs() # type: ignore +Option.__pydantic_model__.update_forward_refs() # type: ignore +Api.__pydantic_model__.update_forward_refs() # type: ignore +Method.__pydantic_model__.update_forward_refs() # type: ignore +FileDescriptorSet.__pydantic_model__.update_forward_refs() # type: ignore +FileDescriptorProto.__pydantic_model__.update_forward_refs() # type: ignore +DescriptorProto.__pydantic_model__.update_forward_refs() # type: ignore +DescriptorProtoExtensionRange.__pydantic_model__.update_forward_refs() # type: ignore +ExtensionRangeOptions.__pydantic_model__.update_forward_refs() # type: ignore +FieldDescriptorProto.__pydantic_model__.update_forward_refs() # type: ignore +OneofDescriptorProto.__pydantic_model__.update_forward_refs() # type: ignore +EnumDescriptorProto.__pydantic_model__.update_forward_refs() # type: ignore +EnumValueDescriptorProto.__pydantic_model__.update_forward_refs() # type: ignore +ServiceDescriptorProto.__pydantic_model__.update_forward_refs() # type: ignore +MethodDescriptorProto.__pydantic_model__.update_forward_refs() # type: ignore +FileOptions.__pydantic_model__.update_forward_refs() # type: ignore +MessageOptions.__pydantic_model__.update_forward_refs() # type: ignore +FieldOptions.__pydantic_model__.update_forward_refs() # type: ignore +FieldOptionsEditionDefault.__pydantic_model__.update_forward_refs() # type: ignore +FieldOptionsFeatureSupport.__pydantic_model__.update_forward_refs() # type: ignore +OneofOptions.__pydantic_model__.update_forward_refs() # type: ignore +EnumOptions.__pydantic_model__.update_forward_refs() # type: ignore +EnumValueOptions.__pydantic_model__.update_forward_refs() # type: ignore +ServiceOptions.__pydantic_model__.update_forward_refs() # type: ignore +MethodOptions.__pydantic_model__.update_forward_refs() # type: ignore +UninterpretedOption.__pydantic_model__.update_forward_refs() # type: ignore +FeatureSet.__pydantic_model__.update_forward_refs() # type: ignore +FeatureSetDefaults.__pydantic_model__.update_forward_refs() # type: ignore +FeatureSetDefaultsFeatureSetEditionDefault.__pydantic_model__.update_forward_refs() # type: ignore +SourceCodeInfo.__pydantic_model__.update_forward_refs() # type: ignore +GeneratedCodeInfo.__pydantic_model__.update_forward_refs() # type: ignore +GeneratedCodeInfoAnnotation.__pydantic_model__.update_forward_refs() # type: ignore +Struct.__pydantic_model__.update_forward_refs() # type: ignore +Value.__pydantic_model__.update_forward_refs() # type: ignore +ListValue.__pydantic_model__.update_forward_refs() # type: ignore diff --git a/src/aristaproto/lib/pydantic/google/protobuf/compiler/__init__.py b/src/aristaproto/lib/pydantic/google/protobuf/compiler/__init__.py new file mode 100644 index 0000000..495c555 --- /dev/null +++ b/src/aristaproto/lib/pydantic/google/protobuf/compiler/__init__.py @@ -0,0 +1,210 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# sources: google/protobuf/compiler/plugin.proto +# plugin: python-aristaproto +# This file has been @generated + +from typing import TYPE_CHECKING + + +if TYPE_CHECKING: + from dataclasses import dataclass +else: + from pydantic.dataclasses import dataclass + +from typing import List + +import aristaproto +import aristaproto.lib.pydantic.google.protobuf as aristaproto_lib_pydantic_google_protobuf + + +class CodeGeneratorResponseFeature(aristaproto.Enum): + """Sync with code_generator.h.""" + + FEATURE_NONE = 0 + FEATURE_PROTO3_OPTIONAL = 1 + FEATURE_SUPPORTS_EDITIONS = 2 + + +@dataclass(eq=False, repr=False) +class Version(aristaproto.Message): + """The version number of protocol compiler.""" + + major: int = aristaproto.int32_field(1) + minor: int = aristaproto.int32_field(2) + patch: int = aristaproto.int32_field(3) + suffix: str = aristaproto.string_field(4) + """ + A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should + be empty for mainline stable releases. + """ + + +@dataclass(eq=False, repr=False) +class CodeGeneratorRequest(aristaproto.Message): + """An encoded CodeGeneratorRequest is written to the plugin's stdin.""" + + file_to_generate: List[str] = aristaproto.string_field(1) + """ + The .proto files that were explicitly listed on the command-line. The + code generator should generate code only for these files. Each file's + descriptor will be included in proto_file, below. + """ + + parameter: str = aristaproto.string_field(2) + """The generator parameter passed on the command-line.""" + + proto_file: List[ + "aristaproto_lib_pydantic_google_protobuf.FileDescriptorProto" + ] = aristaproto.message_field(15) + """ + FileDescriptorProtos for all files in files_to_generate and everything + they import. The files will appear in topological order, so each file + appears before any file that imports it. + + Note: the files listed in files_to_generate will include runtime-retention + options only, but all other files will include source-retention options. + The source_file_descriptors field below is available in case you need + source-retention options for files_to_generate. + + protoc guarantees that all proto_files will be written after + the fields above, even though this is not technically guaranteed by the + protobuf wire format. This theoretically could allow a plugin to stream + in the FileDescriptorProtos and handle them one by one rather than read + the entire set into memory at once. However, as of this writing, this + is not similarly optimized on protoc's end -- it will store all fields in + memory at once before sending them to the plugin. + + Type names of fields and extensions in the FileDescriptorProto are always + fully qualified. + """ + + source_file_descriptors: List[ + "aristaproto_lib_pydantic_google_protobuf.FileDescriptorProto" + ] = aristaproto.message_field(17) + """ + File descriptors with all options, including source-retention options. + These descriptors are only provided for the files listed in + files_to_generate. + """ + + compiler_version: "Version" = aristaproto.message_field(3) + """The version number of protocol compiler.""" + + +@dataclass(eq=False, repr=False) +class CodeGeneratorResponse(aristaproto.Message): + """The plugin writes an encoded CodeGeneratorResponse to stdout.""" + + error: str = aristaproto.string_field(1) + """ + Error message. If non-empty, code generation failed. The plugin process + should exit with status code zero even if it reports an error in this way. + + This should be used to indicate errors in .proto files which prevent the + code generator from generating correct code. Errors which indicate a + problem in protoc itself -- such as the input CodeGeneratorRequest being + unparseable -- should be reported by writing a message to stderr and + exiting with a non-zero status code. + """ + + supported_features: int = aristaproto.uint64_field(2) + """ + A bitmask of supported features that the code generator supports. + This is a bitwise "or" of values from the Feature enum. + """ + + minimum_edition: int = aristaproto.int32_field(3) + """ + The minimum edition this plugin supports. This will be treated as an + Edition enum, but we want to allow unknown values. It should be specified + according the edition enum value, *not* the edition number. Only takes + effect for plugins that have FEATURE_SUPPORTS_EDITIONS set. + """ + + maximum_edition: int = aristaproto.int32_field(4) + """ + The maximum edition this plugin supports. This will be treated as an + Edition enum, but we want to allow unknown values. It should be specified + according the edition enum value, *not* the edition number. Only takes + effect for plugins that have FEATURE_SUPPORTS_EDITIONS set. + """ + + file: List["CodeGeneratorResponseFile"] = aristaproto.message_field(15) + + +@dataclass(eq=False, repr=False) +class CodeGeneratorResponseFile(aristaproto.Message): + """Represents a single generated file.""" + + name: str = aristaproto.string_field(1) + """ + The file name, relative to the output directory. The name must not + contain "." or ".." components and must be relative, not be absolute (so, + the file cannot lie outside the output directory). "/" must be used as + the path separator, not "\". + + If the name is omitted, the content will be appended to the previous + file. This allows the generator to break large files into small chunks, + and allows the generated text to be streamed back to protoc so that large + files need not reside completely in memory at one time. Note that as of + this writing protoc does not optimize for this -- it will read the entire + CodeGeneratorResponse before writing files to disk. + """ + + insertion_point: str = aristaproto.string_field(2) + """ + If non-empty, indicates that the named file should already exist, and the + content here is to be inserted into that file at a defined insertion + point. This feature allows a code generator to extend the output + produced by another code generator. The original generator may provide + insertion points by placing special annotations in the file that look + like: + @@protoc_insertion_point(NAME) + The annotation can have arbitrary text before and after it on the line, + which allows it to be placed in a comment. NAME should be replaced with + an identifier naming the point -- this is what other generators will use + as the insertion_point. Code inserted at this point will be placed + immediately above the line containing the insertion point (thus multiple + insertions to the same point will come out in the order they were added). + The double-@ is intended to make it unlikely that the generated code + could contain things that look like insertion points by accident. + + For example, the C++ code generator places the following line in the + .pb.h files that it generates: + // @@protoc_insertion_point(namespace_scope) + This line appears within the scope of the file's package namespace, but + outside of any particular class. Another plugin can then specify the + insertion_point "namespace_scope" to generate additional classes or + other declarations that should be placed in this scope. + + Note that if the line containing the insertion point begins with + whitespace, the same whitespace will be added to every line of the + inserted text. This is useful for languages like Python, where + indentation matters. In these languages, the insertion point comment + should be indented the same amount as any inserted code will need to be + in order to work correctly in that context. + + The code generator that generates the initial file and the one which + inserts into it must both run as part of a single invocation of protoc. + Code generators are executed in the order in which they appear on the + command line. + + If |insertion_point| is present, |name| must also be present. + """ + + content: str = aristaproto.string_field(15) + """The file contents.""" + + generated_code_info: ( + "aristaproto_lib_pydantic_google_protobuf.GeneratedCodeInfo" + ) = aristaproto.message_field(16) + """ + Information describing the file content being inserted. If an insertion + point is used, this information will be appropriately offset and inserted + into the code generation metadata for the generated files. + """ + + +CodeGeneratorRequest.__pydantic_model__.update_forward_refs() # type: ignore +CodeGeneratorResponse.__pydantic_model__.update_forward_refs() # type: ignore +CodeGeneratorResponseFile.__pydantic_model__.update_forward_refs() # type: ignore diff --git a/src/aristaproto/lib/std/__init__.py b/src/aristaproto/lib/std/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/aristaproto/lib/std/__init__.py diff --git a/src/aristaproto/lib/std/google/__init__.py b/src/aristaproto/lib/std/google/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/aristaproto/lib/std/google/__init__.py diff --git a/src/aristaproto/lib/std/google/protobuf/__init__.py b/src/aristaproto/lib/std/google/protobuf/__init__.py new file mode 100644 index 0000000..783676a --- /dev/null +++ b/src/aristaproto/lib/std/google/protobuf/__init__.py @@ -0,0 +1,2526 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# sources: google/protobuf/any.proto, google/protobuf/api.proto, google/protobuf/descriptor.proto, google/protobuf/duration.proto, google/protobuf/empty.proto, google/protobuf/field_mask.proto, google/protobuf/source_context.proto, google/protobuf/struct.proto, google/protobuf/timestamp.proto, google/protobuf/type.proto, google/protobuf/wrappers.proto +# plugin: python-aristaproto + +import warnings +from dataclasses import dataclass +from typing import ( + Dict, + List, + Mapping, +) + +from typing_extensions import Self + +import aristaproto +from aristaproto.utils import hybridmethod + + +class Syntax(aristaproto.Enum): + """The syntax in which a protocol buffer element is defined.""" + + PROTO2 = 0 + """Syntax `proto2`.""" + + PROTO3 = 1 + """Syntax `proto3`.""" + + EDITIONS = 2 + """Syntax `editions`.""" + + +class FieldKind(aristaproto.Enum): + """Basic field types.""" + + TYPE_UNKNOWN = 0 + """Field type unknown.""" + + TYPE_DOUBLE = 1 + """Field type double.""" + + TYPE_FLOAT = 2 + """Field type float.""" + + TYPE_INT64 = 3 + """Field type int64.""" + + TYPE_UINT64 = 4 + """Field type uint64.""" + + TYPE_INT32 = 5 + """Field type int32.""" + + TYPE_FIXED64 = 6 + """Field type fixed64.""" + + TYPE_FIXED32 = 7 + """Field type fixed32.""" + + TYPE_BOOL = 8 + """Field type bool.""" + + TYPE_STRING = 9 + """Field type string.""" + + TYPE_GROUP = 10 + """Field type group. Proto2 syntax only, and deprecated.""" + + TYPE_MESSAGE = 11 + """Field type message.""" + + TYPE_BYTES = 12 + """Field type bytes.""" + + TYPE_UINT32 = 13 + """Field type uint32.""" + + TYPE_ENUM = 14 + """Field type enum.""" + + TYPE_SFIXED32 = 15 + """Field type sfixed32.""" + + TYPE_SFIXED64 = 16 + """Field type sfixed64.""" + + TYPE_SINT32 = 17 + """Field type sint32.""" + + TYPE_SINT64 = 18 + """Field type sint64.""" + + +class FieldCardinality(aristaproto.Enum): + """Whether a field is optional, required, or repeated.""" + + CARDINALITY_UNKNOWN = 0 + """For fields with unknown cardinality.""" + + CARDINALITY_OPTIONAL = 1 + """For optional fields.""" + + CARDINALITY_REQUIRED = 2 + """For required fields. Proto2 syntax only.""" + + CARDINALITY_REPEATED = 3 + """For repeated fields.""" + + +class Edition(aristaproto.Enum): + """The full set of known editions.""" + + UNKNOWN = 0 + """A placeholder for an unknown edition value.""" + + PROTO2 = 998 + """ + Legacy syntax "editions". These pre-date editions, but behave much like + distinct editions. These can't be used to specify the edition of proto + files, but feature definitions must supply proto2/proto3 defaults for + backwards compatibility. + """ + + PROTO3 = 999 + _2023 = 1000 + """ + Editions that have been released. The specific values are arbitrary and + should not be depended on, but they will always be time-ordered for easy + comparison. + """ + + _2024 = 1001 + _1_TEST_ONLY = 1 + """ + Placeholder editions for testing feature resolution. These should not be + used or relyed on outside of tests. + """ + + _2_TEST_ONLY = 2 + _99997_TEST_ONLY = 99997 + _99998_TEST_ONLY = 99998 + _99999_TEST_ONLY = 99999 + MAX = 2147483647 + """ + Placeholder for specifying unbounded edition support. This should only + ever be used by plugins that can expect to never require any changes to + support a new edition. + """ + + +class ExtensionRangeOptionsVerificationState(aristaproto.Enum): + """The verification state of the extension range.""" + + DECLARATION = 0 + """All the extensions of the range must be declared.""" + + UNVERIFIED = 1 + + +class FieldDescriptorProtoType(aristaproto.Enum): + TYPE_DOUBLE = 1 + """ + 0 is reserved for errors. + Order is weird for historical reasons. + """ + + TYPE_FLOAT = 2 + TYPE_INT64 = 3 + """ + Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if + negative values are likely. + """ + + TYPE_UINT64 = 4 + TYPE_INT32 = 5 + """ + Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if + negative values are likely. + """ + + TYPE_FIXED64 = 6 + TYPE_FIXED32 = 7 + TYPE_BOOL = 8 + TYPE_STRING = 9 + TYPE_GROUP = 10 + """ + Tag-delimited aggregate. + Group type is deprecated and not supported after google.protobuf. However, Proto3 + implementations should still be able to parse the group wire format and + treat group fields as unknown fields. In Editions, the group wire format + can be enabled via the `message_encoding` feature. + """ + + TYPE_MESSAGE = 11 + TYPE_BYTES = 12 + """New in version 2.""" + + TYPE_UINT32 = 13 + TYPE_ENUM = 14 + TYPE_SFIXED32 = 15 + TYPE_SFIXED64 = 16 + TYPE_SINT32 = 17 + TYPE_SINT64 = 18 + + +class FieldDescriptorProtoLabel(aristaproto.Enum): + LABEL_OPTIONAL = 1 + """0 is reserved for errors""" + + LABEL_REPEATED = 3 + LABEL_REQUIRED = 2 + """ + The required label is only allowed in google.protobuf. In proto3 and Editions + it's explicitly prohibited. In Editions, the `field_presence` feature + can be used to get this behavior. + """ + + +class FileOptionsOptimizeMode(aristaproto.Enum): + """Generated classes can be optimized for speed or code size.""" + + SPEED = 1 + CODE_SIZE = 2 + """etc.""" + + LITE_RUNTIME = 3 + + +class FieldOptionsCType(aristaproto.Enum): + STRING = 0 + """Default mode.""" + + CORD = 1 + """ + The option [ctype=CORD] may be applied to a non-repeated field of type + "bytes". It indicates that in C++, the data should be stored in a Cord + instead of a string. For very large strings, this may reduce memory + fragmentation. It may also allow better performance when parsing from a + Cord, or when parsing with aliasing enabled, as the parsed Cord may then + alias the original buffer. + """ + + STRING_PIECE = 2 + + +class FieldOptionsJsType(aristaproto.Enum): + JS_NORMAL = 0 + """Use the default type.""" + + JS_STRING = 1 + """Use JavaScript strings.""" + + JS_NUMBER = 2 + """Use JavaScript numbers.""" + + +class FieldOptionsOptionRetention(aristaproto.Enum): + """ + If set to RETENTION_SOURCE, the option will be omitted from the binary. + Note: as of January 2023, support for this is in progress and does not yet + have an effect (b/264593489). + """ + + RETENTION_UNKNOWN = 0 + RETENTION_RUNTIME = 1 + RETENTION_SOURCE = 2 + + +class FieldOptionsOptionTargetType(aristaproto.Enum): + """ + This indicates the types of entities that the field may apply to when used + as an option. If it is unset, then the field may be freely used as an + option on any kind of entity. Note: as of January 2023, support for this is + in progress and does not yet have an effect (b/264593489). + """ + + TARGET_TYPE_UNKNOWN = 0 + TARGET_TYPE_FILE = 1 + TARGET_TYPE_EXTENSION_RANGE = 2 + TARGET_TYPE_MESSAGE = 3 + TARGET_TYPE_FIELD = 4 + TARGET_TYPE_ONEOF = 5 + TARGET_TYPE_ENUM = 6 + TARGET_TYPE_ENUM_ENTRY = 7 + TARGET_TYPE_SERVICE = 8 + TARGET_TYPE_METHOD = 9 + + +class MethodOptionsIdempotencyLevel(aristaproto.Enum): + """ + Is this method side-effect-free (or safe in HTTP parlance), or idempotent, + or neither? HTTP based RPC implementation may choose GET verb for safe + methods, and PUT verb for idempotent methods instead of the default POST. + """ + + IDEMPOTENCY_UNKNOWN = 0 + NO_SIDE_EFFECTS = 1 + IDEMPOTENT = 2 + + +class FeatureSetFieldPresence(aristaproto.Enum): + FIELD_PRESENCE_UNKNOWN = 0 + EXPLICIT = 1 + IMPLICIT = 2 + LEGACY_REQUIRED = 3 + + +class FeatureSetEnumType(aristaproto.Enum): + ENUM_TYPE_UNKNOWN = 0 + OPEN = 1 + CLOSED = 2 + + +class FeatureSetRepeatedFieldEncoding(aristaproto.Enum): + REPEATED_FIELD_ENCODING_UNKNOWN = 0 + PACKED = 1 + EXPANDED = 2 + + +class FeatureSetUtf8Validation(aristaproto.Enum): + UTF8_VALIDATION_UNKNOWN = 0 + VERIFY = 2 + NONE = 3 + + +class FeatureSetMessageEncoding(aristaproto.Enum): + MESSAGE_ENCODING_UNKNOWN = 0 + LENGTH_PREFIXED = 1 + DELIMITED = 2 + + +class FeatureSetJsonFormat(aristaproto.Enum): + JSON_FORMAT_UNKNOWN = 0 + ALLOW = 1 + LEGACY_BEST_EFFORT = 2 + + +class GeneratedCodeInfoAnnotationSemantic(aristaproto.Enum): + """ + Represents the identified object's effect on the element in the original + .proto file. + """ + + NONE = 0 + """There is no effect or the effect is indescribable.""" + + SET = 1 + """The element is set or otherwise mutated.""" + + ALIAS = 2 + """An alias to the element is returned.""" + + +class NullValue(aristaproto.Enum): + """ + `NullValue` is a singleton enumeration to represent the null value for the + `Value` type union. + + The JSON representation for `NullValue` is JSON `null`. + """ + + _ = 0 + """Null value.""" + + +@dataclass(eq=False, repr=False) +class Any(aristaproto.Message): + """ + `Any` contains an arbitrary serialized protocol buffer message along with a + URL that describes the type of the serialized message. + + Protobuf library provides support to pack/unpack Any values in the form + of utility functions or additional generated methods of the Any type. + + Example 1: Pack and unpack a message in C++. + + Foo foo = ...; + Any any; + any.PackFrom(foo); + ... + if (any.UnpackTo(&foo)) { + ... + } + + Example 2: Pack and unpack a message in Java. + + Foo foo = ...; + Any any = Any.pack(foo); + ... + if (any.is(Foo.class)) { + foo = any.unpack(Foo.class); + } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } + + Example 3: Pack and unpack a message in Python. + + foo = Foo(...) + any = Any() + any.Pack(foo) + ... + if any.Is(Foo.DESCRIPTOR): + any.Unpack(foo) + ... + + Example 4: Pack and unpack a message in Go + + foo := &pb.Foo{...} + any, err := anypb.New(foo) + if err != nil { + ... + } + ... + foo := &pb.Foo{} + if err := any.UnmarshalTo(foo); err != nil { + ... + } + + The pack methods provided by protobuf library will by default use + 'type.googleapis.com/full.type.name' as the type URL and the unpack + methods only use the fully qualified type name after the last '/' + in the type URL, for example "foo.bar.com/x/y.z" will yield type + name "y.z". + + JSON + ==== + The JSON representation of an `Any` value uses the regular + representation of the deserialized, embedded message, with an + additional field `@type` which contains the type URL. Example: + + package google.profile; + message Person { + string first_name = 1; + string last_name = 2; + } + + { + "@type": "type.googleapis.com/google.profile.Person", + "firstName": <string>, + "lastName": <string> + } + + If the embedded message type is well-known and has a custom JSON + representation, that representation will be embedded adding a field + `value` which holds the custom JSON in addition to the `@type` + field. Example (for message [google.protobuf.Duration][]): + + { + "@type": "type.googleapis.com/google.protobuf.Duration", + "value": "1.212s" + } + """ + + type_url: str = aristaproto.string_field(1) + """ + A URL/resource name that uniquely identifies the type of the serialized + protocol buffer message. This string must contain at least + one "/" character. The last segment of the URL's path must represent + the fully qualified name of the type (as in + `path/google.protobuf.Duration`). The name should be in a canonical form + (e.g., leading "." is not accepted). + + In practice, teams usually precompile into the binary all types that they + expect it to use in the context of Any. However, for URLs which use the + scheme `http`, `https`, or no scheme, one can optionally set up a type + server that maps type URLs to message definitions as follows: + + * If no scheme is provided, `https` is assumed. + * An HTTP GET on the URL must yield a [google.protobuf.Type][] + value in binary format, or produce an error. + * Applications are allowed to cache lookup results based on the + URL, or have them precompiled into a binary to avoid any + lookup. Therefore, binary compatibility needs to be preserved + on changes to types. (Use versioned type names to manage + breaking changes.) + + Note: this functionality is not currently available in the official + protobuf release, and it is not used for type URLs beginning with + type.googleapis.com. As of May 2023, there are no widely used type server + implementations and no plans to implement one. + + Schemes other than `http`, `https` (or the empty scheme) might be + used with implementation specific semantics. + """ + + value: bytes = aristaproto.bytes_field(2) + """ + Must be a valid serialized protocol buffer of the above specified type. + """ + + +@dataclass(eq=False, repr=False) +class SourceContext(aristaproto.Message): + """ + `SourceContext` represents information about the source of a + protobuf element, like the file in which it is defined. + """ + + file_name: str = aristaproto.string_field(1) + """ + The path-qualified name of the .proto file that contained the associated + protobuf element. For example: `"google/protobuf/source_context.proto"`. + """ + + +@dataclass(eq=False, repr=False) +class Type(aristaproto.Message): + """A protocol buffer message type.""" + + name: str = aristaproto.string_field(1) + """The fully qualified message name.""" + + fields: List["Field"] = aristaproto.message_field(2) + """The list of fields.""" + + oneofs: List[str] = aristaproto.string_field(3) + """The list of types appearing in `oneof` definitions in this type.""" + + options: List["Option"] = aristaproto.message_field(4) + """The protocol buffer options.""" + + source_context: "SourceContext" = aristaproto.message_field(5) + """The source context.""" + + syntax: "Syntax" = aristaproto.enum_field(6) + """The source syntax.""" + + edition: str = aristaproto.string_field(7) + """ + The source edition string, only valid when syntax is SYNTAX_EDITIONS. + """ + + +@dataclass(eq=False, repr=False) +class Field(aristaproto.Message): + """A single field of a message type.""" + + kind: "FieldKind" = aristaproto.enum_field(1) + """The field type.""" + + cardinality: "FieldCardinality" = aristaproto.enum_field(2) + """The field cardinality.""" + + number: int = aristaproto.int32_field(3) + """The field number.""" + + name: str = aristaproto.string_field(4) + """The field name.""" + + type_url: str = aristaproto.string_field(6) + """ + The field type URL, without the scheme, for message or enumeration + types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`. + """ + + oneof_index: int = aristaproto.int32_field(7) + """ + The index of the field type in `Type.oneofs`, for message or enumeration + types. The first type has index 1; zero means the type is not in the list. + """ + + packed: bool = aristaproto.bool_field(8) + """Whether to use alternative packed wire representation.""" + + options: List["Option"] = aristaproto.message_field(9) + """The protocol buffer options.""" + + json_name: str = aristaproto.string_field(10) + """The field JSON name.""" + + default_value: str = aristaproto.string_field(11) + """ + The string value of the default value of this field. Proto2 syntax only. + """ + + +@dataclass(eq=False, repr=False) +class Enum(aristaproto.Message): + """Enum type definition.""" + + name: str = aristaproto.string_field(1) + """Enum type name.""" + + enumvalue: List["EnumValue"] = aristaproto.message_field( + 2, wraps=aristaproto.TYPE_ENUM + ) + """Enum value definitions.""" + + options: List["Option"] = aristaproto.message_field(3) + """Protocol buffer options.""" + + source_context: "SourceContext" = aristaproto.message_field(4) + """The source context.""" + + syntax: "Syntax" = aristaproto.enum_field(5) + """The source syntax.""" + + edition: str = aristaproto.string_field(6) + """ + The source edition string, only valid when syntax is SYNTAX_EDITIONS. + """ + + +@dataclass(eq=False, repr=False) +class EnumValue(aristaproto.Message): + """Enum value definition.""" + + name: str = aristaproto.string_field(1) + """Enum value name.""" + + number: int = aristaproto.int32_field(2) + """Enum value number.""" + + options: List["Option"] = aristaproto.message_field(3) + """Protocol buffer options.""" + + +@dataclass(eq=False, repr=False) +class Option(aristaproto.Message): + """ + A protocol buffer option, which can be attached to a message, field, + enumeration, etc. + """ + + name: str = aristaproto.string_field(1) + """ + The option's name. For protobuf built-in options (options defined in + descriptor.proto), this is the short name. For example, `"map_entry"`. + For custom options, it should be the fully-qualified name. For example, + `"google.api.http"`. + """ + + value: "Any" = aristaproto.message_field(2) + """ + The option's value packed in an Any message. If the value is a primitive, + the corresponding wrapper type defined in google/protobuf/wrappers.proto + should be used. If the value is an enum, it should be stored as an int32 + value using the google.protobuf.Int32Value type. + """ + + +@dataclass(eq=False, repr=False) +class Api(aristaproto.Message): + """ + Api is a light-weight descriptor for an API Interface. + + Interfaces are also described as "protocol buffer services" in some contexts, + such as by the "service" keyword in a .proto file, but they are different + from API Services, which represent a concrete implementation of an interface + as opposed to simply a description of methods and bindings. They are also + sometimes simply referred to as "APIs" in other contexts, such as the name of + this message itself. See https://cloud.google.com/apis/design/glossary for + detailed terminology. + """ + + name: str = aristaproto.string_field(1) + """ + The fully qualified name of this interface, including package name + followed by the interface's simple name. + """ + + methods: List["Method"] = aristaproto.message_field(2) + """The methods of this interface, in unspecified order.""" + + options: List["Option"] = aristaproto.message_field(3) + """Any metadata attached to the interface.""" + + version: str = aristaproto.string_field(4) + """ + A version string for this interface. If specified, must have the form + `major-version.minor-version`, as in `1.10`. If the minor version is + omitted, it defaults to zero. If the entire version field is empty, the + major version is derived from the package name, as outlined below. If the + field is not empty, the version in the package name will be verified to be + consistent with what is provided here. + + The versioning schema uses [semantic + versioning](http://semver.org) where the major version number + indicates a breaking change and the minor version an additive, + non-breaking change. Both version numbers are signals to users + what to expect from different versions, and should be carefully + chosen based on the product plan. + + The major version is also reflected in the package name of the + interface, which must end in `v<major-version>`, as in + `google.feature.v1`. For major versions 0 and 1, the suffix can + be omitted. Zero major versions must only be used for + experimental, non-GA interfaces. + """ + + source_context: "SourceContext" = aristaproto.message_field(5) + """ + Source context for the protocol buffer service represented by this + message. + """ + + mixins: List["Mixin"] = aristaproto.message_field(6) + """Included interfaces. See [Mixin][].""" + + syntax: "Syntax" = aristaproto.enum_field(7) + """The source syntax of the service.""" + + +@dataclass(eq=False, repr=False) +class Method(aristaproto.Message): + """Method represents a method of an API interface.""" + + name: str = aristaproto.string_field(1) + """The simple name of this method.""" + + request_type_url: str = aristaproto.string_field(2) + """A URL of the input message type.""" + + request_streaming: bool = aristaproto.bool_field(3) + """If true, the request is streamed.""" + + response_type_url: str = aristaproto.string_field(4) + """The URL of the output message type.""" + + response_streaming: bool = aristaproto.bool_field(5) + """If true, the response is streamed.""" + + options: List["Option"] = aristaproto.message_field(6) + """Any metadata attached to the method.""" + + syntax: "Syntax" = aristaproto.enum_field(7) + """The source syntax of this method.""" + + +@dataclass(eq=False, repr=False) +class Mixin(aristaproto.Message): + """ + Declares an API Interface to be included in this interface. The including + interface must redeclare all the methods from the included interface, but + documentation and options are inherited as follows: + + - If after comment and whitespace stripping, the documentation + string of the redeclared method is empty, it will be inherited + from the original method. + + - Each annotation belonging to the service config (http, + visibility) which is not set in the redeclared method will be + inherited. + + - If an http annotation is inherited, the path pattern will be + modified as follows. Any version prefix will be replaced by the + version of the including interface plus the [root][] path if + specified. + + Example of a simple mixin: + + package google.acl.v1; + service AccessControl { + // Get the underlying ACL object. + rpc GetAcl(GetAclRequest) returns (Acl) { + option (google.api.http).get = "/v1/{resource=**}:getAcl"; + } + } + + package google.storage.v2; + service Storage { + rpc GetAcl(GetAclRequest) returns (Acl); + + // Get a data record. + rpc GetData(GetDataRequest) returns (Data) { + option (google.api.http).get = "/v2/{resource=**}"; + } + } + + Example of a mixin configuration: + + apis: + - name: google.storage.v2.Storage + mixins: + - name: google.acl.v1.AccessControl + + The mixin construct implies that all methods in `AccessControl` are + also declared with same name and request/response types in + `Storage`. A documentation generator or annotation processor will + see the effective `Storage.GetAcl` method after inherting + documentation and annotations as follows: + + service Storage { + // Get the underlying ACL object. + rpc GetAcl(GetAclRequest) returns (Acl) { + option (google.api.http).get = "/v2/{resource=**}:getAcl"; + } + ... + } + + Note how the version in the path pattern changed from `v1` to `v2`. + + If the `root` field in the mixin is specified, it should be a + relative path under which inherited HTTP paths are placed. Example: + + apis: + - name: google.storage.v2.Storage + mixins: + - name: google.acl.v1.AccessControl + root: acls + + This implies the following inherited HTTP annotation: + + service Storage { + // Get the underlying ACL object. + rpc GetAcl(GetAclRequest) returns (Acl) { + option (google.api.http).get = "/v2/acls/{resource=**}:getAcl"; + } + ... + } + """ + + name: str = aristaproto.string_field(1) + """The fully qualified name of the interface which is included.""" + + root: str = aristaproto.string_field(2) + """ + If non-empty specifies a path under which inherited HTTP paths + are rooted. + """ + + +@dataclass(eq=False, repr=False) +class FileDescriptorSet(aristaproto.Message): + """ + The protocol compiler can output a FileDescriptorSet containing the .proto + files it parses. + """ + + file: List["FileDescriptorProto"] = aristaproto.message_field(1) + + +@dataclass(eq=False, repr=False) +class FileDescriptorProto(aristaproto.Message): + """Describes a complete .proto file.""" + + name: str = aristaproto.string_field(1) + package: str = aristaproto.string_field(2) + dependency: List[str] = aristaproto.string_field(3) + """Names of files imported by this file.""" + + public_dependency: List[int] = aristaproto.int32_field(10) + """Indexes of the public imported files in the dependency list above.""" + + weak_dependency: List[int] = aristaproto.int32_field(11) + """ + Indexes of the weak imported files in the dependency list. + For Google-internal migration only. Do not use. + """ + + message_type: List["DescriptorProto"] = aristaproto.message_field(4) + """All top-level definitions in this file.""" + + enum_type: List["EnumDescriptorProto"] = aristaproto.message_field(5) + service: List["ServiceDescriptorProto"] = aristaproto.message_field(6) + extension: List["FieldDescriptorProto"] = aristaproto.message_field(7) + options: "FileOptions" = aristaproto.message_field(8) + source_code_info: "SourceCodeInfo" = aristaproto.message_field(9) + """ + This field contains optional information about the original source code. + You may safely remove this entire field without harming runtime + functionality of the descriptors -- the information is needed only by + development tools. + """ + + syntax: str = aristaproto.string_field(12) + """ + The syntax of the proto file. + The supported values are "proto2", "proto3", and "editions". + + If `edition` is present, this value must be "editions". + """ + + edition: "Edition" = aristaproto.enum_field(14) + """The edition of the proto file.""" + + +@dataclass(eq=False, repr=False) +class DescriptorProto(aristaproto.Message): + """Describes a message type.""" + + name: str = aristaproto.string_field(1) + field: List["FieldDescriptorProto"] = aristaproto.message_field(2) + extension: List["FieldDescriptorProto"] = aristaproto.message_field(6) + nested_type: List["DescriptorProto"] = aristaproto.message_field(3) + enum_type: List["EnumDescriptorProto"] = aristaproto.message_field(4) + extension_range: List["DescriptorProtoExtensionRange"] = aristaproto.message_field( + 5 + ) + oneof_decl: List["OneofDescriptorProto"] = aristaproto.message_field(8) + options: "MessageOptions" = aristaproto.message_field(7) + reserved_range: List["DescriptorProtoReservedRange"] = aristaproto.message_field(9) + reserved_name: List[str] = aristaproto.string_field(10) + """ + Reserved field names, which may not be used by fields in the same message. + A given name may only be reserved once. + """ + + +@dataclass(eq=False, repr=False) +class DescriptorProtoExtensionRange(aristaproto.Message): + start: int = aristaproto.int32_field(1) + end: int = aristaproto.int32_field(2) + options: "ExtensionRangeOptions" = aristaproto.message_field(3) + + +@dataclass(eq=False, repr=False) +class DescriptorProtoReservedRange(aristaproto.Message): + """ + Range of reserved tag numbers. Reserved tag numbers may not be used by + fields or extension ranges in the same message. Reserved ranges may + not overlap. + """ + + start: int = aristaproto.int32_field(1) + end: int = aristaproto.int32_field(2) + + +@dataclass(eq=False, repr=False) +class ExtensionRangeOptions(aristaproto.Message): + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """The parser stores options it doesn't recognize here. See above.""" + + declaration: List["ExtensionRangeOptionsDeclaration"] = aristaproto.message_field(2) + """ + For external users: DO NOT USE. We are in the process of open sourcing + extension declaration and executing internal cleanups before it can be + used externally. + """ + + features: "FeatureSet" = aristaproto.message_field(50) + """Any features defined in the specific edition.""" + + verification: "ExtensionRangeOptionsVerificationState" = aristaproto.enum_field(3) + """ + The verification state of the range. + TODO: flip the default to DECLARATION once all empty ranges + are marked as UNVERIFIED. + """ + + +@dataclass(eq=False, repr=False) +class ExtensionRangeOptionsDeclaration(aristaproto.Message): + number: int = aristaproto.int32_field(1) + """The extension number declared within the extension range.""" + + full_name: str = aristaproto.string_field(2) + """ + The fully-qualified name of the extension field. There must be a leading + dot in front of the full name. + """ + + type: str = aristaproto.string_field(3) + """ + The fully-qualified type name of the extension field. Unlike + Metadata.type, Declaration.type must have a leading dot for messages + and enums. + """ + + reserved: bool = aristaproto.bool_field(5) + """ + If true, indicates that the number is reserved in the extension range, + and any extension field with the number will fail to compile. Set this + when a declared extension field is deleted. + """ + + repeated: bool = aristaproto.bool_field(6) + """ + If true, indicates that the extension must be defined as repeated. + Otherwise the extension must be defined as optional. + """ + + +@dataclass(eq=False, repr=False) +class FieldDescriptorProto(aristaproto.Message): + """Describes a field within a message.""" + + name: str = aristaproto.string_field(1) + number: int = aristaproto.int32_field(3) + label: "FieldDescriptorProtoLabel" = aristaproto.enum_field(4) + type: "FieldDescriptorProtoType" = aristaproto.enum_field(5) + """ + If type_name is set, this need not be set. If both this and type_name + are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP. + """ + + type_name: str = aristaproto.string_field(6) + """ + For message and enum types, this is the name of the type. If the name + starts with a '.', it is fully-qualified. Otherwise, C++-like scoping + rules are used to find the type (i.e. first the nested types within this + message are searched, then within the parent, on up to the root + namespace). + """ + + extendee: str = aristaproto.string_field(2) + """ + For extensions, this is the name of the type being extended. It is + resolved in the same manner as type_name. + """ + + default_value: str = aristaproto.string_field(7) + """ + For numeric types, contains the original text representation of the value. + For booleans, "true" or "false". + For strings, contains the default text contents (not escaped in any way). + For bytes, contains the C escaped value. All bytes >= 128 are escaped. + """ + + oneof_index: int = aristaproto.int32_field(9) + """ + If set, gives the index of a oneof in the containing type's oneof_decl + list. This field is a member of that oneof. + """ + + json_name: str = aristaproto.string_field(10) + """ + JSON name of this field. The value is set by protocol compiler. If the + user has set a "json_name" option on this field, that option's value + will be used. Otherwise, it's deduced from the field's name by converting + it to camelCase. + """ + + options: "FieldOptions" = aristaproto.message_field(8) + proto3_optional: bool = aristaproto.bool_field(17) + """ + If true, this is a proto3 "optional". When a proto3 field is optional, it + tracks presence regardless of field type. + + When proto3_optional is true, this field must belong to a oneof to signal + to old proto3 clients that presence is tracked for this field. This oneof + is known as a "synthetic" oneof, and this field must be its sole member + (each proto3 optional field gets its own synthetic oneof). Synthetic oneofs + exist in the descriptor only, and do not generate any API. Synthetic oneofs + must be ordered after all "real" oneofs. + + For message fields, proto3_optional doesn't create any semantic change, + since non-repeated message fields always track presence. However it still + indicates the semantic detail of whether the user wrote "optional" or not. + This can be useful for round-tripping the .proto file. For consistency we + give message fields a synthetic oneof also, even though it is not required + to track presence. This is especially important because the parser can't + tell if a field is a message or an enum, so it must always create a + synthetic oneof. + + Proto2 optional fields do not set this flag, because they already indicate + optional with `LABEL_OPTIONAL`. + """ + + +@dataclass(eq=False, repr=False) +class OneofDescriptorProto(aristaproto.Message): + """Describes a oneof.""" + + name: str = aristaproto.string_field(1) + options: "OneofOptions" = aristaproto.message_field(2) + + +@dataclass(eq=False, repr=False) +class EnumDescriptorProto(aristaproto.Message): + """Describes an enum type.""" + + name: str = aristaproto.string_field(1) + value: List["EnumValueDescriptorProto"] = aristaproto.message_field(2) + options: "EnumOptions" = aristaproto.message_field(3) + reserved_range: List[ + "EnumDescriptorProtoEnumReservedRange" + ] = aristaproto.message_field(4) + """ + Range of reserved numeric values. Reserved numeric values may not be used + by enum values in the same enum declaration. Reserved ranges may not + overlap. + """ + + reserved_name: List[str] = aristaproto.string_field(5) + """ + Reserved enum value names, which may not be reused. A given name may only + be reserved once. + """ + + +@dataclass(eq=False, repr=False) +class EnumDescriptorProtoEnumReservedRange(aristaproto.Message): + """ + Range of reserved numeric values. Reserved values may not be used by + entries in the same enum. Reserved ranges may not overlap. + + Note that this is distinct from DescriptorProto.ReservedRange in that it + is inclusive such that it can appropriately represent the entire int32 + domain. + """ + + start: int = aristaproto.int32_field(1) + end: int = aristaproto.int32_field(2) + + +@dataclass(eq=False, repr=False) +class EnumValueDescriptorProto(aristaproto.Message): + """Describes a value within an enum.""" + + name: str = aristaproto.string_field(1) + number: int = aristaproto.int32_field(2) + options: "EnumValueOptions" = aristaproto.message_field(3) + + +@dataclass(eq=False, repr=False) +class ServiceDescriptorProto(aristaproto.Message): + """Describes a service.""" + + name: str = aristaproto.string_field(1) + method: List["MethodDescriptorProto"] = aristaproto.message_field(2) + options: "ServiceOptions" = aristaproto.message_field(3) + + +@dataclass(eq=False, repr=False) +class MethodDescriptorProto(aristaproto.Message): + """Describes a method of a service.""" + + name: str = aristaproto.string_field(1) + input_type: str = aristaproto.string_field(2) + """ + Input and output type names. These are resolved in the same way as + FieldDescriptorProto.type_name, but must refer to a message type. + """ + + output_type: str = aristaproto.string_field(3) + options: "MethodOptions" = aristaproto.message_field(4) + client_streaming: bool = aristaproto.bool_field(5) + """Identifies if client streams multiple client messages""" + + server_streaming: bool = aristaproto.bool_field(6) + """Identifies if server streams multiple server messages""" + + +@dataclass(eq=False, repr=False) +class FileOptions(aristaproto.Message): + java_package: str = aristaproto.string_field(1) + """ + Sets the Java package where classes generated from this .proto will be + placed. By default, the proto package is used, but this is often + inappropriate because proto packages do not normally start with backwards + domain names. + """ + + java_outer_classname: str = aristaproto.string_field(8) + """ + Controls the name of the wrapper Java class generated for the .proto file. + That class will always contain the .proto file's getDescriptor() method as + well as any top-level extensions defined in the .proto file. + If java_multiple_files is disabled, then all the other classes from the + .proto file will be nested inside the single wrapper outer class. + """ + + java_multiple_files: bool = aristaproto.bool_field(10) + """ + If enabled, then the Java code generator will generate a separate .java + file for each top-level message, enum, and service defined in the .proto + file. Thus, these types will *not* be nested inside the wrapper class + named by java_outer_classname. However, the wrapper class will still be + generated to contain the file's getDescriptor() method as well as any + top-level extensions defined in the file. + """ + + java_generate_equals_and_hash: bool = aristaproto.bool_field(20) + """This option does nothing.""" + + java_string_check_utf8: bool = aristaproto.bool_field(27) + """ + A proto2 file can set this to true to opt in to UTF-8 checking for Java, + which will throw an exception if invalid UTF-8 is parsed from the wire or + assigned to a string field. + + TODO: clarify exactly what kinds of field types this option + applies to, and update these docs accordingly. + + Proto3 files already perform these checks. Setting the option explicitly to + false has no effect: it cannot be used to opt proto3 files out of UTF-8 + checks. + """ + + optimize_for: "FileOptionsOptimizeMode" = aristaproto.enum_field(9) + go_package: str = aristaproto.string_field(11) + """ + Sets the Go package where structs generated from this .proto will be + placed. If omitted, the Go package will be derived from the following: + - The basename of the package import path, if provided. + - Otherwise, the package statement in the .proto file, if present. + - Otherwise, the basename of the .proto file, without extension. + """ + + cc_generic_services: bool = aristaproto.bool_field(16) + """ + Should generic services be generated in each language? "Generic" services + are not specific to any particular RPC system. They are generated by the + main code generators in each language (without additional plugins). + Generic services were the only kind of service generation supported by + early versions of google.protobuf. + + Generic services are now considered deprecated in favor of using plugins + that generate code specific to your particular RPC system. Therefore, + these default to false. Old code which depends on generic services should + explicitly set them to true. + """ + + java_generic_services: bool = aristaproto.bool_field(17) + py_generic_services: bool = aristaproto.bool_field(18) + deprecated: bool = aristaproto.bool_field(23) + """ + Is this file deprecated? + Depending on the target platform, this can emit Deprecated annotations + for everything in the file, or it will be completely ignored; in the very + least, this is a formalization for deprecating files. + """ + + cc_enable_arenas: bool = aristaproto.bool_field(31) + """ + Enables the use of arenas for the proto messages in this file. This applies + only to generated classes for C++. + """ + + objc_class_prefix: str = aristaproto.string_field(36) + """ + Sets the objective c class prefix which is prepended to all objective c + generated classes from this .proto. There is no default. + """ + + csharp_namespace: str = aristaproto.string_field(37) + """Namespace for generated classes; defaults to the package.""" + + swift_prefix: str = aristaproto.string_field(39) + """ + By default Swift generators will take the proto package and CamelCase it + replacing '.' with underscore and use that to prefix the types/symbols + defined. When this options is provided, they will use this value instead + to prefix the types/symbols defined. + """ + + php_class_prefix: str = aristaproto.string_field(40) + """ + Sets the php class prefix which is prepended to all php generated classes + from this .proto. Default is empty. + """ + + php_namespace: str = aristaproto.string_field(41) + """ + Use this option to change the namespace of php generated classes. Default + is empty. When this option is empty, the package name will be used for + determining the namespace. + """ + + php_metadata_namespace: str = aristaproto.string_field(44) + """ + Use this option to change the namespace of php generated metadata classes. + Default is empty. When this option is empty, the proto file name will be + used for determining the namespace. + """ + + ruby_package: str = aristaproto.string_field(45) + """ + Use this option to change the package of ruby generated classes. Default + is empty. When this option is not set, the package name will be used for + determining the ruby package. + """ + + features: "FeatureSet" = aristaproto.message_field(50) + """Any features defined in the specific edition.""" + + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """ + The parser stores options it doesn't recognize here. + See the documentation for the "Options" section above. + """ + + def __post_init__(self) -> None: + super().__post_init__() + if self.is_set("java_generate_equals_and_hash"): + warnings.warn( + "FileOptions.java_generate_equals_and_hash is deprecated", + DeprecationWarning, + ) + + +@dataclass(eq=False, repr=False) +class MessageOptions(aristaproto.Message): + message_set_wire_format: bool = aristaproto.bool_field(1) + """ + Set true to use the old proto1 MessageSet wire format for extensions. + This is provided for backwards-compatibility with the MessageSet wire + format. You should not use this for any other reason: It's less + efficient, has fewer features, and is more complicated. + + The message must be defined exactly as follows: + message Foo { + option message_set_wire_format = true; + extensions 4 to max; + } + Note that the message cannot have any defined fields; MessageSets only + have extensions. + + All extensions of your type must be singular messages; e.g. they cannot + be int32s, enums, or repeated messages. + + Because this is an option, the above two restrictions are not enforced by + the protocol compiler. + """ + + no_standard_descriptor_accessor: bool = aristaproto.bool_field(2) + """ + Disables the generation of the standard "descriptor()" accessor, which can + conflict with a field of the same name. This is meant to make migration + from proto1 easier; new code should avoid fields named "descriptor". + """ + + deprecated: bool = aristaproto.bool_field(3) + """ + Is this message deprecated? + Depending on the target platform, this can emit Deprecated annotations + for the message, or it will be completely ignored; in the very least, + this is a formalization for deprecating messages. + """ + + map_entry: bool = aristaproto.bool_field(7) + """ + Whether the message is an automatically generated map entry type for the + maps field. + + For maps fields: + map<KeyType, ValueType> map_field = 1; + The parsed descriptor looks like: + message MapFieldEntry { + option map_entry = true; + optional KeyType key = 1; + optional ValueType value = 2; + } + repeated MapFieldEntry map_field = 1; + + Implementations may choose not to generate the map_entry=true message, but + use a native map in the target language to hold the keys and values. + The reflection APIs in such implementations still need to work as + if the field is a repeated message field. + + NOTE: Do not set the option in .proto files. Always use the maps syntax + instead. The option should only be implicitly set by the proto compiler + parser. + """ + + deprecated_legacy_json_field_conflicts: bool = aristaproto.bool_field(11) + """ + Enable the legacy handling of JSON field name conflicts. This lowercases + and strips underscored from the fields before comparison in proto3 only. + The new behavior takes `json_name` into account and applies to proto2 as + well. + + This should only be used as a temporary measure against broken builds due + to the change in behavior for JSON field name conflicts. + + TODO This is legacy behavior we plan to remove once downstream + teams have had time to migrate. + """ + + features: "FeatureSet" = aristaproto.message_field(12) + """Any features defined in the specific edition.""" + + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """The parser stores options it doesn't recognize here. See above.""" + + def __post_init__(self) -> None: + super().__post_init__() + if self.is_set("deprecated_legacy_json_field_conflicts"): + warnings.warn( + "MessageOptions.deprecated_legacy_json_field_conflicts is deprecated", + DeprecationWarning, + ) + + +@dataclass(eq=False, repr=False) +class FieldOptions(aristaproto.Message): + ctype: "FieldOptionsCType" = aristaproto.enum_field(1) + """ + The ctype option instructs the C++ code generator to use a different + representation of the field than it normally would. See the specific + options below. This option is only implemented to support use of + [ctype=CORD] and [ctype=STRING] (the default) on non-repeated fields of + type "bytes" in the open source release -- sorry, we'll try to include + other types in a future version! + """ + + packed: bool = aristaproto.bool_field(2) + """ + The packed option can be enabled for repeated primitive fields to enable + a more efficient representation on the wire. Rather than repeatedly + writing the tag and type for each element, the entire array is encoded as + a single length-delimited blob. In proto3, only explicit setting it to + false will avoid using packed encoding. This option is prohibited in + Editions, but the `repeated_field_encoding` feature can be used to control + the behavior. + """ + + jstype: "FieldOptionsJsType" = aristaproto.enum_field(6) + """ + The jstype option determines the JavaScript type used for values of the + field. The option is permitted only for 64 bit integral and fixed types + (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING + is represented as JavaScript string, which avoids loss of precision that + can happen when a large value is converted to a floating point JavaScript. + Specifying JS_NUMBER for the jstype causes the generated JavaScript code to + use the JavaScript "number" type. The behavior of the default option + JS_NORMAL is implementation dependent. + + This option is an enum to permit additional types to be added, e.g. + goog.math.Integer. + """ + + lazy: bool = aristaproto.bool_field(5) + """ + Should this field be parsed lazily? Lazy applies only to message-type + fields. It means that when the outer message is initially parsed, the + inner message's contents will not be parsed but instead stored in encoded + form. The inner message will actually be parsed when it is first accessed. + + This is only a hint. Implementations are free to choose whether to use + eager or lazy parsing regardless of the value of this option. However, + setting this option true suggests that the protocol author believes that + using lazy parsing on this field is worth the additional bookkeeping + overhead typically needed to implement it. + + This option does not affect the public interface of any generated code; + all method signatures remain the same. Furthermore, thread-safety of the + interface is not affected by this option; const methods remain safe to + call from multiple threads concurrently, while non-const methods continue + to require exclusive access. + + Note that lazy message fields are still eagerly verified to check + ill-formed wireformat or missing required fields. Calling IsInitialized() + on the outer message would fail if the inner message has missing required + fields. Failed verification would result in parsing failure (except when + uninitialized messages are acceptable). + """ + + unverified_lazy: bool = aristaproto.bool_field(15) + """ + unverified_lazy does no correctness checks on the byte stream. This should + only be used where lazy with verification is prohibitive for performance + reasons. + """ + + deprecated: bool = aristaproto.bool_field(3) + """ + Is this field deprecated? + Depending on the target platform, this can emit Deprecated annotations + for accessors, or it will be completely ignored; in the very least, this + is a formalization for deprecating fields. + """ + + weak: bool = aristaproto.bool_field(10) + """For Google-internal migration only. Do not use.""" + + debug_redact: bool = aristaproto.bool_field(16) + """ + Indicate that the field value should not be printed out when using debug + formats, e.g. when the field contains sensitive credentials. + """ + + retention: "FieldOptionsOptionRetention" = aristaproto.enum_field(17) + targets: List["FieldOptionsOptionTargetType"] = aristaproto.enum_field(19) + edition_defaults: List["FieldOptionsEditionDefault"] = aristaproto.message_field(20) + features: "FeatureSet" = aristaproto.message_field(21) + """Any features defined in the specific edition.""" + + feature_support: "FieldOptionsFeatureSupport" = aristaproto.message_field(22) + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """The parser stores options it doesn't recognize here. See above.""" + + +@dataclass(eq=False, repr=False) +class FieldOptionsEditionDefault(aristaproto.Message): + edition: "Edition" = aristaproto.enum_field(3) + value: str = aristaproto.string_field(2) + + +@dataclass(eq=False, repr=False) +class FieldOptionsFeatureSupport(aristaproto.Message): + """Information about the support window of a feature.""" + + edition_introduced: "Edition" = aristaproto.enum_field(1) + """ + The edition that this feature was first available in. In editions + earlier than this one, the default assigned to EDITION_LEGACY will be + used, and proto files will not be able to override it. + """ + + edition_deprecated: "Edition" = aristaproto.enum_field(2) + """ + The edition this feature becomes deprecated in. Using this after this + edition may trigger warnings. + """ + + deprecation_warning: str = aristaproto.string_field(3) + """ + The deprecation warning text if this feature is used after the edition it + was marked deprecated in. + """ + + edition_removed: "Edition" = aristaproto.enum_field(4) + """ + The edition this feature is no longer available in. In editions after + this one, the last default assigned will be used, and proto files will + not be able to override it. + """ + + +@dataclass(eq=False, repr=False) +class OneofOptions(aristaproto.Message): + features: "FeatureSet" = aristaproto.message_field(1) + """Any features defined in the specific edition.""" + + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """The parser stores options it doesn't recognize here. See above.""" + + +@dataclass(eq=False, repr=False) +class EnumOptions(aristaproto.Message): + allow_alias: bool = aristaproto.bool_field(2) + """ + Set this option to true to allow mapping different tag names to the same + value. + """ + + deprecated: bool = aristaproto.bool_field(3) + """ + Is this enum deprecated? + Depending on the target platform, this can emit Deprecated annotations + for the enum, or it will be completely ignored; in the very least, this + is a formalization for deprecating enums. + """ + + deprecated_legacy_json_field_conflicts: bool = aristaproto.bool_field(6) + """ + Enable the legacy handling of JSON field name conflicts. This lowercases + and strips underscored from the fields before comparison in proto3 only. + The new behavior takes `json_name` into account and applies to proto2 as + well. + TODO Remove this legacy behavior once downstream teams have + had time to migrate. + """ + + features: "FeatureSet" = aristaproto.message_field(7) + """Any features defined in the specific edition.""" + + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """The parser stores options it doesn't recognize here. See above.""" + + def __post_init__(self) -> None: + super().__post_init__() + if self.is_set("deprecated_legacy_json_field_conflicts"): + warnings.warn( + "EnumOptions.deprecated_legacy_json_field_conflicts is deprecated", + DeprecationWarning, + ) + + +@dataclass(eq=False, repr=False) +class EnumValueOptions(aristaproto.Message): + deprecated: bool = aristaproto.bool_field(1) + """ + Is this enum value deprecated? + Depending on the target platform, this can emit Deprecated annotations + for the enum value, or it will be completely ignored; in the very least, + this is a formalization for deprecating enum values. + """ + + features: "FeatureSet" = aristaproto.message_field(2) + """Any features defined in the specific edition.""" + + debug_redact: bool = aristaproto.bool_field(3) + """ + Indicate that fields annotated with this enum value should not be printed + out when using debug formats, e.g. when the field contains sensitive + credentials. + """ + + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """The parser stores options it doesn't recognize here. See above.""" + + +@dataclass(eq=False, repr=False) +class ServiceOptions(aristaproto.Message): + features: "FeatureSet" = aristaproto.message_field(34) + """Any features defined in the specific edition.""" + + deprecated: bool = aristaproto.bool_field(33) + """ + Is this service deprecated? + Depending on the target platform, this can emit Deprecated annotations + for the service, or it will be completely ignored; in the very least, + this is a formalization for deprecating services. + """ + + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """The parser stores options it doesn't recognize here. See above.""" + + +@dataclass(eq=False, repr=False) +class MethodOptions(aristaproto.Message): + deprecated: bool = aristaproto.bool_field(33) + """ + Is this method deprecated? + Depending on the target platform, this can emit Deprecated annotations + for the method, or it will be completely ignored; in the very least, + this is a formalization for deprecating methods. + """ + + idempotency_level: "MethodOptionsIdempotencyLevel" = aristaproto.enum_field(34) + features: "FeatureSet" = aristaproto.message_field(35) + """Any features defined in the specific edition.""" + + uninterpreted_option: List["UninterpretedOption"] = aristaproto.message_field(999) + """The parser stores options it doesn't recognize here. See above.""" + + +@dataclass(eq=False, repr=False) +class UninterpretedOption(aristaproto.Message): + """ + A message representing a option the parser does not recognize. This only + appears in options protos created by the compiler::Parser class. + DescriptorPool resolves these when building Descriptor objects. Therefore, + options protos in descriptor objects (e.g. returned by Descriptor::options(), + or produced by Descriptor::CopyTo()) will never have UninterpretedOptions + in them. + """ + + name: List["UninterpretedOptionNamePart"] = aristaproto.message_field(2) + identifier_value: str = aristaproto.string_field(3) + """ + The value of the uninterpreted option, in whatever type the tokenizer + identified it as during parsing. Exactly one of these should be set. + """ + + positive_int_value: int = aristaproto.uint64_field(4) + negative_int_value: int = aristaproto.int64_field(5) + double_value: float = aristaproto.double_field(6) + string_value: bytes = aristaproto.bytes_field(7) + aggregate_value: str = aristaproto.string_field(8) + + +@dataclass(eq=False, repr=False) +class UninterpretedOptionNamePart(aristaproto.Message): + """ + The name of the uninterpreted option. Each string represents a segment in + a dot-separated name. is_extension is true iff a segment represents an + extension (denoted with parentheses in options specs in .proto files). + E.g.,{ ["foo", false], ["bar.baz", true], ["moo", false] } represents + "foo.(bar.baz).moo". + """ + + name_part: str = aristaproto.string_field(1) + is_extension: bool = aristaproto.bool_field(2) + + +@dataclass(eq=False, repr=False) +class FeatureSet(aristaproto.Message): + """ + TODO Enums in C++ gencode (and potentially other languages) are + not well scoped. This means that each of the feature enums below can clash + with each other. The short names we've chosen maximize call-site + readability, but leave us very open to this scenario. A future feature will + be designed and implemented to handle this, hopefully before we ever hit a + conflict here. + """ + + field_presence: "FeatureSetFieldPresence" = aristaproto.enum_field(1) + enum_type: "FeatureSetEnumType" = aristaproto.enum_field(2) + repeated_field_encoding: "FeatureSetRepeatedFieldEncoding" = aristaproto.enum_field( + 3 + ) + utf8_validation: "FeatureSetUtf8Validation" = aristaproto.enum_field(4) + message_encoding: "FeatureSetMessageEncoding" = aristaproto.enum_field(5) + json_format: "FeatureSetJsonFormat" = aristaproto.enum_field(6) + + +@dataclass(eq=False, repr=False) +class FeatureSetDefaults(aristaproto.Message): + """ + A compiled specification for the defaults of a set of features. These + messages are generated from FeatureSet extensions and can be used to seed + feature resolution. The resolution with this object becomes a simple search + for the closest matching edition, followed by proto merges. + """ + + defaults: List[ + "FeatureSetDefaultsFeatureSetEditionDefault" + ] = aristaproto.message_field(1) + minimum_edition: "Edition" = aristaproto.enum_field(4) + """ + The minimum supported edition (inclusive) when this was constructed. + Editions before this will not have defaults. + """ + + maximum_edition: "Edition" = aristaproto.enum_field(5) + """ + The maximum known edition (inclusive) when this was constructed. Editions + after this will not have reliable defaults. + """ + + +@dataclass(eq=False, repr=False) +class FeatureSetDefaultsFeatureSetEditionDefault(aristaproto.Message): + """ + A map from every known edition with a unique set of defaults to its + defaults. Not all editions may be contained here. For a given edition, + the defaults at the closest matching edition ordered at or before it should + be used. This field must be in strict ascending order by edition. + """ + + edition: "Edition" = aristaproto.enum_field(3) + overridable_features: "FeatureSet" = aristaproto.message_field(4) + """Defaults of features that can be overridden in this edition.""" + + fixed_features: "FeatureSet" = aristaproto.message_field(5) + """Defaults of features that can't be overridden in this edition.""" + + features: "FeatureSet" = aristaproto.message_field(2) + """ + TODO Deprecate and remove this field, which is just the + above two merged. + """ + + +@dataclass(eq=False, repr=False) +class SourceCodeInfo(aristaproto.Message): + """ + Encapsulates information about the original source file from which a + FileDescriptorProto was generated. + """ + + location: List["SourceCodeInfoLocation"] = aristaproto.message_field(1) + """ + A Location identifies a piece of source code in a .proto file which + corresponds to a particular definition. This information is intended + to be useful to IDEs, code indexers, documentation generators, and similar + tools. + + For example, say we have a file like: + message Foo { + optional string foo = 1; + } + Let's look at just the field definition: + optional string foo = 1; + ^ ^^ ^^ ^ ^^^ + a bc de f ghi + We have the following locations: + span path represents + [a,i) [ 4, 0, 2, 0 ] The whole field definition. + [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). + [c,d) [ 4, 0, 2, 0, 5 ] The type (string). + [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). + [g,h) [ 4, 0, 2, 0, 3 ] The number (1). + + Notes: + - A location may refer to a repeated field itself (i.e. not to any + particular index within it). This is used whenever a set of elements are + logically enclosed in a single code segment. For example, an entire + extend block (possibly containing multiple extension definitions) will + have an outer location whose path refers to the "extensions" repeated + field without an index. + - Multiple locations may have the same path. This happens when a single + logical declaration is spread out across multiple places. The most + obvious example is the "extend" block again -- there may be multiple + extend blocks in the same scope, each of which will have the same path. + - A location's span is not always a subset of its parent's span. For + example, the "extendee" of an extension declaration appears at the + beginning of the "extend" block and is shared by all extensions within + the block. + - Just because a location's span is a subset of some other location's span + does not mean that it is a descendant. For example, a "group" defines + both a type and a field in a single declaration. Thus, the locations + corresponding to the type and field and their components will overlap. + - Code which tries to interpret locations should probably be designed to + ignore those that it doesn't understand, as more types of locations could + be recorded in the future. + """ + + +@dataclass(eq=False, repr=False) +class SourceCodeInfoLocation(aristaproto.Message): + path: List[int] = aristaproto.int32_field(1) + """ + Identifies which part of the FileDescriptorProto was defined at this + location. + + Each element is a field number or an index. They form a path from + the root FileDescriptorProto to the place where the definition appears. + For example, this path: + [ 4, 3, 2, 7, 1 ] + refers to: + file.message_type(3) // 4, 3 + .field(7) // 2, 7 + .name() // 1 + This is because FileDescriptorProto.message_type has field number 4: + repeated DescriptorProto message_type = 4; + and DescriptorProto.field has field number 2: + repeated FieldDescriptorProto field = 2; + and FieldDescriptorProto.name has field number 1: + optional string name = 1; + + Thus, the above path gives the location of a field name. If we removed + the last element: + [ 4, 3, 2, 7 ] + this path refers to the whole field declaration (from the beginning + of the label to the terminating semicolon). + """ + + span: List[int] = aristaproto.int32_field(2) + """ + Always has exactly three or four elements: start line, start column, + end line (optional, otherwise assumed same as start line), end column. + These are packed into a single field for efficiency. Note that line + and column numbers are zero-based -- typically you will want to add + 1 to each before displaying to a user. + """ + + leading_comments: str = aristaproto.string_field(3) + """ + If this SourceCodeInfo represents a complete declaration, these are any + comments appearing before and after the declaration which appear to be + attached to the declaration. + + A series of line comments appearing on consecutive lines, with no other + tokens appearing on those lines, will be treated as a single comment. + + leading_detached_comments will keep paragraphs of comments that appear + before (but not connected to) the current element. Each paragraph, + separated by empty lines, will be one comment element in the repeated + field. + + Only the comment content is provided; comment markers (e.g. //) are + stripped out. For block comments, leading whitespace and an asterisk + will be stripped from the beginning of each line other than the first. + Newlines are included in the output. + + Examples: + + optional int32 foo = 1; // Comment attached to foo. + // Comment attached to bar. + optional int32 bar = 2; + + optional string baz = 3; + // Comment attached to baz. + // Another line attached to baz. + + // Comment attached to moo. + // + // Another line attached to moo. + optional double moo = 4; + + // Detached comment for corge. This is not leading or trailing comments + // to moo or corge because there are blank lines separating it from + // both. + + // Detached comment for corge paragraph 2. + + optional string corge = 5; + /* Block comment attached + * to corge. Leading asterisks + * will be removed. */ + /* Block comment attached to + * grault. */ + optional int32 grault = 6; + + // ignored detached comments. + """ + + trailing_comments: str = aristaproto.string_field(4) + leading_detached_comments: List[str] = aristaproto.string_field(6) + + +@dataclass(eq=False, repr=False) +class GeneratedCodeInfo(aristaproto.Message): + """ + Describes the relationship between generated code and its original source + file. A GeneratedCodeInfo message is associated with only one generated + source file, but may contain references to different source .proto files. + """ + + annotation: List["GeneratedCodeInfoAnnotation"] = aristaproto.message_field(1) + """ + An Annotation connects some span of text in generated code to an element + of its generating .proto file. + """ + + +@dataclass(eq=False, repr=False) +class GeneratedCodeInfoAnnotation(aristaproto.Message): + path: List[int] = aristaproto.int32_field(1) + """ + Identifies the element in the original source .proto file. This field + is formatted the same as SourceCodeInfo.Location.path. + """ + + source_file: str = aristaproto.string_field(2) + """Identifies the filesystem path to the original source .proto.""" + + begin: int = aristaproto.int32_field(3) + """ + Identifies the starting offset in bytes in the generated code + that relates to the identified object. + """ + + end: int = aristaproto.int32_field(4) + """ + Identifies the ending offset in bytes in the generated code that + relates to the identified object. The end offset should be one past + the last relevant byte (so the length of the text = end - begin). + """ + + semantic: "GeneratedCodeInfoAnnotationSemantic" = aristaproto.enum_field(5) + + +@dataclass(eq=False, repr=False) +class Duration(aristaproto.Message): + """ + A Duration represents a signed, fixed-length span of time represented + as a count of seconds and fractions of seconds at nanosecond + resolution. It is independent of any calendar and concepts like "day" + or "month". It is related to Timestamp in that the difference between + two Timestamp values is a Duration and it can be added or subtracted + from a Timestamp. Range is approximately +-10,000 years. + + # Examples + + Example 1: Compute Duration from two Timestamps in pseudo code. + + Timestamp start = ...; + Timestamp end = ...; + Duration duration = ...; + + duration.seconds = end.seconds - start.seconds; + duration.nanos = end.nanos - start.nanos; + + if (duration.seconds < 0 && duration.nanos > 0) { + duration.seconds += 1; + duration.nanos -= 1000000000; + } else if (duration.seconds > 0 && duration.nanos < 0) { + duration.seconds -= 1; + duration.nanos += 1000000000; + } + + Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. + + Timestamp start = ...; + Duration duration = ...; + Timestamp end = ...; + + end.seconds = start.seconds + duration.seconds; + end.nanos = start.nanos + duration.nanos; + + if (end.nanos < 0) { + end.seconds -= 1; + end.nanos += 1000000000; + } else if (end.nanos >= 1000000000) { + end.seconds += 1; + end.nanos -= 1000000000; + } + + Example 3: Compute Duration from datetime.timedelta in Python. + + td = datetime.timedelta(days=3, minutes=10) + duration = Duration() + duration.FromTimedelta(td) + + # JSON Mapping + + In JSON format, the Duration type is encoded as a string rather than an + object, where the string ends in the suffix "s" (indicating seconds) and + is preceded by the number of seconds, with nanoseconds expressed as + fractional seconds. For example, 3 seconds with 0 nanoseconds should be + encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should + be expressed in JSON format as "3.000000001s", and 3 seconds and 1 + microsecond should be expressed in JSON format as "3.000001s". + """ + + seconds: int = aristaproto.int64_field(1) + """ + Signed seconds of the span of time. Must be from -315,576,000,000 + to +315,576,000,000 inclusive. Note: these bounds are computed from: + 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years + """ + + nanos: int = aristaproto.int32_field(2) + """ + Signed fractions of a second at nanosecond resolution of the span + of time. Durations less than one second are represented with a 0 + `seconds` field and a positive or negative `nanos` field. For durations + of one second or more, a non-zero value for the `nanos` field must be + of the same sign as the `seconds` field. Must be from -999,999,999 + to +999,999,999 inclusive. + """ + + +@dataclass(eq=False, repr=False) +class Empty(aristaproto.Message): + """ + A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to use it as the request + or the response type of an API method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); + } + """ + + pass + + +@dataclass(eq=False, repr=False) +class FieldMask(aristaproto.Message): + """ + `FieldMask` represents a set of symbolic field paths, for example: + + paths: "f.a" + paths: "f.b.d" + + Here `f` represents a field in some root message, `a` and `b` + fields in the message found in `f`, and `d` a field found in the + message in `f.b`. + + Field masks are used to specify a subset of fields that should be + returned by a get operation or modified by an update operation. + Field masks also have a custom JSON encoding (see below). + + # Field Masks in Projections + + When used in the context of a projection, a response message or + sub-message is filtered by the API to only contain those fields as + specified in the mask. For example, if the mask in the previous + example is applied to a response message as follows: + + f { + a : 22 + b { + d : 1 + x : 2 + } + y : 13 + } + z: 8 + + The result will not contain specific values for fields x,y and z + (their value will be set to the default, and omitted in proto text + output): + + + f { + a : 22 + b { + d : 1 + } + } + + A repeated field is not allowed except at the last position of a + paths string. + + If a FieldMask object is not present in a get operation, the + operation applies to all fields (as if a FieldMask of all fields + had been specified). + + Note that a field mask does not necessarily apply to the + top-level response message. In case of a REST get operation, the + field mask applies directly to the response, but in case of a REST + list operation, the mask instead applies to each individual message + in the returned resource list. In case of a REST custom method, + other definitions may be used. Where the mask applies will be + clearly documented together with its declaration in the API. In + any case, the effect on the returned resource/resources is required + behavior for APIs. + + # Field Masks in Update Operations + + A field mask in update operations specifies which fields of the + targeted resource are going to be updated. The API is required + to only change the values of the fields as specified in the mask + and leave the others untouched. If a resource is passed in to + describe the updated values, the API ignores the values of all + fields not covered by the mask. + + If a repeated field is specified for an update operation, new values will + be appended to the existing repeated field in the target resource. Note that + a repeated field is only allowed in the last position of a `paths` string. + + If a sub-message is specified in the last position of the field mask for an + update operation, then new value will be merged into the existing sub-message + in the target resource. + + For example, given the target message: + + f { + b { + d: 1 + x: 2 + } + c: [1] + } + + And an update message: + + f { + b { + d: 10 + } + c: [2] + } + + then if the field mask is: + + paths: ["f.b", "f.c"] + + then the result will be: + + f { + b { + d: 10 + x: 2 + } + c: [1, 2] + } + + An implementation may provide options to override this default behavior for + repeated and message fields. + + In order to reset a field's value to the default, the field must + be in the mask and set to the default value in the provided resource. + Hence, in order to reset all fields of a resource, provide a default + instance of the resource and set all fields in the mask, or do + not provide a mask as described below. + + If a field mask is not present on update, the operation applies to + all fields (as if a field mask of all fields has been specified). + Note that in the presence of schema evolution, this may mean that + fields the client does not know and has therefore not filled into + the request will be reset to their default. If this is unwanted + behavior, a specific service may require a client to always specify + a field mask, producing an error if not. + + As with get operations, the location of the resource which + describes the updated values in the request message depends on the + operation kind. In any case, the effect of the field mask is + required to be honored by the API. + + ## Considerations for HTTP REST + + The HTTP kind of an update operation which uses a field mask must + be set to PATCH instead of PUT in order to satisfy HTTP semantics + (PUT must only be used for full updates). + + # JSON Encoding of Field Masks + + In JSON, a field mask is encoded as a single string where paths are + separated by a comma. Fields name in each path are converted + to/from lower-camel naming conventions. + + As an example, consider the following message declarations: + + message Profile { + User user = 1; + Photo photo = 2; + } + message User { + string display_name = 1; + string address = 2; + } + + In proto a field mask for `Profile` may look as such: + + mask { + paths: "user.display_name" + paths: "photo" + } + + In JSON, the same mask is represented as below: + + { + mask: "user.displayName,photo" + } + + # Field Masks and Oneof Fields + + Field masks treat fields in oneofs just as regular fields. Consider the + following message: + + message SampleMessage { + oneof test_oneof { + string name = 4; + SubMessage sub_message = 9; + } + } + + The field mask can be: + + mask { + paths: "name" + } + + Or: + + mask { + paths: "sub_message" + } + + Note that oneof type names ("test_oneof" in this case) cannot be used in + paths. + + ## Field Mask Verification + + The implementation of any API method which has a FieldMask type field in the + request should verify the included field paths, and return an + `INVALID_ARGUMENT` error if any path is unmappable. + """ + + paths: List[str] = aristaproto.string_field(1) + """The set of field mask paths.""" + + +@dataclass(eq=False, repr=False) +class Struct(aristaproto.Message): + """ + `Struct` represents a structured data value, consisting of fields + which map to dynamically typed values. In some languages, `Struct` + might be supported by a native representation. For example, in + scripting languages like JS a struct is represented as an + object. The details of that representation are described together + with the proto support for the language. + + The JSON representation for `Struct` is JSON object. + """ + + fields: Dict[str, "Value"] = aristaproto.map_field( + 1, aristaproto.TYPE_STRING, aristaproto.TYPE_MESSAGE + ) + """Unordered map of dynamically typed values.""" + + @hybridmethod + def from_dict(cls: "type[Self]", value: Mapping[str, Any]) -> Self: # type: ignore + self = cls() + return self.from_dict(value) + + @from_dict.instancemethod + def from_dict(self, value: Mapping[str, Any]) -> Self: + fields = {**value} + for k in fields: + if hasattr(fields[k], "from_dict"): + fields[k] = fields[k].from_dict() + + self.fields = fields + return self + + def to_dict( + self, + casing: aristaproto.Casing = aristaproto.Casing.CAMEL, + include_default_values: bool = False, + ) -> Dict[str, Any]: + output = {**self.fields} + for k in self.fields: + if hasattr(self.fields[k], "to_dict"): + output[k] = self.fields[k].to_dict(casing, include_default_values) + return output + + +@dataclass(eq=False, repr=False) +class Value(aristaproto.Message): + """ + `Value` represents a dynamically typed value which can be either + null, a number, a string, a boolean, a recursive struct value, or a + list of values. A producer of value is expected to set one of these + variants. Absence of any variant indicates an error. + + The JSON representation for `Value` is JSON value. + """ + + null_value: "NullValue" = aristaproto.enum_field(1, group="kind") + """Represents a null value.""" + + number_value: float = aristaproto.double_field(2, group="kind") + """Represents a double value.""" + + string_value: str = aristaproto.string_field(3, group="kind") + """Represents a string value.""" + + bool_value: bool = aristaproto.bool_field(4, group="kind") + """Represents a boolean value.""" + + struct_value: "Struct" = aristaproto.message_field(5, group="kind") + """Represents a structured value.""" + + list_value: "ListValue" = aristaproto.message_field(6, group="kind") + """Represents a repeated `Value`.""" + + +@dataclass(eq=False, repr=False) +class ListValue(aristaproto.Message): + """ + `ListValue` is a wrapper around a repeated field of values. + + The JSON representation for `ListValue` is JSON array. + """ + + values: List["Value"] = aristaproto.message_field(1) + """Repeated field of dynamically typed values.""" + + +@dataclass(eq=False, repr=False) +class Timestamp(aristaproto.Message): + """ + A Timestamp represents a point in time independent of any time zone or local + calendar, encoded as a count of seconds and fractions of seconds at + nanosecond resolution. The count is relative to an epoch at UTC midnight on + January 1, 1970, in the proleptic Gregorian calendar which extends the + Gregorian calendar backwards to year one. + + All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap + second table is needed for interpretation, using a [24-hour linear + smear](https://developers.google.com/time/smear). + + The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By + restricting to that range, we ensure that we can convert to and from [RFC + 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. + + # Examples + + Example 1: Compute Timestamp from POSIX `time()`. + + Timestamp timestamp; + timestamp.set_seconds(time(NULL)); + timestamp.set_nanos(0); + + Example 2: Compute Timestamp from POSIX `gettimeofday()`. + + struct timeval tv; + gettimeofday(&tv, NULL); + + Timestamp timestamp; + timestamp.set_seconds(tv.tv_sec); + timestamp.set_nanos(tv.tv_usec * 1000); + + Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. + + FILETIME ft; + GetSystemTimeAsFileTime(&ft); + UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + + // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z + // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. + Timestamp timestamp; + timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); + timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); + + Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. + + long millis = System.currentTimeMillis(); + + Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) + .setNanos((int) ((millis % 1000) * 1000000)).build(); + + Example 5: Compute Timestamp from Java `Instant.now()`. + + Instant now = Instant.now(); + + Timestamp timestamp = + Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + .setNanos(now.getNano()).build(); + + Example 6: Compute Timestamp from current time in Python. + + timestamp = Timestamp() + timestamp.GetCurrentTime() + + # JSON Mapping + + In JSON format, the Timestamp type is encoded as a string in the + [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the + format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" + where {year} is always expressed using four digits while {month}, {day}, + {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional + seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), + are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone + is required. A proto3 JSON serializer should always use UTC (as indicated by + "Z") when printing the Timestamp type and a proto3 JSON parser should be + able to accept both UTC and other timezones (as indicated by an offset). + + For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past + 01:30 UTC on January 15, 2017. + + In JavaScript, one can convert a Date object to this format using the + standard + [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) + method. In Python, a standard `datetime.datetime` object can be converted + to this format using + [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with + the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use + the Joda Time's [`ISODateTimeFormat.dateTime()`]( + http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime() + ) to obtain a formatter capable of generating timestamps in this format. + """ + + seconds: int = aristaproto.int64_field(1) + """ + Represents seconds of UTC time since Unix epoch + 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + 9999-12-31T23:59:59Z inclusive. + """ + + nanos: int = aristaproto.int32_field(2) + """ + Non-negative fractions of a second at nanosecond resolution. Negative + second values with fractions must still have non-negative nanos values + that count forward in time. Must be from 0 to 999,999,999 + inclusive. + """ + + +@dataclass(eq=False, repr=False) +class DoubleValue(aristaproto.Message): + """ + Wrapper message for `double`. + + The JSON representation for `DoubleValue` is JSON number. + """ + + value: float = aristaproto.double_field(1) + """The double value.""" + + +@dataclass(eq=False, repr=False) +class FloatValue(aristaproto.Message): + """ + Wrapper message for `float`. + + The JSON representation for `FloatValue` is JSON number. + """ + + value: float = aristaproto.float_field(1) + """The float value.""" + + +@dataclass(eq=False, repr=False) +class Int64Value(aristaproto.Message): + """ + Wrapper message for `int64`. + + The JSON representation for `Int64Value` is JSON string. + """ + + value: int = aristaproto.int64_field(1) + """The int64 value.""" + + +@dataclass(eq=False, repr=False) +class UInt64Value(aristaproto.Message): + """ + Wrapper message for `uint64`. + + The JSON representation for `UInt64Value` is JSON string. + """ + + value: int = aristaproto.uint64_field(1) + """The uint64 value.""" + + +@dataclass(eq=False, repr=False) +class Int32Value(aristaproto.Message): + """ + Wrapper message for `int32`. + + The JSON representation for `Int32Value` is JSON number. + """ + + value: int = aristaproto.int32_field(1) + """The int32 value.""" + + +@dataclass(eq=False, repr=False) +class UInt32Value(aristaproto.Message): + """ + Wrapper message for `uint32`. + + The JSON representation for `UInt32Value` is JSON number. + """ + + value: int = aristaproto.uint32_field(1) + """The uint32 value.""" + + +@dataclass(eq=False, repr=False) +class BoolValue(aristaproto.Message): + """ + Wrapper message for `bool`. + + The JSON representation for `BoolValue` is JSON `true` and `false`. + """ + + value: bool = aristaproto.bool_field(1) + """The bool value.""" + + +@dataclass(eq=False, repr=False) +class StringValue(aristaproto.Message): + """ + Wrapper message for `string`. + + The JSON representation for `StringValue` is JSON string. + """ + + value: str = aristaproto.string_field(1) + """The string value.""" + + +@dataclass(eq=False, repr=False) +class BytesValue(aristaproto.Message): + """ + Wrapper message for `bytes`. + + The JSON representation for `BytesValue` is JSON string. + """ + + value: bytes = aristaproto.bytes_field(1) + """The bytes value.""" diff --git a/src/aristaproto/lib/std/google/protobuf/compiler/__init__.py b/src/aristaproto/lib/std/google/protobuf/compiler/__init__.py new file mode 100644 index 0000000..a26dc86 --- /dev/null +++ b/src/aristaproto/lib/std/google/protobuf/compiler/__init__.py @@ -0,0 +1,198 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# sources: google/protobuf/compiler/plugin.proto +# plugin: python-aristaproto +# This file has been @generated + +from dataclasses import dataclass +from typing import List + +import aristaproto +import aristaproto.lib.google.protobuf as aristaproto_lib_google_protobuf + + +class CodeGeneratorResponseFeature(aristaproto.Enum): + """Sync with code_generator.h.""" + + FEATURE_NONE = 0 + FEATURE_PROTO3_OPTIONAL = 1 + FEATURE_SUPPORTS_EDITIONS = 2 + + +@dataclass(eq=False, repr=False) +class Version(aristaproto.Message): + """The version number of protocol compiler.""" + + major: int = aristaproto.int32_field(1) + minor: int = aristaproto.int32_field(2) + patch: int = aristaproto.int32_field(3) + suffix: str = aristaproto.string_field(4) + """ + A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should + be empty for mainline stable releases. + """ + + +@dataclass(eq=False, repr=False) +class CodeGeneratorRequest(aristaproto.Message): + """An encoded CodeGeneratorRequest is written to the plugin's stdin.""" + + file_to_generate: List[str] = aristaproto.string_field(1) + """ + The .proto files that were explicitly listed on the command-line. The + code generator should generate code only for these files. Each file's + descriptor will be included in proto_file, below. + """ + + parameter: str = aristaproto.string_field(2) + """The generator parameter passed on the command-line.""" + + proto_file: List[ + "aristaproto_lib_google_protobuf.FileDescriptorProto" + ] = aristaproto.message_field(15) + """ + FileDescriptorProtos for all files in files_to_generate and everything + they import. The files will appear in topological order, so each file + appears before any file that imports it. + + Note: the files listed in files_to_generate will include runtime-retention + options only, but all other files will include source-retention options. + The source_file_descriptors field below is available in case you need + source-retention options for files_to_generate. + + protoc guarantees that all proto_files will be written after + the fields above, even though this is not technically guaranteed by the + protobuf wire format. This theoretically could allow a plugin to stream + in the FileDescriptorProtos and handle them one by one rather than read + the entire set into memory at once. However, as of this writing, this + is not similarly optimized on protoc's end -- it will store all fields in + memory at once before sending them to the plugin. + + Type names of fields and extensions in the FileDescriptorProto are always + fully qualified. + """ + + source_file_descriptors: List[ + "aristaproto_lib_google_protobuf.FileDescriptorProto" + ] = aristaproto.message_field(17) + """ + File descriptors with all options, including source-retention options. + These descriptors are only provided for the files listed in + files_to_generate. + """ + + compiler_version: "Version" = aristaproto.message_field(3) + """The version number of protocol compiler.""" + + +@dataclass(eq=False, repr=False) +class CodeGeneratorResponse(aristaproto.Message): + """The plugin writes an encoded CodeGeneratorResponse to stdout.""" + + error: str = aristaproto.string_field(1) + """ + Error message. If non-empty, code generation failed. The plugin process + should exit with status code zero even if it reports an error in this way. + + This should be used to indicate errors in .proto files which prevent the + code generator from generating correct code. Errors which indicate a + problem in protoc itself -- such as the input CodeGeneratorRequest being + unparseable -- should be reported by writing a message to stderr and + exiting with a non-zero status code. + """ + + supported_features: int = aristaproto.uint64_field(2) + """ + A bitmask of supported features that the code generator supports. + This is a bitwise "or" of values from the Feature enum. + """ + + minimum_edition: int = aristaproto.int32_field(3) + """ + The minimum edition this plugin supports. This will be treated as an + Edition enum, but we want to allow unknown values. It should be specified + according the edition enum value, *not* the edition number. Only takes + effect for plugins that have FEATURE_SUPPORTS_EDITIONS set. + """ + + maximum_edition: int = aristaproto.int32_field(4) + """ + The maximum edition this plugin supports. This will be treated as an + Edition enum, but we want to allow unknown values. It should be specified + according the edition enum value, *not* the edition number. Only takes + effect for plugins that have FEATURE_SUPPORTS_EDITIONS set. + """ + + file: List["CodeGeneratorResponseFile"] = aristaproto.message_field(15) + + +@dataclass(eq=False, repr=False) +class CodeGeneratorResponseFile(aristaproto.Message): + """Represents a single generated file.""" + + name: str = aristaproto.string_field(1) + """ + The file name, relative to the output directory. The name must not + contain "." or ".." components and must be relative, not be absolute (so, + the file cannot lie outside the output directory). "/" must be used as + the path separator, not "\". + + If the name is omitted, the content will be appended to the previous + file. This allows the generator to break large files into small chunks, + and allows the generated text to be streamed back to protoc so that large + files need not reside completely in memory at one time. Note that as of + this writing protoc does not optimize for this -- it will read the entire + CodeGeneratorResponse before writing files to disk. + """ + + insertion_point: str = aristaproto.string_field(2) + """ + If non-empty, indicates that the named file should already exist, and the + content here is to be inserted into that file at a defined insertion + point. This feature allows a code generator to extend the output + produced by another code generator. The original generator may provide + insertion points by placing special annotations in the file that look + like: + @@protoc_insertion_point(NAME) + The annotation can have arbitrary text before and after it on the line, + which allows it to be placed in a comment. NAME should be replaced with + an identifier naming the point -- this is what other generators will use + as the insertion_point. Code inserted at this point will be placed + immediately above the line containing the insertion point (thus multiple + insertions to the same point will come out in the order they were added). + The double-@ is intended to make it unlikely that the generated code + could contain things that look like insertion points by accident. + + For example, the C++ code generator places the following line in the + .pb.h files that it generates: + // @@protoc_insertion_point(namespace_scope) + This line appears within the scope of the file's package namespace, but + outside of any particular class. Another plugin can then specify the + insertion_point "namespace_scope" to generate additional classes or + other declarations that should be placed in this scope. + + Note that if the line containing the insertion point begins with + whitespace, the same whitespace will be added to every line of the + inserted text. This is useful for languages like Python, where + indentation matters. In these languages, the insertion point comment + should be indented the same amount as any inserted code will need to be + in order to work correctly in that context. + + The code generator that generates the initial file and the one which + inserts into it must both run as part of a single invocation of protoc. + Code generators are executed in the order in which they appear on the + command line. + + If |insertion_point| is present, |name| must also be present. + """ + + content: str = aristaproto.string_field(15) + """The file contents.""" + + generated_code_info: "aristaproto_lib_google_protobuf.GeneratedCodeInfo" = ( + aristaproto.message_field(16) + ) + """ + Information describing the file content being inserted. If an insertion + point is used, this information will be appropriately offset and inserted + into the code generation metadata for the generated files. + """ diff --git a/src/aristaproto/plugin/__init__.py b/src/aristaproto/plugin/__init__.py new file mode 100644 index 0000000..c28a133 --- /dev/null +++ b/src/aristaproto/plugin/__init__.py @@ -0,0 +1 @@ +from .main import main diff --git a/src/aristaproto/plugin/__main__.py b/src/aristaproto/plugin/__main__.py new file mode 100644 index 0000000..bd95dae --- /dev/null +++ b/src/aristaproto/plugin/__main__.py @@ -0,0 +1,4 @@ +from .main import main + + +main() diff --git a/src/aristaproto/plugin/compiler.py b/src/aristaproto/plugin/compiler.py new file mode 100644 index 0000000..4bbcc48 --- /dev/null +++ b/src/aristaproto/plugin/compiler.py @@ -0,0 +1,50 @@ +import os.path + + +try: + # aristaproto[compiler] specific dependencies + import black + import isort.api + import jinja2 +except ImportError as err: + print( + "\033[31m" + f"Unable to import `{err.name}` from aristaproto plugin! " + "Please ensure that you've installed aristaproto as " + '`pip install "aristaproto[compiler]"` so that compiler dependencies ' + "are included." + "\033[0m" + ) + raise SystemExit(1) + +from .models import OutputTemplate + + +def outputfile_compiler(output_file: OutputTemplate) -> str: + templates_folder = os.path.abspath( + os.path.join(os.path.dirname(__file__), "..", "templates") + ) + + env = jinja2.Environment( + trim_blocks=True, + lstrip_blocks=True, + loader=jinja2.FileSystemLoader(templates_folder), + ) + template = env.get_template("template.py.j2") + + code = template.render(output_file=output_file) + code = isort.api.sort_code_string( + code=code, + show_diff=False, + py_version=37, + profile="black", + combine_as_imports=True, + lines_after_imports=2, + quiet=True, + force_grid_wrap=2, + known_third_party=["grpclib", "aristaproto"], + ) + return black.format_str( + src_contents=code, + mode=black.Mode(), + ) diff --git a/src/aristaproto/plugin/main.py b/src/aristaproto/plugin/main.py new file mode 100755 index 0000000..aff3614 --- /dev/null +++ b/src/aristaproto/plugin/main.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +import os +import sys + +from aristaproto.lib.google.protobuf.compiler import ( + CodeGeneratorRequest, + CodeGeneratorResponse, +) +from aristaproto.plugin.models import monkey_patch_oneof_index +from aristaproto.plugin.parser import generate_code + + +def main() -> None: + """The plugin's main entry point.""" + # Read request message from stdin + data = sys.stdin.buffer.read() + + # Apply Work around for proto2/3 difference in protoc messages + monkey_patch_oneof_index() + + # Parse request + request = CodeGeneratorRequest() + request.parse(data) + + dump_file = os.getenv("ARISTAPROTO_DUMP") + if dump_file: + dump_request(dump_file, request) + + # Generate code + response = generate_code(request) + + # Serialise response message + output = response.SerializeToString() + + # Write to stdout + sys.stdout.buffer.write(output) + + +def dump_request(dump_file: str, request: CodeGeneratorRequest) -> None: + """ + For developers: Supports running plugin.py standalone so its possible to debug it. + Run protoc (or generate.py) with ARISTAPROTO_DUMP="yourfile.bin" to write the request to a file. + Then run plugin.py from your IDE in debugging mode, and redirect stdin to the file. + """ + with open(str(dump_file), "wb") as fh: + sys.stderr.write(f"\033[31mWriting input from protoc to: {dump_file}\033[0m\n") + fh.write(request.SerializeToString()) + + +if __name__ == "__main__": + main() diff --git a/src/aristaproto/plugin/models.py b/src/aristaproto/plugin/models.py new file mode 100644 index 0000000..484b40d --- /dev/null +++ b/src/aristaproto/plugin/models.py @@ -0,0 +1,851 @@ +"""Plugin model dataclasses. + +These classes are meant to be an intermediate representation +of protobuf objects. They are used to organize the data collected during parsing. + +The general intention is to create a doubly-linked tree-like structure +with the following types of references: +- Downwards references: from message -> fields, from output package -> messages +or from service -> service methods +- Upwards references: from field -> message, message -> package. +- Input/output message references: from a service method to it's corresponding +input/output messages, which may even be in another package. + +There are convenience methods to allow climbing up and down this tree, for +example to retrieve the list of all messages that are in the same package as +the current message. + +Most of these classes take as inputs: +- proto_obj: A reference to it's corresponding protobuf object as +presented by the protoc plugin. +- parent: a reference to the parent object in the tree. + +With this information, the class is able to expose attributes, +such as a pythonized name, that will be calculated from proto_obj. + +The instantiation should also attach a reference to the new object +into the corresponding place within it's parent object. For example, +instantiating field `A` with parent message `B` should add a +reference to `A` to `B`'s `fields` attribute. +""" + + +import builtins +import re +import textwrap +from dataclasses import ( + dataclass, + field, +) +from typing import ( + Dict, + Iterable, + Iterator, + List, + Optional, + Set, + Type, + Union, +) + +import aristaproto +from aristaproto import which_one_of +from aristaproto.casing import sanitize_name +from aristaproto.compile.importing import ( + get_type_reference, + parse_source_type_name, +) +from aristaproto.compile.naming import ( + pythonize_class_name, + pythonize_field_name, + pythonize_method_name, +) +from aristaproto.lib.google.protobuf import ( + DescriptorProto, + EnumDescriptorProto, + Field, + FieldDescriptorProto, + FieldDescriptorProtoLabel, + FieldDescriptorProtoType, + FileDescriptorProto, + MethodDescriptorProto, +) +from aristaproto.lib.google.protobuf.compiler import CodeGeneratorRequest + +from ..compile.importing import ( + get_type_reference, + parse_source_type_name, +) +from ..compile.naming import ( + pythonize_class_name, + pythonize_enum_member_name, + pythonize_field_name, + pythonize_method_name, +) + + +# Create a unique placeholder to deal with +# https://stackoverflow.com/questions/51575931/class-inheritance-in-python-3-7-dataclasses +PLACEHOLDER = object() + +# Organize proto types into categories +PROTO_FLOAT_TYPES = ( + FieldDescriptorProtoType.TYPE_DOUBLE, # 1 + FieldDescriptorProtoType.TYPE_FLOAT, # 2 +) +PROTO_INT_TYPES = ( + FieldDescriptorProtoType.TYPE_INT64, # 3 + FieldDescriptorProtoType.TYPE_UINT64, # 4 + FieldDescriptorProtoType.TYPE_INT32, # 5 + FieldDescriptorProtoType.TYPE_FIXED64, # 6 + FieldDescriptorProtoType.TYPE_FIXED32, # 7 + FieldDescriptorProtoType.TYPE_UINT32, # 13 + FieldDescriptorProtoType.TYPE_SFIXED32, # 15 + FieldDescriptorProtoType.TYPE_SFIXED64, # 16 + FieldDescriptorProtoType.TYPE_SINT32, # 17 + FieldDescriptorProtoType.TYPE_SINT64, # 18 +) +PROTO_BOOL_TYPES = (FieldDescriptorProtoType.TYPE_BOOL,) # 8 +PROTO_STR_TYPES = (FieldDescriptorProtoType.TYPE_STRING,) # 9 +PROTO_BYTES_TYPES = (FieldDescriptorProtoType.TYPE_BYTES,) # 12 +PROTO_MESSAGE_TYPES = ( + FieldDescriptorProtoType.TYPE_MESSAGE, # 11 + FieldDescriptorProtoType.TYPE_ENUM, # 14 +) +PROTO_MAP_TYPES = (FieldDescriptorProtoType.TYPE_MESSAGE,) # 11 +PROTO_PACKED_TYPES = ( + FieldDescriptorProtoType.TYPE_DOUBLE, # 1 + FieldDescriptorProtoType.TYPE_FLOAT, # 2 + FieldDescriptorProtoType.TYPE_INT64, # 3 + FieldDescriptorProtoType.TYPE_UINT64, # 4 + FieldDescriptorProtoType.TYPE_INT32, # 5 + FieldDescriptorProtoType.TYPE_FIXED64, # 6 + FieldDescriptorProtoType.TYPE_FIXED32, # 7 + FieldDescriptorProtoType.TYPE_BOOL, # 8 + FieldDescriptorProtoType.TYPE_UINT32, # 13 + FieldDescriptorProtoType.TYPE_SFIXED32, # 15 + FieldDescriptorProtoType.TYPE_SFIXED64, # 16 + FieldDescriptorProtoType.TYPE_SINT32, # 17 + FieldDescriptorProtoType.TYPE_SINT64, # 18 +) + + +def monkey_patch_oneof_index(): + """ + The compiler message types are written for proto2, but we read them as proto3. + For this to work in the case of the oneof_index fields, which depend on being able + to tell whether they were set, we have to treat them as oneof fields. This method + monkey patches the generated classes after the fact to force this behaviour. + """ + object.__setattr__( + FieldDescriptorProto.__dataclass_fields__["oneof_index"].metadata[ + "aristaproto" + ], + "group", + "oneof_index", + ) + object.__setattr__( + Field.__dataclass_fields__["oneof_index"].metadata["aristaproto"], + "group", + "oneof_index", + ) + + +def get_comment( + proto_file: "FileDescriptorProto", path: List[int], indent: int = 4 +) -> str: + pad = " " * indent + for sci_loc in proto_file.source_code_info.location: + if list(sci_loc.path) == path and sci_loc.leading_comments: + lines = sci_loc.leading_comments.strip().replace("\t", " ").split("\n") + # This is a field, message, enum, service, or method + if len(lines) == 1 and len(lines[0]) < 79 - indent - 6: + lines[0] = lines[0].strip('"') + # rstrip to remove trailing spaces including whitespaces from empty lines. + return f'{pad}"""{lines[0]}"""' + else: + # rstrip to remove trailing spaces including empty lines. + padded = [f"\n{pad}{line}".rstrip(" ") for line in lines] + joined = "".join(padded) + return f'{pad}"""{joined}\n{pad}"""' + + return "" + + +class ProtoContentBase: + """Methods common to MessageCompiler, ServiceCompiler and ServiceMethodCompiler.""" + + source_file: FileDescriptorProto + path: List[int] + comment_indent: int = 4 + parent: Union["aristaproto.Message", "OutputTemplate"] + + __dataclass_fields__: Dict[str, object] + + def __post_init__(self) -> None: + """Checks that no fake default fields were left as placeholders.""" + for field_name, field_val in self.__dataclass_fields__.items(): + if field_val is PLACEHOLDER: + raise ValueError(f"`{field_name}` is a required field.") + + @property + def output_file(self) -> "OutputTemplate": + current = self + while not isinstance(current, OutputTemplate): + current = current.parent + return current + + @property + def request(self) -> "PluginRequestCompiler": + current = self + while not isinstance(current, OutputTemplate): + current = current.parent + return current.parent_request + + @property + def comment(self) -> str: + """Crawl the proto source code and retrieve comments + for this object. + """ + return get_comment( + proto_file=self.source_file, path=self.path, indent=self.comment_indent + ) + + +@dataclass +class PluginRequestCompiler: + plugin_request_obj: CodeGeneratorRequest + output_packages: Dict[str, "OutputTemplate"] = field(default_factory=dict) + + @property + def all_messages(self) -> List["MessageCompiler"]: + """All of the messages in this request. + + Returns + ------- + List[MessageCompiler] + List of all of the messages in this request. + """ + return [ + msg for output in self.output_packages.values() for msg in output.messages + ] + + +@dataclass +class OutputTemplate: + """Representation of an output .py file. + + Each output file corresponds to a .proto input file, + but may need references to other .proto files to be + built. + """ + + parent_request: PluginRequestCompiler + package_proto_obj: FileDescriptorProto + input_files: List[str] = field(default_factory=list) + imports: Set[str] = field(default_factory=set) + datetime_imports: Set[str] = field(default_factory=set) + typing_imports: Set[str] = field(default_factory=set) + pydantic_imports: Set[str] = field(default_factory=set) + builtins_import: bool = False + messages: List["MessageCompiler"] = field(default_factory=list) + enums: List["EnumDefinitionCompiler"] = field(default_factory=list) + services: List["ServiceCompiler"] = field(default_factory=list) + imports_type_checking_only: Set[str] = field(default_factory=set) + pydantic_dataclasses: bool = False + output: bool = True + + @property + def package(self) -> str: + """Name of input package. + + Returns + ------- + str + Name of input package. + """ + return self.package_proto_obj.package + + @property + def input_filenames(self) -> Iterable[str]: + """Names of the input files used to build this output. + + Returns + ------- + Iterable[str] + Names of the input files used to build this output. + """ + return sorted(f.name for f in self.input_files) + + @property + def python_module_imports(self) -> Set[str]: + imports = set() + if any(x for x in self.messages if any(x.deprecated_fields)): + imports.add("warnings") + if self.builtins_import: + imports.add("builtins") + return imports + + +@dataclass +class MessageCompiler(ProtoContentBase): + """Representation of a protobuf message.""" + + source_file: FileDescriptorProto + parent: Union["MessageCompiler", OutputTemplate] = PLACEHOLDER + proto_obj: DescriptorProto = PLACEHOLDER + path: List[int] = PLACEHOLDER + fields: List[Union["FieldCompiler", "MessageCompiler"]] = field( + default_factory=list + ) + deprecated: bool = field(default=False, init=False) + builtins_types: Set[str] = field(default_factory=set) + + def __post_init__(self) -> None: + # Add message to output file + if isinstance(self.parent, OutputTemplate): + if isinstance(self, EnumDefinitionCompiler): + self.output_file.enums.append(self) + else: + self.output_file.messages.append(self) + self.deprecated = self.proto_obj.options.deprecated + super().__post_init__() + + @property + def proto_name(self) -> str: + return self.proto_obj.name + + @property + def py_name(self) -> str: + return pythonize_class_name(self.proto_name) + + @property + def annotation(self) -> str: + if self.repeated: + return f"List[{self.py_name}]" + return self.py_name + + @property + def deprecated_fields(self) -> Iterator[str]: + for f in self.fields: + if f.deprecated: + yield f.py_name + + @property + def has_deprecated_fields(self) -> bool: + return any(self.deprecated_fields) + + @property + def has_oneof_fields(self) -> bool: + return any(isinstance(field, OneOfFieldCompiler) for field in self.fields) + + @property + def has_message_field(self) -> bool: + return any( + ( + field.proto_obj.type in PROTO_MESSAGE_TYPES + for field in self.fields + if isinstance(field.proto_obj, FieldDescriptorProto) + ) + ) + + +def is_map( + proto_field_obj: FieldDescriptorProto, parent_message: DescriptorProto +) -> bool: + """True if proto_field_obj is a map, otherwise False.""" + if proto_field_obj.type == FieldDescriptorProtoType.TYPE_MESSAGE: + if not hasattr(parent_message, "nested_type"): + return False + + # This might be a map... + message_type = proto_field_obj.type_name.split(".").pop().lower() + map_entry = f"{proto_field_obj.name.replace('_', '').lower()}entry" + if message_type == map_entry: + for nested in parent_message.nested_type: # parent message + if ( + nested.name.replace("_", "").lower() == map_entry + and nested.options.map_entry + ): + return True + return False + + +def is_oneof(proto_field_obj: FieldDescriptorProto) -> bool: + """ + True if proto_field_obj is a OneOf, otherwise False. + + .. warning:: + Becuase the message from protoc is defined in proto2, and aristaproto works with + proto3, and interpreting the FieldDescriptorProto.oneof_index field requires + distinguishing between default and unset values (which proto3 doesn't support), + we have to hack the generated FieldDescriptorProto class for this to work. + The hack consists of setting group="oneof_index" in the field metadata, + essentially making oneof_index the sole member of a one_of group, which allows + us to tell whether it was set, via the which_one_of interface. + """ + + return ( + not proto_field_obj.proto3_optional + and which_one_of(proto_field_obj, "oneof_index")[0] == "oneof_index" + ) + + +@dataclass +class FieldCompiler(MessageCompiler): + parent: MessageCompiler = PLACEHOLDER + proto_obj: FieldDescriptorProto = PLACEHOLDER + + def __post_init__(self) -> None: + # Add field to message + self.parent.fields.append(self) + # Check for new imports + self.add_imports_to(self.output_file) + super().__post_init__() # call FieldCompiler-> MessageCompiler __post_init__ + + def get_field_string(self, indent: int = 4) -> str: + """Construct string representation of this field as a field.""" + name = f"{self.py_name}" + annotations = f": {self.annotation}" + field_args = ", ".join( + ([""] + self.aristaproto_field_args) if self.aristaproto_field_args else [] + ) + aristaproto_field_type = ( + f"aristaproto.{self.field_type}_field({self.proto_obj.number}{field_args})" + ) + if self.py_name in dir(builtins): + self.parent.builtins_types.add(self.py_name) + return f"{name}{annotations} = {aristaproto_field_type}" + + @property + def aristaproto_field_args(self) -> List[str]: + args = [] + if self.field_wraps: + args.append(f"wraps={self.field_wraps}") + if self.optional: + args.append(f"optional=True") + return args + + @property + def datetime_imports(self) -> Set[str]: + imports = set() + annotation = self.annotation + # FIXME: false positives - e.g. `MyDatetimedelta` + if "timedelta" in annotation: + imports.add("timedelta") + if "datetime" in annotation: + imports.add("datetime") + return imports + + @property + def typing_imports(self) -> Set[str]: + imports = set() + annotation = self.annotation + if "Optional[" in annotation: + imports.add("Optional") + if "List[" in annotation: + imports.add("List") + if "Dict[" in annotation: + imports.add("Dict") + return imports + + @property + def pydantic_imports(self) -> Set[str]: + return set() + + @property + def use_builtins(self) -> bool: + return self.py_type in self.parent.builtins_types or ( + self.py_type == self.py_name and self.py_name in dir(builtins) + ) + + def add_imports_to(self, output_file: OutputTemplate) -> None: + output_file.datetime_imports.update(self.datetime_imports) + output_file.typing_imports.update(self.typing_imports) + output_file.pydantic_imports.update(self.pydantic_imports) + output_file.builtins_import = output_file.builtins_import or self.use_builtins + + @property + def field_wraps(self) -> Optional[str]: + """Returns aristaproto wrapped field type or None.""" + match_wrapper = re.match( + r"\.google\.protobuf\.(.+)Value$", self.proto_obj.type_name + ) + if match_wrapper: + wrapped_type = "TYPE_" + match_wrapper.group(1).upper() + if hasattr(aristaproto, wrapped_type): + return f"aristaproto.{wrapped_type}" + return None + + @property + def repeated(self) -> bool: + return ( + self.proto_obj.label == FieldDescriptorProtoLabel.LABEL_REPEATED + and not is_map(self.proto_obj, self.parent) + ) + + @property + def optional(self) -> bool: + return self.proto_obj.proto3_optional + + @property + def mutable(self) -> bool: + """True if the field is a mutable type, otherwise False.""" + return self.annotation.startswith(("List[", "Dict[")) + + @property + def field_type(self) -> str: + """String representation of proto field type.""" + return ( + FieldDescriptorProtoType(self.proto_obj.type) + .name.lower() + .replace("type_", "") + ) + + @property + def default_value_string(self) -> str: + """Python representation of the default proto value.""" + if self.repeated: + return "[]" + if self.optional: + return "None" + if self.py_type == "int": + return "0" + if self.py_type == "float": + return "0.0" + elif self.py_type == "bool": + return "False" + elif self.py_type == "str": + return '""' + elif self.py_type == "bytes": + return 'b""' + elif self.field_type == "enum": + enum_proto_obj_name = self.proto_obj.type_name.split(".").pop() + enum = next( + e + for e in self.output_file.enums + if e.proto_obj.name == enum_proto_obj_name + ) + return enum.default_value_string + else: + # Message type + return "None" + + @property + def packed(self) -> bool: + """True if the wire representation is a packed format.""" + return self.repeated and self.proto_obj.type in PROTO_PACKED_TYPES + + @property + def py_name(self) -> str: + """Pythonized name.""" + return pythonize_field_name(self.proto_name) + + @property + def proto_name(self) -> str: + """Original protobuf name.""" + return self.proto_obj.name + + @property + def py_type(self) -> str: + """String representation of Python type.""" + if self.proto_obj.type in PROTO_FLOAT_TYPES: + return "float" + elif self.proto_obj.type in PROTO_INT_TYPES: + return "int" + elif self.proto_obj.type in PROTO_BOOL_TYPES: + return "bool" + elif self.proto_obj.type in PROTO_STR_TYPES: + return "str" + elif self.proto_obj.type in PROTO_BYTES_TYPES: + return "bytes" + elif self.proto_obj.type in PROTO_MESSAGE_TYPES: + # Type referencing another defined Message or a named enum + return get_type_reference( + package=self.output_file.package, + imports=self.output_file.imports, + source_type=self.proto_obj.type_name, + pydantic=self.output_file.pydantic_dataclasses, + ) + else: + raise NotImplementedError(f"Unknown type {self.proto_obj.type}") + + @property + def annotation(self) -> str: + py_type = self.py_type + if self.use_builtins: + py_type = f"builtins.{py_type}" + if self.repeated: + return f"List[{py_type}]" + if self.optional: + return f"Optional[{py_type}]" + return py_type + + +@dataclass +class OneOfFieldCompiler(FieldCompiler): + @property + def aristaproto_field_args(self) -> List[str]: + args = super().aristaproto_field_args + group = self.parent.proto_obj.oneof_decl[self.proto_obj.oneof_index].name + args.append(f'group="{group}"') + return args + + +@dataclass +class PydanticOneOfFieldCompiler(OneOfFieldCompiler): + @property + def optional(self) -> bool: + # Force the optional to be True. This will allow the pydantic dataclass + # to validate the object correctly by allowing the field to be let empty. + # We add a pydantic validator later to ensure exactly one field is defined. + return True + + @property + def pydantic_imports(self) -> Set[str]: + return {"root_validator"} + + +@dataclass +class MapEntryCompiler(FieldCompiler): + py_k_type: Type = PLACEHOLDER + py_v_type: Type = PLACEHOLDER + proto_k_type: str = PLACEHOLDER + proto_v_type: str = PLACEHOLDER + + def __post_init__(self) -> None: + """Explore nested types and set k_type and v_type if unset.""" + map_entry = f"{self.proto_obj.name.replace('_', '').lower()}entry" + for nested in self.parent.proto_obj.nested_type: + if ( + nested.name.replace("_", "").lower() == map_entry + and nested.options.map_entry + ): + # Get Python types + self.py_k_type = FieldCompiler( + source_file=self.source_file, + parent=self, + proto_obj=nested.field[0], # key + ).py_type + self.py_v_type = FieldCompiler( + source_file=self.source_file, + parent=self, + proto_obj=nested.field[1], # value + ).py_type + + # Get proto types + self.proto_k_type = FieldDescriptorProtoType(nested.field[0].type).name + self.proto_v_type = FieldDescriptorProtoType(nested.field[1].type).name + super().__post_init__() # call FieldCompiler-> MessageCompiler __post_init__ + + @property + def aristaproto_field_args(self) -> List[str]: + return [f"aristaproto.{self.proto_k_type}", f"aristaproto.{self.proto_v_type}"] + + @property + def field_type(self) -> str: + return "map" + + @property + def annotation(self) -> str: + return f"Dict[{self.py_k_type}, {self.py_v_type}]" + + @property + def repeated(self) -> bool: + return False # maps cannot be repeated + + +@dataclass +class EnumDefinitionCompiler(MessageCompiler): + """Representation of a proto Enum definition.""" + + proto_obj: EnumDescriptorProto = PLACEHOLDER + entries: List["EnumDefinitionCompiler.EnumEntry"] = PLACEHOLDER + + @dataclass(unsafe_hash=True) + class EnumEntry: + """Representation of an Enum entry.""" + + name: str + value: int + comment: str + + def __post_init__(self) -> None: + # Get entries/allowed values for this Enum + self.entries = [ + self.EnumEntry( + name=pythonize_enum_member_name( + entry_proto_value.name, self.proto_obj.name + ), + value=entry_proto_value.number, + comment=get_comment( + proto_file=self.source_file, path=self.path + [2, entry_number] + ), + ) + for entry_number, entry_proto_value in enumerate(self.proto_obj.value) + ] + super().__post_init__() # call MessageCompiler __post_init__ + + @property + def default_value_string(self) -> str: + """Python representation of the default value for Enums. + + As per the spec, this is the first value of the Enum. + """ + return str(self.entries[0].value) # ideally, should ALWAYS be int(0)! + + +@dataclass +class ServiceCompiler(ProtoContentBase): + parent: OutputTemplate = PLACEHOLDER + proto_obj: DescriptorProto = PLACEHOLDER + path: List[int] = PLACEHOLDER + methods: List["ServiceMethodCompiler"] = field(default_factory=list) + + def __post_init__(self) -> None: + # Add service to output file + self.output_file.services.append(self) + self.output_file.typing_imports.add("Dict") + super().__post_init__() # check for unset fields + + @property + def proto_name(self) -> str: + return self.proto_obj.name + + @property + def py_name(self) -> str: + return pythonize_class_name(self.proto_name) + + +@dataclass +class ServiceMethodCompiler(ProtoContentBase): + parent: ServiceCompiler + proto_obj: MethodDescriptorProto + path: List[int] = PLACEHOLDER + comment_indent: int = 8 + + def __post_init__(self) -> None: + # Add method to service + self.parent.methods.append(self) + + # Check for imports + if "Optional" in self.py_output_message_type: + self.output_file.typing_imports.add("Optional") + + # Check for Async imports + if self.client_streaming: + self.output_file.typing_imports.add("AsyncIterable") + self.output_file.typing_imports.add("Iterable") + self.output_file.typing_imports.add("Union") + + # Required by both client and server + if self.client_streaming or self.server_streaming: + self.output_file.typing_imports.add("AsyncIterator") + + # add imports required for request arguments timeout, deadline and metadata + self.output_file.typing_imports.add("Optional") + self.output_file.imports_type_checking_only.add("import grpclib.server") + self.output_file.imports_type_checking_only.add( + "from aristaproto.grpc.grpclib_client import MetadataLike" + ) + self.output_file.imports_type_checking_only.add( + "from grpclib.metadata import Deadline" + ) + + super().__post_init__() # check for unset fields + + @property + def py_name(self) -> str: + """Pythonized method name.""" + return pythonize_method_name(self.proto_obj.name) + + @property + def proto_name(self) -> str: + """Original protobuf name.""" + return self.proto_obj.name + + @property + def route(self) -> str: + package_part = ( + f"{self.output_file.package}." if self.output_file.package else "" + ) + return f"/{package_part}{self.parent.proto_name}/{self.proto_name}" + + @property + def py_input_message(self) -> Optional[MessageCompiler]: + """Find the input message object. + + Returns + ------- + Optional[MessageCompiler] + Method instance representing the input message. + If not input message could be found or there are no + input messages, None is returned. + """ + package, name = parse_source_type_name(self.proto_obj.input_type) + + # Nested types are currently flattened without dots. + # Todo: keep a fully quantified name in types, that is + # comparable with method.input_type + for msg in self.request.all_messages: + if ( + msg.py_name == pythonize_class_name(name.replace(".", "")) + and msg.output_file.package == package + ): + return msg + return None + + @property + def py_input_message_type(self) -> str: + """String representation of the Python type corresponding to the + input message. + + Returns + ------- + str + String representation of the Python type corresponding to the input message. + """ + return get_type_reference( + package=self.output_file.package, + imports=self.output_file.imports, + source_type=self.proto_obj.input_type, + unwrap=False, + pydantic=self.output_file.pydantic_dataclasses, + ).strip('"') + + @property + def py_input_message_param(self) -> str: + """Param name corresponding to py_input_message_type. + + Returns + ------- + str + Param name corresponding to py_input_message_type. + """ + return pythonize_field_name(self.py_input_message_type) + + @property + def py_output_message_type(self) -> str: + """String representation of the Python type corresponding to the + output message. + + Returns + ------- + str + String representation of the Python type corresponding to the output message. + """ + return get_type_reference( + package=self.output_file.package, + imports=self.output_file.imports, + source_type=self.proto_obj.output_type, + unwrap=False, + pydantic=self.output_file.pydantic_dataclasses, + ).strip('"') + + @property + def client_streaming(self) -> bool: + return self.proto_obj.client_streaming + + @property + def server_streaming(self) -> bool: + return self.proto_obj.server_streaming diff --git a/src/aristaproto/plugin/parser.py b/src/aristaproto/plugin/parser.py new file mode 100644 index 0000000..f761af6 --- /dev/null +++ b/src/aristaproto/plugin/parser.py @@ -0,0 +1,221 @@ +import pathlib +import sys +from typing import ( + Generator, + List, + Set, + Tuple, + Union, +) + +from aristaproto.lib.google.protobuf import ( + DescriptorProto, + EnumDescriptorProto, + FieldDescriptorProto, + FileDescriptorProto, + ServiceDescriptorProto, +) +from aristaproto.lib.google.protobuf.compiler import ( + CodeGeneratorRequest, + CodeGeneratorResponse, + CodeGeneratorResponseFeature, + CodeGeneratorResponseFile, +) + +from .compiler import outputfile_compiler +from .models import ( + EnumDefinitionCompiler, + FieldCompiler, + MapEntryCompiler, + MessageCompiler, + OneOfFieldCompiler, + OutputTemplate, + PluginRequestCompiler, + PydanticOneOfFieldCompiler, + ServiceCompiler, + ServiceMethodCompiler, + is_map, + is_oneof, +) + + +def traverse( + proto_file: FileDescriptorProto, +) -> Generator[ + Tuple[Union[EnumDescriptorProto, DescriptorProto], List[int]], None, None +]: + # Todo: Keep information about nested hierarchy + def _traverse( + path: List[int], + items: Union[List[EnumDescriptorProto], List[DescriptorProto]], + prefix: str = "", + ) -> Generator[ + Tuple[Union[EnumDescriptorProto, DescriptorProto], List[int]], None, None + ]: + for i, item in enumerate(items): + # Adjust the name since we flatten the hierarchy. + # Todo: don't change the name, but include full name in returned tuple + item.name = next_prefix = f"{prefix}_{item.name}" + yield item, [*path, i] + + if isinstance(item, DescriptorProto): + # Get nested types. + yield from _traverse([*path, i, 4], item.enum_type, next_prefix) + yield from _traverse([*path, i, 3], item.nested_type, next_prefix) + + yield from _traverse([5], proto_file.enum_type) + yield from _traverse([4], proto_file.message_type) + + +def generate_code(request: CodeGeneratorRequest) -> CodeGeneratorResponse: + response = CodeGeneratorResponse() + + plugin_options = request.parameter.split(",") if request.parameter else [] + response.supported_features = CodeGeneratorResponseFeature.FEATURE_PROTO3_OPTIONAL + + request_data = PluginRequestCompiler(plugin_request_obj=request) + # Gather output packages + for proto_file in request.proto_file: + output_package_name = proto_file.package + if output_package_name not in request_data.output_packages: + # Create a new output if there is no output for this package + request_data.output_packages[output_package_name] = OutputTemplate( + parent_request=request_data, package_proto_obj=proto_file + ) + # Add this input file to the output corresponding to this package + request_data.output_packages[output_package_name].input_files.append(proto_file) + + if ( + proto_file.package == "google.protobuf" + and "INCLUDE_GOOGLE" not in plugin_options + ): + # If not INCLUDE_GOOGLE, + # skip outputting Google's well-known types + request_data.output_packages[output_package_name].output = False + + if "pydantic_dataclasses" in plugin_options: + request_data.output_packages[ + output_package_name + ].pydantic_dataclasses = True + + # Read Messages and Enums + # We need to read Messages before Services in so that we can + # get the references to input/output messages for each service + for output_package_name, output_package in request_data.output_packages.items(): + for proto_input_file in output_package.input_files: + for item, path in traverse(proto_input_file): + read_protobuf_type( + source_file=proto_input_file, + item=item, + path=path, + output_package=output_package, + ) + + # Read Services + for output_package_name, output_package in request_data.output_packages.items(): + for proto_input_file in output_package.input_files: + for index, service in enumerate(proto_input_file.service): + read_protobuf_service(service, index, output_package) + + # Generate output files + output_paths: Set[pathlib.Path] = set() + for output_package_name, output_package in request_data.output_packages.items(): + if not output_package.output: + continue + + # Add files to the response object + output_path = pathlib.Path(*output_package_name.split("."), "__init__.py") + output_paths.add(output_path) + + response.file.append( + CodeGeneratorResponseFile( + name=str(output_path), + # Render and then format the output file + content=outputfile_compiler(output_file=output_package), + ) + ) + + # Make each output directory a package with __init__ file + init_files = { + directory.joinpath("__init__.py") + for path in output_paths + for directory in path.parents + if not directory.joinpath("__init__.py").exists() + } - output_paths + + for init_file in init_files: + response.file.append(CodeGeneratorResponseFile(name=str(init_file))) + + for output_package_name in sorted(output_paths.union(init_files)): + print(f"Writing {output_package_name}", file=sys.stderr) + + return response + + +def _make_one_of_field_compiler( + output_package: OutputTemplate, + source_file: "FileDescriptorProto", + parent: MessageCompiler, + proto_obj: "FieldDescriptorProto", + path: List[int], +) -> FieldCompiler: + pydantic = output_package.pydantic_dataclasses + Cls = PydanticOneOfFieldCompiler if pydantic else OneOfFieldCompiler + return Cls( + source_file=source_file, + parent=parent, + proto_obj=proto_obj, + path=path, + ) + + +def read_protobuf_type( + item: DescriptorProto, + path: List[int], + source_file: "FileDescriptorProto", + output_package: OutputTemplate, +) -> None: + if isinstance(item, DescriptorProto): + if item.options.map_entry: + # Skip generated map entry messages since we just use dicts + return + # Process Message + message_data = MessageCompiler( + source_file=source_file, parent=output_package, proto_obj=item, path=path + ) + for index, field in enumerate(item.field): + if is_map(field, item): + MapEntryCompiler( + source_file=source_file, + parent=message_data, + proto_obj=field, + path=path + [2, index], + ) + elif is_oneof(field): + _make_one_of_field_compiler( + output_package, source_file, message_data, field, path + [2, index] + ) + else: + FieldCompiler( + source_file=source_file, + parent=message_data, + proto_obj=field, + path=path + [2, index], + ) + elif isinstance(item, EnumDescriptorProto): + # Enum + EnumDefinitionCompiler( + source_file=source_file, parent=output_package, proto_obj=item, path=path + ) + + +def read_protobuf_service( + service: ServiceDescriptorProto, index: int, output_package: OutputTemplate +) -> None: + service_data = ServiceCompiler( + parent=output_package, proto_obj=service, path=[6, index] + ) + for j, method in enumerate(service.method): + ServiceMethodCompiler( + parent=service_data, proto_obj=method, path=[6, index, 2, j] + ) diff --git a/src/aristaproto/plugin/plugin.bat b/src/aristaproto/plugin/plugin.bat new file mode 100644 index 0000000..2a4444d --- /dev/null +++ b/src/aristaproto/plugin/plugin.bat @@ -0,0 +1,2 @@ +@SET plugin_dir=%~dp0 +@python -m %plugin_dir% %*
\ No newline at end of file diff --git a/src/aristaproto/py.typed b/src/aristaproto/py.typed new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/aristaproto/py.typed diff --git a/src/aristaproto/templates/template.py.j2 b/src/aristaproto/templates/template.py.j2 new file mode 100644 index 0000000..f2f1425 --- /dev/null +++ b/src/aristaproto/templates/template.py.j2 @@ -0,0 +1,257 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# sources: {{ ', '.join(output_file.input_filenames) }} +# plugin: python-aristaproto +# This file has been @generated +{% for i in output_file.python_module_imports|sort %} +import {{ i }} +{% endfor %} + +{% if output_file.pydantic_dataclasses %} +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from dataclasses import dataclass +else: + from pydantic.dataclasses import dataclass +{%- else -%} +from dataclasses import dataclass +{% endif %} + +{% if output_file.datetime_imports %} +from datetime import {% for i in output_file.datetime_imports|sort %}{{ i }}{% if not loop.last %}, {% endif %}{% endfor %} + +{% endif%} +{% if output_file.typing_imports %} +from typing import {% for i in output_file.typing_imports|sort %}{{ i }}{% if not loop.last %}, {% endif %}{% endfor %} + +{% endif %} + +{% if output_file.pydantic_imports %} +from pydantic import {% for i in output_file.pydantic_imports|sort %}{{ i }}{% if not loop.last %}, {% endif %}{% endfor %} + +{% endif %} + +import aristaproto +{% if output_file.services %} +from aristaproto.grpc.grpclib_server import ServiceBase +import grpclib +{% endif %} + +{% for i in output_file.imports|sort %} +{{ i }} +{% endfor %} + +{% if output_file.imports_type_checking_only %} +from typing import TYPE_CHECKING + +if TYPE_CHECKING: +{% for i in output_file.imports_type_checking_only|sort %} {{ i }} +{% endfor %} +{% endif %} + +{% if output_file.enums %}{% for enum in output_file.enums %} +class {{ enum.py_name }}(aristaproto.Enum): + {% if enum.comment %} +{{ enum.comment }} + + {% endif %} + {% for entry in enum.entries %} + {{ entry.name }} = {{ entry.value }} + {% if entry.comment %} +{{ entry.comment }} + + {% endif %} + {% endfor %} + + +{% endfor %} +{% endif %} +{% for message in output_file.messages %} +@dataclass(eq=False, repr=False) +class {{ message.py_name }}(aristaproto.Message): + {% if message.comment %} +{{ message.comment }} + + {% endif %} + {% for field in message.fields %} + {{ field.get_field_string() }} + {% if field.comment %} +{{ field.comment }} + + {% endif %} + {% endfor %} + {% if not message.fields %} + pass + {% endif %} + + {% if message.deprecated or message.has_deprecated_fields %} + def __post_init__(self) -> None: + {% if message.deprecated %} + warnings.warn("{{ message.py_name }} is deprecated", DeprecationWarning) + {% endif %} + super().__post_init__() + {% for field in message.deprecated_fields %} + if self.is_set("{{ field }}"): + warnings.warn("{{ message.py_name }}.{{ field }} is deprecated", DeprecationWarning) + {% endfor %} + {% endif %} + + {% if output_file.pydantic_dataclasses and message.has_oneof_fields %} + @root_validator() + def check_oneof(cls, values): + return cls._validate_field_groups(values) + {% endif %} + +{% endfor %} +{% for service in output_file.services %} +class {{ service.py_name }}Stub(aristaproto.ServiceStub): + {% if service.comment %} +{{ service.comment }} + + {% elif not service.methods %} + pass + {% endif %} + {% for method in service.methods %} + async def {{ method.py_name }}(self + {%- if not method.client_streaming -%} + {%- if method.py_input_message -%}, {{ method.py_input_message_param }}: "{{ method.py_input_message_type }}"{%- endif -%} + {%- else -%} + {# Client streaming: need a request iterator instead #} + , {{ method.py_input_message_param }}_iterator: Union[AsyncIterable["{{ method.py_input_message_type }}"], Iterable["{{ method.py_input_message_type }}"]] + {%- endif -%} + , + * + , timeout: Optional[float] = None + , deadline: Optional["Deadline"] = None + , metadata: Optional["MetadataLike"] = None + ) -> {% if method.server_streaming %}AsyncIterator["{{ method.py_output_message_type }}"]{% else %}"{{ method.py_output_message_type }}"{% endif %}: + {% if method.comment %} +{{ method.comment }} + + {% endif %} + {% if method.server_streaming %} + {% if method.client_streaming %} + async for response in self._stream_stream( + "{{ method.route }}", + {{ method.py_input_message_param }}_iterator, + {{ method.py_input_message_type }}, + {{ method.py_output_message_type.strip('"') }}, + timeout=timeout, + deadline=deadline, + metadata=metadata, + ): + yield response + {% else %}{# i.e. not client streaming #} + async for response in self._unary_stream( + "{{ method.route }}", + {{ method.py_input_message_param }}, + {{ method.py_output_message_type.strip('"') }}, + timeout=timeout, + deadline=deadline, + metadata=metadata, + ): + yield response + + {% endif %}{# if client streaming #} + {% else %}{# i.e. not server streaming #} + {% if method.client_streaming %} + return await self._stream_unary( + "{{ method.route }}", + {{ method.py_input_message_param }}_iterator, + {{ method.py_input_message_type }}, + {{ method.py_output_message_type.strip('"') }}, + timeout=timeout, + deadline=deadline, + metadata=metadata, + ) + {% else %}{# i.e. not client streaming #} + return await self._unary_unary( + "{{ method.route }}", + {{ method.py_input_message_param }}, + {{ method.py_output_message_type.strip('"') }}, + timeout=timeout, + deadline=deadline, + metadata=metadata, + ) + {% endif %}{# client streaming #} + {% endif %} + + {% endfor %} +{% endfor %} + +{% for service in output_file.services %} +class {{ service.py_name }}Base(ServiceBase): + {% if service.comment %} +{{ service.comment }} + + {% endif %} + + {% for method in service.methods %} + async def {{ method.py_name }}(self + {%- if not method.client_streaming -%} + {%- if method.py_input_message -%}, {{ method.py_input_message_param }}: "{{ method.py_input_message_type }}"{%- endif -%} + {%- else -%} + {# Client streaming: need a request iterator instead #} + , {{ method.py_input_message_param }}_iterator: AsyncIterator["{{ method.py_input_message_type }}"] + {%- endif -%} + ) -> {% if method.server_streaming %}AsyncIterator["{{ method.py_output_message_type }}"]{% else %}"{{ method.py_output_message_type }}"{% endif %}: + {% if method.comment %} +{{ method.comment }} + + {% endif %} + raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED) + {% if method.server_streaming %} + {# Commented out to avoid unreachable code. #} + {# yield {{ method.py_output_message_type }}() #} + {% endif %} + + {% endfor %} + + {% for method in service.methods %} + async def __rpc_{{ method.py_name }}(self, stream: "grpclib.server.Stream[{{ method.py_input_message_type }}, {{ method.py_output_message_type }}]") -> None: + {% if not method.client_streaming %} + request = await stream.recv_message() + {% else %} + request = stream.__aiter__() + {% endif %} + {% if not method.server_streaming %} + response = await self.{{ method.py_name }}(request) + await stream.send_message(response) + {% else %} + await self._call_rpc_handler_server_stream( + self.{{ method.py_name }}, + stream, + request, + ) + {% endif %} + + {% endfor %} + + def __mapping__(self) -> Dict[str, grpclib.const.Handler]: + return { + {% for method in service.methods %} + "{{ method.route }}": grpclib.const.Handler( + self.__rpc_{{ method.py_name }}, + {% if not method.client_streaming and not method.server_streaming %} + grpclib.const.Cardinality.UNARY_UNARY, + {% elif not method.client_streaming and method.server_streaming %} + grpclib.const.Cardinality.UNARY_STREAM, + {% elif method.client_streaming and not method.server_streaming %} + grpclib.const.Cardinality.STREAM_UNARY, + {% else %} + grpclib.const.Cardinality.STREAM_STREAM, + {% endif %} + {{ method.py_input_message_type }}, + {{ method.py_output_message_type }}, + ), + {% endfor %} + } + +{% endfor %} + +{% if output_file.pydantic_dataclasses %} +{% for message in output_file.messages %} +{% if message.has_message_field %} +{{ message.py_name }}.__pydantic_model__.update_forward_refs() # type: ignore +{% endif %} +{% endfor %} +{% endif %} diff --git a/src/aristaproto/utils.py b/src/aristaproto/utils.py new file mode 100644 index 0000000..b977fc7 --- /dev/null +++ b/src/aristaproto/utils.py @@ -0,0 +1,56 @@ +from __future__ import annotations + +from typing import ( + Any, + Callable, + Generic, + Optional, + Type, + TypeVar, +) + +from typing_extensions import ( + Concatenate, + ParamSpec, + Self, +) + + +SelfT = TypeVar("SelfT") +P = ParamSpec("P") +HybridT = TypeVar("HybridT", covariant=True) + + +class hybridmethod(Generic[SelfT, P, HybridT]): + def __init__( + self, + func: Callable[ + Concatenate[type[SelfT], P], HybridT + ], # Must be the classmethod version + ): + self.cls_func = func + self.__doc__ = func.__doc__ + + def instancemethod(self, func: Callable[Concatenate[SelfT, P], HybridT]) -> Self: + self.instance_func = func + return self + + def __get__( + self, instance: Optional[SelfT], owner: Type[SelfT] + ) -> Callable[P, HybridT]: + if instance is None or self.instance_func is None: + # either bound to the class, or no instance method available + return self.cls_func.__get__(owner, None) + return self.instance_func.__get__(instance, owner) + + +T_co = TypeVar("T_co") +TT_co = TypeVar("TT_co", bound="type[Any]") + + +class classproperty(Generic[TT_co, T_co]): + def __init__(self, func: Callable[[TT_co], T_co]): + self.__func__ = func + + def __get__(self, instance: Any, type: TT_co) -> T_co: + return self.__func__(type) diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..1301f6b --- /dev/null +++ b/tests/README.md @@ -0,0 +1,91 @@ +# Standard Tests Development Guide + +Standard test cases are found in [aristaproto/tests/inputs](inputs), where each subdirectory represents a testcase, that is verified in isolation. + +``` +inputs/ + bool/ + double/ + int32/ + ... +``` + +## Test case directory structure + +Each testcase has a `<name>.proto` file with a message called `Test`, and optionally a matching `.json` file and a custom test called `test_*.py`. + +```bash +bool/ + bool.proto + bool.json # optional + test_bool.py # optional +``` + +### proto + +`<name>.proto` — *The protobuf message to test* + +```protobuf +syntax = "proto3"; + +message Test { + bool value = 1; +} +``` + +You can add multiple `.proto` files to the test case, as long as one file matches the directory name. + +### json + +`<name>.json` —Â *Test-data to validate the message with* + +```json +{ + "value": true +} +``` + +### pytest + +`test_<name>.py` — *Custom test to validate specific aspects of the generated class* + +```python +from tests.output_aristaproto.bool.bool import Test + +def test_value(): + message = Test() + assert not message.value, "Boolean is False by default" +``` + +## Standard tests + +The following tests are automatically executed for all cases: + +- [x] Can the generated python code be imported? +- [x] Can the generated message class be instantiated? +- [x] Is the generated code compatible with the Google's `grpc_tools.protoc` implementation? + - _when `.json` is present_ + +## Running the tests + +- `pipenv run generate` + This generates: + - `aristaproto/tests/output_aristaproto` —Â *the plugin generated python classes* + - `aristaproto/tests/output_reference` — *reference implementation classes* +- `pipenv run test` + +## Intentionally Failing tests + +The standard test suite includes tests that fail by intention. These tests document known bugs and missing features that are intended to be corrected in the future. + +When running `pytest`, they show up as `x` or `X` in the test results. + +``` +aristaproto/tests/test_inputs.py ..x...x..x...x.X........xx........x.....x.......x.xx....x...................... [ 84%] +``` + +- `.` — PASSED +- `x` —Â XFAIL: expected failure +- `X` —Â XPASS: expected failure, but still passed + +Test cases marked for expected failure are declared in [inputs/config.py](inputs/config.py)
\ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/__init__.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..c6b256d --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,22 @@ +import copy +import sys + +import pytest + + +def pytest_addoption(parser): + parser.addoption( + "--repeat", type=int, default=1, help="repeat the operation multiple times" + ) + + +@pytest.fixture(scope="session") +def repeat(request): + return request.config.getoption("repeat") + + +@pytest.fixture +def reset_sys_path(): + original = copy.deepcopy(sys.path) + yield + sys.path = original diff --git a/tests/generate.py b/tests/generate.py new file mode 100755 index 0000000..d6f36de --- /dev/null +++ b/tests/generate.py @@ -0,0 +1,196 @@ +#!/usr/bin/env python +import asyncio +import os +import platform +import shutil +import sys +from pathlib import Path +from typing import Set + +from tests.util import ( + get_directories, + inputs_path, + output_path_aristaproto, + output_path_aristaproto_pydantic, + output_path_reference, + protoc, +) + + +# Force pure-python implementation instead of C++, otherwise imports +# break things because we can't properly reset the symbol database. +os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python" + + +def clear_directory(dir_path: Path): + for file_or_directory in dir_path.glob("*"): + if file_or_directory.is_dir(): + shutil.rmtree(file_or_directory) + else: + file_or_directory.unlink() + + +async def generate(whitelist: Set[str], verbose: bool): + test_case_names = set(get_directories(inputs_path)) - {"__pycache__"} + + path_whitelist = set() + name_whitelist = set() + for item in whitelist: + if item in test_case_names: + name_whitelist.add(item) + continue + path_whitelist.add(item) + + generation_tasks = [] + for test_case_name in sorted(test_case_names): + test_case_input_path = inputs_path.joinpath(test_case_name).resolve() + if ( + whitelist + and str(test_case_input_path) not in path_whitelist + and test_case_name not in name_whitelist + ): + continue + generation_tasks.append( + generate_test_case_output(test_case_input_path, test_case_name, verbose) + ) + + failed_test_cases = [] + # Wait for all subprocs and match any failures to names to report + for test_case_name, result in zip( + sorted(test_case_names), await asyncio.gather(*generation_tasks) + ): + if result != 0: + failed_test_cases.append(test_case_name) + + if len(failed_test_cases) > 0: + sys.stderr.write( + "\n\033[31;1;4mFailed to generate the following test cases:\033[0m\n" + ) + for failed_test_case in failed_test_cases: + sys.stderr.write(f"- {failed_test_case}\n") + + sys.exit(1) + + +async def generate_test_case_output( + test_case_input_path: Path, test_case_name: str, verbose: bool +) -> int: + """ + Returns the max of the subprocess return values + """ + + test_case_output_path_reference = output_path_reference.joinpath(test_case_name) + test_case_output_path_aristaproto = output_path_aristaproto + test_case_output_path_aristaproto_pyd = output_path_aristaproto_pydantic + + os.makedirs(test_case_output_path_reference, exist_ok=True) + os.makedirs(test_case_output_path_aristaproto, exist_ok=True) + os.makedirs(test_case_output_path_aristaproto_pyd, exist_ok=True) + + clear_directory(test_case_output_path_reference) + clear_directory(test_case_output_path_aristaproto) + + ( + (ref_out, ref_err, ref_code), + (plg_out, plg_err, plg_code), + (plg_out_pyd, plg_err_pyd, plg_code_pyd), + ) = await asyncio.gather( + protoc(test_case_input_path, test_case_output_path_reference, True), + protoc(test_case_input_path, test_case_output_path_aristaproto, False), + protoc( + test_case_input_path, test_case_output_path_aristaproto_pyd, False, True + ), + ) + + if ref_code == 0: + print(f"\033[31;1;4mGenerated reference output for {test_case_name!r}\033[0m") + else: + print( + f"\033[31;1;4mFailed to generate reference output for {test_case_name!r}\033[0m" + ) + + if verbose: + if ref_out: + print("Reference stdout:") + sys.stdout.buffer.write(ref_out) + sys.stdout.buffer.flush() + + if ref_err: + print("Reference stderr:") + sys.stderr.buffer.write(ref_err) + sys.stderr.buffer.flush() + + if plg_code == 0: + print(f"\033[31;1;4mGenerated plugin output for {test_case_name!r}\033[0m") + else: + print( + f"\033[31;1;4mFailed to generate plugin output for {test_case_name!r}\033[0m" + ) + + if verbose: + if plg_out: + print("Plugin stdout:") + sys.stdout.buffer.write(plg_out) + sys.stdout.buffer.flush() + + if plg_err: + print("Plugin stderr:") + sys.stderr.buffer.write(plg_err) + sys.stderr.buffer.flush() + + if plg_code_pyd == 0: + print( + f"\033[31;1;4mGenerated plugin (pydantic compatible) output for {test_case_name!r}\033[0m" + ) + else: + print( + f"\033[31;1;4mFailed to generate plugin (pydantic compatible) output for {test_case_name!r}\033[0m" + ) + + if verbose: + if plg_out_pyd: + print("Plugin stdout:") + sys.stdout.buffer.write(plg_out_pyd) + sys.stdout.buffer.flush() + + if plg_err_pyd: + print("Plugin stderr:") + sys.stderr.buffer.write(plg_err_pyd) + sys.stderr.buffer.flush() + + return max(ref_code, plg_code, plg_code_pyd) + + +HELP = "\n".join( + ( + "Usage: python generate.py [-h] [-v] [DIRECTORIES or NAMES]", + "Generate python classes for standard tests.", + "", + "DIRECTORIES One or more relative or absolute directories of test-cases to generate classes for.", + " python generate.py inputs/bool inputs/double inputs/enum", + "", + "NAMES One or more test-case names to generate classes for.", + " python generate.py bool double enums", + ) +) + + +def main(): + if set(sys.argv).intersection({"-h", "--help"}): + print(HELP) + return + if sys.argv[1:2] == ["-v"]: + verbose = True + whitelist = set(sys.argv[2:]) + else: + verbose = False + whitelist = set(sys.argv[1:]) + + if platform.system() == "Windows": + asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy()) + + asyncio.run(generate(whitelist, verbose)) + + +if __name__ == "__main__": + main() diff --git a/tests/grpc/__init__.py b/tests/grpc/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/grpc/__init__.py diff --git a/tests/grpc/test_grpclib_client.py b/tests/grpc/test_grpclib_client.py new file mode 100644 index 0000000..d36e4a5 --- /dev/null +++ b/tests/grpc/test_grpclib_client.py @@ -0,0 +1,298 @@ +import asyncio +import sys +import uuid + +import grpclib +import grpclib.client +import grpclib.metadata +import grpclib.server +import pytest +from grpclib.testing import ChannelFor + +from aristaproto.grpc.util.async_channel import AsyncChannel +from tests.output_aristaproto.service import ( + DoThingRequest, + DoThingResponse, + GetThingRequest, + TestStub as ThingServiceClient, +) + +from .thing_service import ThingService + + +async def _test_client(client: ThingServiceClient, name="clean room", **kwargs): + response = await client.do_thing(DoThingRequest(name=name), **kwargs) + assert response.names == [name] + + +def _assert_request_meta_received(deadline, metadata): + def server_side_test(stream): + assert stream.deadline._timestamp == pytest.approx( + deadline._timestamp, 1 + ), "The provided deadline should be received serverside" + assert ( + stream.metadata["authorization"] == metadata["authorization"] + ), "The provided authorization metadata should be received serverside" + + return server_side_test + + +@pytest.fixture +def handler_trailer_only_unauthenticated(): + async def handler(stream: grpclib.server.Stream): + await stream.recv_message() + await stream.send_initial_metadata() + await stream.send_trailing_metadata(status=grpclib.Status.UNAUTHENTICATED) + + return handler + + +@pytest.mark.asyncio +async def test_simple_service_call(): + async with ChannelFor([ThingService()]) as channel: + await _test_client(ThingServiceClient(channel)) + + +@pytest.mark.asyncio +async def test_trailer_only_error_unary_unary( + mocker, handler_trailer_only_unauthenticated +): + service = ThingService() + mocker.patch.object( + service, + "do_thing", + side_effect=handler_trailer_only_unauthenticated, + autospec=True, + ) + async with ChannelFor([service]) as channel: + with pytest.raises(grpclib.exceptions.GRPCError) as e: + await ThingServiceClient(channel).do_thing(DoThingRequest(name="something")) + assert e.value.status == grpclib.Status.UNAUTHENTICATED + + +@pytest.mark.asyncio +async def test_trailer_only_error_stream_unary( + mocker, handler_trailer_only_unauthenticated +): + service = ThingService() + mocker.patch.object( + service, + "do_many_things", + side_effect=handler_trailer_only_unauthenticated, + autospec=True, + ) + async with ChannelFor([service]) as channel: + with pytest.raises(grpclib.exceptions.GRPCError) as e: + await ThingServiceClient(channel).do_many_things( + do_thing_request_iterator=[DoThingRequest(name="something")] + ) + await _test_client(ThingServiceClient(channel)) + assert e.value.status == grpclib.Status.UNAUTHENTICATED + + +@pytest.mark.asyncio +@pytest.mark.skipif( + sys.version_info < (3, 8), reason="async mock spy does works for python3.8+" +) +async def test_service_call_mutable_defaults(mocker): + async with ChannelFor([ThingService()]) as channel: + client = ThingServiceClient(channel) + spy = mocker.spy(client, "_unary_unary") + await _test_client(client) + comments = spy.call_args_list[-1].args[1].comments + await _test_client(client) + assert spy.call_args_list[-1].args[1].comments is not comments + + +@pytest.mark.asyncio +async def test_service_call_with_upfront_request_params(): + # Setting deadline + deadline = grpclib.metadata.Deadline.from_timeout(22) + metadata = {"authorization": "12345"} + async with ChannelFor( + [ThingService(test_hook=_assert_request_meta_received(deadline, metadata))] + ) as channel: + await _test_client( + ThingServiceClient(channel, deadline=deadline, metadata=metadata) + ) + + # Setting timeout + timeout = 99 + deadline = grpclib.metadata.Deadline.from_timeout(timeout) + metadata = {"authorization": "12345"} + async with ChannelFor( + [ThingService(test_hook=_assert_request_meta_received(deadline, metadata))] + ) as channel: + await _test_client( + ThingServiceClient(channel, timeout=timeout, metadata=metadata) + ) + + +@pytest.mark.asyncio +async def test_service_call_lower_level_with_overrides(): + THING_TO_DO = "get milk" + + # Setting deadline + deadline = grpclib.metadata.Deadline.from_timeout(22) + metadata = {"authorization": "12345"} + kwarg_deadline = grpclib.metadata.Deadline.from_timeout(28) + kwarg_metadata = {"authorization": "12345"} + async with ChannelFor( + [ThingService(test_hook=_assert_request_meta_received(deadline, metadata))] + ) as channel: + client = ThingServiceClient(channel, deadline=deadline, metadata=metadata) + response = await client._unary_unary( + "/service.Test/DoThing", + DoThingRequest(THING_TO_DO), + DoThingResponse, + deadline=kwarg_deadline, + metadata=kwarg_metadata, + ) + assert response.names == [THING_TO_DO] + + # Setting timeout + timeout = 99 + deadline = grpclib.metadata.Deadline.from_timeout(timeout) + metadata = {"authorization": "12345"} + kwarg_timeout = 9000 + kwarg_deadline = grpclib.metadata.Deadline.from_timeout(kwarg_timeout) + kwarg_metadata = {"authorization": "09876"} + async with ChannelFor( + [ + ThingService( + test_hook=_assert_request_meta_received(kwarg_deadline, kwarg_metadata), + ) + ] + ) as channel: + client = ThingServiceClient(channel, deadline=deadline, metadata=metadata) + response = await client._unary_unary( + "/service.Test/DoThing", + DoThingRequest(THING_TO_DO), + DoThingResponse, + timeout=kwarg_timeout, + metadata=kwarg_metadata, + ) + assert response.names == [THING_TO_DO] + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + ("overrides_gen",), + [ + (lambda: dict(timeout=10),), + (lambda: dict(deadline=grpclib.metadata.Deadline.from_timeout(10)),), + (lambda: dict(metadata={"authorization": str(uuid.uuid4())}),), + (lambda: dict(timeout=20, metadata={"authorization": str(uuid.uuid4())}),), + ], +) +async def test_service_call_high_level_with_overrides(mocker, overrides_gen): + overrides = overrides_gen() + request_spy = mocker.spy(grpclib.client.Channel, "request") + name = str(uuid.uuid4()) + defaults = dict( + timeout=99, + deadline=grpclib.metadata.Deadline.from_timeout(99), + metadata={"authorization": name}, + ) + + async with ChannelFor( + [ + ThingService( + test_hook=_assert_request_meta_received( + deadline=grpclib.metadata.Deadline.from_timeout( + overrides.get("timeout", 99) + ), + metadata=overrides.get("metadata", defaults.get("metadata")), + ) + ) + ] + ) as channel: + client = ThingServiceClient(channel, **defaults) + await _test_client(client, name=name, **overrides) + assert request_spy.call_count == 1 + + # for python <3.8 request_spy.call_args.kwargs do not work + _, request_spy_call_kwargs = request_spy.call_args_list[0] + + # ensure all overrides were successful + for key, value in overrides.items(): + assert key in request_spy_call_kwargs + assert request_spy_call_kwargs[key] == value + + # ensure default values were retained + for key in set(defaults.keys()) - set(overrides.keys()): + assert key in request_spy_call_kwargs + assert request_spy_call_kwargs[key] == defaults[key] + + +@pytest.mark.asyncio +async def test_async_gen_for_unary_stream_request(): + thing_name = "my milkshakes" + + async with ChannelFor([ThingService()]) as channel: + client = ThingServiceClient(channel) + expected_versions = [5, 4, 3, 2, 1] + async for response in client.get_thing_versions( + GetThingRequest(name=thing_name) + ): + assert response.name == thing_name + assert response.version == expected_versions.pop() + + +@pytest.mark.asyncio +async def test_async_gen_for_stream_stream_request(): + some_things = ["cake", "cricket", "coral reef"] + more_things = ["ball", "that", "56kmodem", "liberal humanism", "cheesesticks"] + expected_things = (*some_things, *more_things) + + async with ChannelFor([ThingService()]) as channel: + client = ThingServiceClient(channel) + # Use an AsyncChannel to decouple sending and recieving, it'll send some_things + # immediately and we'll use it to send more_things later, after recieving some + # results + request_chan = AsyncChannel() + send_initial_requests = asyncio.ensure_future( + request_chan.send_from(GetThingRequest(name) for name in some_things) + ) + response_index = 0 + async for response in client.get_different_things(request_chan): + assert response.name == expected_things[response_index] + assert response.version == response_index + 1 + response_index += 1 + if more_things: + # Send some more requests as we receive responses to be sure coordination of + # send/receive events doesn't matter + await request_chan.send(GetThingRequest(more_things.pop(0))) + elif not send_initial_requests.done(): + # Make sure the sending task it completed + await send_initial_requests + else: + # No more things to send make sure channel is closed + request_chan.close() + assert response_index == len( + expected_things + ), "Didn't receive all expected responses" + + +@pytest.mark.asyncio +async def test_stream_unary_with_empty_iterable(): + things = [] # empty + + async with ChannelFor([ThingService()]) as channel: + client = ThingServiceClient(channel) + requests = [DoThingRequest(name) for name in things] + response = await client.do_many_things(requests) + assert len(response.names) == 0 + + +@pytest.mark.asyncio +async def test_stream_stream_with_empty_iterable(): + things = [] # empty + + async with ChannelFor([ThingService()]) as channel: + client = ThingServiceClient(channel) + requests = [GetThingRequest(name) for name in things] + responses = [ + response async for response in client.get_different_things(requests) + ] + assert len(responses) == 0 diff --git a/tests/grpc/test_stream_stream.py b/tests/grpc/test_stream_stream.py new file mode 100644 index 0000000..d4b27e5 --- /dev/null +++ b/tests/grpc/test_stream_stream.py @@ -0,0 +1,99 @@ +import asyncio +from dataclasses import dataclass +from typing import AsyncIterator + +import pytest + +import aristaproto +from aristaproto.grpc.util.async_channel import AsyncChannel + + +@dataclass +class Message(aristaproto.Message): + body: str = aristaproto.string_field(1) + + +@pytest.fixture +def expected_responses(): + return [Message("Hello world 1"), Message("Hello world 2"), Message("Done")] + + +class ClientStub: + async def connect(self, requests: AsyncIterator): + await asyncio.sleep(0.1) + async for request in requests: + await asyncio.sleep(0.1) + yield request + await asyncio.sleep(0.1) + yield Message("Done") + + +async def to_list(generator: AsyncIterator): + return [value async for value in generator] + + +@pytest.fixture +def client(): + # channel = Channel(host='127.0.0.1', port=50051) + # return ClientStub(channel) + return ClientStub() + + +@pytest.mark.asyncio +async def test_send_from_before_connect_and_close_automatically( + client, expected_responses +): + requests = AsyncChannel() + await requests.send_from( + [Message(body="Hello world 1"), Message(body="Hello world 2")], close=True + ) + responses = client.connect(requests) + + assert await to_list(responses) == expected_responses + + +@pytest.mark.asyncio +async def test_send_from_after_connect_and_close_automatically( + client, expected_responses +): + requests = AsyncChannel() + responses = client.connect(requests) + await requests.send_from( + [Message(body="Hello world 1"), Message(body="Hello world 2")], close=True + ) + + assert await to_list(responses) == expected_responses + + +@pytest.mark.asyncio +async def test_send_from_close_manually_immediately(client, expected_responses): + requests = AsyncChannel() + responses = client.connect(requests) + await requests.send_from( + [Message(body="Hello world 1"), Message(body="Hello world 2")], close=False + ) + requests.close() + + assert await to_list(responses) == expected_responses + + +@pytest.mark.asyncio +async def test_send_individually_and_close_before_connect(client, expected_responses): + requests = AsyncChannel() + await requests.send(Message(body="Hello world 1")) + await requests.send(Message(body="Hello world 2")) + requests.close() + responses = client.connect(requests) + + assert await to_list(responses) == expected_responses + + +@pytest.mark.asyncio +async def test_send_individually_and_close_after_connect(client, expected_responses): + requests = AsyncChannel() + await requests.send(Message(body="Hello world 1")) + await requests.send(Message(body="Hello world 2")) + responses = client.connect(requests) + requests.close() + + assert await to_list(responses) == expected_responses diff --git a/tests/grpc/thing_service.py b/tests/grpc/thing_service.py new file mode 100644 index 0000000..5b00cbe --- /dev/null +++ b/tests/grpc/thing_service.py @@ -0,0 +1,85 @@ +from typing import Dict + +import grpclib +import grpclib.server + +from tests.output_aristaproto.service import ( + DoThingRequest, + DoThingResponse, + GetThingRequest, + GetThingResponse, +) + + +class ThingService: + def __init__(self, test_hook=None): + # This lets us pass assertions to the servicer ;) + self.test_hook = test_hook + + async def do_thing( + self, stream: "grpclib.server.Stream[DoThingRequest, DoThingResponse]" + ): + request = await stream.recv_message() + if self.test_hook is not None: + self.test_hook(stream) + await stream.send_message(DoThingResponse([request.name])) + + async def do_many_things( + self, stream: "grpclib.server.Stream[DoThingRequest, DoThingResponse]" + ): + thing_names = [request.name async for request in stream] + if self.test_hook is not None: + self.test_hook(stream) + await stream.send_message(DoThingResponse(thing_names)) + + async def get_thing_versions( + self, stream: "grpclib.server.Stream[GetThingRequest, GetThingResponse]" + ): + request = await stream.recv_message() + if self.test_hook is not None: + self.test_hook(stream) + for version_num in range(1, 6): + await stream.send_message( + GetThingResponse(name=request.name, version=version_num) + ) + + async def get_different_things( + self, stream: "grpclib.server.Stream[GetThingRequest, GetThingResponse]" + ): + if self.test_hook is not None: + self.test_hook(stream) + # Respond to each input item immediately + response_num = 0 + async for request in stream: + response_num += 1 + await stream.send_message( + GetThingResponse(name=request.name, version=response_num) + ) + + def __mapping__(self) -> Dict[str, "grpclib.const.Handler"]: + return { + "/service.Test/DoThing": grpclib.const.Handler( + self.do_thing, + grpclib.const.Cardinality.UNARY_UNARY, + DoThingRequest, + DoThingResponse, + ), + "/service.Test/DoManyThings": grpclib.const.Handler( + self.do_many_things, + grpclib.const.Cardinality.STREAM_UNARY, + DoThingRequest, + DoThingResponse, + ), + "/service.Test/GetThingVersions": grpclib.const.Handler( + self.get_thing_versions, + grpclib.const.Cardinality.UNARY_STREAM, + GetThingRequest, + GetThingResponse, + ), + "/service.Test/GetDifferentThings": grpclib.const.Handler( + self.get_different_things, + grpclib.const.Cardinality.STREAM_STREAM, + GetThingRequest, + GetThingResponse, + ), + } diff --git a/tests/inputs/bool/bool.json b/tests/inputs/bool/bool.json new file mode 100644 index 0000000..348e031 --- /dev/null +++ b/tests/inputs/bool/bool.json @@ -0,0 +1,3 @@ +{ + "value": true +} diff --git a/tests/inputs/bool/bool.proto b/tests/inputs/bool/bool.proto new file mode 100644 index 0000000..77836b8 --- /dev/null +++ b/tests/inputs/bool/bool.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package bool; + +message Test { + bool value = 1; +} diff --git a/tests/inputs/bool/test_bool.py b/tests/inputs/bool/test_bool.py new file mode 100644 index 0000000..f9554ae --- /dev/null +++ b/tests/inputs/bool/test_bool.py @@ -0,0 +1,19 @@ +import pytest + +from tests.output_aristaproto.bool import Test +from tests.output_aristaproto_pydantic.bool import Test as TestPyd + + +def test_value(): + message = Test() + assert not message.value, "Boolean is False by default" + + +def test_pydantic_no_value(): + with pytest.raises(ValueError): + TestPyd() + + +def test_pydantic_value(): + message = Test(value=False) + assert not message.value diff --git a/tests/inputs/bytes/bytes.json b/tests/inputs/bytes/bytes.json new file mode 100644 index 0000000..34c4554 --- /dev/null +++ b/tests/inputs/bytes/bytes.json @@ -0,0 +1,3 @@ +{ + "data": "SGVsbG8sIFdvcmxkIQ==" +} diff --git a/tests/inputs/bytes/bytes.proto b/tests/inputs/bytes/bytes.proto new file mode 100644 index 0000000..9895468 --- /dev/null +++ b/tests/inputs/bytes/bytes.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package bytes; + +message Test { + bytes data = 1; +} diff --git a/tests/inputs/casing/casing.json b/tests/inputs/casing/casing.json new file mode 100644 index 0000000..559104b --- /dev/null +++ b/tests/inputs/casing/casing.json @@ -0,0 +1,4 @@ +{ + "camelCase": 1, + "snakeCase": "ONE" +} diff --git a/tests/inputs/casing/casing.proto b/tests/inputs/casing/casing.proto new file mode 100644 index 0000000..2023d93 --- /dev/null +++ b/tests/inputs/casing/casing.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; + +package casing; + +enum my_enum { + ZERO = 0; + ONE = 1; + TWO = 2; +} + +message Test { + int32 camelCase = 1; + my_enum snake_case = 2; + snake_case_message snake_case_message = 3; + int32 UPPERCASE = 4; +} + +message snake_case_message { + +}
\ No newline at end of file diff --git a/tests/inputs/casing/test_casing.py b/tests/inputs/casing/test_casing.py new file mode 100644 index 0000000..0fa609b --- /dev/null +++ b/tests/inputs/casing/test_casing.py @@ -0,0 +1,23 @@ +import tests.output_aristaproto.casing as casing +from tests.output_aristaproto.casing import Test + + +def test_message_attributes(): + message = Test() + assert hasattr( + message, "snake_case_message" + ), "snake_case field name is same in python" + assert hasattr(message, "camel_case"), "CamelCase field is snake_case in python" + assert hasattr(message, "uppercase"), "UPPERCASE field is lowercase in python" + + +def test_message_casing(): + assert hasattr( + casing, "SnakeCaseMessage" + ), "snake_case Message name is converted to CamelCase in python" + + +def test_enum_casing(): + assert hasattr( + casing, "MyEnum" + ), "snake_case Enum name is converted to CamelCase in python" diff --git a/tests/inputs/casing_inner_class/casing_inner_class.proto b/tests/inputs/casing_inner_class/casing_inner_class.proto new file mode 100644 index 0000000..fae2a4c --- /dev/null +++ b/tests/inputs/casing_inner_class/casing_inner_class.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package casing_inner_class; + +message Test { + message inner_class { + sint32 old_exp = 1; + } + inner_class inner = 2; +}
\ No newline at end of file diff --git a/tests/inputs/casing_inner_class/test_casing_inner_class.py b/tests/inputs/casing_inner_class/test_casing_inner_class.py new file mode 100644 index 0000000..7c43add --- /dev/null +++ b/tests/inputs/casing_inner_class/test_casing_inner_class.py @@ -0,0 +1,14 @@ +import tests.output_aristaproto.casing_inner_class as casing_inner_class + + +def test_message_casing_inner_class_name(): + assert hasattr( + casing_inner_class, "TestInnerClass" + ), "Inline defined Message is correctly converted to CamelCase" + + +def test_message_casing_inner_class_attributes(): + message = casing_inner_class.Test() + assert hasattr( + message.inner, "old_exp" + ), "Inline defined Message attribute is snake_case" diff --git a/tests/inputs/casing_message_field_uppercase/casing_message_field_uppercase.proto b/tests/inputs/casing_message_field_uppercase/casing_message_field_uppercase.proto new file mode 100644 index 0000000..c6d42c3 --- /dev/null +++ b/tests/inputs/casing_message_field_uppercase/casing_message_field_uppercase.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package casing_message_field_uppercase; + +message Test { + int32 UPPERCASE = 1; + int32 UPPERCASE_V2 = 2; + int32 UPPER_CAMEL_CASE = 3; +}
\ No newline at end of file diff --git a/tests/inputs/casing_message_field_uppercase/casing_message_field_uppercase.py b/tests/inputs/casing_message_field_uppercase/casing_message_field_uppercase.py new file mode 100644 index 0000000..01a5234 --- /dev/null +++ b/tests/inputs/casing_message_field_uppercase/casing_message_field_uppercase.py @@ -0,0 +1,14 @@ +from tests.output_aristaproto.casing_message_field_uppercase import Test + + +def test_message_casing(): + message = Test() + assert hasattr( + message, "uppercase" + ), "UPPERCASE attribute is converted to 'uppercase' in python" + assert hasattr( + message, "uppercase_v2" + ), "UPPERCASE_V2 attribute is converted to 'uppercase_v2' in python" + assert hasattr( + message, "upper_camel_case" + ), "UPPER_CAMEL_CASE attribute is converted to upper_camel_case in python" diff --git a/tests/inputs/config.py b/tests/inputs/config.py new file mode 100644 index 0000000..6da1f88 --- /dev/null +++ b/tests/inputs/config.py @@ -0,0 +1,30 @@ +# Test cases that are expected to fail, e.g. unimplemented features or bug-fixes. +# Remove from list when fixed. +xfail = { + "namespace_keywords", # 70 + "googletypes_struct", # 9 + "googletypes_value", # 9 + "import_capitalized_package", + "example", # This is the example in the readme. Not a test. +} + +services = { + "googletypes_request", + "googletypes_response", + "googletypes_response_embedded", + "service", + "service_separate_packages", + "import_service_input_message", + "googletypes_service_returns_empty", + "googletypes_service_returns_googletype", + "example_service", + "empty_service", + "service_uppercase", +} + + +# Indicate json sample messages to skip when testing that json (de)serialization +# is symmetrical becuase some cases legitimately are not symmetrical. +# Each key references the name of the test scenario and the values in the tuple +# Are the names of the json files. +non_symmetrical_json = {"empty_repeated": ("empty_repeated",)} diff --git a/tests/inputs/deprecated/deprecated.json b/tests/inputs/deprecated/deprecated.json new file mode 100644 index 0000000..43b2b65 --- /dev/null +++ b/tests/inputs/deprecated/deprecated.json @@ -0,0 +1,6 @@ +{ + "message": { + "value": "hello" + }, + "value": 10 +} diff --git a/tests/inputs/deprecated/deprecated.proto b/tests/inputs/deprecated/deprecated.proto new file mode 100644 index 0000000..81d69c0 --- /dev/null +++ b/tests/inputs/deprecated/deprecated.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +package deprecated; + +// Some documentation about the Test message. +message Test { + Message message = 1 [deprecated=true]; + int32 value = 2; +} + +message Message { + option deprecated = true; + string value = 1; +} diff --git a/tests/inputs/double/double-negative.json b/tests/inputs/double/double-negative.json new file mode 100644 index 0000000..e0776c7 --- /dev/null +++ b/tests/inputs/double/double-negative.json @@ -0,0 +1,3 @@ +{ + "count": -123.45 +} diff --git a/tests/inputs/double/double.json b/tests/inputs/double/double.json new file mode 100644 index 0000000..321412e --- /dev/null +++ b/tests/inputs/double/double.json @@ -0,0 +1,3 @@ +{ + "count": 123.45 +} diff --git a/tests/inputs/double/double.proto b/tests/inputs/double/double.proto new file mode 100644 index 0000000..66aea95 --- /dev/null +++ b/tests/inputs/double/double.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package double; + +message Test { + double count = 1; +} diff --git a/tests/inputs/empty_repeated/empty_repeated.json b/tests/inputs/empty_repeated/empty_repeated.json new file mode 100644 index 0000000..12a801c --- /dev/null +++ b/tests/inputs/empty_repeated/empty_repeated.json @@ -0,0 +1,3 @@ +{ + "msg": [{"values":[]}] +} diff --git a/tests/inputs/empty_repeated/empty_repeated.proto b/tests/inputs/empty_repeated/empty_repeated.proto new file mode 100644 index 0000000..f787301 --- /dev/null +++ b/tests/inputs/empty_repeated/empty_repeated.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package empty_repeated; + +message MessageA { + repeated float values = 1; +} + +message Test { + repeated MessageA msg = 1; +} diff --git a/tests/inputs/empty_service/empty_service.proto b/tests/inputs/empty_service/empty_service.proto new file mode 100644 index 0000000..e96ff64 --- /dev/null +++ b/tests/inputs/empty_service/empty_service.proto @@ -0,0 +1,7 @@ +/* Empty service without comments */ +syntax = "proto3"; + +package empty_service; + +service Test { +} diff --git a/tests/inputs/entry/entry.proto b/tests/inputs/entry/entry.proto new file mode 100644 index 0000000..3f2af4d --- /dev/null +++ b/tests/inputs/entry/entry.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; + +package entry; + +// This is a minimal example of a repeated message field that caused issues when +// checking whether a message is a map. +// +// During the check wheter a field is a "map", the string "entry" is added to +// the field name, checked against the type name and then further checks are +// made against the nested type of a parent message. In this edge-case, the +// first check would pass even though it shouldn't and that would cause an +// error because the parent type does not have a "nested_type" attribute. + +message Test { + repeated ExportEntry export = 1; +} + +message ExportEntry { + string name = 1; +} diff --git a/tests/inputs/enum/enum.json b/tests/inputs/enum/enum.json new file mode 100644 index 0000000..d68f1c5 --- /dev/null +++ b/tests/inputs/enum/enum.json @@ -0,0 +1,9 @@ +{ + "choice": "FOUR", + "choices": [ + "ZERO", + "ONE", + "THREE", + "FOUR" + ] +} diff --git a/tests/inputs/enum/enum.proto b/tests/inputs/enum/enum.proto new file mode 100644 index 0000000..5e2e80c --- /dev/null +++ b/tests/inputs/enum/enum.proto @@ -0,0 +1,25 @@ +syntax = "proto3"; + +package enum; + +// Tests that enums are correctly serialized and that it correctly handles skipped and out-of-order enum values +message Test { + Choice choice = 1; + repeated Choice choices = 2; +} + +enum Choice { + ZERO = 0; + ONE = 1; + // TWO = 2; + FOUR = 4; + THREE = 3; +} + +// A "C" like enum with the enum name prefixed onto members, these should be stripped +enum ArithmeticOperator { + ARITHMETIC_OPERATOR_NONE = 0; + ARITHMETIC_OPERATOR_PLUS = 1; + ARITHMETIC_OPERATOR_MINUS = 2; + ARITHMETIC_OPERATOR_0_PREFIXED = 3; +} diff --git a/tests/inputs/enum/test_enum.py b/tests/inputs/enum/test_enum.py new file mode 100644 index 0000000..cf14c68 --- /dev/null +++ b/tests/inputs/enum/test_enum.py @@ -0,0 +1,114 @@ +from tests.output_aristaproto.enum import ( + ArithmeticOperator, + Choice, + Test, +) + + +def test_enum_set_and_get(): + assert Test(choice=Choice.ZERO).choice == Choice.ZERO + assert Test(choice=Choice.ONE).choice == Choice.ONE + assert Test(choice=Choice.THREE).choice == Choice.THREE + assert Test(choice=Choice.FOUR).choice == Choice.FOUR + + +def test_enum_set_with_int(): + assert Test(choice=0).choice == Choice.ZERO + assert Test(choice=1).choice == Choice.ONE + assert Test(choice=3).choice == Choice.THREE + assert Test(choice=4).choice == Choice.FOUR + + +def test_enum_is_comparable_with_int(): + assert Test(choice=Choice.ZERO).choice == 0 + assert Test(choice=Choice.ONE).choice == 1 + assert Test(choice=Choice.THREE).choice == 3 + assert Test(choice=Choice.FOUR).choice == 4 + + +def test_enum_to_dict(): + assert ( + "choice" not in Test(choice=Choice.ZERO).to_dict() + ), "Default enum value is not serialized" + assert ( + Test(choice=Choice.ZERO).to_dict(include_default_values=True)["choice"] + == "ZERO" + ) + assert Test(choice=Choice.ONE).to_dict()["choice"] == "ONE" + assert Test(choice=Choice.THREE).to_dict()["choice"] == "THREE" + assert Test(choice=Choice.FOUR).to_dict()["choice"] == "FOUR" + + +def test_repeated_enum_is_comparable_with_int(): + assert Test(choices=[Choice.ZERO]).choices == [0] + assert Test(choices=[Choice.ONE]).choices == [1] + assert Test(choices=[Choice.THREE]).choices == [3] + assert Test(choices=[Choice.FOUR]).choices == [4] + + +def test_repeated_enum_set_and_get(): + assert Test(choices=[Choice.ZERO]).choices == [Choice.ZERO] + assert Test(choices=[Choice.ONE]).choices == [Choice.ONE] + assert Test(choices=[Choice.THREE]).choices == [Choice.THREE] + assert Test(choices=[Choice.FOUR]).choices == [Choice.FOUR] + + +def test_repeated_enum_to_dict(): + assert Test(choices=[Choice.ZERO]).to_dict()["choices"] == ["ZERO"] + assert Test(choices=[Choice.ONE]).to_dict()["choices"] == ["ONE"] + assert Test(choices=[Choice.THREE]).to_dict()["choices"] == ["THREE"] + assert Test(choices=[Choice.FOUR]).to_dict()["choices"] == ["FOUR"] + + all_enums_dict = Test( + choices=[Choice.ZERO, Choice.ONE, Choice.THREE, Choice.FOUR] + ).to_dict() + assert (all_enums_dict["choices"]) == ["ZERO", "ONE", "THREE", "FOUR"] + + +def test_repeated_enum_with_single_value_to_dict(): + assert Test(choices=Choice.ONE).to_dict()["choices"] == ["ONE"] + assert Test(choices=1).to_dict()["choices"] == ["ONE"] + + +def test_repeated_enum_with_non_list_iterables_to_dict(): + assert Test(choices=(1, 3)).to_dict()["choices"] == ["ONE", "THREE"] + assert Test(choices=(1, 3)).to_dict()["choices"] == ["ONE", "THREE"] + assert Test(choices=(Choice.ONE, Choice.THREE)).to_dict()["choices"] == [ + "ONE", + "THREE", + ] + + def enum_generator(): + yield Choice.ONE + yield Choice.THREE + + assert Test(choices=enum_generator()).to_dict()["choices"] == ["ONE", "THREE"] + + +def test_enum_mapped_on_parse(): + # test default value + b = Test().parse(bytes(Test())) + assert b.choice.name == Choice.ZERO.name + assert b.choices == [] + + # test non default value + a = Test().parse(bytes(Test(choice=Choice.ONE))) + assert a.choice.name == Choice.ONE.name + assert b.choices == [] + + # test repeated + c = Test().parse(bytes(Test(choices=[Choice.THREE, Choice.FOUR]))) + assert c.choices[0].name == Choice.THREE.name + assert c.choices[1].name == Choice.FOUR.name + + # bonus: defaults after empty init are also mapped + assert Test().choice.name == Choice.ZERO.name + + +def test_renamed_enum_members(): + assert set(ArithmeticOperator.__members__) == { + "NONE", + "PLUS", + "MINUS", + "_0_PREFIXED", + } diff --git a/tests/inputs/example/example.proto b/tests/inputs/example/example.proto new file mode 100644 index 0000000..56bd364 --- /dev/null +++ b/tests/inputs/example/example.proto @@ -0,0 +1,911 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// The messages in this file describe the definitions found in .proto files. +// A valid .proto file can be translated directly to a FileDescriptorProto +// without any other information (e.g. without reading its imports). + + +syntax = "proto2"; + +package example; + +// package google.protobuf; + +option go_package = "google.golang.org/protobuf/types/descriptorpb"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "DescriptorProtos"; +option csharp_namespace = "Google.Protobuf.Reflection"; +option objc_class_prefix = "GPB"; +option cc_enable_arenas = true; + +// descriptor.proto must be optimized for speed because reflection-based +// algorithms don't work during bootstrapping. +option optimize_for = SPEED; + +// The protocol compiler can output a FileDescriptorSet containing the .proto +// files it parses. +message FileDescriptorSet { + repeated FileDescriptorProto file = 1; +} + +// Describes a complete .proto file. +message FileDescriptorProto { + optional string name = 1; // file name, relative to root of source tree + optional string package = 2; // e.g. "foo", "foo.bar", etc. + + // Names of files imported by this file. + repeated string dependency = 3; + // Indexes of the public imported files in the dependency list above. + repeated int32 public_dependency = 10; + // Indexes of the weak imported files in the dependency list. + // For Google-internal migration only. Do not use. + repeated int32 weak_dependency = 11; + + // All top-level definitions in this file. + repeated DescriptorProto message_type = 4; + repeated EnumDescriptorProto enum_type = 5; + repeated ServiceDescriptorProto service = 6; + repeated FieldDescriptorProto extension = 7; + + optional FileOptions options = 8; + + // This field contains optional information about the original source code. + // You may safely remove this entire field without harming runtime + // functionality of the descriptors -- the information is needed only by + // development tools. + optional SourceCodeInfo source_code_info = 9; + + // The syntax of the proto file. + // The supported values are "proto2" and "proto3". + optional string syntax = 12; +} + +// Describes a message type. +message DescriptorProto { + optional string name = 1; + + repeated FieldDescriptorProto field = 2; + repeated FieldDescriptorProto extension = 6; + + repeated DescriptorProto nested_type = 3; + repeated EnumDescriptorProto enum_type = 4; + + message ExtensionRange { + optional int32 start = 1; // Inclusive. + optional int32 end = 2; // Exclusive. + + optional ExtensionRangeOptions options = 3; + } + repeated ExtensionRange extension_range = 5; + + repeated OneofDescriptorProto oneof_decl = 8; + + optional MessageOptions options = 7; + + // Range of reserved tag numbers. Reserved tag numbers may not be used by + // fields or extension ranges in the same message. Reserved ranges may + // not overlap. + message ReservedRange { + optional int32 start = 1; // Inclusive. + optional int32 end = 2; // Exclusive. + } + repeated ReservedRange reserved_range = 9; + // Reserved field names, which may not be used by fields in the same message. + // A given name may only be reserved once. + repeated string reserved_name = 10; +} + +message ExtensionRangeOptions { + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +// Describes a field within a message. +message FieldDescriptorProto { + enum Type { + // 0 is reserved for errors. + // Order is weird for historical reasons. + TYPE_DOUBLE = 1; + TYPE_FLOAT = 2; + // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if + // negative values are likely. + TYPE_INT64 = 3; + TYPE_UINT64 = 4; + // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if + // negative values are likely. + TYPE_INT32 = 5; + TYPE_FIXED64 = 6; + TYPE_FIXED32 = 7; + TYPE_BOOL = 8; + TYPE_STRING = 9; + // Tag-delimited aggregate. + // Group type is deprecated and not supported in proto3. However, Proto3 + // implementations should still be able to parse the group wire format and + // treat group fields as unknown fields. + TYPE_GROUP = 10; + TYPE_MESSAGE = 11; // Length-delimited aggregate. + + // New in version 2. + TYPE_BYTES = 12; + TYPE_UINT32 = 13; + TYPE_ENUM = 14; + TYPE_SFIXED32 = 15; + TYPE_SFIXED64 = 16; + TYPE_SINT32 = 17; // Uses ZigZag encoding. + TYPE_SINT64 = 18; // Uses ZigZag encoding. + } + + enum Label { + // 0 is reserved for errors + LABEL_OPTIONAL = 1; + LABEL_REQUIRED = 2; + LABEL_REPEATED = 3; + } + + optional string name = 1; + optional int32 number = 3; + optional Label label = 4; + + // If type_name is set, this need not be set. If both this and type_name + // are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP. + optional Type type = 5; + + // For message and enum types, this is the name of the type. If the name + // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping + // rules are used to find the type (i.e. first the nested types within this + // message are searched, then within the parent, on up to the root + // namespace). + optional string type_name = 6; + + // For extensions, this is the name of the type being extended. It is + // resolved in the same manner as type_name. + optional string extendee = 2; + + // For numeric types, contains the original text representation of the value. + // For booleans, "true" or "false". + // For strings, contains the default text contents (not escaped in any way). + // For bytes, contains the C escaped value. All bytes >= 128 are escaped. + // TODO(kenton): Base-64 encode? + optional string default_value = 7; + + // If set, gives the index of a oneof in the containing type's oneof_decl + // list. This field is a member of that oneof. + optional int32 oneof_index = 9; + + // JSON name of this field. The value is set by protocol compiler. If the + // user has set a "json_name" option on this field, that option's value + // will be used. Otherwise, it's deduced from the field's name by converting + // it to camelCase. + optional string json_name = 10; + + optional FieldOptions options = 8; + + // If true, this is a proto3 "optional". When a proto3 field is optional, it + // tracks presence regardless of field type. + // + // When proto3_optional is true, this field must be belong to a oneof to + // signal to old proto3 clients that presence is tracked for this field. This + // oneof is known as a "synthetic" oneof, and this field must be its sole + // member (each proto3 optional field gets its own synthetic oneof). Synthetic + // oneofs exist in the descriptor only, and do not generate any API. Synthetic + // oneofs must be ordered after all "real" oneofs. + // + // For message fields, proto3_optional doesn't create any semantic change, + // since non-repeated message fields always track presence. However it still + // indicates the semantic detail of whether the user wrote "optional" or not. + // This can be useful for round-tripping the .proto file. For consistency we + // give message fields a synthetic oneof also, even though it is not required + // to track presence. This is especially important because the parser can't + // tell if a field is a message or an enum, so it must always create a + // synthetic oneof. + // + // Proto2 optional fields do not set this flag, because they already indicate + // optional with `LABEL_OPTIONAL`. + optional bool proto3_optional = 17; +} + +// Describes a oneof. +message OneofDescriptorProto { + optional string name = 1; + optional OneofOptions options = 2; +} + +// Describes an enum type. +message EnumDescriptorProto { + optional string name = 1; + + repeated EnumValueDescriptorProto value = 2; + + optional EnumOptions options = 3; + + // Range of reserved numeric values. Reserved values may not be used by + // entries in the same enum. Reserved ranges may not overlap. + // + // Note that this is distinct from DescriptorProto.ReservedRange in that it + // is inclusive such that it can appropriately represent the entire int32 + // domain. + message EnumReservedRange { + optional int32 start = 1; // Inclusive. + optional int32 end = 2; // Inclusive. + } + + // Range of reserved numeric values. Reserved numeric values may not be used + // by enum values in the same enum declaration. Reserved ranges may not + // overlap. + repeated EnumReservedRange reserved_range = 4; + + // Reserved enum value names, which may not be reused. A given name may only + // be reserved once. + repeated string reserved_name = 5; +} + +// Describes a value within an enum. +message EnumValueDescriptorProto { + optional string name = 1; + optional int32 number = 2; + + optional EnumValueOptions options = 3; +} + +// Describes a service. +message ServiceDescriptorProto { + optional string name = 1; + repeated MethodDescriptorProto method = 2; + + optional ServiceOptions options = 3; +} + +// Describes a method of a service. +message MethodDescriptorProto { + optional string name = 1; + + // Input and output type names. These are resolved in the same way as + // FieldDescriptorProto.type_name, but must refer to a message type. + optional string input_type = 2; + optional string output_type = 3; + + optional MethodOptions options = 4; + + // Identifies if client streams multiple client messages + optional bool client_streaming = 5 [default = false]; + // Identifies if server streams multiple server messages + optional bool server_streaming = 6 [default = false]; +} + + +// =================================================================== +// Options + +// Each of the definitions above may have "options" attached. These are +// just annotations which may cause code to be generated slightly differently +// or may contain hints for code that manipulates protocol messages. +// +// Clients may define custom options as extensions of the *Options messages. +// These extensions may not yet be known at parsing time, so the parser cannot +// store the values in them. Instead it stores them in a field in the *Options +// message called uninterpreted_option. This field must have the same name +// across all *Options messages. We then use this field to populate the +// extensions when we build a descriptor, at which point all protos have been +// parsed and so all extensions are known. +// +// Extension numbers for custom options may be chosen as follows: +// * For options which will only be used within a single application or +// organization, or for experimental options, use field numbers 50000 +// through 99999. It is up to you to ensure that you do not use the +// same number for multiple options. +// * For options which will be published and used publicly by multiple +// independent entities, e-mail protobuf-global-extension-registry@google.com +// to reserve extension numbers. Simply provide your project name (e.g. +// Objective-C plugin) and your project website (if available) -- there's no +// need to explain how you intend to use them. Usually you only need one +// extension number. You can declare multiple options with only one extension +// number by putting them in a sub-message. See the Custom Options section of +// the docs for examples: +// https://developers.google.com/protocol-buffers/docs/proto#options +// If this turns out to be popular, a web service will be set up +// to automatically assign option numbers. + +message FileOptions { + + // Sets the Java package where classes generated from this .proto will be + // placed. By default, the proto package is used, but this is often + // inappropriate because proto packages do not normally start with backwards + // domain names. + optional string java_package = 1; + + + // If set, all the classes from the .proto file are wrapped in a single + // outer class with the given name. This applies to both Proto1 + // (equivalent to the old "--one_java_file" option) and Proto2 (where + // a .proto always translates to a single class, but you may want to + // explicitly choose the class name). + optional string java_outer_classname = 8; + + // If set true, then the Java code generator will generate a separate .java + // file for each top-level message, enum, and service defined in the .proto + // file. Thus, these types will *not* be nested inside the outer class + // named by java_outer_classname. However, the outer class will still be + // generated to contain the file's getDescriptor() method as well as any + // top-level extensions defined in the file. + optional bool java_multiple_files = 10 [default = false]; + + // This option does nothing. + optional bool java_generate_equals_and_hash = 20 [deprecated=true]; + + // If set true, then the Java2 code generator will generate code that + // throws an exception whenever an attempt is made to assign a non-UTF-8 + // byte sequence to a string field. + // Message reflection will do the same. + // However, an extension field still accepts non-UTF-8 byte sequences. + // This option has no effect on when used with the lite runtime. + optional bool java_string_check_utf8 = 27 [default = false]; + + + // Generated classes can be optimized for speed or code size. + enum OptimizeMode { + SPEED = 1; // Generate complete code for parsing, serialization, + // etc. + CODE_SIZE = 2; // Use ReflectionOps to implement these methods. + LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime. + } + optional OptimizeMode optimize_for = 9 [default = SPEED]; + + // Sets the Go package where structs generated from this .proto will be + // placed. If omitted, the Go package will be derived from the following: + // - The basename of the package import path, if provided. + // - Otherwise, the package statement in the .proto file, if present. + // - Otherwise, the basename of the .proto file, without extension. + optional string go_package = 11; + + + + + // Should generic services be generated in each language? "Generic" services + // are not specific to any particular RPC system. They are generated by the + // main code generators in each language (without additional plugins). + // Generic services were the only kind of service generation supported by + // early versions of google.protobuf. + // + // Generic services are now considered deprecated in favor of using plugins + // that generate code specific to your particular RPC system. Therefore, + // these default to false. Old code which depends on generic services should + // explicitly set them to true. + optional bool cc_generic_services = 16 [default = false]; + optional bool java_generic_services = 17 [default = false]; + optional bool py_generic_services = 18 [default = false]; + optional bool php_generic_services = 42 [default = false]; + + // Is this file deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for everything in the file, or it will be completely ignored; in the very + // least, this is a formalization for deprecating files. + optional bool deprecated = 23 [default = false]; + + // Enables the use of arenas for the proto messages in this file. This applies + // only to generated classes for C++. + optional bool cc_enable_arenas = 31 [default = true]; + + + // Sets the objective c class prefix which is prepended to all objective c + // generated classes from this .proto. There is no default. + optional string objc_class_prefix = 36; + + // Namespace for generated classes; defaults to the package. + optional string csharp_namespace = 37; + + // By default Swift generators will take the proto package and CamelCase it + // replacing '.' with underscore and use that to prefix the types/symbols + // defined. When this options is provided, they will use this value instead + // to prefix the types/symbols defined. + optional string swift_prefix = 39; + + // Sets the php class prefix which is prepended to all php generated classes + // from this .proto. Default is empty. + optional string php_class_prefix = 40; + + // Use this option to change the namespace of php generated classes. Default + // is empty. When this option is empty, the package name will be used for + // determining the namespace. + optional string php_namespace = 41; + + // Use this option to change the namespace of php generated metadata classes. + // Default is empty. When this option is empty, the proto file name will be + // used for determining the namespace. + optional string php_metadata_namespace = 44; + + // Use this option to change the package of ruby generated classes. Default + // is empty. When this option is not set, the package name will be used for + // determining the ruby package. + optional string ruby_package = 45; + + + // The parser stores options it doesn't recognize here. + // See the documentation for the "Options" section above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. + // See the documentation for the "Options" section above. + extensions 1000 to max; + + reserved 38; +} + +message MessageOptions { + // Set true to use the old proto1 MessageSet wire format for extensions. + // This is provided for backwards-compatibility with the MessageSet wire + // format. You should not use this for any other reason: It's less + // efficient, has fewer features, and is more complicated. + // + // The message must be defined exactly as follows: + // message Foo { + // option message_set_wire_format = true; + // extensions 4 to max; + // } + // Note that the message cannot have any defined fields; MessageSets only + // have extensions. + // + // All extensions of your type must be singular messages; e.g. they cannot + // be int32s, enums, or repeated messages. + // + // Because this is an option, the above two restrictions are not enforced by + // the protocol compiler. + optional bool message_set_wire_format = 1 [default = false]; + + // Disables the generation of the standard "descriptor()" accessor, which can + // conflict with a field of the same name. This is meant to make migration + // from proto1 easier; new code should avoid fields named "descriptor". + optional bool no_standard_descriptor_accessor = 2 [default = false]; + + // Is this message deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the message, or it will be completely ignored; in the very least, + // this is a formalization for deprecating messages. + optional bool deprecated = 3 [default = false]; + + // Whether the message is an automatically generated map entry type for the + // maps field. + // + // For maps fields: + // map<KeyType, ValueType> map_field = 1; + // The parsed descriptor looks like: + // message MapFieldEntry { + // option map_entry = true; + // optional KeyType key = 1; + // optional ValueType value = 2; + // } + // repeated MapFieldEntry map_field = 1; + // + // Implementations may choose not to generate the map_entry=true message, but + // use a native map in the target language to hold the keys and values. + // The reflection APIs in such implementations still need to work as + // if the field is a repeated message field. + // + // NOTE: Do not set the option in .proto files. Always use the maps syntax + // instead. The option should only be implicitly set by the proto compiler + // parser. + optional bool map_entry = 7; + + reserved 8; // javalite_serializable + reserved 9; // javanano_as_lite + + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message FieldOptions { + // The ctype option instructs the C++ code generator to use a different + // representation of the field than it normally would. See the specific + // options below. This option is not yet implemented in the open source + // release -- sorry, we'll try to include it in a future version! + optional CType ctype = 1 [default = STRING]; + enum CType { + // Default mode. + STRING = 0; + + CORD = 1; + + STRING_PIECE = 2; + } + // The packed option can be enabled for repeated primitive fields to enable + // a more efficient representation on the wire. Rather than repeatedly + // writing the tag and type for each element, the entire array is encoded as + // a single length-delimited blob. In proto3, only explicit setting it to + // false will avoid using packed encoding. + optional bool packed = 2; + + // The jstype option determines the JavaScript type used for values of the + // field. The option is permitted only for 64 bit integral and fixed types + // (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING + // is represented as JavaScript string, which avoids loss of precision that + // can happen when a large value is converted to a floating point JavaScript. + // Specifying JS_NUMBER for the jstype causes the generated JavaScript code to + // use the JavaScript "number" type. The behavior of the default option + // JS_NORMAL is implementation dependent. + // + // This option is an enum to permit additional types to be added, e.g. + // goog.math.Integer. + optional JSType jstype = 6 [default = JS_NORMAL]; + enum JSType { + // Use the default type. + JS_NORMAL = 0; + + // Use JavaScript strings. + JS_STRING = 1; + + // Use JavaScript numbers. + JS_NUMBER = 2; + } + + // Should this field be parsed lazily? Lazy applies only to message-type + // fields. It means that when the outer message is initially parsed, the + // inner message's contents will not be parsed but instead stored in encoded + // form. The inner message will actually be parsed when it is first accessed. + // + // This is only a hint. Implementations are free to choose whether to use + // eager or lazy parsing regardless of the value of this option. However, + // setting this option true suggests that the protocol author believes that + // using lazy parsing on this field is worth the additional bookkeeping + // overhead typically needed to implement it. + // + // This option does not affect the public interface of any generated code; + // all method signatures remain the same. Furthermore, thread-safety of the + // interface is not affected by this option; const methods remain safe to + // call from multiple threads concurrently, while non-const methods continue + // to require exclusive access. + // + // + // Note that implementations may choose not to check required fields within + // a lazy sub-message. That is, calling IsInitialized() on the outer message + // may return true even if the inner message has missing required fields. + // This is necessary because otherwise the inner message would have to be + // parsed in order to perform the check, defeating the purpose of lazy + // parsing. An implementation which chooses not to check required fields + // must be consistent about it. That is, for any particular sub-message, the + // implementation must either *always* check its required fields, or *never* + // check its required fields, regardless of whether or not the message has + // been parsed. + optional bool lazy = 5 [default = false]; + + // Is this field deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for accessors, or it will be completely ignored; in the very least, this + // is a formalization for deprecating fields. + optional bool deprecated = 3 [default = false]; + + // For Google-internal migration only. Do not use. + optional bool weak = 10 [default = false]; + + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; + + reserved 4; // removed jtype +} + +message OneofOptions { + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message EnumOptions { + + // Set this option to true to allow mapping different tag names to the same + // value. + optional bool allow_alias = 2; + + // Is this enum deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the enum, or it will be completely ignored; in the very least, this + // is a formalization for deprecating enums. + optional bool deprecated = 3 [default = false]; + + reserved 5; // javanano_as_lite + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message EnumValueOptions { + // Is this enum value deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the enum value, or it will be completely ignored; in the very least, + // this is a formalization for deprecating enum values. + optional bool deprecated = 1 [default = false]; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message ServiceOptions { + + // Note: Field numbers 1 through 32 are reserved for Google's internal RPC + // framework. We apologize for hoarding these numbers to ourselves, but + // we were already using them long before we decided to release Protocol + // Buffers. + + // Is this service deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the service, or it will be completely ignored; in the very least, + // this is a formalization for deprecating services. + optional bool deprecated = 33 [default = false]; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message MethodOptions { + + // Note: Field numbers 1 through 32 are reserved for Google's internal RPC + // framework. We apologize for hoarding these numbers to ourselves, but + // we were already using them long before we decided to release Protocol + // Buffers. + + // Is this method deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the method, or it will be completely ignored; in the very least, + // this is a formalization for deprecating methods. + optional bool deprecated = 33 [default = false]; + + // Is this method side-effect-free (or safe in HTTP parlance), or idempotent, + // or neither? HTTP based RPC implementation may choose GET verb for safe + // methods, and PUT verb for idempotent methods instead of the default POST. + enum IdempotencyLevel { + IDEMPOTENCY_UNKNOWN = 0; + NO_SIDE_EFFECTS = 1; // implies idempotent + IDEMPOTENT = 2; // idempotent, but may have side effects + } + optional IdempotencyLevel idempotency_level = 34 + [default = IDEMPOTENCY_UNKNOWN]; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + + +// A message representing a option the parser does not recognize. This only +// appears in options protos created by the compiler::Parser class. +// DescriptorPool resolves these when building Descriptor objects. Therefore, +// options protos in descriptor objects (e.g. returned by Descriptor::options(), +// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions +// in them. +message UninterpretedOption { + // The name of the uninterpreted option. Each string represents a segment in + // a dot-separated name. is_extension is true iff a segment represents an + // extension (denoted with parentheses in options specs in .proto files). + // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents + // "foo.(bar.baz).qux". + message NamePart { + required string name_part = 1; + required bool is_extension = 2; + } + repeated NamePart name = 2; + + // The value of the uninterpreted option, in whatever type the tokenizer + // identified it as during parsing. Exactly one of these should be set. + optional string identifier_value = 3; + optional uint64 positive_int_value = 4; + optional int64 negative_int_value = 5; + optional double double_value = 6; + optional bytes string_value = 7; + optional string aggregate_value = 8; +} + +// =================================================================== +// Optional source code info + +// Encapsulates information about the original source file from which a +// FileDescriptorProto was generated. +message SourceCodeInfo { + // A Location identifies a piece of source code in a .proto file which + // corresponds to a particular definition. This information is intended + // to be useful to IDEs, code indexers, documentation generators, and similar + // tools. + // + // For example, say we have a file like: + // message Foo { + // optional string foo = 1; + // } + // Let's look at just the field definition: + // optional string foo = 1; + // ^ ^^ ^^ ^ ^^^ + // a bc de f ghi + // We have the following locations: + // span path represents + // [a,i) [ 4, 0, 2, 0 ] The whole field definition. + // [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). + // [c,d) [ 4, 0, 2, 0, 5 ] The type (string). + // [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). + // [g,h) [ 4, 0, 2, 0, 3 ] The number (1). + // + // Notes: + // - A location may refer to a repeated field itself (i.e. not to any + // particular index within it). This is used whenever a set of elements are + // logically enclosed in a single code segment. For example, an entire + // extend block (possibly containing multiple extension definitions) will + // have an outer location whose path refers to the "extensions" repeated + // field without an index. + // - Multiple locations may have the same path. This happens when a single + // logical declaration is spread out across multiple places. The most + // obvious example is the "extend" block again -- there may be multiple + // extend blocks in the same scope, each of which will have the same path. + // - A location's span is not always a subset of its parent's span. For + // example, the "extendee" of an extension declaration appears at the + // beginning of the "extend" block and is shared by all extensions within + // the block. + // - Just because a location's span is a subset of some other location's span + // does not mean that it is a descendant. For example, a "group" defines + // both a type and a field in a single declaration. Thus, the locations + // corresponding to the type and field and their components will overlap. + // - Code which tries to interpret locations should probably be designed to + // ignore those that it doesn't understand, as more types of locations could + // be recorded in the future. + repeated Location location = 1; + message Location { + // Identifies which part of the FileDescriptorProto was defined at this + // location. + // + // Each element is a field number or an index. They form a path from + // the root FileDescriptorProto to the place where the definition. For + // example, this path: + // [ 4, 3, 2, 7, 1 ] + // refers to: + // file.message_type(3) // 4, 3 + // .field(7) // 2, 7 + // .name() // 1 + // This is because FileDescriptorProto.message_type has field number 4: + // repeated DescriptorProto message_type = 4; + // and DescriptorProto.field has field number 2: + // repeated FieldDescriptorProto field = 2; + // and FieldDescriptorProto.name has field number 1: + // optional string name = 1; + // + // Thus, the above path gives the location of a field name. If we removed + // the last element: + // [ 4, 3, 2, 7 ] + // this path refers to the whole field declaration (from the beginning + // of the label to the terminating semicolon). + repeated int32 path = 1 [packed = true]; + + // Always has exactly three or four elements: start line, start column, + // end line (optional, otherwise assumed same as start line), end column. + // These are packed into a single field for efficiency. Note that line + // and column numbers are zero-based -- typically you will want to add + // 1 to each before displaying to a user. + repeated int32 span = 2 [packed = true]; + + // If this SourceCodeInfo represents a complete declaration, these are any + // comments appearing before and after the declaration which appear to be + // attached to the declaration. + // + // A series of line comments appearing on consecutive lines, with no other + // tokens appearing on those lines, will be treated as a single comment. + // + // leading_detached_comments will keep paragraphs of comments that appear + // before (but not connected to) the current element. Each paragraph, + // separated by empty lines, will be one comment element in the repeated + // field. + // + // Only the comment content is provided; comment markers (e.g. //) are + // stripped out. For block comments, leading whitespace and an asterisk + // will be stripped from the beginning of each line other than the first. + // Newlines are included in the output. + // + // Examples: + // + // optional int32 foo = 1; // Comment attached to foo. + // // Comment attached to bar. + // optional int32 bar = 2; + // + // optional string baz = 3; + // // Comment attached to baz. + // // Another line attached to baz. + // + // // Comment attached to qux. + // // + // // Another line attached to qux. + // optional double qux = 4; + // + // // Detached comment for corge. This is not leading or trailing comments + // // to qux or corge because there are blank lines separating it from + // // both. + // + // // Detached comment for corge paragraph 2. + // + // optional string corge = 5; + // /* Block comment attached + // * to corge. Leading asterisks + // * will be removed. */ + // /* Block comment attached to + // * grault. */ + // optional int32 grault = 6; + // + // // ignored detached comments. + optional string leading_comments = 3; + optional string trailing_comments = 4; + repeated string leading_detached_comments = 6; + } +} + +// Describes the relationship between generated code and its original source +// file. A GeneratedCodeInfo message is associated with only one generated +// source file, but may contain references to different source .proto files. +message GeneratedCodeInfo { + // An Annotation connects some span of text in generated code to an element + // of its generating .proto file. + repeated Annotation annotation = 1; + message Annotation { + // Identifies the element in the original source .proto file. This field + // is formatted the same as SourceCodeInfo.Location.path. + repeated int32 path = 1 [packed = true]; + + // Identifies the filesystem path to the original source .proto. + optional string source_file = 2; + + // Identifies the starting offset in bytes in the generated code + // that relates to the identified object. + optional int32 begin = 3; + + // Identifies the ending offset in bytes in the generated code that + // relates to the identified offset. The end offset should be one past + // the last relevant byte (so the length of the text = end - begin). + optional int32 end = 4; + } +} diff --git a/tests/inputs/example_service/example_service.proto b/tests/inputs/example_service/example_service.proto new file mode 100644 index 0000000..96455cc --- /dev/null +++ b/tests/inputs/example_service/example_service.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; + +package example_service; + +service Test { + rpc ExampleUnaryUnary(ExampleRequest) returns (ExampleResponse); + rpc ExampleUnaryStream(ExampleRequest) returns (stream ExampleResponse); + rpc ExampleStreamUnary(stream ExampleRequest) returns (ExampleResponse); + rpc ExampleStreamStream(stream ExampleRequest) returns (stream ExampleResponse); +} + +message ExampleRequest { + string example_string = 1; + int64 example_integer = 2; +} + +message ExampleResponse { + string example_string = 1; + int64 example_integer = 2; +} diff --git a/tests/inputs/example_service/test_example_service.py b/tests/inputs/example_service/test_example_service.py new file mode 100644 index 0000000..551e3fe --- /dev/null +++ b/tests/inputs/example_service/test_example_service.py @@ -0,0 +1,86 @@ +from typing import ( + AsyncIterable, + AsyncIterator, +) + +import pytest +from grpclib.testing import ChannelFor + +from tests.output_aristaproto.example_service import ( + ExampleRequest, + ExampleResponse, + TestBase, + TestStub, +) + + +class ExampleService(TestBase): + async def example_unary_unary( + self, example_request: ExampleRequest + ) -> "ExampleResponse": + return ExampleResponse( + example_string=example_request.example_string, + example_integer=example_request.example_integer, + ) + + async def example_unary_stream( + self, example_request: ExampleRequest + ) -> AsyncIterator["ExampleResponse"]: + response = ExampleResponse( + example_string=example_request.example_string, + example_integer=example_request.example_integer, + ) + yield response + yield response + yield response + + async def example_stream_unary( + self, example_request_iterator: AsyncIterator["ExampleRequest"] + ) -> "ExampleResponse": + async for example_request in example_request_iterator: + return ExampleResponse( + example_string=example_request.example_string, + example_integer=example_request.example_integer, + ) + + async def example_stream_stream( + self, example_request_iterator: AsyncIterator["ExampleRequest"] + ) -> AsyncIterator["ExampleResponse"]: + async for example_request in example_request_iterator: + yield ExampleResponse( + example_string=example_request.example_string, + example_integer=example_request.example_integer, + ) + + +@pytest.mark.asyncio +async def test_calls_with_different_cardinalities(): + example_request = ExampleRequest("test string", 42) + + async with ChannelFor([ExampleService()]) as channel: + stub = TestStub(channel) + + # unary unary + response = await stub.example_unary_unary(example_request) + assert response.example_string == example_request.example_string + assert response.example_integer == example_request.example_integer + + # unary stream + async for response in stub.example_unary_stream(example_request): + assert response.example_string == example_request.example_string + assert response.example_integer == example_request.example_integer + + # stream unary + async def request_iterator(): + yield example_request + yield example_request + yield example_request + + response = await stub.example_stream_unary(request_iterator()) + assert response.example_string == example_request.example_string + assert response.example_integer == example_request.example_integer + + # stream stream + async for response in stub.example_stream_stream(request_iterator()): + assert response.example_string == example_request.example_string + assert response.example_integer == example_request.example_integer diff --git a/tests/inputs/field_name_identical_to_type/field_name_identical_to_type.json b/tests/inputs/field_name_identical_to_type/field_name_identical_to_type.json new file mode 100644 index 0000000..7a6e7ae --- /dev/null +++ b/tests/inputs/field_name_identical_to_type/field_name_identical_to_type.json @@ -0,0 +1,7 @@ +{ + "int": 26, + "float": 26.0, + "str": "value-for-str", + "bytes": "001a", + "bool": true +}
\ No newline at end of file diff --git a/tests/inputs/field_name_identical_to_type/field_name_identical_to_type.proto b/tests/inputs/field_name_identical_to_type/field_name_identical_to_type.proto new file mode 100644 index 0000000..81a0fc4 --- /dev/null +++ b/tests/inputs/field_name_identical_to_type/field_name_identical_to_type.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package field_name_identical_to_type; + +// Tests that messages may contain fields with names that are identical to their python types (PR #294) + +message Test { + int32 int = 1; + float float = 2; + string str = 3; + bytes bytes = 4; + bool bool = 5; +}
\ No newline at end of file diff --git a/tests/inputs/fixed/fixed.json b/tests/inputs/fixed/fixed.json new file mode 100644 index 0000000..8858780 --- /dev/null +++ b/tests/inputs/fixed/fixed.json @@ -0,0 +1,6 @@ +{ + "foo": 4294967295, + "bar": -2147483648, + "baz": "18446744073709551615", + "qux": "-9223372036854775808" +} diff --git a/tests/inputs/fixed/fixed.proto b/tests/inputs/fixed/fixed.proto new file mode 100644 index 0000000..0f0ffb4 --- /dev/null +++ b/tests/inputs/fixed/fixed.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package fixed; + +message Test { + fixed32 foo = 1; + sfixed32 bar = 2; + fixed64 baz = 3; + sfixed64 qux = 4; +} diff --git a/tests/inputs/float/float.json b/tests/inputs/float/float.json new file mode 100644 index 0000000..3adac97 --- /dev/null +++ b/tests/inputs/float/float.json @@ -0,0 +1,9 @@ +{ + "positive": "Infinity", + "negative": "-Infinity", + "nan": "NaN", + "three": 3.0, + "threePointOneFour": 3.14, + "negThree": -3.0, + "negThreePointOneFour": -3.14 + } diff --git a/tests/inputs/float/float.proto b/tests/inputs/float/float.proto new file mode 100644 index 0000000..fea12b3 --- /dev/null +++ b/tests/inputs/float/float.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +package float; + +// Some documentation about the Test message. +message Test { + double positive = 1; + double negative = 2; + double nan = 3; + double three = 4; + double three_point_one_four = 5; + double neg_three = 6; + double neg_three_point_one_four = 7; +} diff --git a/tests/inputs/google_impl_behavior_equivalence/google_impl_behavior_equivalence.proto b/tests/inputs/google_impl_behavior_equivalence/google_impl_behavior_equivalence.proto new file mode 100644 index 0000000..66ef8a6 --- /dev/null +++ b/tests/inputs/google_impl_behavior_equivalence/google_impl_behavior_equivalence.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; + +import "google/protobuf/timestamp.proto"; +package google_impl_behavior_equivalence; + +message Foo { int64 bar = 1; } + +message Test { + oneof group { + string string = 1; + int64 integer = 2; + Foo foo = 3; + } +} + +message Spam { + google.protobuf.Timestamp ts = 1; +} + +message Request { Empty foo = 1; } + +message Empty {} diff --git a/tests/inputs/google_impl_behavior_equivalence/test_google_impl_behavior_equivalence.py b/tests/inputs/google_impl_behavior_equivalence/test_google_impl_behavior_equivalence.py new file mode 100644 index 0000000..c621f11 --- /dev/null +++ b/tests/inputs/google_impl_behavior_equivalence/test_google_impl_behavior_equivalence.py @@ -0,0 +1,93 @@ +from datetime import ( + datetime, + timezone, +) + +import pytest +from google.protobuf import json_format +from google.protobuf.timestamp_pb2 import Timestamp + +import aristaproto +from tests.output_aristaproto.google_impl_behavior_equivalence import ( + Empty, + Foo, + Request, + Spam, + Test, +) +from tests.output_reference.google_impl_behavior_equivalence.google_impl_behavior_equivalence_pb2 import ( + Empty as ReferenceEmpty, + Foo as ReferenceFoo, + Request as ReferenceRequest, + Spam as ReferenceSpam, + Test as ReferenceTest, +) + + +def test_oneof_serializes_similar_to_google_oneof(): + tests = [ + (Test(string="abc"), ReferenceTest(string="abc")), + (Test(integer=2), ReferenceTest(integer=2)), + (Test(foo=Foo(bar=1)), ReferenceTest(foo=ReferenceFoo(bar=1))), + # Default values should also behave the same within oneofs + (Test(string=""), ReferenceTest(string="")), + (Test(integer=0), ReferenceTest(integer=0)), + (Test(foo=Foo(bar=0)), ReferenceTest(foo=ReferenceFoo(bar=0))), + ] + for message, message_reference in tests: + # NOTE: As of July 2020, MessageToJson inserts newlines in the output string so, + # just compare dicts + assert message.to_dict() == json_format.MessageToDict(message_reference) + + +def test_bytes_are_the_same_for_oneof(): + message = Test(string="") + message_reference = ReferenceTest(string="") + + message_bytes = bytes(message) + message_reference_bytes = message_reference.SerializeToString() + + assert message_bytes == message_reference_bytes + + message2 = Test().parse(message_reference_bytes) + message_reference2 = ReferenceTest() + message_reference2.ParseFromString(message_reference_bytes) + + assert message == message2 + assert message_reference == message_reference2 + + # None of these fields were explicitly set BUT they should not actually be null + # themselves + assert not hasattr(message, "foo") + assert object.__getattribute__(message, "foo") == aristaproto.PLACEHOLDER + assert not hasattr(message2, "foo") + assert object.__getattribute__(message2, "foo") == aristaproto.PLACEHOLDER + + assert isinstance(message_reference.foo, ReferenceFoo) + assert isinstance(message_reference2.foo, ReferenceFoo) + + +@pytest.mark.parametrize("dt", (datetime.min.replace(tzinfo=timezone.utc),)) +def test_datetime_clamping(dt): # see #407 + ts = Timestamp() + ts.FromDatetime(dt) + assert bytes(Spam(dt)) == ReferenceSpam(ts=ts).SerializeToString() + message_bytes = bytes(Spam(dt)) + + assert ( + Spam().parse(message_bytes).ts.timestamp() + == ReferenceSpam.FromString(message_bytes).ts.seconds + ) + + +def test_empty_message_field(): + message = Request() + reference_message = ReferenceRequest() + + message.foo = Empty() + reference_message.foo.CopyFrom(ReferenceEmpty()) + + assert aristaproto.serialized_on_wire(message.foo) + assert reference_message.HasField("foo") + + assert bytes(message) == reference_message.SerializeToString() diff --git a/tests/inputs/googletypes/googletypes-missing.json b/tests/inputs/googletypes/googletypes-missing.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/inputs/googletypes/googletypes-missing.json @@ -0,0 +1 @@ +{} diff --git a/tests/inputs/googletypes/googletypes.json b/tests/inputs/googletypes/googletypes.json new file mode 100644 index 0000000..0a002e9 --- /dev/null +++ b/tests/inputs/googletypes/googletypes.json @@ -0,0 +1,7 @@ +{ + "maybe": false, + "ts": "1972-01-01T10:00:20.021Z", + "duration": "1.200s", + "important": 10, + "empty": {} +} diff --git a/tests/inputs/googletypes/googletypes.proto b/tests/inputs/googletypes/googletypes.proto new file mode 100644 index 0000000..ef8cb4a --- /dev/null +++ b/tests/inputs/googletypes/googletypes.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; + +package googletypes; + +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; +import "google/protobuf/empty.proto"; + +message Test { + google.protobuf.BoolValue maybe = 1; + google.protobuf.Timestamp ts = 2; + google.protobuf.Duration duration = 3; + google.protobuf.Int32Value important = 4; + google.protobuf.Empty empty = 5; +} diff --git a/tests/inputs/googletypes_request/googletypes_request.proto b/tests/inputs/googletypes_request/googletypes_request.proto new file mode 100644 index 0000000..1cedcaa --- /dev/null +++ b/tests/inputs/googletypes_request/googletypes_request.proto @@ -0,0 +1,29 @@ +syntax = "proto3"; + +package googletypes_request; + +import "google/protobuf/duration.proto"; +import "google/protobuf/empty.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; + +// Tests that google types can be used as params + +service Test { + rpc SendDouble (google.protobuf.DoubleValue) returns (Input); + rpc SendFloat (google.protobuf.FloatValue) returns (Input); + rpc SendInt64 (google.protobuf.Int64Value) returns (Input); + rpc SendUInt64 (google.protobuf.UInt64Value) returns (Input); + rpc SendInt32 (google.protobuf.Int32Value) returns (Input); + rpc SendUInt32 (google.protobuf.UInt32Value) returns (Input); + rpc SendBool (google.protobuf.BoolValue) returns (Input); + rpc SendString (google.protobuf.StringValue) returns (Input); + rpc SendBytes (google.protobuf.BytesValue) returns (Input); + rpc SendDatetime (google.protobuf.Timestamp) returns (Input); + rpc SendTimedelta (google.protobuf.Duration) returns (Input); + rpc SendEmpty (google.protobuf.Empty) returns (Input); +} + +message Input { + +} diff --git a/tests/inputs/googletypes_request/test_googletypes_request.py b/tests/inputs/googletypes_request/test_googletypes_request.py new file mode 100644 index 0000000..8351f71 --- /dev/null +++ b/tests/inputs/googletypes_request/test_googletypes_request.py @@ -0,0 +1,47 @@ +from datetime import ( + datetime, + timedelta, +) +from typing import ( + Any, + Callable, +) + +import pytest + +import aristaproto.lib.google.protobuf as protobuf +from tests.mocks import MockChannel +from tests.output_aristaproto.googletypes_request import ( + Input, + TestStub, +) + + +test_cases = [ + (TestStub.send_double, protobuf.DoubleValue, 2.5), + (TestStub.send_float, protobuf.FloatValue, 2.5), + (TestStub.send_int64, protobuf.Int64Value, -64), + (TestStub.send_u_int64, protobuf.UInt64Value, 64), + (TestStub.send_int32, protobuf.Int32Value, -32), + (TestStub.send_u_int32, protobuf.UInt32Value, 32), + (TestStub.send_bool, protobuf.BoolValue, True), + (TestStub.send_string, protobuf.StringValue, "string"), + (TestStub.send_bytes, protobuf.BytesValue, bytes(0xFF)[0:4]), + (TestStub.send_datetime, protobuf.Timestamp, datetime(2038, 1, 19, 3, 14, 8)), + (TestStub.send_timedelta, protobuf.Duration, timedelta(seconds=123456)), +] + + +@pytest.mark.asyncio +@pytest.mark.parametrize(["service_method", "wrapper_class", "value"], test_cases) +async def test_channel_receives_wrapped_type( + service_method: Callable[[TestStub, Input], Any], wrapper_class: Callable, value +): + wrapped_value = wrapper_class() + wrapped_value.value = value + channel = MockChannel(responses=[Input()]) + service = TestStub(channel) + + await service_method(service, wrapped_value) + + assert channel.requests[0]["request"] == type(wrapped_value) diff --git a/tests/inputs/googletypes_response/googletypes_response.proto b/tests/inputs/googletypes_response/googletypes_response.proto new file mode 100644 index 0000000..8917d1c --- /dev/null +++ b/tests/inputs/googletypes_response/googletypes_response.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; + +package googletypes_response; + +import "google/protobuf/wrappers.proto"; + +// Tests that wrapped values can be used directly as return values + +service Test { + rpc GetDouble (Input) returns (google.protobuf.DoubleValue); + rpc GetFloat (Input) returns (google.protobuf.FloatValue); + rpc GetInt64 (Input) returns (google.protobuf.Int64Value); + rpc GetUInt64 (Input) returns (google.protobuf.UInt64Value); + rpc GetInt32 (Input) returns (google.protobuf.Int32Value); + rpc GetUInt32 (Input) returns (google.protobuf.UInt32Value); + rpc GetBool (Input) returns (google.protobuf.BoolValue); + rpc GetString (Input) returns (google.protobuf.StringValue); + rpc GetBytes (Input) returns (google.protobuf.BytesValue); +} + +message Input { + +} diff --git a/tests/inputs/googletypes_response/test_googletypes_response.py b/tests/inputs/googletypes_response/test_googletypes_response.py new file mode 100644 index 0000000..4ac340e --- /dev/null +++ b/tests/inputs/googletypes_response/test_googletypes_response.py @@ -0,0 +1,64 @@ +from typing import ( + Any, + Callable, + Optional, +) + +import pytest + +import aristaproto.lib.google.protobuf as protobuf +from tests.mocks import MockChannel +from tests.output_aristaproto.googletypes_response import ( + Input, + TestStub, +) + + +test_cases = [ + (TestStub.get_double, protobuf.DoubleValue, 2.5), + (TestStub.get_float, protobuf.FloatValue, 2.5), + (TestStub.get_int64, protobuf.Int64Value, -64), + (TestStub.get_u_int64, protobuf.UInt64Value, 64), + (TestStub.get_int32, protobuf.Int32Value, -32), + (TestStub.get_u_int32, protobuf.UInt32Value, 32), + (TestStub.get_bool, protobuf.BoolValue, True), + (TestStub.get_string, protobuf.StringValue, "string"), + (TestStub.get_bytes, protobuf.BytesValue, bytes(0xFF)[0:4]), +] + + +@pytest.mark.asyncio +@pytest.mark.parametrize(["service_method", "wrapper_class", "value"], test_cases) +async def test_channel_receives_wrapped_type( + service_method: Callable[[TestStub, Input], Any], wrapper_class: Callable, value +): + wrapped_value = wrapper_class() + wrapped_value.value = value + channel = MockChannel(responses=[wrapped_value]) + service = TestStub(channel) + method_param = Input() + + await service_method(service, method_param) + + assert channel.requests[0]["response_type"] != Optional[type(value)] + assert channel.requests[0]["response_type"] == type(wrapped_value) + + +@pytest.mark.asyncio +@pytest.mark.xfail +@pytest.mark.parametrize(["service_method", "wrapper_class", "value"], test_cases) +async def test_service_unwraps_response( + service_method: Callable[[TestStub, Input], Any], wrapper_class: Callable, value +): + """ + grpclib does not unwrap wrapper values returned by services + """ + wrapped_value = wrapper_class() + wrapped_value.value = value + service = TestStub(MockChannel(responses=[wrapped_value])) + method_param = Input() + + response_value = await service_method(service, method_param) + + assert response_value == value + assert type(response_value) == type(value) diff --git a/tests/inputs/googletypes_response_embedded/googletypes_response_embedded.proto b/tests/inputs/googletypes_response_embedded/googletypes_response_embedded.proto new file mode 100644 index 0000000..47284e3 --- /dev/null +++ b/tests/inputs/googletypes_response_embedded/googletypes_response_embedded.proto @@ -0,0 +1,26 @@ +syntax = "proto3"; + +package googletypes_response_embedded; + +import "google/protobuf/wrappers.proto"; + +// Tests that wrapped values are supported as part of output message +service Test { + rpc getOutput (Input) returns (Output); +} + +message Input { + +} + +message Output { + google.protobuf.DoubleValue double_value = 1; + google.protobuf.FloatValue float_value = 2; + google.protobuf.Int64Value int64_value = 3; + google.protobuf.UInt64Value uint64_value = 4; + google.protobuf.Int32Value int32_value = 5; + google.protobuf.UInt32Value uint32_value = 6; + google.protobuf.BoolValue bool_value = 7; + google.protobuf.StringValue string_value = 8; + google.protobuf.BytesValue bytes_value = 9; +} diff --git a/tests/inputs/googletypes_response_embedded/test_googletypes_response_embedded.py b/tests/inputs/googletypes_response_embedded/test_googletypes_response_embedded.py new file mode 100644 index 0000000..3d31728 --- /dev/null +++ b/tests/inputs/googletypes_response_embedded/test_googletypes_response_embedded.py @@ -0,0 +1,40 @@ +import pytest + +from tests.mocks import MockChannel +from tests.output_aristaproto.googletypes_response_embedded import ( + Input, + Output, + TestStub, +) + + +@pytest.mark.asyncio +async def test_service_passes_through_unwrapped_values_embedded_in_response(): + """ + We do not not need to implement value unwrapping for embedded well-known types, + as this is already handled by grpclib. This test merely shows that this is the case. + """ + output = Output( + double_value=10.0, + float_value=12.0, + int64_value=-13, + uint64_value=14, + int32_value=-15, + uint32_value=16, + bool_value=True, + string_value="string", + bytes_value=bytes(0xFF)[0:4], + ) + + service = TestStub(MockChannel(responses=[output])) + response = await service.get_output(Input()) + + assert response.double_value == 10.0 + assert response.float_value == 12.0 + assert response.int64_value == -13 + assert response.uint64_value == 14 + assert response.int32_value == -15 + assert response.uint32_value == 16 + assert response.bool_value + assert response.string_value == "string" + assert response.bytes_value == bytes(0xFF)[0:4] diff --git a/tests/inputs/googletypes_service_returns_empty/googletypes_service_returns_empty.proto b/tests/inputs/googletypes_service_returns_empty/googletypes_service_returns_empty.proto new file mode 100644 index 0000000..2153ad5 --- /dev/null +++ b/tests/inputs/googletypes_service_returns_empty/googletypes_service_returns_empty.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package googletypes_service_returns_empty; + +import "google/protobuf/empty.proto"; + +service Test { + rpc Send (RequestMessage) returns (google.protobuf.Empty) { + } +} + +message RequestMessage { +}
\ No newline at end of file diff --git a/tests/inputs/googletypes_service_returns_googletype/googletypes_service_returns_googletype.proto b/tests/inputs/googletypes_service_returns_googletype/googletypes_service_returns_googletype.proto new file mode 100644 index 0000000..457707b --- /dev/null +++ b/tests/inputs/googletypes_service_returns_googletype/googletypes_service_returns_googletype.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package googletypes_service_returns_googletype; + +import "google/protobuf/empty.proto"; +import "google/protobuf/struct.proto"; + +// Tests that imports are generated correctly when returning Google well-known types + +service Test { + rpc GetEmpty (RequestMessage) returns (google.protobuf.Empty); + rpc GetStruct (RequestMessage) returns (google.protobuf.Struct); + rpc GetListValue (RequestMessage) returns (google.protobuf.ListValue); + rpc GetValue (RequestMessage) returns (google.protobuf.Value); +} + +message RequestMessage { +}
\ No newline at end of file diff --git a/tests/inputs/googletypes_struct/googletypes_struct.json b/tests/inputs/googletypes_struct/googletypes_struct.json new file mode 100644 index 0000000..ecc175e --- /dev/null +++ b/tests/inputs/googletypes_struct/googletypes_struct.json @@ -0,0 +1,5 @@ +{ + "struct": { + "key": true + } +} diff --git a/tests/inputs/googletypes_struct/googletypes_struct.proto b/tests/inputs/googletypes_struct/googletypes_struct.proto new file mode 100644 index 0000000..2b8b5c5 --- /dev/null +++ b/tests/inputs/googletypes_struct/googletypes_struct.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package googletypes_struct; + +import "google/protobuf/struct.proto"; + +message Test { + google.protobuf.Struct struct = 1; +} diff --git a/tests/inputs/googletypes_value/googletypes_value.json b/tests/inputs/googletypes_value/googletypes_value.json new file mode 100644 index 0000000..db52d5c --- /dev/null +++ b/tests/inputs/googletypes_value/googletypes_value.json @@ -0,0 +1,11 @@ +{ + "value1": "hello world", + "value2": true, + "value3": 1, + "value4": null, + "value5": [ + 1, + 2, + 3 + ] +} diff --git a/tests/inputs/googletypes_value/googletypes_value.proto b/tests/inputs/googletypes_value/googletypes_value.proto new file mode 100644 index 0000000..d5089d5 --- /dev/null +++ b/tests/inputs/googletypes_value/googletypes_value.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package googletypes_value; + +import "google/protobuf/struct.proto"; + +// Tests that fields of type google.protobuf.Value can contain arbitrary JSON-values. + +message Test { + google.protobuf.Value value1 = 1; + google.protobuf.Value value2 = 2; + google.protobuf.Value value3 = 3; + google.protobuf.Value value4 = 4; + google.protobuf.Value value5 = 5; +} diff --git a/tests/inputs/import_capitalized_package/capitalized.proto b/tests/inputs/import_capitalized_package/capitalized.proto new file mode 100644 index 0000000..e80c95c --- /dev/null +++ b/tests/inputs/import_capitalized_package/capitalized.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + + +package import_capitalized_package.Capitalized; + +message Message { + +} diff --git a/tests/inputs/import_capitalized_package/test.proto b/tests/inputs/import_capitalized_package/test.proto new file mode 100644 index 0000000..38c9b2d --- /dev/null +++ b/tests/inputs/import_capitalized_package/test.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package import_capitalized_package; + +import "capitalized.proto"; + +// Tests that we can import from a package with a capital name, that looks like a nested type, but isn't. + +message Test { + Capitalized.Message message = 1; +} diff --git a/tests/inputs/import_child_package_from_package/child.proto b/tests/inputs/import_child_package_from_package/child.proto new file mode 100644 index 0000000..d99c7c3 --- /dev/null +++ b/tests/inputs/import_child_package_from_package/child.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package import_child_package_from_package.package.childpackage; + +message ChildMessage { + +} diff --git a/tests/inputs/import_child_package_from_package/import_child_package_from_package.proto b/tests/inputs/import_child_package_from_package/import_child_package_from_package.proto new file mode 100644 index 0000000..66e0aa8 --- /dev/null +++ b/tests/inputs/import_child_package_from_package/import_child_package_from_package.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package import_child_package_from_package; + +import "package_message.proto"; + +// Tests generated imports when a message in a package refers to a message in a nested child package. + +message Test { + package.PackageMessage message = 1; +} diff --git a/tests/inputs/import_child_package_from_package/package_message.proto b/tests/inputs/import_child_package_from_package/package_message.proto new file mode 100644 index 0000000..79d66f3 --- /dev/null +++ b/tests/inputs/import_child_package_from_package/package_message.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +import "child.proto"; + +package import_child_package_from_package.package; + +message PackageMessage { + package.childpackage.ChildMessage c = 1; +} diff --git a/tests/inputs/import_child_package_from_root/child.proto b/tests/inputs/import_child_package_from_root/child.proto new file mode 100644 index 0000000..2a46d5f --- /dev/null +++ b/tests/inputs/import_child_package_from_root/child.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package import_child_package_from_root.childpackage; + +message Message { + +} diff --git a/tests/inputs/import_child_package_from_root/import_child_package_from_root.proto b/tests/inputs/import_child_package_from_root/import_child_package_from_root.proto new file mode 100644 index 0000000..6299831 --- /dev/null +++ b/tests/inputs/import_child_package_from_root/import_child_package_from_root.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package import_child_package_from_root; + +import "child.proto"; + +// Tests generated imports when a message in root refers to a message in a child package. + +message Test { + childpackage.Message child = 1; +} diff --git a/tests/inputs/import_circular_dependency/import_circular_dependency.proto b/tests/inputs/import_circular_dependency/import_circular_dependency.proto new file mode 100644 index 0000000..8b159e2 --- /dev/null +++ b/tests/inputs/import_circular_dependency/import_circular_dependency.proto @@ -0,0 +1,30 @@ +syntax = "proto3"; + +package import_circular_dependency; + +import "root.proto"; +import "other.proto"; + +// This test-case verifies support for circular dependencies in the generated python files. +// +// This is important because we generate 1 python file/module per package, rather than 1 file per proto file. +// +// Scenario: +// +// The proto messages depend on each other in a non-circular way: +// +// Test -------> RootPackageMessage <--------------. +// `------------------------------------> OtherPackageMessage +// +// Test and RootPackageMessage are in different files, but belong to the same package (root): +// +// (Test -------> RootPackageMessage) <------------. +// `------------------------------------> OtherPackageMessage +// +// After grouping the packages into single files or modules, a circular dependency is created: +// +// (root: Test & RootPackageMessage) <-------> (other: OtherPackageMessage) +message Test { + RootPackageMessage message = 1; + other.OtherPackageMessage other = 2; +} diff --git a/tests/inputs/import_circular_dependency/other.proto b/tests/inputs/import_circular_dependency/other.proto new file mode 100644 index 0000000..833b869 --- /dev/null +++ b/tests/inputs/import_circular_dependency/other.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +import "root.proto"; +package import_circular_dependency.other; + +message OtherPackageMessage { + RootPackageMessage rootPackageMessage = 1; +} diff --git a/tests/inputs/import_circular_dependency/root.proto b/tests/inputs/import_circular_dependency/root.proto new file mode 100644 index 0000000..7383947 --- /dev/null +++ b/tests/inputs/import_circular_dependency/root.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package import_circular_dependency; + +message RootPackageMessage { + +} diff --git a/tests/inputs/import_cousin_package/cousin.proto b/tests/inputs/import_cousin_package/cousin.proto new file mode 100644 index 0000000..2870dfe --- /dev/null +++ b/tests/inputs/import_cousin_package/cousin.proto @@ -0,0 +1,6 @@ +syntax = "proto3"; + +package import_cousin_package.cousin.cousin_subpackage; + +message CousinMessage { +} diff --git a/tests/inputs/import_cousin_package/test.proto b/tests/inputs/import_cousin_package/test.proto new file mode 100644 index 0000000..89ec3d8 --- /dev/null +++ b/tests/inputs/import_cousin_package/test.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package import_cousin_package.test.subpackage; + +import "cousin.proto"; + +// Verify that we can import message unrelated to us + +message Test { + cousin.cousin_subpackage.CousinMessage message = 1; +} diff --git a/tests/inputs/import_cousin_package_same_name/cousin.proto b/tests/inputs/import_cousin_package_same_name/cousin.proto new file mode 100644 index 0000000..84b6a40 --- /dev/null +++ b/tests/inputs/import_cousin_package_same_name/cousin.proto @@ -0,0 +1,6 @@ +syntax = "proto3"; + +package import_cousin_package_same_name.cousin.subpackage; + +message CousinMessage { +} diff --git a/tests/inputs/import_cousin_package_same_name/test.proto b/tests/inputs/import_cousin_package_same_name/test.proto new file mode 100644 index 0000000..7b420d3 --- /dev/null +++ b/tests/inputs/import_cousin_package_same_name/test.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package import_cousin_package_same_name.test.subpackage; + +import "cousin.proto"; + +// Verify that we can import a message unrelated to us, in a subpackage with the same name as us. + +message Test { + cousin.subpackage.CousinMessage message = 1; +} diff --git a/tests/inputs/import_packages_same_name/import_packages_same_name.proto b/tests/inputs/import_packages_same_name/import_packages_same_name.proto new file mode 100644 index 0000000..dff7efe --- /dev/null +++ b/tests/inputs/import_packages_same_name/import_packages_same_name.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package import_packages_same_name; + +import "users_v1.proto"; +import "posts_v1.proto"; + +// Tests generated message can correctly reference two packages with the same leaf-name + +message Test { + users.v1.User user = 1; + posts.v1.Post post = 2; +} diff --git a/tests/inputs/import_packages_same_name/posts_v1.proto b/tests/inputs/import_packages_same_name/posts_v1.proto new file mode 100644 index 0000000..d3b9b1c --- /dev/null +++ b/tests/inputs/import_packages_same_name/posts_v1.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package import_packages_same_name.posts.v1; + +message Post { + +} diff --git a/tests/inputs/import_packages_same_name/users_v1.proto b/tests/inputs/import_packages_same_name/users_v1.proto new file mode 100644 index 0000000..d3a17e9 --- /dev/null +++ b/tests/inputs/import_packages_same_name/users_v1.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package import_packages_same_name.users.v1; + +message User { + +} diff --git a/tests/inputs/import_parent_package_from_child/import_parent_package_from_child.proto b/tests/inputs/import_parent_package_from_child/import_parent_package_from_child.proto new file mode 100644 index 0000000..edc4736 --- /dev/null +++ b/tests/inputs/import_parent_package_from_child/import_parent_package_from_child.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +import "parent_package_message.proto"; + +package import_parent_package_from_child.parent.child; + +// Tests generated imports when a message refers to a message defined in its parent package + +message Test { + ParentPackageMessage message_implicit = 1; + parent.ParentPackageMessage message_explicit = 2; +} diff --git a/tests/inputs/import_parent_package_from_child/parent_package_message.proto b/tests/inputs/import_parent_package_from_child/parent_package_message.proto new file mode 100644 index 0000000..fb3fd31 --- /dev/null +++ b/tests/inputs/import_parent_package_from_child/parent_package_message.proto @@ -0,0 +1,6 @@ +syntax = "proto3"; + +package import_parent_package_from_child.parent; + +message ParentPackageMessage { +} diff --git a/tests/inputs/import_root_package_from_child/child.proto b/tests/inputs/import_root_package_from_child/child.proto new file mode 100644 index 0000000..bd51967 --- /dev/null +++ b/tests/inputs/import_root_package_from_child/child.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package import_root_package_from_child.child; + +import "root.proto"; + +// Verify that we can import root message from child package + +message Test { + RootMessage message = 1; +} diff --git a/tests/inputs/import_root_package_from_child/root.proto b/tests/inputs/import_root_package_from_child/root.proto new file mode 100644 index 0000000..6ae955a --- /dev/null +++ b/tests/inputs/import_root_package_from_child/root.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package import_root_package_from_child; + + +message RootMessage { +} diff --git a/tests/inputs/import_root_sibling/import_root_sibling.proto b/tests/inputs/import_root_sibling/import_root_sibling.proto new file mode 100644 index 0000000..759e606 --- /dev/null +++ b/tests/inputs/import_root_sibling/import_root_sibling.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package import_root_sibling; + +import "sibling.proto"; + +// Tests generated imports when a message in the root package refers to another message in the root package + +message Test { + SiblingMessage sibling = 1; +} diff --git a/tests/inputs/import_root_sibling/sibling.proto b/tests/inputs/import_root_sibling/sibling.proto new file mode 100644 index 0000000..6b6ba2e --- /dev/null +++ b/tests/inputs/import_root_sibling/sibling.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package import_root_sibling; + +message SiblingMessage { + +} diff --git a/tests/inputs/import_service_input_message/child_package_request_message.proto b/tests/inputs/import_service_input_message/child_package_request_message.proto new file mode 100644 index 0000000..54fc112 --- /dev/null +++ b/tests/inputs/import_service_input_message/child_package_request_message.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package import_service_input_message.child; + +message ChildRequestMessage { + int32 child_argument = 1; +}
\ No newline at end of file diff --git a/tests/inputs/import_service_input_message/import_service_input_message.proto b/tests/inputs/import_service_input_message/import_service_input_message.proto new file mode 100644 index 0000000..cbf48fa --- /dev/null +++ b/tests/inputs/import_service_input_message/import_service_input_message.proto @@ -0,0 +1,25 @@ +syntax = "proto3"; + +package import_service_input_message; + +import "request_message.proto"; +import "child_package_request_message.proto"; + +// Tests generated service correctly imports the RequestMessage + +service Test { + rpc DoThing (RequestMessage) returns (RequestResponse); + rpc DoThing2 (child.ChildRequestMessage) returns (RequestResponse); + rpc DoThing3 (Nested.RequestMessage) returns (RequestResponse); +} + + +message RequestResponse { + int32 value = 1; +} + +message Nested { + message RequestMessage { + int32 nestedArgument = 1; + } +}
\ No newline at end of file diff --git a/tests/inputs/import_service_input_message/request_message.proto b/tests/inputs/import_service_input_message/request_message.proto new file mode 100644 index 0000000..36a6e78 --- /dev/null +++ b/tests/inputs/import_service_input_message/request_message.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package import_service_input_message; + +message RequestMessage { + int32 argument = 1; +}
\ No newline at end of file diff --git a/tests/inputs/import_service_input_message/test_import_service_input_message.py b/tests/inputs/import_service_input_message/test_import_service_input_message.py new file mode 100644 index 0000000..66c654b --- /dev/null +++ b/tests/inputs/import_service_input_message/test_import_service_input_message.py @@ -0,0 +1,36 @@ +import pytest + +from tests.mocks import MockChannel +from tests.output_aristaproto.import_service_input_message import ( + NestedRequestMessage, + RequestMessage, + RequestResponse, + TestStub, +) +from tests.output_aristaproto.import_service_input_message.child import ( + ChildRequestMessage, +) + + +@pytest.mark.asyncio +async def test_service_correctly_imports_reference_message(): + mock_response = RequestResponse(value=10) + service = TestStub(MockChannel([mock_response])) + response = await service.do_thing(RequestMessage(1)) + assert mock_response == response + + +@pytest.mark.asyncio +async def test_service_correctly_imports_reference_message_from_child_package(): + mock_response = RequestResponse(value=10) + service = TestStub(MockChannel([mock_response])) + response = await service.do_thing2(ChildRequestMessage(1)) + assert mock_response == response + + +@pytest.mark.asyncio +async def test_service_correctly_imports_nested_reference(): + mock_response = RequestResponse(value=10) + service = TestStub(MockChannel([mock_response])) + response = await service.do_thing3(NestedRequestMessage(1)) + assert mock_response == response diff --git a/tests/inputs/int32/int32.json b/tests/inputs/int32/int32.json new file mode 100644 index 0000000..34d4111 --- /dev/null +++ b/tests/inputs/int32/int32.json @@ -0,0 +1,4 @@ +{ + "positive": 150, + "negative": -150 +} diff --git a/tests/inputs/int32/int32.proto b/tests/inputs/int32/int32.proto new file mode 100644 index 0000000..4721c23 --- /dev/null +++ b/tests/inputs/int32/int32.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package int32; + +// Some documentation about the Test message. +message Test { + // Some documentation about the count. + int32 positive = 1; + int32 negative = 2; +} diff --git a/tests/inputs/map/map.json b/tests/inputs/map/map.json new file mode 100644 index 0000000..6a1e853 --- /dev/null +++ b/tests/inputs/map/map.json @@ -0,0 +1,7 @@ +{ + "counts": { + "item1": 1, + "item2": 2, + "item3": 3 + } +} diff --git a/tests/inputs/map/map.proto b/tests/inputs/map/map.proto new file mode 100644 index 0000000..ecef3cc --- /dev/null +++ b/tests/inputs/map/map.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package map; + +message Test { + map<string, int32> counts = 1; +} diff --git a/tests/inputs/mapmessage/mapmessage.json b/tests/inputs/mapmessage/mapmessage.json new file mode 100644 index 0000000..a944ddd --- /dev/null +++ b/tests/inputs/mapmessage/mapmessage.json @@ -0,0 +1,10 @@ +{ + "items": { + "foo": { + "count": 1 + }, + "bar": { + "count": 2 + } + } +} diff --git a/tests/inputs/mapmessage/mapmessage.proto b/tests/inputs/mapmessage/mapmessage.proto new file mode 100644 index 0000000..2c704a4 --- /dev/null +++ b/tests/inputs/mapmessage/mapmessage.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package mapmessage; + +message Test { + map<string, Nested> items = 1; +} + +message Nested { + int32 count = 1; +}
\ No newline at end of file diff --git a/tests/inputs/namespace_builtin_types/namespace_builtin_types.json b/tests/inputs/namespace_builtin_types/namespace_builtin_types.json new file mode 100644 index 0000000..8200032 --- /dev/null +++ b/tests/inputs/namespace_builtin_types/namespace_builtin_types.json @@ -0,0 +1,16 @@ +{ + "int": "value-for-int", + "float": "value-for-float", + "complex": "value-for-complex", + "list": "value-for-list", + "tuple": "value-for-tuple", + "range": "value-for-range", + "str": "value-for-str", + "bytearray": "value-for-bytearray", + "bytes": "value-for-bytes", + "memoryview": "value-for-memoryview", + "set": "value-for-set", + "frozenset": "value-for-frozenset", + "map": "value-for-map", + "bool": "value-for-bool" +}
\ No newline at end of file diff --git a/tests/inputs/namespace_builtin_types/namespace_builtin_types.proto b/tests/inputs/namespace_builtin_types/namespace_builtin_types.proto new file mode 100644 index 0000000..71cb029 --- /dev/null +++ b/tests/inputs/namespace_builtin_types/namespace_builtin_types.proto @@ -0,0 +1,40 @@ +syntax = "proto3"; + +package namespace_builtin_types; + +// Tests that messages may contain fields with names that are python types + +message Test { + // https://docs.python.org/2/library/stdtypes.html#numeric-types-int-float-long-complex + string int = 1; + string float = 2; + string complex = 3; + + // https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range + string list = 4; + string tuple = 5; + string range = 6; + + // https://docs.python.org/3/library/stdtypes.html#str + string str = 7; + + // https://docs.python.org/3/library/stdtypes.html#bytearray-objects + string bytearray = 8; + + // https://docs.python.org/3/library/stdtypes.html#bytes-and-bytearray-operations + string bytes = 9; + + // https://docs.python.org/3/library/stdtypes.html#memory-views + string memoryview = 10; + + // https://docs.python.org/3/library/stdtypes.html#set-types-set-frozenset + string set = 11; + string frozenset = 12; + + // https://docs.python.org/3/library/stdtypes.html#dict + string map = 13; + string dict = 14; + + // https://docs.python.org/3/library/stdtypes.html#boolean-values + string bool = 15; +}
\ No newline at end of file diff --git a/tests/inputs/namespace_keywords/namespace_keywords.json b/tests/inputs/namespace_keywords/namespace_keywords.json new file mode 100644 index 0000000..4f11b60 --- /dev/null +++ b/tests/inputs/namespace_keywords/namespace_keywords.json @@ -0,0 +1,37 @@ +{ + "False": 1, + "None": 2, + "True": 3, + "and": 4, + "as": 5, + "assert": 6, + "async": 7, + "await": 8, + "break": 9, + "class": 10, + "continue": 11, + "def": 12, + "del": 13, + "elif": 14, + "else": 15, + "except": 16, + "finally": 17, + "for": 18, + "from": 19, + "global": 20, + "if": 21, + "import": 22, + "in": 23, + "is": 24, + "lambda": 25, + "nonlocal": 26, + "not": 27, + "or": 28, + "pass": 29, + "raise": 30, + "return": 31, + "try": 32, + "while": 33, + "with": 34, + "yield": 35 +} diff --git a/tests/inputs/namespace_keywords/namespace_keywords.proto b/tests/inputs/namespace_keywords/namespace_keywords.proto new file mode 100644 index 0000000..ac3e5c5 --- /dev/null +++ b/tests/inputs/namespace_keywords/namespace_keywords.proto @@ -0,0 +1,46 @@ +syntax = "proto3"; + +package namespace_keywords; + +// Tests that messages may contain fields that are Python keywords +// +// Generated with Python 3.7.6 +// print('\n'.join(f'string {k} = {i+1};' for i,k in enumerate(keyword.kwlist))) + +message Test { + string False = 1; + string None = 2; + string True = 3; + string and = 4; + string as = 5; + string assert = 6; + string async = 7; + string await = 8; + string break = 9; + string class = 10; + string continue = 11; + string def = 12; + string del = 13; + string elif = 14; + string else = 15; + string except = 16; + string finally = 17; + string for = 18; + string from = 19; + string global = 20; + string if = 21; + string import = 22; + string in = 23; + string is = 24; + string lambda = 25; + string nonlocal = 26; + string not = 27; + string or = 28; + string pass = 29; + string raise = 30; + string return = 31; + string try = 32; + string while = 33; + string with = 34; + string yield = 35; +}
\ No newline at end of file diff --git a/tests/inputs/nested/nested.json b/tests/inputs/nested/nested.json new file mode 100644 index 0000000..f460cad --- /dev/null +++ b/tests/inputs/nested/nested.json @@ -0,0 +1,7 @@ +{ + "nested": { + "count": 150 + }, + "sibling": {}, + "msg": "THIS" +} diff --git a/tests/inputs/nested/nested.proto b/tests/inputs/nested/nested.proto new file mode 100644 index 0000000..619c721 --- /dev/null +++ b/tests/inputs/nested/nested.proto @@ -0,0 +1,26 @@ +syntax = "proto3"; + +package nested; + +// A test message with a nested message inside of it. +message Test { + // This is the nested type. + message Nested { + // Stores a simple counter. + int32 count = 1; + } + // This is the nested enum. + enum Msg { + NONE = 0; + THIS = 1; + } + + Nested nested = 1; + Sibling sibling = 2; + Sibling sibling2 = 3; + Msg msg = 4; +} + +message Sibling { + int32 foo = 1; +}
\ No newline at end of file diff --git a/tests/inputs/nested2/nested2.proto b/tests/inputs/nested2/nested2.proto new file mode 100644 index 0000000..cd6510c --- /dev/null +++ b/tests/inputs/nested2/nested2.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; + +package nested2; + +import "package.proto"; + +message Game { + message Player { + enum Race { + human = 0; + orc = 1; + } + } +} + +message Test { + Game game = 1; + Game.Player GamePlayer = 2; + Game.Player.Race GamePlayerRace = 3; + equipment.Weapon Weapon = 4; +}
\ No newline at end of file diff --git a/tests/inputs/nested2/package.proto b/tests/inputs/nested2/package.proto new file mode 100644 index 0000000..e12abb1 --- /dev/null +++ b/tests/inputs/nested2/package.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package nested2.equipment; + +message Weapon { + +}
\ No newline at end of file diff --git a/tests/inputs/nestedtwice/nestedtwice.json b/tests/inputs/nestedtwice/nestedtwice.json new file mode 100644 index 0000000..c953132 --- /dev/null +++ b/tests/inputs/nestedtwice/nestedtwice.json @@ -0,0 +1,11 @@ +{ + "top": { + "name": "double-nested", + "middle": { + "bottom": [{"foo": "hello"}], + "enumBottom": ["A"], + "topMiddleBottom": [{"a": "hello"}], + "bar": true + } + } +} diff --git a/tests/inputs/nestedtwice/nestedtwice.proto b/tests/inputs/nestedtwice/nestedtwice.proto new file mode 100644 index 0000000..84d142a --- /dev/null +++ b/tests/inputs/nestedtwice/nestedtwice.proto @@ -0,0 +1,40 @@ +syntax = "proto3"; + +package nestedtwice; + +/* Test doc. */ +message Test { + /* Top doc. */ + message Top { + /* Middle doc. */ + message Middle { + /* TopMiddleBottom doc.*/ + message TopMiddleBottom { + // TopMiddleBottom.a doc. + string a = 1; + } + /* EnumBottom doc. */ + enum EnumBottom{ + /* EnumBottom.A doc. */ + A = 0; + B = 1; + } + /* Bottom doc. */ + message Bottom { + /* Bottom.foo doc. */ + string foo = 1; + } + reserved 1; + /* Middle.bottom doc. */ + repeated Bottom bottom = 2; + repeated EnumBottom enumBottom=3; + repeated TopMiddleBottom topMiddleBottom=4; + bool bar = 5; + } + /* Top.name doc. */ + string name = 1; + Middle middle = 2; + } + /* Test.top doc. */ + Top top = 1; +} diff --git a/tests/inputs/nestedtwice/test_nestedtwice.py b/tests/inputs/nestedtwice/test_nestedtwice.py new file mode 100644 index 0000000..502e710 --- /dev/null +++ b/tests/inputs/nestedtwice/test_nestedtwice.py @@ -0,0 +1,25 @@ +import pytest + +from tests.output_aristaproto.nestedtwice import ( + Test, + TestTop, + TestTopMiddle, + TestTopMiddleBottom, + TestTopMiddleEnumBottom, + TestTopMiddleTopMiddleBottom, +) + + +@pytest.mark.parametrize( + ("cls", "expected_comment"), + [ + (Test, "Test doc."), + (TestTopMiddleEnumBottom, "EnumBottom doc."), + (TestTop, "Top doc."), + (TestTopMiddle, "Middle doc."), + (TestTopMiddleTopMiddleBottom, "TopMiddleBottom doc."), + (TestTopMiddleBottom, "Bottom doc."), + ], +) +def test_comment(cls, expected_comment): + assert cls.__doc__ == expected_comment diff --git a/tests/inputs/oneof/oneof-name.json b/tests/inputs/oneof/oneof-name.json new file mode 100644 index 0000000..605484b --- /dev/null +++ b/tests/inputs/oneof/oneof-name.json @@ -0,0 +1,3 @@ +{ + "pitier": "Mr. T" +} diff --git a/tests/inputs/oneof/oneof.json b/tests/inputs/oneof/oneof.json new file mode 100644 index 0000000..65cafc5 --- /dev/null +++ b/tests/inputs/oneof/oneof.json @@ -0,0 +1,3 @@ +{ + "pitied": 100 +} diff --git a/tests/inputs/oneof/oneof.proto b/tests/inputs/oneof/oneof.proto new file mode 100644 index 0000000..41f93b0 --- /dev/null +++ b/tests/inputs/oneof/oneof.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; + +package oneof; + +message MixedDrink { + int32 shots = 1; +} + +message Test { + oneof foo { + int32 pitied = 1; + string pitier = 2; + } + + int32 just_a_regular_field = 3; + + oneof bar { + int32 drinks = 11; + string bar_name = 12; + MixedDrink mixed_drink = 13; + } +} + diff --git a/tests/inputs/oneof/oneof_name.json b/tests/inputs/oneof/oneof_name.json new file mode 100644 index 0000000..605484b --- /dev/null +++ b/tests/inputs/oneof/oneof_name.json @@ -0,0 +1,3 @@ +{ + "pitier": "Mr. T" +} diff --git a/tests/inputs/oneof/test_oneof.py b/tests/inputs/oneof/test_oneof.py new file mode 100644 index 0000000..8a38496 --- /dev/null +++ b/tests/inputs/oneof/test_oneof.py @@ -0,0 +1,43 @@ +import pytest + +import aristaproto +from tests.output_aristaproto.oneof import ( + MixedDrink, + Test, +) +from tests.output_aristaproto_pydantic.oneof import Test as TestPyd +from tests.util import get_test_case_json_data + + +def test_which_count(): + message = Test() + message.from_json(get_test_case_json_data("oneof")[0].json) + assert aristaproto.which_one_of(message, "foo") == ("pitied", 100) + + +def test_which_name(): + message = Test() + message.from_json(get_test_case_json_data("oneof", "oneof_name.json")[0].json) + assert aristaproto.which_one_of(message, "foo") == ("pitier", "Mr. T") + + +def test_which_count_pyd(): + message = TestPyd(pitier="Mr. T", just_a_regular_field=2, bar_name="a_bar") + assert aristaproto.which_one_of(message, "foo") == ("pitier", "Mr. T") + + +def test_oneof_constructor_assign(): + message = Test(mixed_drink=MixedDrink(shots=42)) + field, value = aristaproto.which_one_of(message, "bar") + assert field == "mixed_drink" + assert value.shots == 42 + + +# Issue #305: +@pytest.mark.xfail +def test_oneof_nested_assign(): + message = Test() + message.mixed_drink.shots = 42 + field, value = aristaproto.which_one_of(message, "bar") + assert field == "mixed_drink" + assert value.shots == 42 diff --git a/tests/inputs/oneof_default_value_serialization/oneof_default_value_serialization.proto b/tests/inputs/oneof_default_value_serialization/oneof_default_value_serialization.proto new file mode 100644 index 0000000..f7ac6fe --- /dev/null +++ b/tests/inputs/oneof_default_value_serialization/oneof_default_value_serialization.proto @@ -0,0 +1,30 @@ +syntax = "proto3"; + +package oneof_default_value_serialization; + +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; + +message Message{ + int64 value = 1; +} + +message NestedMessage{ + int64 id = 1; + oneof value_type{ + Message wrapped_message_value = 2; + } +} + +message Test{ + oneof value_type { + bool bool_value = 1; + int64 int64_value = 2; + google.protobuf.Timestamp timestamp_value = 3; + google.protobuf.Duration duration_value = 4; + Message wrapped_message_value = 5; + NestedMessage wrapped_nested_message_value = 6; + google.protobuf.BoolValue wrapped_bool_value = 7; + } +}
\ No newline at end of file diff --git a/tests/inputs/oneof_default_value_serialization/test_oneof_default_value_serialization.py b/tests/inputs/oneof_default_value_serialization/test_oneof_default_value_serialization.py new file mode 100644 index 0000000..0fad3d6 --- /dev/null +++ b/tests/inputs/oneof_default_value_serialization/test_oneof_default_value_serialization.py @@ -0,0 +1,75 @@ +import datetime + +import pytest + +import aristaproto +from tests.output_aristaproto.oneof_default_value_serialization import ( + Message, + NestedMessage, + Test, +) + + +def assert_round_trip_serialization_works(message: Test) -> None: + assert aristaproto.which_one_of(message, "value_type") == aristaproto.which_one_of( + Test().from_json(message.to_json()), "value_type" + ) + + +def test_oneof_default_value_serialization_works_for_all_values(): + """ + Serialization from message with oneof set to default -> JSON -> message should keep + default value field intact. + """ + + test_cases = [ + Test(bool_value=False), + Test(int64_value=0), + Test( + timestamp_value=datetime.datetime( + year=1970, + month=1, + day=1, + hour=0, + minute=0, + tzinfo=datetime.timezone.utc, + ) + ), + Test(duration_value=datetime.timedelta(0)), + Test(wrapped_message_value=Message(value=0)), + # NOTE: Do NOT use aristaproto.BoolValue here, it will cause JSON serialization + # errors. + # TODO: Do we want to allow use of BoolValue directly within a wrapped field or + # should we simply hard fail here? + Test(wrapped_bool_value=False), + ] + for message in test_cases: + assert_round_trip_serialization_works(message) + + +def test_oneof_no_default_values_passed(): + message = Test() + assert ( + aristaproto.which_one_of(message, "value_type") + == aristaproto.which_one_of(Test().from_json(message.to_json()), "value_type") + == ("", None) + ) + + +def test_oneof_nested_oneof_messages_are_serialized_with_defaults(): + """ + Nested messages with oneofs should also be handled + """ + message = Test( + wrapped_nested_message_value=NestedMessage( + id=0, wrapped_message_value=Message(value=0) + ) + ) + assert ( + aristaproto.which_one_of(message, "value_type") + == aristaproto.which_one_of(Test().from_json(message.to_json()), "value_type") + == ( + "wrapped_nested_message_value", + NestedMessage(id=0, wrapped_message_value=Message(value=0)), + ) + ) diff --git a/tests/inputs/oneof_empty/oneof_empty.json b/tests/inputs/oneof_empty/oneof_empty.json new file mode 100644 index 0000000..9d21c89 --- /dev/null +++ b/tests/inputs/oneof_empty/oneof_empty.json @@ -0,0 +1,3 @@ +{ + "nothing": {} +} diff --git a/tests/inputs/oneof_empty/oneof_empty.proto b/tests/inputs/oneof_empty/oneof_empty.proto new file mode 100644 index 0000000..ca51d5a --- /dev/null +++ b/tests/inputs/oneof_empty/oneof_empty.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +package oneof_empty; + +message Nothing {} + +message MaybeNothing { + string sometimes = 42; +} + +message Test { + oneof empty { + Nothing nothing = 1; + MaybeNothing maybe1 = 2; + MaybeNothing maybe2 = 3; + } +} diff --git a/tests/inputs/oneof_empty/oneof_empty_maybe1.json b/tests/inputs/oneof_empty/oneof_empty_maybe1.json new file mode 100644 index 0000000..f7a2d27 --- /dev/null +++ b/tests/inputs/oneof_empty/oneof_empty_maybe1.json @@ -0,0 +1,3 @@ +{ + "maybe1": {} +} diff --git a/tests/inputs/oneof_empty/oneof_empty_maybe2.json b/tests/inputs/oneof_empty/oneof_empty_maybe2.json new file mode 100644 index 0000000..bc2b385 --- /dev/null +++ b/tests/inputs/oneof_empty/oneof_empty_maybe2.json @@ -0,0 +1,5 @@ +{ + "maybe2": { + "sometimes": "now" + } +} diff --git a/tests/inputs/oneof_empty/test_oneof_empty.py b/tests/inputs/oneof_empty/test_oneof_empty.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/inputs/oneof_empty/test_oneof_empty.py diff --git a/tests/inputs/oneof_enum/oneof_enum-enum-0.json b/tests/inputs/oneof_enum/oneof_enum-enum-0.json new file mode 100644 index 0000000..be30cf0 --- /dev/null +++ b/tests/inputs/oneof_enum/oneof_enum-enum-0.json @@ -0,0 +1,3 @@ +{ + "signal": "PASS" +} diff --git a/tests/inputs/oneof_enum/oneof_enum-enum-1.json b/tests/inputs/oneof_enum/oneof_enum-enum-1.json new file mode 100644 index 0000000..cb63873 --- /dev/null +++ b/tests/inputs/oneof_enum/oneof_enum-enum-1.json @@ -0,0 +1,3 @@ +{ + "signal": "RESIGN" +} diff --git a/tests/inputs/oneof_enum/oneof_enum.json b/tests/inputs/oneof_enum/oneof_enum.json new file mode 100644 index 0000000..3220b70 --- /dev/null +++ b/tests/inputs/oneof_enum/oneof_enum.json @@ -0,0 +1,6 @@ +{ + "move": { + "x": 2, + "y": 3 + } +} diff --git a/tests/inputs/oneof_enum/oneof_enum.proto b/tests/inputs/oneof_enum/oneof_enum.proto new file mode 100644 index 0000000..906abcb --- /dev/null +++ b/tests/inputs/oneof_enum/oneof_enum.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; + +package oneof_enum; + +message Test { + oneof action { + Signal signal = 1; + Move move = 2; + } +} + +enum Signal { + PASS = 0; + RESIGN = 1; +} + +message Move { + int32 x = 1; + int32 y = 2; +}
\ No newline at end of file diff --git a/tests/inputs/oneof_enum/test_oneof_enum.py b/tests/inputs/oneof_enum/test_oneof_enum.py new file mode 100644 index 0000000..98de22a --- /dev/null +++ b/tests/inputs/oneof_enum/test_oneof_enum.py @@ -0,0 +1,47 @@ +import pytest + +import aristaproto +from tests.output_aristaproto.oneof_enum import ( + Move, + Signal, + Test, +) +from tests.util import get_test_case_json_data + + +def test_which_one_of_returns_enum_with_default_value(): + """ + returns first field when it is enum and set with default value + """ + message = Test() + message.from_json( + get_test_case_json_data("oneof_enum", "oneof_enum-enum-0.json")[0].json + ) + + assert not hasattr(message, "move") + assert object.__getattribute__(message, "move") == aristaproto.PLACEHOLDER + assert message.signal == Signal.PASS + assert aristaproto.which_one_of(message, "action") == ("signal", Signal.PASS) + + +def test_which_one_of_returns_enum_with_non_default_value(): + """ + returns first field when it is enum and set with non default value + """ + message = Test() + message.from_json( + get_test_case_json_data("oneof_enum", "oneof_enum-enum-1.json")[0].json + ) + assert not hasattr(message, "move") + assert object.__getattribute__(message, "move") == aristaproto.PLACEHOLDER + assert message.signal == Signal.RESIGN + assert aristaproto.which_one_of(message, "action") == ("signal", Signal.RESIGN) + + +def test_which_one_of_returns_second_field_when_set(): + message = Test() + message.from_json(get_test_case_json_data("oneof_enum")[0].json) + assert message.move == Move(x=2, y=3) + assert not hasattr(message, "signal") + assert object.__getattribute__(message, "signal") == aristaproto.PLACEHOLDER + assert aristaproto.which_one_of(message, "action") == ("move", Move(x=2, y=3)) diff --git a/tests/inputs/proto3_field_presence/proto3_field_presence.json b/tests/inputs/proto3_field_presence/proto3_field_presence.json new file mode 100644 index 0000000..988df8e --- /dev/null +++ b/tests/inputs/proto3_field_presence/proto3_field_presence.json @@ -0,0 +1,13 @@ +{ + "test1": 128, + "test2": true, + "test3": "A value", + "test4": "aGVsbG8=", + "test5": { + "test": "Hello" + }, + "test6": "B", + "test7": "8589934592", + "test8": 2.5, + "test9": "2022-01-24T12:12:42Z" +} diff --git a/tests/inputs/proto3_field_presence/proto3_field_presence.proto b/tests/inputs/proto3_field_presence/proto3_field_presence.proto new file mode 100644 index 0000000..f28123d --- /dev/null +++ b/tests/inputs/proto3_field_presence/proto3_field_presence.proto @@ -0,0 +1,26 @@ +syntax = "proto3"; + +package proto3_field_presence; + +import "google/protobuf/timestamp.proto"; + +message InnerTest { + string test = 1; +} + +message Test { + optional uint32 test1 = 1; + optional bool test2 = 2; + optional string test3 = 3; + optional bytes test4 = 4; + optional InnerTest test5 = 5; + optional TestEnum test6 = 6; + optional uint64 test7 = 7; + optional float test8 = 8; + optional google.protobuf.Timestamp test9 = 9; +} + +enum TestEnum { + A = 0; + B = 1; +} diff --git a/tests/inputs/proto3_field_presence/proto3_field_presence_default.json b/tests/inputs/proto3_field_presence/proto3_field_presence_default.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/inputs/proto3_field_presence/proto3_field_presence_default.json @@ -0,0 +1 @@ +{} diff --git a/tests/inputs/proto3_field_presence/proto3_field_presence_missing.json b/tests/inputs/proto3_field_presence/proto3_field_presence_missing.json new file mode 100644 index 0000000..b19ae98 --- /dev/null +++ b/tests/inputs/proto3_field_presence/proto3_field_presence_missing.json @@ -0,0 +1,9 @@ +{ + "test1": 0, + "test2": false, + "test3": "", + "test4": "", + "test6": "A", + "test7": "0", + "test8": 0 +} diff --git a/tests/inputs/proto3_field_presence/test_proto3_field_presence.py b/tests/inputs/proto3_field_presence/test_proto3_field_presence.py new file mode 100644 index 0000000..80696b2 --- /dev/null +++ b/tests/inputs/proto3_field_presence/test_proto3_field_presence.py @@ -0,0 +1,48 @@ +import json + +from tests.output_aristaproto.proto3_field_presence import ( + InnerTest, + Test, + TestEnum, +) + + +def test_null_fields_json(): + """Ensure that using "null" in JSON is equivalent to not specifying a + field, for fields with explicit presence""" + + def test_json(ref_json: str, obj_json: str) -> None: + """`ref_json` and `obj_json` are JSON strings describing a `Test` object. + Test that deserializing both leads to the same object, and that + `ref_json` is the normalized format.""" + ref_obj = Test().from_json(ref_json) + obj = Test().from_json(obj_json) + + assert obj == ref_obj + assert json.loads(obj.to_json(0)) == json.loads(ref_json) + + test_json("{}", '{ "test1": null, "test2": null, "test3": null }') + test_json("{}", '{ "test4": null, "test5": null, "test6": null }') + test_json("{}", '{ "test7": null, "test8": null }') + test_json('{ "test5": {} }', '{ "test3": null, "test5": {} }') + + # Make sure that if include_default_values is set, None values are + # exported. + obj = Test() + assert obj.to_dict() == {} + assert obj.to_dict(include_default_values=True) == { + "test1": None, + "test2": None, + "test3": None, + "test4": None, + "test5": None, + "test6": None, + "test7": None, + "test8": None, + "test9": None, + } + + +def test_unset_access(): # see #523 + assert Test().test1 is None + assert Test(test1=None).test1 is None diff --git a/tests/inputs/proto3_field_presence_oneof/proto3_field_presence_oneof.json b/tests/inputs/proto3_field_presence_oneof/proto3_field_presence_oneof.json new file mode 100644 index 0000000..da08192 --- /dev/null +++ b/tests/inputs/proto3_field_presence_oneof/proto3_field_presence_oneof.json @@ -0,0 +1,3 @@ +{ + "nested": {} +} diff --git a/tests/inputs/proto3_field_presence_oneof/proto3_field_presence_oneof.proto b/tests/inputs/proto3_field_presence_oneof/proto3_field_presence_oneof.proto new file mode 100644 index 0000000..caa76ec --- /dev/null +++ b/tests/inputs/proto3_field_presence_oneof/proto3_field_presence_oneof.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; + +package proto3_field_presence_oneof; + +message Test { + oneof kind { + Nested nested = 1; + WithOptional with_optional = 2; + } +} + +message InnerNested { + optional bool a = 1; +} + +message Nested { + InnerNested inner = 1; +} + +message WithOptional { + optional bool b = 2; +} diff --git a/tests/inputs/proto3_field_presence_oneof/test_proto3_field_presence_oneof.py b/tests/inputs/proto3_field_presence_oneof/test_proto3_field_presence_oneof.py new file mode 100644 index 0000000..f13c973 --- /dev/null +++ b/tests/inputs/proto3_field_presence_oneof/test_proto3_field_presence_oneof.py @@ -0,0 +1,29 @@ +from tests.output_aristaproto.proto3_field_presence_oneof import ( + InnerNested, + Nested, + Test, + WithOptional, +) + + +def test_serialization(): + """Ensure that serialization of fields unset but with explicit field + presence do not bloat the serialized payload with length-delimited fields + with length 0""" + + def test_empty_nested(message: Test) -> None: + # '0a' => tag 1, length delimited + # '00' => length: 0 + assert bytes(message) == bytearray.fromhex("0a 00") + + test_empty_nested(Test(nested=Nested())) + test_empty_nested(Test(nested=Nested(inner=None))) + test_empty_nested(Test(nested=Nested(inner=InnerNested(a=None)))) + + def test_empty_with_optional(message: Test) -> None: + # '12' => tag 2, length delimited + # '00' => length: 0 + assert bytes(message) == bytearray.fromhex("12 00") + + test_empty_with_optional(Test(with_optional=WithOptional())) + test_empty_with_optional(Test(with_optional=WithOptional(b=None))) diff --git a/tests/inputs/recursivemessage/recursivemessage.json b/tests/inputs/recursivemessage/recursivemessage.json new file mode 100644 index 0000000..e92c3fb --- /dev/null +++ b/tests/inputs/recursivemessage/recursivemessage.json @@ -0,0 +1,12 @@ +{ + "name": "Zues", + "child": { + "name": "Hercules" + }, + "intermediate": { + "child": { + "name": "Douglas Adams" + }, + "number": 42 + } +} diff --git a/tests/inputs/recursivemessage/recursivemessage.proto b/tests/inputs/recursivemessage/recursivemessage.proto new file mode 100644 index 0000000..1da2b57 --- /dev/null +++ b/tests/inputs/recursivemessage/recursivemessage.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package recursivemessage; + +message Test { + string name = 1; + Test child = 2; + Intermediate intermediate = 3; +} + + +message Intermediate { + int32 number = 1; + Test child = 2; +} diff --git a/tests/inputs/ref/ref.json b/tests/inputs/ref/ref.json new file mode 100644 index 0000000..2c6bdc1 --- /dev/null +++ b/tests/inputs/ref/ref.json @@ -0,0 +1,5 @@ +{ + "greeting": { + "greeting": "hello" + } +} diff --git a/tests/inputs/ref/ref.proto b/tests/inputs/ref/ref.proto new file mode 100644 index 0000000..6945590 --- /dev/null +++ b/tests/inputs/ref/ref.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package ref; + +import "repeatedmessage.proto"; + +message Test { + repeatedmessage.Sub greeting = 1; +} diff --git a/tests/inputs/ref/repeatedmessage.proto b/tests/inputs/ref/repeatedmessage.proto new file mode 100644 index 0000000..0ffacaf --- /dev/null +++ b/tests/inputs/ref/repeatedmessage.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package repeatedmessage; + +message Test { + repeated Sub greetings = 1; +} + +message Sub { + string greeting = 1; +}
\ No newline at end of file diff --git a/tests/inputs/regression_387/regression_387.proto b/tests/inputs/regression_387/regression_387.proto new file mode 100644 index 0000000..57bd954 --- /dev/null +++ b/tests/inputs/regression_387/regression_387.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package regression_387; + +message Test { + uint64 id = 1; +} + +message ParentElement { + string name = 1; + repeated Test elems = 2; +}
\ No newline at end of file diff --git a/tests/inputs/regression_387/test_regression_387.py b/tests/inputs/regression_387/test_regression_387.py new file mode 100644 index 0000000..92d96ba --- /dev/null +++ b/tests/inputs/regression_387/test_regression_387.py @@ -0,0 +1,12 @@ +from tests.output_aristaproto.regression_387 import ( + ParentElement, + Test, +) + + +def test_regression_387(): + el = ParentElement(name="test", elems=[Test(id=0), Test(id=42)]) + binary = bytes(el) + decoded = ParentElement().parse(binary) + assert decoded == el + assert decoded.elems == [Test(id=0), Test(id=42)] diff --git a/tests/inputs/regression_414/regression_414.proto b/tests/inputs/regression_414/regression_414.proto new file mode 100644 index 0000000..d20ddda --- /dev/null +++ b/tests/inputs/regression_414/regression_414.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package regression_414; + +message Test { + bytes body = 1; + bytes auth = 2; + repeated bytes signatures = 3; +}
\ No newline at end of file diff --git a/tests/inputs/regression_414/test_regression_414.py b/tests/inputs/regression_414/test_regression_414.py new file mode 100644 index 0000000..9441470 --- /dev/null +++ b/tests/inputs/regression_414/test_regression_414.py @@ -0,0 +1,15 @@ +from tests.output_aristaproto.regression_414 import Test + + +def test_full_cycle(): + body = bytes([0, 1]) + auth = bytes([2, 3]) + sig = [b""] + + obj = Test(body=body, auth=auth, signatures=sig) + + decoded = Test().parse(bytes(obj)) + assert decoded == obj + assert decoded.body == body + assert decoded.auth == auth + assert decoded.signatures == sig diff --git a/tests/inputs/repeated/repeated.json b/tests/inputs/repeated/repeated.json new file mode 100644 index 0000000..b8a7c4e --- /dev/null +++ b/tests/inputs/repeated/repeated.json @@ -0,0 +1,3 @@ +{ + "names": ["one", "two", "three"] +} diff --git a/tests/inputs/repeated/repeated.proto b/tests/inputs/repeated/repeated.proto new file mode 100644 index 0000000..4f3c788 --- /dev/null +++ b/tests/inputs/repeated/repeated.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package repeated; + +message Test { + repeated string names = 1; +} diff --git a/tests/inputs/repeated_duration_timestamp/repeated_duration_timestamp.json b/tests/inputs/repeated_duration_timestamp/repeated_duration_timestamp.json new file mode 100644 index 0000000..6ce7b34 --- /dev/null +++ b/tests/inputs/repeated_duration_timestamp/repeated_duration_timestamp.json @@ -0,0 +1,4 @@ +{ + "times": ["1972-01-01T10:00:20.021Z", "1972-01-01T10:00:20.021Z"], + "durations": ["1.200s", "1.200s"] +} diff --git a/tests/inputs/repeated_duration_timestamp/repeated_duration_timestamp.proto b/tests/inputs/repeated_duration_timestamp/repeated_duration_timestamp.proto new file mode 100644 index 0000000..38f1eaa --- /dev/null +++ b/tests/inputs/repeated_duration_timestamp/repeated_duration_timestamp.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package repeated_duration_timestamp; + +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; + + +message Test { + repeated google.protobuf.Timestamp times = 1; + repeated google.protobuf.Duration durations = 2; +} diff --git a/tests/inputs/repeated_duration_timestamp/test_repeated_duration_timestamp.py b/tests/inputs/repeated_duration_timestamp/test_repeated_duration_timestamp.py new file mode 100644 index 0000000..aafc951 --- /dev/null +++ b/tests/inputs/repeated_duration_timestamp/test_repeated_duration_timestamp.py @@ -0,0 +1,12 @@ +from datetime import ( + datetime, + timedelta, +) + +from tests.output_aristaproto.repeated_duration_timestamp import Test + + +def test_roundtrip(): + message = Test() + message.times = [datetime.now(), datetime.now()] + message.durations = [timedelta(), timedelta()] diff --git a/tests/inputs/repeatedmessage/repeatedmessage.json b/tests/inputs/repeatedmessage/repeatedmessage.json new file mode 100644 index 0000000..90ec596 --- /dev/null +++ b/tests/inputs/repeatedmessage/repeatedmessage.json @@ -0,0 +1,10 @@ +{ + "greetings": [ + { + "greeting": "hello" + }, + { + "greeting": "hi" + } + ] +} diff --git a/tests/inputs/repeatedmessage/repeatedmessage.proto b/tests/inputs/repeatedmessage/repeatedmessage.proto new file mode 100644 index 0000000..0ffacaf --- /dev/null +++ b/tests/inputs/repeatedmessage/repeatedmessage.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package repeatedmessage; + +message Test { + repeated Sub greetings = 1; +} + +message Sub { + string greeting = 1; +}
\ No newline at end of file diff --git a/tests/inputs/repeatedpacked/repeatedpacked.json b/tests/inputs/repeatedpacked/repeatedpacked.json new file mode 100644 index 0000000..106fd90 --- /dev/null +++ b/tests/inputs/repeatedpacked/repeatedpacked.json @@ -0,0 +1,5 @@ +{ + "counts": [1, 2, -1, -2], + "signed": ["1", "2", "-1", "-2"], + "fixed": [1.0, 2.7, 3.4] +} diff --git a/tests/inputs/repeatedpacked/repeatedpacked.proto b/tests/inputs/repeatedpacked/repeatedpacked.proto new file mode 100644 index 0000000..a037d1b --- /dev/null +++ b/tests/inputs/repeatedpacked/repeatedpacked.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package repeatedpacked; + +message Test { + repeated int32 counts = 1; + repeated sint64 signed = 2; + repeated double fixed = 3; +} diff --git a/tests/inputs/service/service.proto b/tests/inputs/service/service.proto new file mode 100644 index 0000000..53d84fb --- /dev/null +++ b/tests/inputs/service/service.proto @@ -0,0 +1,35 @@ +syntax = "proto3"; + +package service; + +enum ThingType { + UNKNOWN = 0; + LIVING = 1; + DEAD = 2; +} + +message DoThingRequest { + string name = 1; + repeated string comments = 2; + ThingType type = 3; +} + +message DoThingResponse { + repeated string names = 1; +} + +message GetThingRequest { + string name = 1; +} + +message GetThingResponse { + string name = 1; + int32 version = 2; +} + +service Test { + rpc DoThing (DoThingRequest) returns (DoThingResponse); + rpc DoManyThings (stream DoThingRequest) returns (DoThingResponse); + rpc GetThingVersions (GetThingRequest) returns (stream GetThingResponse); + rpc GetDifferentThings (stream GetThingRequest) returns (stream GetThingResponse); +} diff --git a/tests/inputs/service_separate_packages/messages.proto b/tests/inputs/service_separate_packages/messages.proto new file mode 100644 index 0000000..270b188 --- /dev/null +++ b/tests/inputs/service_separate_packages/messages.proto @@ -0,0 +1,31 @@ +syntax = "proto3"; + +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; + +package service_separate_packages.things.messages; + +message DoThingRequest { + string name = 1; + + // use `repeated` so we can check if `List` is correctly imported + repeated string comments = 2; + + // use google types `timestamp` and `duration` so we can check + // if everything from `datetime` is correctly imported + google.protobuf.Timestamp when = 3; + google.protobuf.Duration duration = 4; +} + +message DoThingResponse { + repeated string names = 1; +} + +message GetThingRequest { + string name = 1; +} + +message GetThingResponse { + string name = 1; + int32 version = 2; +} diff --git a/tests/inputs/service_separate_packages/service.proto b/tests/inputs/service_separate_packages/service.proto new file mode 100644 index 0000000..950eab4 --- /dev/null +++ b/tests/inputs/service_separate_packages/service.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +import "messages.proto"; + +package service_separate_packages.things.service; + +service Test { + rpc DoThing (things.messages.DoThingRequest) returns (things.messages.DoThingResponse); + rpc DoManyThings (stream things.messages.DoThingRequest) returns (things.messages.DoThingResponse); + rpc GetThingVersions (things.messages.GetThingRequest) returns (stream things.messages.GetThingResponse); + rpc GetDifferentThings (stream things.messages.GetThingRequest) returns (stream things.messages.GetThingResponse); +} diff --git a/tests/inputs/service_uppercase/service.proto b/tests/inputs/service_uppercase/service.proto new file mode 100644 index 0000000..786eec2 --- /dev/null +++ b/tests/inputs/service_uppercase/service.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; + +package service_uppercase; + +message DoTHINGRequest { + string name = 1; + repeated string comments = 2; +} + +message DoTHINGResponse { + repeated string names = 1; +} + +service Test { + rpc DoThing (DoTHINGRequest) returns (DoTHINGResponse); +} diff --git a/tests/inputs/service_uppercase/test_service.py b/tests/inputs/service_uppercase/test_service.py new file mode 100644 index 0000000..d10fccf --- /dev/null +++ b/tests/inputs/service_uppercase/test_service.py @@ -0,0 +1,8 @@ +import inspect + +from tests.output_aristaproto.service_uppercase import TestStub + + +def test_parameters(): + sig = inspect.signature(TestStub.do_thing) + assert len(sig.parameters) == 5, "Expected 5 parameters" diff --git a/tests/inputs/signed/signed.json b/tests/inputs/signed/signed.json new file mode 100644 index 0000000..b171e15 --- /dev/null +++ b/tests/inputs/signed/signed.json @@ -0,0 +1,6 @@ +{ + "signed32": 150, + "negative32": -150, + "string64": "150", + "negative64": "-150" +} diff --git a/tests/inputs/signed/signed.proto b/tests/inputs/signed/signed.proto new file mode 100644 index 0000000..b40aad4 --- /dev/null +++ b/tests/inputs/signed/signed.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package signed; + +message Test { + // todo: rename fields after fixing bug where 'signed_32_positive' will map to 'signed_32Positive' as output json + sint32 signed32 = 1; // signed_32_positive + sint32 negative32 = 2; // signed_32_negative + sint64 string64 = 3; // signed_64_positive + sint64 negative64 = 4; // signed_64_negative +} diff --git a/tests/inputs/timestamp_dict_encode/test_timestamp_dict_encode.py b/tests/inputs/timestamp_dict_encode/test_timestamp_dict_encode.py new file mode 100644 index 0000000..59be3d1 --- /dev/null +++ b/tests/inputs/timestamp_dict_encode/test_timestamp_dict_encode.py @@ -0,0 +1,82 @@ +from datetime import ( + datetime, + timedelta, + timezone, +) + +import pytest + +from tests.output_aristaproto.timestamp_dict_encode import Test + + +# Current World Timezone range (UTC-12 to UTC+14) +MIN_UTC_OFFSET_MIN = -12 * 60 +MAX_UTC_OFFSET_MIN = 14 * 60 + +# Generate all timezones in range in 15 min increments +timezones = [ + timezone(timedelta(minutes=x)) + for x in range(MIN_UTC_OFFSET_MIN, MAX_UTC_OFFSET_MIN + 1, 15) +] + + +@pytest.mark.parametrize("tz", timezones) +def test_timezone_aware_datetime_dict_encode(tz: timezone): + original_time = datetime.now(tz=tz) + original_message = Test() + original_message.ts = original_time + encoded = original_message.to_dict() + decoded_message = Test() + decoded_message.from_dict(encoded) + + # check that the timestamps are equal after decoding from dict + assert original_message.ts.tzinfo is not None + assert decoded_message.ts.tzinfo is not None + assert original_message.ts == decoded_message.ts + + +def test_naive_datetime_dict_encode(): + # make suer naive datetime objects are still treated as utc + original_time = datetime.now() + assert original_time.tzinfo is None + original_message = Test() + original_message.ts = original_time + original_time_utc = original_time.replace(tzinfo=timezone.utc) + encoded = original_message.to_dict() + decoded_message = Test() + decoded_message.from_dict(encoded) + + # check that the timestamps are equal after decoding from dict + assert decoded_message.ts.tzinfo is not None + assert original_time_utc == decoded_message.ts + + +@pytest.mark.parametrize("tz", timezones) +def test_timezone_aware_json_serialize(tz: timezone): + original_time = datetime.now(tz=tz) + original_message = Test() + original_message.ts = original_time + json_serialized = original_message.to_json() + decoded_message = Test() + decoded_message.from_json(json_serialized) + + # check that the timestamps are equal after decoding from dict + assert original_message.ts.tzinfo is not None + assert decoded_message.ts.tzinfo is not None + assert original_message.ts == decoded_message.ts + + +def test_naive_datetime_json_serialize(): + # make suer naive datetime objects are still treated as utc + original_time = datetime.now() + assert original_time.tzinfo is None + original_message = Test() + original_message.ts = original_time + original_time_utc = original_time.replace(tzinfo=timezone.utc) + json_serialized = original_message.to_json() + decoded_message = Test() + decoded_message.from_json(json_serialized) + + # check that the timestamps are equal after decoding from dict + assert decoded_message.ts.tzinfo is not None + assert original_time_utc == decoded_message.ts diff --git a/tests/inputs/timestamp_dict_encode/timestamp_dict_encode.json b/tests/inputs/timestamp_dict_encode/timestamp_dict_encode.json new file mode 100644 index 0000000..3f45558 --- /dev/null +++ b/tests/inputs/timestamp_dict_encode/timestamp_dict_encode.json @@ -0,0 +1,3 @@ +{ + "ts" : "2023-03-15T22:35:51.253277Z" +}
\ No newline at end of file diff --git a/tests/inputs/timestamp_dict_encode/timestamp_dict_encode.proto b/tests/inputs/timestamp_dict_encode/timestamp_dict_encode.proto new file mode 100644 index 0000000..9c4081a --- /dev/null +++ b/tests/inputs/timestamp_dict_encode/timestamp_dict_encode.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package timestamp_dict_encode; + +import "google/protobuf/timestamp.proto"; + +message Test { + google.protobuf.Timestamp ts = 1; +}
\ No newline at end of file diff --git a/tests/mocks.py b/tests/mocks.py new file mode 100644 index 0000000..dc6e117 --- /dev/null +++ b/tests/mocks.py @@ -0,0 +1,40 @@ +from typing import List + +from grpclib.client import Channel + + +class MockChannel(Channel): + # noinspection PyMissingConstructor + def __init__(self, responses=None) -> None: + self.responses = responses or [] + self.requests = [] + self._loop = None + + def request(self, route, cardinality, request, response_type, **kwargs): + self.requests.append( + { + "route": route, + "cardinality": cardinality, + "request": request, + "response_type": response_type, + } + ) + return MockStream(self.responses) + + +class MockStream: + def __init__(self, responses: List) -> None: + super().__init__() + self.responses = responses + + async def recv_message(self): + return self.responses.pop(0) + + async def send_message(self, *args, **kwargs): + pass + + async def __aexit__(self, exc_type, exc_val, exc_tb): + return True + + async def __aenter__(self): + return self diff --git a/tests/oneof_pattern_matching.py b/tests/oneof_pattern_matching.py new file mode 100644 index 0000000..2c5e797 --- /dev/null +++ b/tests/oneof_pattern_matching.py @@ -0,0 +1,46 @@ +from dataclasses import dataclass + +import pytest + +import aristaproto + + +def test_oneof_pattern_matching(): + @dataclass + class Sub(aristaproto.Message): + val: int = aristaproto.int32_field(1) + + @dataclass + class Foo(aristaproto.Message): + bar: int = aristaproto.int32_field(1, group="group1") + baz: str = aristaproto.string_field(2, group="group1") + sub: Sub = aristaproto.message_field(3, group="group2") + abc: str = aristaproto.string_field(4, group="group2") + + foo = Foo(baz="test1", abc="test2") + + match foo: + case Foo(bar=_): + pytest.fail("Matched 'bar' instead of 'baz'") + case Foo(baz=v): + assert v == "test1" + case _: + pytest.fail("Matched neither 'bar' nor 'baz'") + + match foo: + case Foo(sub=_): + pytest.fail("Matched 'sub' instead of 'abc'") + case Foo(abc=v): + assert v == "test2" + case _: + pytest.fail("Matched neither 'sub' nor 'abc'") + + foo.sub = Sub(val=1) + + match foo: + case Foo(sub=Sub(val=v)): + assert v == 1 + case Foo(abc=v): + pytest.fail("Matched 'abc' instead of 'sub'") + case _: + pytest.fail("Matched neither 'sub' nor 'abc'") diff --git a/tests/streams/delimited_messages.in b/tests/streams/delimited_messages.in new file mode 100644 index 0000000..5993ac6 --- /dev/null +++ b/tests/streams/delimited_messages.in @@ -0,0 +1,2 @@ +•šï:bTesting•šï:bTesting +
\ No newline at end of file diff --git a/tests/streams/dump_varint_negative.expected b/tests/streams/dump_varint_negative.expected new file mode 100644 index 0000000..0954822 --- /dev/null +++ b/tests/streams/dump_varint_negative.expected @@ -0,0 +1 @@ +ÿÿÿÿÿÿÿÿÿ€Óûÿÿÿÿÿ€€€€€€€€€€€€€€€€€
\ No newline at end of file diff --git a/tests/streams/dump_varint_positive.expected b/tests/streams/dump_varint_positive.expected new file mode 100644 index 0000000..8614b9d --- /dev/null +++ b/tests/streams/dump_varint_positive.expected @@ -0,0 +1 @@ +ۉ
\ No newline at end of file diff --git a/tests/streams/java/.gitignore b/tests/streams/java/.gitignore new file mode 100644 index 0000000..9b1ebba --- /dev/null +++ b/tests/streams/java/.gitignore @@ -0,0 +1,38 @@ +### Output ### +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ +dependency-reduced-pom.xml +MANIFEST.MF + +### IntelliJ IDEA ### +.idea/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store
\ No newline at end of file diff --git a/tests/streams/java/pom.xml b/tests/streams/java/pom.xml new file mode 100644 index 0000000..e39c567 --- /dev/null +++ b/tests/streams/java/pom.xml @@ -0,0 +1,94 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>aristaproto</groupId> + <artifactId>compatibility-test</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <properties> + <maven.compiler.source>11</maven.compiler.source> + <maven.compiler.target>11</maven.compiler.target> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <protobuf.version>3.23.4</protobuf.version> + </properties> + + <dependencies> + <dependency> + <groupId>com.google.protobuf</groupId> + <artifactId>protobuf-java</artifactId> + <version>${protobuf.version}</version> + </dependency> + </dependencies> + + <build> + <extensions> + <extension> + <groupId>kr.motd.maven</groupId> + <artifactId>os-maven-plugin</artifactId> + <version>1.7.1</version> + </extension> + </extensions> + + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.5.0</version> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> + <mainClass>aristaproto.CompatibilityTest</mainClass> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>3.3.0</version> + <configuration> + <archive> + <manifest> + <addClasspath>true</addClasspath> + <mainClass>aristaproto.CompatibilityTest</mainClass> + </manifest> + </archive> + </configuration> + </plugin> + + <plugin> + <groupId>org.xolstice.maven.plugins</groupId> + <artifactId>protobuf-maven-plugin</artifactId> + <version>0.6.1</version> + <executions> + <execution> + <goals> + <goal>compile</goal> + </goals> + </execution> + </executions> + <configuration> + <protocArtifact> + com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier} + </protocArtifact> + </configuration> + </plugin> + </plugins> + + <finalName>${project.artifactId}</finalName> + </build> + +</project>
\ No newline at end of file diff --git a/tests/streams/java/src/main/java/aristaproto/CompatibilityTest.java b/tests/streams/java/src/main/java/aristaproto/CompatibilityTest.java new file mode 100644 index 0000000..b0cff9f --- /dev/null +++ b/tests/streams/java/src/main/java/aristaproto/CompatibilityTest.java @@ -0,0 +1,41 @@ +package aristaproto; + +import java.io.IOException; + +public class CompatibilityTest { + public static void main(String[] args) throws IOException { + if (args.length < 2) + throw new RuntimeException("Attempted to run without the required arguments."); + else if (args.length > 2) + throw new RuntimeException( + "Attempted to run with more than the expected number of arguments (>1)."); + + Tests tests = new Tests(args[1]); + + switch (args[0]) { + case "single_varint": + tests.testSingleVarint(); + break; + + case "multiple_varints": + tests.testMultipleVarints(); + break; + + case "single_message": + tests.testSingleMessage(); + break; + + case "multiple_messages": + tests.testMultipleMessages(); + break; + + case "infinite_messages": + tests.testInfiniteMessages(); + break; + + default: + throw new RuntimeException( + "Attempted to run with unknown argument '" + args[0] + "'."); + } + } +} diff --git a/tests/streams/java/src/main/java/aristaproto/Tests.java b/tests/streams/java/src/main/java/aristaproto/Tests.java new file mode 100644 index 0000000..aabbac7 --- /dev/null +++ b/tests/streams/java/src/main/java/aristaproto/Tests.java @@ -0,0 +1,115 @@ +package aristaproto; + +import aristaproto.nested.NestedOuterClass; +import aristaproto.oneof.Oneof; + +import com.google.protobuf.CodedInputStream; +import com.google.protobuf.CodedOutputStream; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; + +public class Tests { + String path; + + public Tests(String path) { + this.path = path; + } + + public void testSingleVarint() throws IOException { + // Read in the Python-generated single varint file + FileInputStream inputStream = new FileInputStream(path + "/py_single_varint.out"); + CodedInputStream codedInput = CodedInputStream.newInstance(inputStream); + + int value = codedInput.readUInt32(); + + inputStream.close(); + + // Write the value back to a file + FileOutputStream outputStream = new FileOutputStream(path + "/java_single_varint.out"); + CodedOutputStream codedOutput = CodedOutputStream.newInstance(outputStream); + + codedOutput.writeUInt32NoTag(value); + + codedOutput.flush(); + outputStream.close(); + } + + public void testMultipleVarints() throws IOException { + // Read in the Python-generated multiple varints file + FileInputStream inputStream = new FileInputStream(path + "/py_multiple_varints.out"); + CodedInputStream codedInput = CodedInputStream.newInstance(inputStream); + + int value1 = codedInput.readUInt32(); + int value2 = codedInput.readUInt32(); + long value3 = codedInput.readUInt64(); + + inputStream.close(); + + // Write the values back to a file + FileOutputStream outputStream = new FileOutputStream(path + "/java_multiple_varints.out"); + CodedOutputStream codedOutput = CodedOutputStream.newInstance(outputStream); + + codedOutput.writeUInt32NoTag(value1); + codedOutput.writeUInt64NoTag(value2); + codedOutput.writeUInt64NoTag(value3); + + codedOutput.flush(); + outputStream.close(); + } + + public void testSingleMessage() throws IOException { + // Read in the Python-generated single message file + FileInputStream inputStream = new FileInputStream(path + "/py_single_message.out"); + CodedInputStream codedInput = CodedInputStream.newInstance(inputStream); + + Oneof.Test message = Oneof.Test.parseFrom(codedInput); + + inputStream.close(); + + // Write the message back to a file + FileOutputStream outputStream = new FileOutputStream(path + "/java_single_message.out"); + CodedOutputStream codedOutput = CodedOutputStream.newInstance(outputStream); + + message.writeTo(codedOutput); + + codedOutput.flush(); + outputStream.close(); + } + + public void testMultipleMessages() throws IOException { + // Read in the Python-generated multi-message file + FileInputStream inputStream = new FileInputStream(path + "/py_multiple_messages.out"); + + Oneof.Test oneof = Oneof.Test.parseDelimitedFrom(inputStream); + NestedOuterClass.Test nested = NestedOuterClass.Test.parseDelimitedFrom(inputStream); + + inputStream.close(); + + // Write the messages back to a file + FileOutputStream outputStream = new FileOutputStream(path + "/java_multiple_messages.out"); + + oneof.writeDelimitedTo(outputStream); + nested.writeDelimitedTo(outputStream); + + outputStream.flush(); + outputStream.close(); + } + + public void testInfiniteMessages() throws IOException { + // Read in as many messages as are present in the Python-generated file and write them back + FileInputStream inputStream = new FileInputStream(path + "/py_infinite_messages.out"); + FileOutputStream outputStream = new FileOutputStream(path + "/java_infinite_messages.out"); + + Oneof.Test current = Oneof.Test.parseDelimitedFrom(inputStream); + while (current != null) { + current.writeDelimitedTo(outputStream); + current = Oneof.Test.parseDelimitedFrom(inputStream); + } + + inputStream.close(); + outputStream.flush(); + outputStream.close(); + } +} diff --git a/tests/streams/java/src/main/proto/aristaproto/nested.proto b/tests/streams/java/src/main/proto/aristaproto/nested.proto new file mode 100644 index 0000000..46a5783 --- /dev/null +++ b/tests/streams/java/src/main/proto/aristaproto/nested.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; + +package nested; +option java_package = "aristaproto.nested"; + +// A test message with a nested message inside of it. +message Test { + // This is the nested type. + message Nested { + // Stores a simple counter. + int32 count = 1; + } + // This is the nested enum. + enum Msg { + NONE = 0; + THIS = 1; + } + + Nested nested = 1; + Sibling sibling = 2; + Sibling sibling2 = 3; + Msg msg = 4; +} + +message Sibling { + int32 foo = 1; +}
\ No newline at end of file diff --git a/tests/streams/java/src/main/proto/aristaproto/oneof.proto b/tests/streams/java/src/main/proto/aristaproto/oneof.proto new file mode 100644 index 0000000..44a8949 --- /dev/null +++ b/tests/streams/java/src/main/proto/aristaproto/oneof.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +package oneof; +option java_package = "aristaproto.oneof"; + +message Test { + oneof foo { + int32 pitied = 1; + string pitier = 2; + } + + int32 just_a_regular_field = 3; + + oneof bar { + int32 drinks = 11; + string bar_name = 12; + } +} + diff --git a/tests/streams/load_varint_cutoff.in b/tests/streams/load_varint_cutoff.in new file mode 100644 index 0000000..52b9bf1 --- /dev/null +++ b/tests/streams/load_varint_cutoff.in @@ -0,0 +1 @@ +È
\ No newline at end of file diff --git a/tests/streams/message_dump_file_multiple.expected b/tests/streams/message_dump_file_multiple.expected new file mode 100644 index 0000000..b5fdf9c --- /dev/null +++ b/tests/streams/message_dump_file_multiple.expected @@ -0,0 +1,2 @@ +•šï:bTesting•šï:bTesting +
\ No newline at end of file diff --git a/tests/streams/message_dump_file_single.expected b/tests/streams/message_dump_file_single.expected new file mode 100644 index 0000000..9b7bafb --- /dev/null +++ b/tests/streams/message_dump_file_single.expected @@ -0,0 +1 @@ +•šï:bTesting
\ No newline at end of file diff --git a/tests/test_casing.py b/tests/test_casing.py new file mode 100644 index 0000000..b16d326 --- /dev/null +++ b/tests/test_casing.py @@ -0,0 +1,129 @@ +import pytest + +from aristaproto.casing import ( + camel_case, + pascal_case, + snake_case, +) + + +@pytest.mark.parametrize( + ["value", "expected"], + [ + ("", ""), + ("a", "A"), + ("foobar", "Foobar"), + ("fooBar", "FooBar"), + ("FooBar", "FooBar"), + ("foo.bar", "FooBar"), + ("foo_bar", "FooBar"), + ("FOOBAR", "Foobar"), + ("FOOBar", "FooBar"), + ("UInt32", "UInt32"), + ("FOO_BAR", "FooBar"), + ("FOOBAR1", "Foobar1"), + ("FOOBAR_1", "Foobar1"), + ("FOO1BAR2", "Foo1Bar2"), + ("foo__bar", "FooBar"), + ("_foobar", "Foobar"), + ("foobaR", "FoobaR"), + ("foo~bar", "FooBar"), + ("foo:bar", "FooBar"), + ("1foobar", "1Foobar"), + ], +) +def test_pascal_case(value, expected): + actual = pascal_case(value, strict=True) + assert actual == expected, f"{value} => {expected} (actual: {actual})" + + +@pytest.mark.parametrize( + ["value", "expected"], + [ + ("", ""), + ("a", "a"), + ("foobar", "foobar"), + ("fooBar", "fooBar"), + ("FooBar", "fooBar"), + ("foo.bar", "fooBar"), + ("foo_bar", "fooBar"), + ("FOOBAR", "foobar"), + ("FOO_BAR", "fooBar"), + ("FOOBAR1", "foobar1"), + ("FOOBAR_1", "foobar1"), + ("FOO1BAR2", "foo1Bar2"), + ("foo__bar", "fooBar"), + ("_foobar", "foobar"), + ("foobaR", "foobaR"), + ("foo~bar", "fooBar"), + ("foo:bar", "fooBar"), + ("1foobar", "1Foobar"), + ], +) +def test_camel_case_strict(value, expected): + actual = camel_case(value, strict=True) + assert actual == expected, f"{value} => {expected} (actual: {actual})" + + +@pytest.mark.parametrize( + ["value", "expected"], + [ + ("foo_bar", "fooBar"), + ("FooBar", "fooBar"), + ("foo__bar", "foo_Bar"), + ("foo__Bar", "foo__Bar"), + ], +) +def test_camel_case_not_strict(value, expected): + actual = camel_case(value, strict=False) + assert actual == expected, f"{value} => {expected} (actual: {actual})" + + +@pytest.mark.parametrize( + ["value", "expected"], + [ + ("", ""), + ("a", "a"), + ("foobar", "foobar"), + ("fooBar", "foo_bar"), + ("FooBar", "foo_bar"), + ("foo.bar", "foo_bar"), + ("foo_bar", "foo_bar"), + ("foo_Bar", "foo_bar"), + ("FOOBAR", "foobar"), + ("FOOBar", "foo_bar"), + ("UInt32", "u_int32"), + ("FOO_BAR", "foo_bar"), + ("FOOBAR1", "foobar1"), + ("FOOBAR_1", "foobar_1"), + ("FOOBAR_123", "foobar_123"), + ("FOO1BAR2", "foo1_bar2"), + ("foo__bar", "foo_bar"), + ("_foobar", "foobar"), + ("foobaR", "fooba_r"), + ("foo~bar", "foo_bar"), + ("foo:bar", "foo_bar"), + ("1foobar", "1_foobar"), + ("GetUInt64", "get_u_int64"), + ], +) +def test_snake_case_strict(value, expected): + actual = snake_case(value) + assert actual == expected, f"{value} => {expected} (actual: {actual})" + + +@pytest.mark.parametrize( + ["value", "expected"], + [ + ("fooBar", "foo_bar"), + ("FooBar", "foo_bar"), + ("foo_Bar", "foo__bar"), + ("foo__bar", "foo__bar"), + ("FOOBar", "foo_bar"), + ("__foo", "__foo"), + ("GetUInt64", "get_u_int64"), + ], +) +def test_snake_case_not_strict(value, expected): + actual = snake_case(value, strict=False) + assert actual == expected, f"{value} => {expected} (actual: {actual})" diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py new file mode 100644 index 0000000..fd4de82 --- /dev/null +++ b/tests/test_deprecated.py @@ -0,0 +1,45 @@ +import warnings + +import pytest + +from tests.output_aristaproto.deprecated import ( + Message, + Test, +) + + +@pytest.fixture +def message(): + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=DeprecationWarning) + return Message(value="hello") + + +def test_deprecated_message(): + with pytest.warns(DeprecationWarning) as record: + Message(value="hello") + + assert len(record) == 1 + assert str(record[0].message) == f"{Message.__name__} is deprecated" + + +def test_message_with_deprecated_field(message): + with pytest.warns(DeprecationWarning) as record: + Test(message=message, value=10) + + assert len(record) == 1 + assert str(record[0].message) == f"{Test.__name__}.message is deprecated" + + +def test_message_with_deprecated_field_not_set(message): + with pytest.warns(None) as record: + Test(value=10) + + assert not record + + +def test_message_with_deprecated_field_not_set_default(message): + with pytest.warns(None) as record: + _ = Test(value=10).message + + assert not record diff --git a/tests/test_enum.py b/tests/test_enum.py new file mode 100644 index 0000000..807e785 --- /dev/null +++ b/tests/test_enum.py @@ -0,0 +1,79 @@ +from typing import ( + Optional, + Tuple, +) + +import pytest + +import aristaproto + + +class Colour(aristaproto.Enum): + RED = 1 + GREEN = 2 + BLUE = 3 + + +PURPLE = Colour.__new__(Colour, name=None, value=4) + + +@pytest.mark.parametrize( + "member, str_value", + [ + (Colour.RED, "RED"), + (Colour.GREEN, "GREEN"), + (Colour.BLUE, "BLUE"), + ], +) +def test_str(member: Colour, str_value: str) -> None: + assert str(member) == str_value + + +@pytest.mark.parametrize( + "member, repr_value", + [ + (Colour.RED, "Colour.RED"), + (Colour.GREEN, "Colour.GREEN"), + (Colour.BLUE, "Colour.BLUE"), + ], +) +def test_repr(member: Colour, repr_value: str) -> None: + assert repr(member) == repr_value + + +@pytest.mark.parametrize( + "member, values", + [ + (Colour.RED, ("RED", 1)), + (Colour.GREEN, ("GREEN", 2)), + (Colour.BLUE, ("BLUE", 3)), + (PURPLE, (None, 4)), + ], +) +def test_name_values(member: Colour, values: Tuple[Optional[str], int]) -> None: + assert (member.name, member.value) == values + + +@pytest.mark.parametrize( + "member, input_str", + [ + (Colour.RED, "RED"), + (Colour.GREEN, "GREEN"), + (Colour.BLUE, "BLUE"), + ], +) +def test_from_string(member: Colour, input_str: str) -> None: + assert Colour.from_string(input_str) == member + + +@pytest.mark.parametrize( + "member, input_int", + [ + (Colour.RED, 1), + (Colour.GREEN, 2), + (Colour.BLUE, 3), + (PURPLE, 4), + ], +) +def test_try_value(member: Colour, input_int: int) -> None: + assert Colour.try_value(input_int) == member diff --git a/tests/test_features.py b/tests/test_features.py new file mode 100644 index 0000000..638e668 --- /dev/null +++ b/tests/test_features.py @@ -0,0 +1,682 @@ +import json +import sys +from copy import ( + copy, + deepcopy, +) +from dataclasses import dataclass +from datetime import ( + datetime, + timedelta, +) +from inspect import ( + Parameter, + signature, +) +from typing import ( + Dict, + List, + Optional, +) +from unittest.mock import ANY + +import pytest + +import aristaproto + + +def test_has_field(): + @dataclass + class Bar(aristaproto.Message): + baz: int = aristaproto.int32_field(1) + + @dataclass + class Foo(aristaproto.Message): + bar: Bar = aristaproto.message_field(1) + + # Unset by default + foo = Foo() + assert aristaproto.serialized_on_wire(foo.bar) is False + + # Serialized after setting something + foo.bar.baz = 1 + assert aristaproto.serialized_on_wire(foo.bar) is True + + # Still has it after setting the default value + foo.bar.baz = 0 + assert aristaproto.serialized_on_wire(foo.bar) is True + + # Manual override (don't do this) + foo.bar._serialized_on_wire = False + assert aristaproto.serialized_on_wire(foo.bar) is False + + # Can manually set it but defaults to false + foo.bar = Bar() + assert aristaproto.serialized_on_wire(foo.bar) is False + + @dataclass + class WithCollections(aristaproto.Message): + test_list: List[str] = aristaproto.string_field(1) + test_map: Dict[str, str] = aristaproto.map_field( + 2, aristaproto.TYPE_STRING, aristaproto.TYPE_STRING + ) + + # Is always set from parse, even if all collections are empty + with_collections_empty = WithCollections().parse(bytes(WithCollections())) + assert aristaproto.serialized_on_wire(with_collections_empty) == True + with_collections_list = WithCollections().parse( + bytes(WithCollections(test_list=["a", "b", "c"])) + ) + assert aristaproto.serialized_on_wire(with_collections_list) == True + with_collections_map = WithCollections().parse( + bytes(WithCollections(test_map={"a": "b", "c": "d"})) + ) + assert aristaproto.serialized_on_wire(with_collections_map) == True + + +def test_class_init(): + @dataclass + class Bar(aristaproto.Message): + name: str = aristaproto.string_field(1) + + @dataclass + class Foo(aristaproto.Message): + name: str = aristaproto.string_field(1) + child: Bar = aristaproto.message_field(2) + + foo = Foo(name="foo", child=Bar(name="bar")) + + assert foo.to_dict() == {"name": "foo", "child": {"name": "bar"}} + assert foo.to_pydict() == {"name": "foo", "child": {"name": "bar"}} + + +def test_enum_as_int_json(): + class TestEnum(aristaproto.Enum): + ZERO = 0 + ONE = 1 + + @dataclass + class Foo(aristaproto.Message): + bar: TestEnum = aristaproto.enum_field(1) + + # JSON strings are supported, but ints should still be supported too. + foo = Foo().from_dict({"bar": 1}) + assert foo.bar == TestEnum.ONE + + # Plain-ol'-ints should serialize properly too. + foo.bar = 1 + assert foo.to_dict() == {"bar": "ONE"} + + # Similar expectations for pydict + foo = Foo().from_pydict({"bar": 1}) + assert foo.bar == TestEnum.ONE + assert foo.to_pydict() == {"bar": TestEnum.ONE} + + +def test_unknown_fields(): + @dataclass + class Newer(aristaproto.Message): + foo: bool = aristaproto.bool_field(1) + bar: int = aristaproto.int32_field(2) + baz: str = aristaproto.string_field(3) + + @dataclass + class Older(aristaproto.Message): + foo: bool = aristaproto.bool_field(1) + + newer = Newer(foo=True, bar=1, baz="Hello") + serialized_newer = bytes(newer) + + # Unknown fields in `Newer` should round trip with `Older` + round_trip = bytes(Older().parse(serialized_newer)) + assert serialized_newer == round_trip + + new_again = Newer().parse(round_trip) + assert newer == new_again + + +def test_oneof_support(): + @dataclass + class Sub(aristaproto.Message): + val: int = aristaproto.int32_field(1) + + @dataclass + class Foo(aristaproto.Message): + bar: int = aristaproto.int32_field(1, group="group1") + baz: str = aristaproto.string_field(2, group="group1") + sub: Sub = aristaproto.message_field(3, group="group2") + abc: str = aristaproto.string_field(4, group="group2") + + foo = Foo() + + assert aristaproto.which_one_of(foo, "group1")[0] == "" + + foo.bar = 1 + foo.baz = "test" + + # Other oneof fields should now be unset + assert not hasattr(foo, "bar") + assert object.__getattribute__(foo, "bar") == aristaproto.PLACEHOLDER + assert aristaproto.which_one_of(foo, "group1")[0] == "baz" + + foo.sub = Sub(val=1) + assert aristaproto.serialized_on_wire(foo.sub) + + foo.abc = "test" + + # Group 1 shouldn't be touched, group 2 should have reset + assert not hasattr(foo, "sub") + assert object.__getattribute__(foo, "sub") == aristaproto.PLACEHOLDER + assert aristaproto.which_one_of(foo, "group2")[0] == "abc" + + # Zero value should always serialize for one-of + foo = Foo(bar=0) + assert aristaproto.which_one_of(foo, "group1")[0] == "bar" + assert bytes(foo) == b"\x08\x00" + + # Round trip should also work + foo2 = Foo().parse(bytes(foo)) + assert aristaproto.which_one_of(foo2, "group1")[0] == "bar" + assert foo.bar == 0 + assert aristaproto.which_one_of(foo2, "group2")[0] == "" + + +@pytest.mark.skipif( + sys.version_info < (3, 10), + reason="pattern matching is only supported in python3.10+", +) +def test_oneof_pattern_matching(): + from .oneof_pattern_matching import test_oneof_pattern_matching + + test_oneof_pattern_matching() + + +def test_json_casing(): + @dataclass + class CasingTest(aristaproto.Message): + pascal_case: int = aristaproto.int32_field(1) + camel_case: int = aristaproto.int32_field(2) + snake_case: int = aristaproto.int32_field(3) + kabob_case: int = aristaproto.int32_field(4) + + # Parsing should accept almost any input + test = CasingTest().from_dict( + {"PascalCase": 1, "camelCase": 2, "snake_case": 3, "kabob-case": 4} + ) + + assert test == CasingTest(1, 2, 3, 4) + + # Serializing should be strict. + assert json.loads(test.to_json()) == { + "pascalCase": 1, + "camelCase": 2, + "snakeCase": 3, + "kabobCase": 4, + } + + assert json.loads(test.to_json(casing=aristaproto.Casing.SNAKE)) == { + "pascal_case": 1, + "camel_case": 2, + "snake_case": 3, + "kabob_case": 4, + } + + +def test_dict_casing(): + @dataclass + class CasingTest(aristaproto.Message): + pascal_case: int = aristaproto.int32_field(1) + camel_case: int = aristaproto.int32_field(2) + snake_case: int = aristaproto.int32_field(3) + kabob_case: int = aristaproto.int32_field(4) + + # Parsing should accept almost any input + test = CasingTest().from_dict( + {"PascalCase": 1, "camelCase": 2, "snake_case": 3, "kabob-case": 4} + ) + + assert test == CasingTest(1, 2, 3, 4) + + # Serializing should be strict. + assert test.to_dict() == { + "pascalCase": 1, + "camelCase": 2, + "snakeCase": 3, + "kabobCase": 4, + } + assert test.to_pydict() == { + "pascalCase": 1, + "camelCase": 2, + "snakeCase": 3, + "kabobCase": 4, + } + + assert test.to_dict(casing=aristaproto.Casing.SNAKE) == { + "pascal_case": 1, + "camel_case": 2, + "snake_case": 3, + "kabob_case": 4, + } + assert test.to_pydict(casing=aristaproto.Casing.SNAKE) == { + "pascal_case": 1, + "camel_case": 2, + "snake_case": 3, + "kabob_case": 4, + } + + +def test_optional_flag(): + @dataclass + class Request(aristaproto.Message): + flag: Optional[bool] = aristaproto.message_field(1, wraps=aristaproto.TYPE_BOOL) + + # Serialization of not passed vs. set vs. zero-value. + assert bytes(Request()) == b"" + assert bytes(Request(flag=True)) == b"\n\x02\x08\x01" + assert bytes(Request(flag=False)) == b"\n\x00" + + # Differentiate between not passed and the zero-value. + assert Request().parse(b"").flag is None + assert Request().parse(b"\n\x00").flag is False + + +def test_optional_datetime_to_dict(): + @dataclass + class Request(aristaproto.Message): + date: Optional[datetime] = aristaproto.message_field(1, optional=True) + + # Check dict serialization + assert Request().to_dict() == {} + assert Request().to_dict(include_default_values=True) == {"date": None} + assert Request(date=datetime(2020, 1, 1)).to_dict() == { + "date": "2020-01-01T00:00:00Z" + } + assert Request(date=datetime(2020, 1, 1)).to_dict(include_default_values=True) == { + "date": "2020-01-01T00:00:00Z" + } + + # Check pydict serialization + assert Request().to_pydict() == {} + assert Request().to_pydict(include_default_values=True) == {"date": None} + assert Request(date=datetime(2020, 1, 1)).to_pydict() == { + "date": datetime(2020, 1, 1) + } + assert Request(date=datetime(2020, 1, 1)).to_pydict( + include_default_values=True + ) == {"date": datetime(2020, 1, 1)} + + +def test_to_json_default_values(): + @dataclass + class TestMessage(aristaproto.Message): + some_int: int = aristaproto.int32_field(1) + some_double: float = aristaproto.double_field(2) + some_str: str = aristaproto.string_field(3) + some_bool: bool = aristaproto.bool_field(4) + + # Empty dict + test = TestMessage().from_dict({}) + + assert json.loads(test.to_json(include_default_values=True)) == { + "someInt": 0, + "someDouble": 0.0, + "someStr": "", + "someBool": False, + } + + # All default values + test = TestMessage().from_dict( + {"someInt": 0, "someDouble": 0.0, "someStr": "", "someBool": False} + ) + + assert json.loads(test.to_json(include_default_values=True)) == { + "someInt": 0, + "someDouble": 0.0, + "someStr": "", + "someBool": False, + } + + +def test_to_dict_default_values(): + @dataclass + class TestMessage(aristaproto.Message): + some_int: int = aristaproto.int32_field(1) + some_double: float = aristaproto.double_field(2) + some_str: str = aristaproto.string_field(3) + some_bool: bool = aristaproto.bool_field(4) + + # Empty dict + test = TestMessage().from_dict({}) + + assert test.to_dict(include_default_values=True) == { + "someInt": 0, + "someDouble": 0.0, + "someStr": "", + "someBool": False, + } + + test = TestMessage().from_pydict({}) + + assert test.to_pydict(include_default_values=True) == { + "someInt": 0, + "someDouble": 0.0, + "someStr": "", + "someBool": False, + } + + # All default values + test = TestMessage().from_dict( + {"someInt": 0, "someDouble": 0.0, "someStr": "", "someBool": False} + ) + + assert test.to_dict(include_default_values=True) == { + "someInt": 0, + "someDouble": 0.0, + "someStr": "", + "someBool": False, + } + + test = TestMessage().from_pydict( + {"someInt": 0, "someDouble": 0.0, "someStr": "", "someBool": False} + ) + + assert test.to_pydict(include_default_values=True) == { + "someInt": 0, + "someDouble": 0.0, + "someStr": "", + "someBool": False, + } + + # Some default and some other values + @dataclass + class TestMessage2(aristaproto.Message): + some_int: int = aristaproto.int32_field(1) + some_double: float = aristaproto.double_field(2) + some_str: str = aristaproto.string_field(3) + some_bool: bool = aristaproto.bool_field(4) + some_default_int: int = aristaproto.int32_field(5) + some_default_double: float = aristaproto.double_field(6) + some_default_str: str = aristaproto.string_field(7) + some_default_bool: bool = aristaproto.bool_field(8) + + test = TestMessage2().from_dict( + { + "someInt": 2, + "someDouble": 1.2, + "someStr": "hello", + "someBool": True, + "someDefaultInt": 0, + "someDefaultDouble": 0.0, + "someDefaultStr": "", + "someDefaultBool": False, + } + ) + + assert test.to_dict(include_default_values=True) == { + "someInt": 2, + "someDouble": 1.2, + "someStr": "hello", + "someBool": True, + "someDefaultInt": 0, + "someDefaultDouble": 0.0, + "someDefaultStr": "", + "someDefaultBool": False, + } + + test = TestMessage2().from_pydict( + { + "someInt": 2, + "someDouble": 1.2, + "someStr": "hello", + "someBool": True, + "someDefaultInt": 0, + "someDefaultDouble": 0.0, + "someDefaultStr": "", + "someDefaultBool": False, + } + ) + + assert test.to_pydict(include_default_values=True) == { + "someInt": 2, + "someDouble": 1.2, + "someStr": "hello", + "someBool": True, + "someDefaultInt": 0, + "someDefaultDouble": 0.0, + "someDefaultStr": "", + "someDefaultBool": False, + } + + # Nested messages + @dataclass + class TestChildMessage(aristaproto.Message): + some_other_int: int = aristaproto.int32_field(1) + + @dataclass + class TestParentMessage(aristaproto.Message): + some_int: int = aristaproto.int32_field(1) + some_double: float = aristaproto.double_field(2) + some_message: TestChildMessage = aristaproto.message_field(3) + + test = TestParentMessage().from_dict({"someInt": 0, "someDouble": 1.2}) + + assert test.to_dict(include_default_values=True) == { + "someInt": 0, + "someDouble": 1.2, + "someMessage": {"someOtherInt": 0}, + } + + test = TestParentMessage().from_pydict({"someInt": 0, "someDouble": 1.2}) + + assert test.to_pydict(include_default_values=True) == { + "someInt": 0, + "someDouble": 1.2, + "someMessage": {"someOtherInt": 0}, + } + + +def test_to_dict_datetime_values(): + @dataclass + class TestDatetimeMessage(aristaproto.Message): + bar: datetime = aristaproto.message_field(1) + baz: timedelta = aristaproto.message_field(2) + + test = TestDatetimeMessage().from_dict( + {"bar": "2020-01-01T00:00:00Z", "baz": "86400.000s"} + ) + + assert test.to_dict() == {"bar": "2020-01-01T00:00:00Z", "baz": "86400.000s"} + + test = TestDatetimeMessage().from_pydict( + {"bar": datetime(year=2020, month=1, day=1), "baz": timedelta(days=1)} + ) + + assert test.to_pydict() == { + "bar": datetime(year=2020, month=1, day=1), + "baz": timedelta(days=1), + } + + +def test_oneof_default_value_set_causes_writes_wire(): + @dataclass + class Empty(aristaproto.Message): + pass + + @dataclass + class Foo(aristaproto.Message): + bar: int = aristaproto.int32_field(1, group="group1") + baz: str = aristaproto.string_field(2, group="group1") + qux: Empty = aristaproto.message_field(3, group="group1") + + def _round_trip_serialization(foo: Foo) -> Foo: + return Foo().parse(bytes(foo)) + + foo1 = Foo(bar=0) + foo2 = Foo(baz="") + foo3 = Foo(qux=Empty()) + foo4 = Foo() + + assert bytes(foo1) == b"\x08\x00" + assert ( + aristaproto.which_one_of(foo1, "group1") + == aristaproto.which_one_of(_round_trip_serialization(foo1), "group1") + == ("bar", 0) + ) + + assert bytes(foo2) == b"\x12\x00" # Baz is just an empty string + assert ( + aristaproto.which_one_of(foo2, "group1") + == aristaproto.which_one_of(_round_trip_serialization(foo2), "group1") + == ("baz", "") + ) + + assert bytes(foo3) == b"\x1a\x00" + assert ( + aristaproto.which_one_of(foo3, "group1") + == aristaproto.which_one_of(_round_trip_serialization(foo3), "group1") + == ("qux", Empty()) + ) + + assert bytes(foo4) == b"" + assert ( + aristaproto.which_one_of(foo4, "group1") + == aristaproto.which_one_of(_round_trip_serialization(foo4), "group1") + == ("", None) + ) + + +def test_message_repr(): + from tests.output_aristaproto.recursivemessage import Test + + assert repr(Test(name="Loki")) == "Test(name='Loki')" + assert repr(Test(child=Test(), name="Loki")) == "Test(name='Loki', child=Test())" + + +def test_bool(): + """Messages should evaluate similarly to a collection + >>> test = [] + >>> bool(test) + ... False + >>> test.append(1) + >>> bool(test) + ... True + >>> del test[0] + >>> bool(test) + ... False + """ + + @dataclass + class Falsy(aristaproto.Message): + pass + + @dataclass + class Truthy(aristaproto.Message): + bar: int = aristaproto.int32_field(1) + + assert not Falsy() + t = Truthy() + assert not t + t.bar = 1 + assert t + t.bar = 0 + assert not t + + +# valid ISO datetimes according to https://www.myintervals.com/blog/2009/05/20/iso-8601-date-validation-that-doesnt-suck/ +iso_candidates = """2009-12-12T12:34 +2009 +2009-05-19 +2009-05-19 +20090519 +2009123 +2009-05 +2009-123 +2009-222 +2009-001 +2009-W01-1 +2009-W51-1 +2009-W33 +2009W511 +2009-05-19 +2009-05-19 00:00 +2009-05-19 14 +2009-05-19 14:31 +2009-05-19 14:39:22 +2009-05-19T14:39Z +2009-W21-2 +2009-W21-2T01:22 +2009-139 +2009-05-19 14:39:22-06:00 +2009-05-19 14:39:22+0600 +2009-05-19 14:39:22-01 +20090621T0545Z +2007-04-06T00:00 +2007-04-05T24:00 +2010-02-18T16:23:48.5 +2010-02-18T16:23:48,444 +2010-02-18T16:23:48,3-06:00 +2010-02-18T16:23:00.4 +2010-02-18T16:23:00,25 +2010-02-18T16:23:00.33+0600 +2010-02-18T16:00:00.23334444 +2010-02-18T16:00:00,2283 +2009-05-19 143922 +2009-05-19 1439""".split( + "\n" +) + + +def test_iso_datetime(): + @dataclass + class Envelope(aristaproto.Message): + ts: datetime = aristaproto.message_field(1) + + msg = Envelope() + + for _, candidate in enumerate(iso_candidates): + msg.from_dict({"ts": candidate}) + assert isinstance(msg.ts, datetime) + + +def test_iso_datetime_list(): + @dataclass + class Envelope(aristaproto.Message): + timestamps: List[datetime] = aristaproto.message_field(1) + + msg = Envelope() + + msg.from_dict({"timestamps": iso_candidates}) + assert all([isinstance(item, datetime) for item in msg.timestamps]) + + +def test_service_argument__expected_parameter(): + from tests.output_aristaproto.service import TestStub + + sig = signature(TestStub.do_thing) + do_thing_request_parameter = sig.parameters["do_thing_request"] + assert do_thing_request_parameter.default is Parameter.empty + assert do_thing_request_parameter.annotation == "DoThingRequest" + + +def test_is_set(): + @dataclass + class Spam(aristaproto.Message): + foo: bool = aristaproto.bool_field(1) + bar: Optional[int] = aristaproto.int32_field(2, optional=True) + + assert not Spam().is_set("foo") + assert not Spam().is_set("bar") + assert Spam(foo=True).is_set("foo") + assert Spam(foo=True, bar=0).is_set("bar") + + +def test_equality_comparison(): + from tests.output_aristaproto.bool import Test as TestMessage + + msg = TestMessage(value=True) + + assert msg == msg + assert msg == ANY + assert msg == TestMessage(value=True) + assert msg != 1 + assert msg != TestMessage(value=False) diff --git a/tests/test_get_ref_type.py b/tests/test_get_ref_type.py new file mode 100644 index 0000000..a4c6f76 --- /dev/null +++ b/tests/test_get_ref_type.py @@ -0,0 +1,371 @@ +import pytest + +from aristaproto.compile.importing import ( + get_type_reference, + parse_source_type_name, +) + + +@pytest.mark.parametrize( + ["google_type", "expected_name", "expected_import"], + [ + ( + ".google.protobuf.Empty", + '"aristaproto_lib_google_protobuf.Empty"', + "import aristaproto.lib.google.protobuf as aristaproto_lib_google_protobuf", + ), + ( + ".google.protobuf.Struct", + '"aristaproto_lib_google_protobuf.Struct"', + "import aristaproto.lib.google.protobuf as aristaproto_lib_google_protobuf", + ), + ( + ".google.protobuf.ListValue", + '"aristaproto_lib_google_protobuf.ListValue"', + "import aristaproto.lib.google.protobuf as aristaproto_lib_google_protobuf", + ), + ( + ".google.protobuf.Value", + '"aristaproto_lib_google_protobuf.Value"', + "import aristaproto.lib.google.protobuf as aristaproto_lib_google_protobuf", + ), + ], +) +def test_reference_google_wellknown_types_non_wrappers( + google_type: str, expected_name: str, expected_import: str +): + imports = set() + name = get_type_reference( + package="", imports=imports, source_type=google_type, pydantic=False + ) + + assert name == expected_name + assert imports.__contains__( + expected_import + ), f"{expected_import} not found in {imports}" + + +@pytest.mark.parametrize( + ["google_type", "expected_name", "expected_import"], + [ + ( + ".google.protobuf.Empty", + '"aristaproto_lib_pydantic_google_protobuf.Empty"', + "import aristaproto.lib.pydantic.google.protobuf as aristaproto_lib_pydantic_google_protobuf", + ), + ( + ".google.protobuf.Struct", + '"aristaproto_lib_pydantic_google_protobuf.Struct"', + "import aristaproto.lib.pydantic.google.protobuf as aristaproto_lib_pydantic_google_protobuf", + ), + ( + ".google.protobuf.ListValue", + '"aristaproto_lib_pydantic_google_protobuf.ListValue"', + "import aristaproto.lib.pydantic.google.protobuf as aristaproto_lib_pydantic_google_protobuf", + ), + ( + ".google.protobuf.Value", + '"aristaproto_lib_pydantic_google_protobuf.Value"', + "import aristaproto.lib.pydantic.google.protobuf as aristaproto_lib_pydantic_google_protobuf", + ), + ], +) +def test_reference_google_wellknown_types_non_wrappers_pydantic( + google_type: str, expected_name: str, expected_import: str +): + imports = set() + name = get_type_reference( + package="", imports=imports, source_type=google_type, pydantic=True + ) + + assert name == expected_name + assert imports.__contains__( + expected_import + ), f"{expected_import} not found in {imports}" + + +@pytest.mark.parametrize( + ["google_type", "expected_name"], + [ + (".google.protobuf.DoubleValue", "Optional[float]"), + (".google.protobuf.FloatValue", "Optional[float]"), + (".google.protobuf.Int32Value", "Optional[int]"), + (".google.protobuf.Int64Value", "Optional[int]"), + (".google.protobuf.UInt32Value", "Optional[int]"), + (".google.protobuf.UInt64Value", "Optional[int]"), + (".google.protobuf.BoolValue", "Optional[bool]"), + (".google.protobuf.StringValue", "Optional[str]"), + (".google.protobuf.BytesValue", "Optional[bytes]"), + ], +) +def test_referenceing_google_wrappers_unwraps_them( + google_type: str, expected_name: str +): + imports = set() + name = get_type_reference(package="", imports=imports, source_type=google_type) + + assert name == expected_name + assert imports == set() + + +@pytest.mark.parametrize( + ["google_type", "expected_name"], + [ + ( + ".google.protobuf.DoubleValue", + '"aristaproto_lib_google_protobuf.DoubleValue"', + ), + (".google.protobuf.FloatValue", '"aristaproto_lib_google_protobuf.FloatValue"'), + (".google.protobuf.Int32Value", '"aristaproto_lib_google_protobuf.Int32Value"'), + (".google.protobuf.Int64Value", '"aristaproto_lib_google_protobuf.Int64Value"'), + ( + ".google.protobuf.UInt32Value", + '"aristaproto_lib_google_protobuf.UInt32Value"', + ), + ( + ".google.protobuf.UInt64Value", + '"aristaproto_lib_google_protobuf.UInt64Value"', + ), + (".google.protobuf.BoolValue", '"aristaproto_lib_google_protobuf.BoolValue"'), + ( + ".google.protobuf.StringValue", + '"aristaproto_lib_google_protobuf.StringValue"', + ), + (".google.protobuf.BytesValue", '"aristaproto_lib_google_protobuf.BytesValue"'), + ], +) +def test_referenceing_google_wrappers_without_unwrapping( + google_type: str, expected_name: str +): + name = get_type_reference( + package="", imports=set(), source_type=google_type, unwrap=False + ) + + assert name == expected_name + + +def test_reference_child_package_from_package(): + imports = set() + name = get_type_reference( + package="package", imports=imports, source_type="package.child.Message" + ) + + assert imports == {"from . import child"} + assert name == '"child.Message"' + + +def test_reference_child_package_from_root(): + imports = set() + name = get_type_reference(package="", imports=imports, source_type="child.Message") + + assert imports == {"from . import child"} + assert name == '"child.Message"' + + +def test_reference_camel_cased(): + imports = set() + name = get_type_reference( + package="", imports=imports, source_type="child_package.example_message" + ) + + assert imports == {"from . import child_package"} + assert name == '"child_package.ExampleMessage"' + + +def test_reference_nested_child_from_root(): + imports = set() + name = get_type_reference( + package="", imports=imports, source_type="nested.child.Message" + ) + + assert imports == {"from .nested import child as nested_child"} + assert name == '"nested_child.Message"' + + +def test_reference_deeply_nested_child_from_root(): + imports = set() + name = get_type_reference( + package="", imports=imports, source_type="deeply.nested.child.Message" + ) + + assert imports == {"from .deeply.nested import child as deeply_nested_child"} + assert name == '"deeply_nested_child.Message"' + + +def test_reference_deeply_nested_child_from_package(): + imports = set() + name = get_type_reference( + package="package", + imports=imports, + source_type="package.deeply.nested.child.Message", + ) + + assert imports == {"from .deeply.nested import child as deeply_nested_child"} + assert name == '"deeply_nested_child.Message"' + + +def test_reference_root_sibling(): + imports = set() + name = get_type_reference(package="", imports=imports, source_type="Message") + + assert imports == set() + assert name == '"Message"' + + +def test_reference_nested_siblings(): + imports = set() + name = get_type_reference(package="foo", imports=imports, source_type="foo.Message") + + assert imports == set() + assert name == '"Message"' + + +def test_reference_deeply_nested_siblings(): + imports = set() + name = get_type_reference( + package="foo.bar", imports=imports, source_type="foo.bar.Message" + ) + + assert imports == set() + assert name == '"Message"' + + +def test_reference_parent_package_from_child(): + imports = set() + name = get_type_reference( + package="package.child", imports=imports, source_type="package.Message" + ) + + assert imports == {"from ... import package as __package__"} + assert name == '"__package__.Message"' + + +def test_reference_parent_package_from_deeply_nested_child(): + imports = set() + name = get_type_reference( + package="package.deeply.nested.child", + imports=imports, + source_type="package.deeply.nested.Message", + ) + + assert imports == {"from ... import nested as __nested__"} + assert name == '"__nested__.Message"' + + +def test_reference_ancestor_package_from_nested_child(): + imports = set() + name = get_type_reference( + package="package.ancestor.nested.child", + imports=imports, + source_type="package.ancestor.Message", + ) + + assert imports == {"from .... import ancestor as ___ancestor__"} + assert name == '"___ancestor__.Message"' + + +def test_reference_root_package_from_child(): + imports = set() + name = get_type_reference( + package="package.child", imports=imports, source_type="Message" + ) + + assert imports == {"from ... import Message as __Message__"} + assert name == '"__Message__"' + + +def test_reference_root_package_from_deeply_nested_child(): + imports = set() + name = get_type_reference( + package="package.deeply.nested.child", imports=imports, source_type="Message" + ) + + assert imports == {"from ..... import Message as ____Message__"} + assert name == '"____Message__"' + + +def test_reference_unrelated_package(): + imports = set() + name = get_type_reference(package="a", imports=imports, source_type="p.Message") + + assert imports == {"from .. import p as _p__"} + assert name == '"_p__.Message"' + + +def test_reference_unrelated_nested_package(): + imports = set() + name = get_type_reference(package="a.b", imports=imports, source_type="p.q.Message") + + assert imports == {"from ...p import q as __p_q__"} + assert name == '"__p_q__.Message"' + + +def test_reference_unrelated_deeply_nested_package(): + imports = set() + name = get_type_reference( + package="a.b.c.d", imports=imports, source_type="p.q.r.s.Message" + ) + + assert imports == {"from .....p.q.r import s as ____p_q_r_s__"} + assert name == '"____p_q_r_s__.Message"' + + +def test_reference_cousin_package(): + imports = set() + name = get_type_reference(package="a.x", imports=imports, source_type="a.y.Message") + + assert imports == {"from .. import y as _y__"} + assert name == '"_y__.Message"' + + +def test_reference_cousin_package_different_name(): + imports = set() + name = get_type_reference( + package="test.package1", imports=imports, source_type="cousin.package2.Message" + ) + + assert imports == {"from ...cousin import package2 as __cousin_package2__"} + assert name == '"__cousin_package2__.Message"' + + +def test_reference_cousin_package_same_name(): + imports = set() + name = get_type_reference( + package="test.package", imports=imports, source_type="cousin.package.Message" + ) + + assert imports == {"from ...cousin import package as __cousin_package__"} + assert name == '"__cousin_package__.Message"' + + +def test_reference_far_cousin_package(): + imports = set() + name = get_type_reference( + package="a.x.y", imports=imports, source_type="a.b.c.Message" + ) + + assert imports == {"from ...b import c as __b_c__"} + assert name == '"__b_c__.Message"' + + +def test_reference_far_far_cousin_package(): + imports = set() + name = get_type_reference( + package="a.x.y.z", imports=imports, source_type="a.b.c.d.Message" + ) + + assert imports == {"from ....b.c import d as ___b_c_d__"} + assert name == '"___b_c_d__.Message"' + + +@pytest.mark.parametrize( + ["full_name", "expected_output"], + [ + ("package.SomeMessage.NestedType", ("package", "SomeMessage.NestedType")), + (".package.SomeMessage.NestedType", ("package", "SomeMessage.NestedType")), + (".service.ExampleRequest", ("service", "ExampleRequest")), + (".package.lower_case_message", ("package", "lower_case_message")), + ], +) +def test_parse_field_type_name(full_name, expected_output): + assert parse_source_type_name(full_name) == expected_output diff --git a/tests/test_inputs.py b/tests/test_inputs.py new file mode 100644 index 0000000..9247e7b --- /dev/null +++ b/tests/test_inputs.py @@ -0,0 +1,225 @@ +import importlib +import json +import math +import os +import sys +from collections import namedtuple +from types import ModuleType +from typing import ( + Any, + Dict, + List, + Set, + Tuple, +) + +import pytest + +import aristaproto +from tests.inputs import config as test_input_config +from tests.mocks import MockChannel +from tests.util import ( + find_module, + get_directories, + get_test_case_json_data, + inputs_path, +) + + +# Force pure-python implementation instead of C++, otherwise imports +# break things because we can't properly reset the symbol database. +os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python" + +from google.protobuf.json_format import Parse + + +class TestCases: + def __init__( + self, + path, + services: Set[str], + xfail: Set[str], + ): + _all = set(get_directories(path)) - {"__pycache__"} + _services = services + _messages = (_all - services) - {"__pycache__"} + _messages_with_json = { + test for test in _messages if get_test_case_json_data(test) + } + + unknown_xfail_tests = xfail - _all + if unknown_xfail_tests: + raise Exception(f"Unknown test(s) in config.py: {unknown_xfail_tests}") + + self.all = self.apply_xfail_marks(_all, xfail) + self.services = self.apply_xfail_marks(_services, xfail) + self.messages = self.apply_xfail_marks(_messages, xfail) + self.messages_with_json = self.apply_xfail_marks(_messages_with_json, xfail) + + @staticmethod + def apply_xfail_marks(test_set: Set[str], xfail: Set[str]): + return [ + pytest.param(test, marks=pytest.mark.xfail) if test in xfail else test + for test in test_set + ] + + +test_cases = TestCases( + path=inputs_path, + services=test_input_config.services, + xfail=test_input_config.xfail, +) + +plugin_output_package = "tests.output_aristaproto" +reference_output_package = "tests.output_reference" + +TestData = namedtuple("TestData", ["plugin_module", "reference_module", "json_data"]) + + +def module_has_entry_point(module: ModuleType): + return any(hasattr(module, attr) for attr in ["Test", "TestStub"]) + + +def list_replace_nans(items: List) -> List[Any]: + """Replace float("nan") in a list with the string "NaN" + + Parameters + ---------- + items : List + List to update + + Returns + ------- + List[Any] + Updated list + """ + result = [] + for item in items: + if isinstance(item, list): + result.append(list_replace_nans(item)) + elif isinstance(item, dict): + result.append(dict_replace_nans(item)) + elif isinstance(item, float) and math.isnan(item): + result.append(aristaproto.NAN) + return result + + +def dict_replace_nans(input_dict: Dict[Any, Any]) -> Dict[Any, Any]: + """Replace float("nan") in a dictionary with the string "NaN" + + Parameters + ---------- + input_dict : Dict[Any, Any] + Dictionary to update + + Returns + ------- + Dict[Any, Any] + Updated dictionary + """ + result = {} + for key, value in input_dict.items(): + if isinstance(value, dict): + value = dict_replace_nans(value) + elif isinstance(value, list): + value = list_replace_nans(value) + elif isinstance(value, float) and math.isnan(value): + value = aristaproto.NAN + result[key] = value + return result + + +@pytest.fixture +def test_data(request, reset_sys_path): + test_case_name = request.param + + reference_module_root = os.path.join( + *reference_output_package.split("."), test_case_name + ) + sys.path.append(reference_module_root) + + plugin_module = importlib.import_module(f"{plugin_output_package}.{test_case_name}") + + plugin_module_entry_point = find_module(plugin_module, module_has_entry_point) + + if not plugin_module_entry_point: + raise Exception( + f"Test case {repr(test_case_name)} has no entry point. " + "Please add a proto message or service called Test and recompile." + ) + + yield ( + TestData( + plugin_module=plugin_module_entry_point, + reference_module=lambda: importlib.import_module( + f"{reference_output_package}.{test_case_name}.{test_case_name}_pb2" + ), + json_data=get_test_case_json_data(test_case_name), + ) + ) + + +@pytest.mark.parametrize("test_data", test_cases.messages, indirect=True) +def test_message_can_instantiated(test_data: TestData) -> None: + plugin_module, *_ = test_data + plugin_module.Test() + + +@pytest.mark.parametrize("test_data", test_cases.messages, indirect=True) +def test_message_equality(test_data: TestData) -> None: + plugin_module, *_ = test_data + message1 = plugin_module.Test() + message2 = plugin_module.Test() + assert message1 == message2 + + +@pytest.mark.parametrize("test_data", test_cases.messages_with_json, indirect=True) +def test_message_json(repeat, test_data: TestData) -> None: + plugin_module, _, json_data = test_data + + for _ in range(repeat): + for sample in json_data: + if sample.belongs_to(test_input_config.non_symmetrical_json): + continue + + message: aristaproto.Message = plugin_module.Test() + + message.from_json(sample.json) + message_json = message.to_json(0) + + assert dict_replace_nans(json.loads(message_json)) == dict_replace_nans( + json.loads(sample.json) + ) + + +@pytest.mark.parametrize("test_data", test_cases.services, indirect=True) +def test_service_can_be_instantiated(test_data: TestData) -> None: + test_data.plugin_module.TestStub(MockChannel()) + + +@pytest.mark.parametrize("test_data", test_cases.messages_with_json, indirect=True) +def test_binary_compatibility(repeat, test_data: TestData) -> None: + plugin_module, reference_module, json_data = test_data + + for sample in json_data: + reference_instance = Parse(sample.json, reference_module().Test()) + reference_binary_output = reference_instance.SerializeToString() + + for _ in range(repeat): + plugin_instance_from_json: aristaproto.Message = ( + plugin_module.Test().from_json(sample.json) + ) + plugin_instance_from_binary = plugin_module.Test.FromString( + reference_binary_output + ) + + # Generally this can't be relied on, but here we are aiming to match the + # existing Python implementation and aren't doing anything tricky. + # https://developers.google.com/protocol-buffers/docs/encoding#implications + assert bytes(plugin_instance_from_json) == reference_binary_output + assert bytes(plugin_instance_from_binary) == reference_binary_output + + assert plugin_instance_from_json == plugin_instance_from_binary + assert dict_replace_nans( + plugin_instance_from_json.to_dict() + ) == dict_replace_nans(plugin_instance_from_binary.to_dict()) diff --git a/tests/test_mapmessage.py b/tests/test_mapmessage.py new file mode 100644 index 0000000..75220e4 --- /dev/null +++ b/tests/test_mapmessage.py @@ -0,0 +1,18 @@ +from tests.output_aristaproto.mapmessage import ( + Nested, + Test, +) + + +def test_mapmessage_to_dict_preserves_message(): + message = Test( + items={ + "test": Nested( + count=1, + ) + } + ) + + message.to_dict() + + assert isinstance(message.items["test"], Nested), "Wrong nested type after to_dict" diff --git a/tests/test_pickling.py b/tests/test_pickling.py new file mode 100644 index 0000000..2356d98 --- /dev/null +++ b/tests/test_pickling.py @@ -0,0 +1,203 @@ +import pickle +from copy import ( + copy, + deepcopy, +) +from dataclasses import dataclass +from typing import ( + Dict, + List, +) +from unittest.mock import ANY + +import cachelib + +import aristaproto +from aristaproto.lib.google import protobuf as google + + +def unpickled(message): + return pickle.loads(pickle.dumps(message)) + + +@dataclass(eq=False, repr=False) +class Fe(aristaproto.Message): + abc: str = aristaproto.string_field(1) + + +@dataclass(eq=False, repr=False) +class Fi(aristaproto.Message): + abc: str = aristaproto.string_field(1) + + +@dataclass(eq=False, repr=False) +class Fo(aristaproto.Message): + abc: str = aristaproto.string_field(1) + + +@dataclass(eq=False, repr=False) +class NestedData(aristaproto.Message): + struct_foo: Dict[str, "google.Struct"] = aristaproto.map_field( + 1, aristaproto.TYPE_STRING, aristaproto.TYPE_MESSAGE + ) + map_str_any_bar: Dict[str, "google.Any"] = aristaproto.map_field( + 2, aristaproto.TYPE_STRING, aristaproto.TYPE_MESSAGE + ) + + +@dataclass(eq=False, repr=False) +class Complex(aristaproto.Message): + foo_str: str = aristaproto.string_field(1) + fe: "Fe" = aristaproto.message_field(3, group="grp") + fi: "Fi" = aristaproto.message_field(4, group="grp") + fo: "Fo" = aristaproto.message_field(5, group="grp") + nested_data: "NestedData" = aristaproto.message_field(6) + mapping: Dict[str, "google.Any"] = aristaproto.map_field( + 7, aristaproto.TYPE_STRING, aristaproto.TYPE_MESSAGE + ) + + +def complex_msg(): + return Complex( + foo_str="yep", + fe=Fe(abc="1"), + nested_data=NestedData( + struct_foo={ + "foo": google.Struct( + fields={ + "hello": google.Value( + list_value=google.ListValue( + values=[google.Value(string_value="world")] + ) + ) + } + ), + }, + map_str_any_bar={ + "key": google.Any(value=b"value"), + }, + ), + mapping={ + "message": google.Any(value=bytes(Fi(abc="hi"))), + "string": google.Any(value=b"howdy"), + }, + ) + + +def test_pickling_complex_message(): + msg = complex_msg() + deser = unpickled(msg) + assert msg == deser + assert msg.fe.abc == "1" + assert msg.is_set("fi") is not True + assert msg.mapping["message"] == google.Any(value=bytes(Fi(abc="hi"))) + assert msg.mapping["string"].value.decode() == "howdy" + assert ( + msg.nested_data.struct_foo["foo"] + .fields["hello"] + .list_value.values[0] + .string_value + == "world" + ) + + +def test_recursive_message(): + from tests.output_aristaproto.recursivemessage import Test as RecursiveMessage + + msg = RecursiveMessage() + msg = unpickled(msg) + + assert msg.child == RecursiveMessage() + + # Lazily-created zero-value children must not affect equality. + assert msg == RecursiveMessage() + + # Lazily-created zero-value children must not affect serialization. + assert bytes(msg) == b"" + + +def test_recursive_message_defaults(): + from tests.output_aristaproto.recursivemessage import ( + Intermediate, + Test as RecursiveMessage, + ) + + msg = RecursiveMessage(name="bob", intermediate=Intermediate(42)) + msg = unpickled(msg) + + # set values are as expected + assert msg == RecursiveMessage(name="bob", intermediate=Intermediate(42)) + + # lazy initialized works modifies the message + assert msg != RecursiveMessage( + name="bob", intermediate=Intermediate(42), child=RecursiveMessage(name="jude") + ) + msg.child.child.name = "jude" + assert msg == RecursiveMessage( + name="bob", + intermediate=Intermediate(42), + child=RecursiveMessage(child=RecursiveMessage(name="jude")), + ) + + # lazily initialization recurses as needed + assert msg.child.child.child.child.child.child.child == RecursiveMessage() + assert msg.intermediate.child.intermediate == Intermediate() + + +@dataclass +class PickledMessage(aristaproto.Message): + foo: bool = aristaproto.bool_field(1) + bar: int = aristaproto.int32_field(2) + baz: List[str] = aristaproto.string_field(3) + + +def test_copyability(): + msg = PickledMessage(bar=12, baz=["hello"]) + msg = unpickled(msg) + + copied = copy(msg) + assert msg == copied + assert msg is not copied + assert msg.baz is copied.baz + + deepcopied = deepcopy(msg) + assert msg == deepcopied + assert msg is not deepcopied + assert msg.baz is not deepcopied.baz + + +def test_message_can_be_cached(): + """Cachelib uses pickling to cache values""" + + cache = cachelib.SimpleCache() + + def use_cache(): + calls = getattr(use_cache, "calls", 0) + result = cache.get("message") + if result is not None: + return result + else: + setattr(use_cache, "calls", calls + 1) + result = complex_msg() + cache.set("message", result) + return result + + for n in range(10): + if n == 0: + assert not cache.has("message") + else: + assert cache.has("message") + + msg = use_cache() + assert use_cache.calls == 1 # The message is only ever built once + assert msg.fe.abc == "1" + assert msg.is_set("fi") is not True + assert msg.mapping["message"] == google.Any(value=bytes(Fi(abc="hi"))) + assert msg.mapping["string"].value.decode() == "howdy" + assert ( + msg.nested_data.struct_foo["foo"] + .fields["hello"] + .list_value.values[0] + .string_value + == "world" + ) diff --git a/tests/test_streams.py b/tests/test_streams.py new file mode 100644 index 0000000..7ae441b --- /dev/null +++ b/tests/test_streams.py @@ -0,0 +1,434 @@ +from dataclasses import dataclass +from io import BytesIO +from pathlib import Path +from shutil import which +from subprocess import run +from typing import Optional + +import pytest + +import aristaproto +from tests.output_aristaproto import ( + map, + nested, + oneof, + repeated, + repeatedpacked, +) + + +oneof_example = oneof.Test().from_dict( + {"pitied": 1, "just_a_regular_field": 123456789, "bar_name": "Testing"} +) + +len_oneof = len(oneof_example) + +nested_example = nested.Test().from_dict( + { + "nested": {"count": 1}, + "sibling": {"foo": 2}, + "sibling2": {"foo": 3}, + "msg": nested.TestMsg.THIS, + } +) + +repeated_example = repeated.Test().from_dict({"names": ["blah", "Blah2"]}) + +packed_example = repeatedpacked.Test().from_dict( + {"counts": [1, 2, 3], "signed": [-1, 2, -3], "fixed": [1.2, -2.3, 3.4]} +) + +map_example = map.Test().from_dict({"counts": {"blah": 1, "Blah2": 2}}) + +streams_path = Path("tests/streams/") + +java = which("java") + + +def test_load_varint_too_long(): + with BytesIO( + b"\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01" + ) as stream, pytest.raises(ValueError): + aristaproto.load_varint(stream) + + with BytesIO(b"\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01") as stream: + # This should not raise a ValueError, as it is within 64 bits + aristaproto.load_varint(stream) + + +def test_load_varint_file(): + with open(streams_path / "message_dump_file_single.expected", "rb") as stream: + assert aristaproto.load_varint(stream) == (8, b"\x08") # Single-byte varint + stream.read(2) # Skip until first multi-byte + assert aristaproto.load_varint(stream) == ( + 123456789, + b"\x95\x9A\xEF\x3A", + ) # Multi-byte varint + + +def test_load_varint_cutoff(): + with open(streams_path / "load_varint_cutoff.in", "rb") as stream: + with pytest.raises(EOFError): + aristaproto.load_varint(stream) + + stream.seek(1) + with pytest.raises(EOFError): + aristaproto.load_varint(stream) + + +def test_dump_varint_file(tmp_path): + # Dump test varints to file + with open(tmp_path / "dump_varint_file.out", "wb") as stream: + aristaproto.dump_varint(8, stream) # Single-byte varint + aristaproto.dump_varint(123456789, stream) # Multi-byte varint + + # Check that file contents are as expected + with open(tmp_path / "dump_varint_file.out", "rb") as test_stream, open( + streams_path / "message_dump_file_single.expected", "rb" + ) as exp_stream: + assert aristaproto.load_varint(test_stream) == aristaproto.load_varint( + exp_stream + ) + exp_stream.read(2) + assert aristaproto.load_varint(test_stream) == aristaproto.load_varint( + exp_stream + ) + + +def test_parse_fields(): + with open(streams_path / "message_dump_file_single.expected", "rb") as stream: + parsed_bytes = aristaproto.parse_fields(stream.read()) + + with open(streams_path / "message_dump_file_single.expected", "rb") as stream: + parsed_stream = aristaproto.load_fields(stream) + for field in parsed_bytes: + assert field == next(parsed_stream) + + +def test_message_dump_file_single(tmp_path): + # Write the message to the stream + with open(tmp_path / "message_dump_file_single.out", "wb") as stream: + oneof_example.dump(stream) + + # Check that the outputted file is exactly as expected + with open(tmp_path / "message_dump_file_single.out", "rb") as test_stream, open( + streams_path / "message_dump_file_single.expected", "rb" + ) as exp_stream: + assert test_stream.read() == exp_stream.read() + + +def test_message_dump_file_multiple(tmp_path): + # Write the same Message twice and another, different message + with open(tmp_path / "message_dump_file_multiple.out", "wb") as stream: + oneof_example.dump(stream) + oneof_example.dump(stream) + nested_example.dump(stream) + + # Check that all three Messages were outputted to the file correctly + with open(tmp_path / "message_dump_file_multiple.out", "rb") as test_stream, open( + streams_path / "message_dump_file_multiple.expected", "rb" + ) as exp_stream: + assert test_stream.read() == exp_stream.read() + + +def test_message_dump_delimited(tmp_path): + with open(tmp_path / "message_dump_delimited.out", "wb") as stream: + oneof_example.dump(stream, aristaproto.SIZE_DELIMITED) + oneof_example.dump(stream, aristaproto.SIZE_DELIMITED) + nested_example.dump(stream, aristaproto.SIZE_DELIMITED) + + with open(tmp_path / "message_dump_delimited.out", "rb") as test_stream, open( + streams_path / "delimited_messages.in", "rb" + ) as exp_stream: + assert test_stream.read() == exp_stream.read() + + +def test_message_len(): + assert len_oneof == len(bytes(oneof_example)) + assert len(nested_example) == len(bytes(nested_example)) + + +def test_message_load_file_single(): + with open(streams_path / "message_dump_file_single.expected", "rb") as stream: + assert oneof.Test().load(stream) == oneof_example + stream.seek(0) + assert oneof.Test().load(stream, len_oneof) == oneof_example + + +def test_message_load_file_multiple(): + with open(streams_path / "message_dump_file_multiple.expected", "rb") as stream: + oneof_size = len_oneof + assert oneof.Test().load(stream, oneof_size) == oneof_example + assert oneof.Test().load(stream, oneof_size) == oneof_example + assert nested.Test().load(stream) == nested_example + assert stream.read(1) == b"" + + +def test_message_load_too_small(): + with open( + streams_path / "message_dump_file_single.expected", "rb" + ) as stream, pytest.raises(ValueError): + oneof.Test().load(stream, len_oneof - 1) + + +def test_message_load_delimited(): + with open(streams_path / "delimited_messages.in", "rb") as stream: + assert oneof.Test().load(stream, aristaproto.SIZE_DELIMITED) == oneof_example + assert oneof.Test().load(stream, aristaproto.SIZE_DELIMITED) == oneof_example + assert nested.Test().load(stream, aristaproto.SIZE_DELIMITED) == nested_example + assert stream.read(1) == b"" + + +def test_message_load_too_large(): + with open( + streams_path / "message_dump_file_single.expected", "rb" + ) as stream, pytest.raises(ValueError): + oneof.Test().load(stream, len_oneof + 1) + + +def test_message_len_optional_field(): + @dataclass + class Request(aristaproto.Message): + flag: Optional[bool] = aristaproto.message_field(1, wraps=aristaproto.TYPE_BOOL) + + assert len(Request()) == len(b"") + assert len(Request(flag=True)) == len(b"\n\x02\x08\x01") + assert len(Request(flag=False)) == len(b"\n\x00") + + +def test_message_len_repeated_field(): + assert len(repeated_example) == len(bytes(repeated_example)) + + +def test_message_len_packed_field(): + assert len(packed_example) == len(bytes(packed_example)) + + +def test_message_len_map_field(): + assert len(map_example) == len(bytes(map_example)) + + +def test_message_len_empty_string(): + @dataclass + class Empty(aristaproto.Message): + string: str = aristaproto.string_field(1, "group") + integer: int = aristaproto.int32_field(2, "group") + + empty = Empty().from_dict({"string": ""}) + assert len(empty) == len(bytes(empty)) + + +def test_calculate_varint_size_negative(): + single_byte = -1 + multi_byte = -10000000 + edge = -(1 << 63) + beyond = -(1 << 63) - 1 + before = -(1 << 63) + 1 + + assert ( + aristaproto.size_varint(single_byte) + == len(aristaproto.encode_varint(single_byte)) + == 10 + ) + assert ( + aristaproto.size_varint(multi_byte) + == len(aristaproto.encode_varint(multi_byte)) + == 10 + ) + assert aristaproto.size_varint(edge) == len(aristaproto.encode_varint(edge)) == 10 + assert ( + aristaproto.size_varint(before) == len(aristaproto.encode_varint(before)) == 10 + ) + + with pytest.raises(ValueError): + aristaproto.size_varint(beyond) + + +def test_calculate_varint_size_positive(): + single_byte = 1 + multi_byte = 10000000 + + assert aristaproto.size_varint(single_byte) == len( + aristaproto.encode_varint(single_byte) + ) + assert aristaproto.size_varint(multi_byte) == len( + aristaproto.encode_varint(multi_byte) + ) + + +def test_dump_varint_negative(tmp_path): + single_byte = -1 + multi_byte = -10000000 + edge = -(1 << 63) + beyond = -(1 << 63) - 1 + before = -(1 << 63) + 1 + + with open(tmp_path / "dump_varint_negative.out", "wb") as stream: + aristaproto.dump_varint(single_byte, stream) + aristaproto.dump_varint(multi_byte, stream) + aristaproto.dump_varint(edge, stream) + aristaproto.dump_varint(before, stream) + + with pytest.raises(ValueError): + aristaproto.dump_varint(beyond, stream) + + with open(streams_path / "dump_varint_negative.expected", "rb") as exp_stream, open( + tmp_path / "dump_varint_negative.out", "rb" + ) as test_stream: + assert test_stream.read() == exp_stream.read() + + +def test_dump_varint_positive(tmp_path): + single_byte = 1 + multi_byte = 10000000 + + with open(tmp_path / "dump_varint_positive.out", "wb") as stream: + aristaproto.dump_varint(single_byte, stream) + aristaproto.dump_varint(multi_byte, stream) + + with open(tmp_path / "dump_varint_positive.out", "rb") as test_stream, open( + streams_path / "dump_varint_positive.expected", "rb" + ) as exp_stream: + assert test_stream.read() == exp_stream.read() + + +# Java compatibility tests + + +@pytest.fixture(scope="module") +def compile_jar(): + # Skip if not all required tools are present + if java is None: + pytest.skip("`java` command is absent and is required") + mvn = which("mvn") + if mvn is None: + pytest.skip("Maven is absent and is required") + + # Compile the JAR + proc_maven = run([mvn, "clean", "install", "-f", "tests/streams/java/pom.xml"]) + if proc_maven.returncode != 0: + pytest.skip( + "Maven compatibility-test.jar build failed (maybe Java version <11?)" + ) + + +jar = "tests/streams/java/target/compatibility-test.jar" + + +def run_jar(command: str, tmp_path): + return run([java, "-jar", jar, command, tmp_path], check=True) + + +def run_java_single_varint(value: int, tmp_path) -> int: + # Write single varint to file + with open(tmp_path / "py_single_varint.out", "wb") as stream: + aristaproto.dump_varint(value, stream) + + # Have Java read this varint and write it back + run_jar("single_varint", tmp_path) + + # Read single varint from Java output file + with open(tmp_path / "java_single_varint.out", "rb") as stream: + returned = aristaproto.load_varint(stream) + with pytest.raises(EOFError): + aristaproto.load_varint(stream) + + return returned + + +def test_single_varint(compile_jar, tmp_path): + single_byte = (1, b"\x01") + multi_byte = (123456789, b"\x95\x9A\xEF\x3A") + + # Write a single-byte varint to a file and have Java read it back + returned = run_java_single_varint(single_byte[0], tmp_path) + assert returned == single_byte + + # Same for a multi-byte varint + returned = run_java_single_varint(multi_byte[0], tmp_path) + assert returned == multi_byte + + +def test_multiple_varints(compile_jar, tmp_path): + single_byte = (1, b"\x01") + multi_byte = (123456789, b"\x95\x9A\xEF\x3A") + over32 = (3000000000, b"\x80\xBC\xC1\x96\x0B") + + # Write two varints to the same file + with open(tmp_path / "py_multiple_varints.out", "wb") as stream: + aristaproto.dump_varint(single_byte[0], stream) + aristaproto.dump_varint(multi_byte[0], stream) + aristaproto.dump_varint(over32[0], stream) + + # Have Java read these varints and write them back + run_jar("multiple_varints", tmp_path) + + # Read varints from Java output file + with open(tmp_path / "java_multiple_varints.out", "rb") as stream: + returned_single = aristaproto.load_varint(stream) + returned_multi = aristaproto.load_varint(stream) + returned_over32 = aristaproto.load_varint(stream) + with pytest.raises(EOFError): + aristaproto.load_varint(stream) + + assert returned_single == single_byte + assert returned_multi == multi_byte + assert returned_over32 == over32 + + +def test_single_message(compile_jar, tmp_path): + # Write message to file + with open(tmp_path / "py_single_message.out", "wb") as stream: + oneof_example.dump(stream) + + # Have Java read and return the message + run_jar("single_message", tmp_path) + + # Read and check the returned message + with open(tmp_path / "java_single_message.out", "rb") as stream: + returned = oneof.Test().load(stream, len(bytes(oneof_example))) + assert stream.read() == b"" + + assert returned == oneof_example + + +def test_multiple_messages(compile_jar, tmp_path): + # Write delimited messages to file + with open(tmp_path / "py_multiple_messages.out", "wb") as stream: + oneof_example.dump(stream, aristaproto.SIZE_DELIMITED) + nested_example.dump(stream, aristaproto.SIZE_DELIMITED) + + # Have Java read and return the messages + run_jar("multiple_messages", tmp_path) + + # Read and check the returned messages + with open(tmp_path / "java_multiple_messages.out", "rb") as stream: + returned_oneof = oneof.Test().load(stream, aristaproto.SIZE_DELIMITED) + returned_nested = nested.Test().load(stream, aristaproto.SIZE_DELIMITED) + assert stream.read() == b"" + + assert returned_oneof == oneof_example + assert returned_nested == nested_example + + +def test_infinite_messages(compile_jar, tmp_path): + num_messages = 5 + + # Write delimited messages to file + with open(tmp_path / "py_infinite_messages.out", "wb") as stream: + for x in range(num_messages): + oneof_example.dump(stream, aristaproto.SIZE_DELIMITED) + + # Have Java read and return the messages + run_jar("infinite_messages", tmp_path) + + # Read and check the returned messages + messages = [] + with open(tmp_path / "java_infinite_messages.out", "rb") as stream: + while True: + try: + messages.append(oneof.Test().load(stream, aristaproto.SIZE_DELIMITED)) + except EOFError: + break + + assert len(messages) == num_messages diff --git a/tests/test_struct.py b/tests/test_struct.py new file mode 100644 index 0000000..c562763 --- /dev/null +++ b/tests/test_struct.py @@ -0,0 +1,36 @@ +import json + +from aristaproto.lib.google.protobuf import Struct +from aristaproto.lib.pydantic.google.protobuf import Struct as StructPydantic + + +def test_struct_roundtrip(): + data = { + "foo": "bar", + "baz": None, + "quux": 123, + "zap": [1, {"two": 3}, "four"], + } + data_json = json.dumps(data) + + struct_from_dict = Struct().from_dict(data) + assert struct_from_dict.fields == data + assert struct_from_dict.to_dict() == data + assert struct_from_dict.to_json() == data_json + + struct_from_json = Struct().from_json(data_json) + assert struct_from_json.fields == data + assert struct_from_json.to_dict() == data + assert struct_from_json == struct_from_dict + assert struct_from_json.to_json() == data_json + + struct_pyd_from_dict = StructPydantic(fields={}).from_dict(data) + assert struct_pyd_from_dict.fields == data + assert struct_pyd_from_dict.to_dict() == data + assert struct_pyd_from_dict.to_json() == data_json + + struct_pyd_from_dict = StructPydantic(fields={}).from_json(data_json) + assert struct_pyd_from_dict.fields == data + assert struct_pyd_from_dict.to_dict() == data + assert struct_pyd_from_dict == struct_pyd_from_dict + assert struct_pyd_from_dict.to_json() == data_json diff --git a/tests/test_timestamp.py b/tests/test_timestamp.py new file mode 100644 index 0000000..dd51420 --- /dev/null +++ b/tests/test_timestamp.py @@ -0,0 +1,27 @@ +from datetime import ( + datetime, + timezone, +) + +import pytest + +from aristaproto import _Timestamp + + +@pytest.mark.parametrize( + "dt", + [ + datetime(2023, 10, 11, 9, 41, 12, tzinfo=timezone.utc), + datetime.now(timezone.utc), + # potential issue with floating point precision: + datetime(2242, 12, 31, 23, 0, 0, 1, tzinfo=timezone.utc), + # potential issue with negative timestamps: + datetime(1969, 12, 31, 23, 0, 0, 1, tzinfo=timezone.utc), + ], +) +def test_timestamp_to_datetime_and_back(dt: datetime): + """ + Make sure converting a datetime to a protobuf timestamp message + and then back again ends up with the same datetime. + """ + assert _Timestamp.from_datetime(dt).to_datetime() == dt diff --git a/tests/test_version.py b/tests/test_version.py new file mode 100644 index 0000000..bfbe842 --- /dev/null +++ b/tests/test_version.py @@ -0,0 +1,16 @@ +from pathlib import Path + +import tomlkit + +from aristaproto import __version__ + + +PROJECT_TOML = Path(__file__).joinpath("..", "..", "pyproject.toml").resolve() + + +def test_version(): + with PROJECT_TOML.open() as toml_file: + project_config = tomlkit.loads(toml_file.read()) + assert ( + __version__ == project_config["tool"]["poetry"]["version"] + ), "Project version should match in package and package config" diff --git a/tests/util.py b/tests/util.py new file mode 100644 index 0000000..2ba7cab --- /dev/null +++ b/tests/util.py @@ -0,0 +1,169 @@ +import asyncio +import atexit +import importlib +import os +import platform +import sys +import tempfile +from dataclasses import dataclass +from pathlib import Path +from types import ModuleType +from typing import ( + Callable, + Dict, + Generator, + List, + Optional, + Tuple, + Union, +) + + +os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python" + +root_path = Path(__file__).resolve().parent +inputs_path = root_path.joinpath("inputs") +output_path_reference = root_path.joinpath("output_reference") +output_path_aristaproto = root_path.joinpath("output_aristaproto") +output_path_aristaproto_pydantic = root_path.joinpath("output_aristaproto_pydantic") + + +def get_files(path, suffix: str) -> Generator[str, None, None]: + for r, dirs, files in os.walk(path): + for filename in [f for f in files if f.endswith(suffix)]: + yield os.path.join(r, filename) + + +def get_directories(path): + for root, directories, files in os.walk(path): + yield from directories + + +async def protoc( + path: Union[str, Path], + output_dir: Union[str, Path], + reference: bool = False, + pydantic_dataclasses: bool = False, +): + path: Path = Path(path).resolve() + output_dir: Path = Path(output_dir).resolve() + python_out_option: str = "python_aristaproto_out" if not reference else "python_out" + + if pydantic_dataclasses: + plugin_path = Path("src/aristaproto/plugin/main.py") + + if "Win" in platform.system(): + with tempfile.NamedTemporaryFile( + "w", encoding="UTF-8", suffix=".bat", delete=False + ) as tf: + # See https://stackoverflow.com/a/42622705 + tf.writelines( + [ + "@echo off", + f"\nchdir {os.getcwd()}", + f"\n{sys.executable} -u {plugin_path.as_posix()}", + ] + ) + + tf.flush() + + plugin_path = Path(tf.name) + atexit.register(os.remove, plugin_path) + + command = [ + sys.executable, + "-m", + "grpc.tools.protoc", + f"--plugin=protoc-gen-custom={plugin_path.as_posix()}", + "--experimental_allow_proto3_optional", + "--custom_opt=pydantic_dataclasses", + f"--proto_path={path.as_posix()}", + f"--custom_out={output_dir.as_posix()}", + *[p.as_posix() for p in path.glob("*.proto")], + ] + else: + command = [ + sys.executable, + "-m", + "grpc.tools.protoc", + f"--proto_path={path.as_posix()}", + f"--{python_out_option}={output_dir.as_posix()}", + *[p.as_posix() for p in path.glob("*.proto")], + ] + proc = await asyncio.create_subprocess_exec( + *command, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE + ) + stdout, stderr = await proc.communicate() + return stdout, stderr, proc.returncode + + +@dataclass +class TestCaseJsonFile: + json: str + test_name: str + file_name: str + + def belongs_to(self, non_symmetrical_json: Dict[str, Tuple[str, ...]]): + return self.file_name in non_symmetrical_json.get(self.test_name, tuple()) + + +def get_test_case_json_data( + test_case_name: str, *json_file_names: str +) -> List[TestCaseJsonFile]: + """ + :return: + A list of all files found in "{inputs_path}/test_case_name" with names matching + f"{test_case_name}.json" or f"{test_case_name}_*.json", OR given by + json_file_names + """ + test_case_dir = inputs_path.joinpath(test_case_name) + possible_file_paths = [ + *(test_case_dir.joinpath(json_file_name) for json_file_name in json_file_names), + test_case_dir.joinpath(f"{test_case_name}.json"), + *test_case_dir.glob(f"{test_case_name}_*.json"), + ] + + result = [] + for test_data_file_path in possible_file_paths: + if not test_data_file_path.exists(): + continue + with test_data_file_path.open("r") as fh: + result.append( + TestCaseJsonFile( + fh.read(), test_case_name, test_data_file_path.name.split(".")[0] + ) + ) + + return result + + +def find_module( + module: ModuleType, predicate: Callable[[ModuleType], bool] +) -> Optional[ModuleType]: + """ + Recursively search module tree for a module that matches the search predicate. + Assumes that the submodules are directories containing __init__.py. + + Example: + + # find module inside foo that contains Test + import foo + test_module = find_module(foo, lambda m: hasattr(m, 'Test')) + """ + if predicate(module): + return module + + module_path = Path(*module.__path__) + + for sub in [sub.parent for sub in module_path.glob("**/__init__.py")]: + if sub == module_path: + continue + sub_module_path = sub.relative_to(module_path) + sub_module_name = ".".join(sub_module_path.parts) + + sub_module = importlib.import_module(f".{sub_module_name}", module.__name__) + + if predicate(sub_module): + return sub_module + + return None |