{{! Copyright (c) Meta Platforms, Inc. and affiliates. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. }}{{! Generates external type annotations for legacy Thrift files. }} {{> common/AutoGeneratedPy}} import typing as __T {{#program:asyncio?}} import asyncio {{/program:asyncio?}} from thrift import Thrift from thrift.protocol.TProtocol import TProtocolBase {{#program:importModules}} import {{.}} {{/program:importModules}} from {{#program:pyNamespaces}}{{value}}.{{/program:pyNamespaces}}ttypes import * {{#service:extends}} import {{#service:pyNamespaces}}{{value}}.{{/service:pyNamespaces}}{{service:name}} {{/service:extends}} class Iface{{! }}{{#service:extends}}({{! }}{{#service:pyNamespaces}}{{value}}.{{/service:pyNamespaces}}{{! }}{{service:name}}.Iface{{! }}){{/service:extends}}:{{^service:functions}} ...{{/service:functions}} # {{service:name}} {{#program:asyncio?}} # These have to be Awaitable because handler methods don't return Futures # Clients do return Futures but lsp requires us to say they are both Awaitable # You can cast the result of a Client if you need Future {{/program:asyncio?}} {{#service:functions}} {{#function:isSupported?}} def {{function:name}}(self{{#function:args}}, {{! }}{{field:py_name}}: {{#field:type}}{{> common/FieldType}}{{/field:type}}{{! }}{{/function:args}}) -> {{! }}{{#program:asyncio?}}__T.Awaitable[{{/program:asyncio?}}{{! }}{{#function:return_type}}{{> common/FieldType}}{{/function:return_type}}{{! }}{{#program:asyncio?}}]{{/program:asyncio?}}{{! }}: ... {{/function:isSupported?}} {{/service:functions}} class Client(Iface, __T.ContextManager[Client]): # {{service:name}} {{#program:asyncio?}}{{! }}def __init__(self, oprot: __T.Optional[TProtocolBase], loop: __T.Optional[asyncio.AbstractEventLoop] = None, cpp_transport: __T.Optional[__T.TypeVar("SyncClient")] = None) -> None: ...{{! }}{{/program:asyncio?}}{{! }}{{^program:asyncio?}}{{! }}def __init__(self, iprot: __T.Optional[TProtocolBase], oprot: __T.Optional[TProtocolBase] = None, cpp_transport: __T.Optional[__T.TypeVar("SyncClient")] = None) -> None: ...{{! }}{{/program:asyncio?}} def set_persistent_header(self, key: str, value: str) -> None: ... def get_persistent_headers(self) -> __T.Mapping[str, str]: ... def clear_persistent_headers(self) -> None: ... def set_onetime_header(self, key: str, value: str) -> None: ... def get_last_response_headers(self) -> __T.Mapping[str, str]: ... def set_max_frame_size(self, size: int) -> None: ... {{#service:functions}} {{#function:isSupported?}} def send_{{function:name}}(self{{#function:args}}, {{! }}{{field:py_name}}: {{#field:type}}{{> common/OptionalFieldType}}{{/field:type}} = ...{{! }}{{/function:args}}) -> None: ... def recv_{{function:name}}(self{{#program:asyncio?}}, iprot: TProtocolBase, mtype: int, rseqid: int{{/program:asyncio?}}) -> {{! }}{{#program:asyncio?}}None{{/program:asyncio?}}{{! }}{{^program:asyncio?}}{{! }}{{#function:return_type}}{{> common/FieldType}}{{/function:return_type}}{{! }}{{/program:asyncio?}}{{! }}: ... {{/function:isSupported?}} {{/service:functions}} class Processor(Iface, Thrift.TProcessor): # {{service:name}} def __init__(self, handler: Iface) -> None: self._handler: Iface self._onewayMethods: __T.Sequence[__T.Callable] self._processMap: __T.Dict[str, __T.Callable] {{#service:functions}} {{#function:isSupported?}} def process_{{function:name}}(self, {{! }}seqid: int, {{! }}iprot: TProtocolBase, {{! }}oprot: TProtocolBase, {{! }}server_ctx: __T.Any = ...{{! }}) -> {{^program:asyncio?}}None{{/program:asyncio?}}{{#program:asyncio?}}asyncio.Future{{/program:asyncio?}}: ... {{/function:isSupported?}} {{/service:functions}} def process_main(self, {{! }}iprot: TProtocolBase, {{! }}oprot: TProtocolBase, {{! }}server_ctx: __T.Any = ...{{! }}) -> {{^program:asyncio?}}__T.Optional[bool]{{/program:asyncio?}}{{#program:asyncio?}}asyncio.Future{{/program:asyncio?}}: ... def onewayMethods(self) -> __T.Tuple[__T.Callable]: ... {{#service:functions}} {{#function:isSupported?}} class {{function:name}}_args: thrift_spec: __T.Tuple[__T.Optional[__T.Tuple[int, int, str, __T.Any, __T.Optional[int], int]]] thrift_field_annotations: __T.Dict[int, __T.Dict[str, str]] thrift_struct_annotations: __T.Dict[str, str] def __init__( self{{#function:args}}, {{field:py_name}}: {{#field:type}}{{> common/OptionalFieldType}}{{/field:type}} = ...{{/function:args}} ) -> None: {{#function:args}} {{#field:type}} self.{{field:py_name}}: {{> common/OptionalFieldType}} {{/field:type}} {{/function:args}} {{^function:args}} ... {{/function:args}} def isUnion(self) -> bool: ... def checkRequired(self) -> None: ... def read(self, iprot: TProtocolBase) -> None: ... def write(self, oprot: TProtocolBase) -> None: ... def __eq__(self, other: __T.Any) -> bool: ... def __ne__(self, other: __T.Any) -> bool: ... class {{function:name}}_result: thrift_spec: __T.Tuple[__T.Optional[__T.Tuple[int, int, str, __T.Any, __T.Optional[int], int]]] thrift_field_annotations: __T.Dict[int, __T.Dict[str, str]] thrift_struct_annotations: __T.Dict[str, str] def __init__(self, {{! }}success: {{#function:return_type}}{{> common/FieldType}}{{! }}{{/function:return_type}} = ...) -> None: self.success: {{#function:return_type}}{{> common/FieldType}}{{! }}{{/function:return_type}} def isUnion(self) -> bool: ... def checkRequired(self) -> None: ... def read(self, iprot: TProtocolBase) -> None: ... def write(self, oprot: TProtocolBase) -> None: ... def __eq__(self, other: __T.Any) -> bool: ... def __ne__(self, other: __T.Any) -> bool: ... {{/function:isSupported?}} {{/service:functions}}