Ejemplo n.º 1
0
 def wiki_path(self, slug):
     url = URL(
         scheme='https',
         host='en.wikipedia.org',
         path=['wiki', str(slug).replace(' ', '_')],
     )
     return url.to_text()
Ejemplo n.º 2
0
from getpass import getpass

from hyperlink import URL
import spotipy.util

USERNAME = "******"
CLIENT_ID = u"9c3971b106ea4e019c04967a0974b1af"
DASHBOARD = URL(scheme=u"https", host=u"beta.developer.spotify.com").child(
    u"dashboard",
    u"applications",
    CLIENT_ID,
)
PROMPT = "Client Secret (" + DASHBOARD.to_text().encode("ascii") + "): "

print spotipy.util.prompt_for_user_token(
    username=USERNAME,
    scope="user-library-read",
    redirect_uri="http://localhost:8080/",
    client_id=CLIENT_ID,
    client_secret=getpass(PROMPT),
)
Ejemplo n.º 3
0
async def test_main(
    chunked_data: typing.List[bytes],
    http_application: quart_trio.QuartTrio,
    url: hyperlink.URL,
    pass_url: bool,
    tmp_path: pathlib.Path,
    pass_destination: bool,
    optional_hold_event: typing.Optional[trio.Event],
) -> None:
    temporary_directory = trio.Path(tmp_path)

    data = b"".join(chunked_data)
    destination = temporary_directory.joinpath("file")

    async with trio.open_nursery() as nursery:
        start = functools.partial(
            qtrio.examples.download.start_downloader,
            url=url if pass_url else None,
            destination=destination if pass_destination else None,
            fps=10,
            http_application=http_application,
            hold_event=optional_hold_event,
        )
        widget: qtrio.examples.download.Downloader = await nursery.start(start)

        if optional_hold_event is not None:
            optional_hold_event.set()

        if not pass_url:
            await widget.text_input_shown_event.wait()
            assert widget.text_input_dialog is not None

            assert widget.text_input_dialog.line_edit is not None
            widget.text_input_dialog.line_edit.setText(url.to_text())

            assert widget.text_input_dialog.accept_button is not None
            widget.text_input_dialog.accept_button.click()

        if not pass_destination:
            await widget.file_dialog_shown_event.wait()
            assert widget.file_dialog is not None

            assert widget.file_dialog.dialog is not None
            await widget.file_dialog.set_path(path=destination)

            assert widget.file_dialog.accept_button is not None
            widget.file_dialog.accept_button.click()

        await widget.get_dialog_created_event.wait()
        assert widget.get_dialog is not None

        await widget.get_dialog.message_box_shown_event.wait()
        assert widget.get_dialog.message_box is not None

        assert widget.get_dialog.message_box.accept_button is not None
        widget.get_dialog.message_box.accept_button.click()

    async with await destination.open("rb") as written_file:
        written = await written_file.read()  # type: ignore[attr-defined]

    assert written == data