#!/usr/bin/env python
# Copyright (c) Microsoft Corporation.
#
# 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.
import inspect
import re
import sys
from types import FunctionType
from typing import Any
import generate_api
from documentation_provider import DocumentationProvider
from generate_api import (
api_globals,
arguments,
generated_types,
get_type_hints,
header,
process_type,
return_type,
return_value,
short_name,
signature,
)
generate_api.SYNC_API = True
documentation_provider = DocumentationProvider(False)
def generate(t: Any) -> None:
print("")
class_name = short_name(t)
base_class = t.__bases__[0].__name__
if class_name in ["Page", "BrowserContext", "Browser", "Disposable"]:
base_sync_class = "SyncContextManager"
elif base_class in ["ChannelOwner", "object", "AssertionsBase"]:
base_sync_class = "SyncBase"
else:
base_sync_class = base_class
print(f"class {class_name}({base_sync_class}):")
print("")
documentation_provider.print_events(class_name)
for [name, type] in get_type_hints(t, api_globals).items():
print("")
print(" @property")
print(f" def {name}(self) -> {process_type(type)}:")
documentation_provider.print_entry(class_name, name, {"return": type}, True)
[prefix, suffix] = return_value(type)
prefix = " return " + prefix + f"self._impl_obj.{name}"
print(f"{prefix}{suffix}")
for [name, value] in t.__dict__.items():
if name.startswith("_"):
continue
if str(value).startswith("