This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| from dataclasses import dataclass | |
| @dataclass | |
| class Point: | |
| x: int | |
| y: int | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # this example is inspired by django docs: https://docs.djangoproject.com/en/3.2/topics/db/queries/#querying-jsonfield | |
| from typing import Optional | |
| import anyio | |
| import databases | |
| import ormar | |
| import sqlalchemy | |
| DATABASE_URL = 'sqlite:///db.sqlite' | |
| database = databases.Database(DATABASE_URL) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Simple example to show how to use the anyio StaticSpider class""" | |
| from datetime import datetime | |
| from pathlib import Path | |
| import anyio | |
| from scalpel import Configuration | |
| from scalpel.any_io import StaticResponse, StaticSpider, read_mp | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import socket | |
| import enum | |
| from kifurushi import Packet, ShortField, ByteField, IntEnumField | |
| HOST = 'disney-stuff.com' | |
| PORT = 14006 | |
| class Mood(enum.Enum): | |
| happy = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import enum | |
| from kifurushi import Packet, ShortField, ByteField, IntEnumField | |
| class Mood(enum.Enum): | |
| happy = 1 | |
| cool = 2 | |
| angry = 4 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pathlib import Path | |
| from typing import List | |
| import anyio | |
| import click | |
| import httpx | |
| from rich.console import Console | |
| from rich.progress import Progress, TaskID | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ipaddress | |
| import click | |
| class IPParamType(click.ParamType): | |
| name = 'ip address' | |
| def convert(self, value, param, ctx): | |
| try: | |
| return ipaddress.ip_address(value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import click | |
| @click.command() | |
| @click.argument('file', type=click.File()) | |
| def cli(file): | |
| """Read file part by part""" | |
| click.echo_via_pager(file.read()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from click.testing import CliRunner | |
| from scripts.pycat import cli | |
| def test_pycat(tmp_path): | |
| hello_file = tmp_path / 'hello.txt' | |
| hello_file.write_text('hello world!') | |
| runner = CliRunner() | |
| result = runner.invoke(cli, [f'{hello_file.resolve()}']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| import click | |
| @click.command() | |
| @click.option('-m', 'chars', is_flag=True, help='number of characters') | |
| @click.option('-l', 'lines', is_flag=True, help='number of lines') | |
| @click.option('-c', 'byte', is_flag=True, help='number of bytes') | |
| @click.option('-w', 'words', is_flag=True, help='number of words') | |
| @click.argument('filename', type=click.Path(exists=True, dir_okay=False)) |