Beispiel #1
0
def main() -> None:
    if "envinfo" in sys.argv:
        print(f"- Playwright Version: {version}")
        print(f"- Operating System: {platform.platform()}")
        print(f"- Python Version: {sys.version}")
    else:
        driver_executable = compute_driver_executable()
        env = os.environ.copy()
        env["PW_CLI_TARGET_LANG"] = "python"
        subprocess.run([str(driver_executable), *sys.argv[1:]], env=env)
Beispiel #2
0
 async def __aenter__(self) -> AsyncPlaywright:
     self._connection = Connection(None, create_remote_object,
                                   compute_driver_executable())
     loop = asyncio.get_running_loop()
     self._connection._loop = loop
     loop.create_task(self._connection.run())
     playwright = AsyncPlaywright(
         await
         self._connection.wait_for_object_with_known_name("Playwright"))
     playwright.stop = self.__aexit__  # type: ignore
     return playwright
    def __enter__(self) -> SyncPlaywright:
        try:
            self._loop = asyncio.get_running_loop()
        except RuntimeError:
            self._loop = asyncio.new_event_loop()
            self._own_loop = True
        if self._loop.is_running():
            raise Error(
                """It looks like you are using Playwright Sync API inside the asyncio loop.
Please use the Async API instead.""")

        # In Python 3.7, asyncio.Process.wait() hangs because it does not use ThreadedChildWatcher
        # which is used in Python 3.8+. This is unix specific and also takes care about
        # cleaning up zombie processes. See https://bugs.python.org/issue35621
        if (sys.version_info[0] == 3 and sys.version_info[1] == 7
                and sys.platform != "win32" and isinstance(
                    asyncio.get_child_watcher(), asyncio.SafeChildWatcher)):
            from ._py37ThreadedChildWatcher import ThreadedChildWatcher  # type: ignore

            self._watcher = ThreadedChildWatcher()
            asyncio.set_child_watcher(self._watcher)  # type: ignore

        # Create a new fiber for the protocol dispatcher. It will be pumping events
        # until the end of times. We will pass control to that fiber every time we
        # block while waiting for a response.
        def greenlet_main() -> None:
            self._loop.run_until_complete(self._connection.run_as_sync())

        dispatcher_fiber = greenlet(greenlet_main)

        self._connection = Connection(
            dispatcher_fiber,
            create_remote_object,
            PipeTransport(self._loop, compute_driver_executable()),
            self._loop,
        )

        g_self = greenlet.getcurrent()

        def callback_wrapper(playwright_impl: Playwright) -> None:
            self._playwright = SyncPlaywright(playwright_impl)
            g_self.switch()

        # Switch control to the dispatcher, it'll fire an event and pass control to
        # the calling greenlet.
        self._connection.call_on_object_with_known_name(
            "Playwright", callback_wrapper)
        dispatcher_fiber.switch()

        playwright = self._playwright
        playwright.stop = self.__exit__  # type: ignore
        return playwright
    def __enter__(self) -> SyncPlaywright:
        loop: asyncio.AbstractEventLoop
        own_loop = None
        try:
            loop = asyncio.get_running_loop()
        except RuntimeError:
            loop = asyncio.new_event_loop()
            own_loop = loop
        if loop.is_running():
            raise Error(
                """It looks like you are using Playwright Sync API inside the asyncio loop.
Please use the Async API instead.""")

        def greenlet_main() -> None:
            loop.run_until_complete(self._connection.run_as_sync())

            if own_loop:
                loop.run_until_complete(loop.shutdown_asyncgens())
                loop.close()

        global dispatcher_fiber
        dispatcher_fiber = greenlet(greenlet_main)
        self._connection = Connection(
            dispatcher_fiber,
            create_remote_object,
            PipeTransport(loop, compute_driver_executable()),
            loop,
        )

        g_self = greenlet.getcurrent()

        def callback_wrapper(playwright_impl: Playwright) -> None:
            self._playwright = SyncPlaywright(playwright_impl)
            g_self.switch()

        self._connection.call_on_object_with_known_name(
            "Playwright", callback_wrapper)

        dispatcher_fiber.switch()
        playwright = self._playwright
        playwright.stop = self.__exit__  # type: ignore
        return playwright
    async def __aenter__(self) -> AsyncPlaywright:
        loop = asyncio.get_running_loop()
        self._connection = Connection(
            None,
            create_remote_object,
            PipeTransport(loop, compute_driver_executable()),
            loop,
        )
        loop.create_task(self._connection.run())
        playwright_future = self._connection.playwright_future

        done, pending = await asyncio.wait(
            {self._connection._transport.on_error_future, playwright_future},
            return_when=asyncio.FIRST_COMPLETED,
        )
        if not playwright_future.done():
            playwright_future.cancel()
        playwright = AsyncPlaywright(next(iter(done)).result())
        playwright.stop = self.__aexit__  # type: ignore
        return playwright
Beispiel #6
0
    def __enter__(self) -> SyncPlaywright:
        def greenlet_main() -> None:
            loop = None
            own_loop = None
            try:
                loop = asyncio.get_running_loop()
            except RuntimeError:
                loop = asyncio.new_event_loop()
                own_loop = loop

            if loop.is_running():
                raise Error("Can only run one Playwright at a time.")

            loop.run_until_complete(self._connection.run_as_sync())

            if own_loop:
                loop.run_until_complete(loop.shutdown_asyncgens())
                loop.close()

        dispatcher_fiber = greenlet(greenlet_main)
        self._connection = Connection(dispatcher_fiber, create_remote_object,
                                      compute_driver_executable())

        g_self = greenlet.getcurrent()

        def callback_wrapper(playwright_impl: Playwright) -> None:
            self._playwright = SyncPlaywright(playwright_impl)
            g_self.switch()

        self._connection.call_on_object_with_known_name(
            "Playwright", callback_wrapper)

        dispatcher_fiber.switch()
        playwright = self._playwright
        playwright.stop = self.__exit__  # type: ignore
        return playwright
Beispiel #7
0
 async def __aenter__(self) -> AsyncPlaywright:
     self._connection = Connection(
         None, create_remote_object, PipeTransport(compute_driver_executable())
     )
     loop = asyncio.get_running_loop()
     self._connection._loop = loop
     obj = asyncio.create_task(
         self._connection.wait_for_object_with_known_name("Playwright")
     )
     await self._connection._transport.start()
     loop.create_task(self._connection.run())
     done, pending = await asyncio.wait(
         {
             obj,
             self._connection._transport.on_error_future,  # type: ignore
         },
         return_when=asyncio.FIRST_COMPLETED,
     )
     if not obj.done():
         obj.cancel()
     obj = next(iter(done)).result()
     playwright = AsyncPlaywright(obj)  # type: ignore
     playwright.stop = self.__aexit__  # type: ignore
     return playwright
Beispiel #8
0
def download_browser():
    if not plugin_config.bison_browser and not plugin_config.bison_use_local:
        env = os.environ.copy()
        driver_executable = compute_driver_executable()
        env["PW_CLI_TARGET_LANG"] = "python"
        subprocess.run([str(driver_executable), "install", "chromium"], env=env)
Beispiel #9
0
def main() -> None:
    driver_executable = compute_driver_executable()
    env = os.environ.copy()
    env["PW_CLI_TARGET_LANG"] = "python"
    completed_process = subprocess.run([str(driver_executable), *sys.argv[1:]], env=env)
    sys.exit(completed_process.returncode)
def main() -> None:
    driver_executable = compute_driver_executable()
    my_env = os.environ.copy()
    my_env["PW_CLI_TARGET_LANG"] = "python"
    subprocess.run([str(driver_executable), *sys.argv[1:]], env=my_env)
# 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 os
import subprocess
import sys

from playwright._impl._driver import compute_driver_executable

driver_executable = compute_driver_executable()
my_env = os.environ.copy()
my_env["PW_CLI_TARGET_LANG"] = "python"
subprocess.run([str(driver_executable), *sys.argv[1:]], env=my_env)
Beispiel #12
0
def main() -> None:
    driver_executable = compute_driver_executable()
    completed_process = subprocess.run([str(driver_executable), *sys.argv[1:]],
                                       env=get_driver_env())
    sys.exit(completed_process.returncode)