A example of custom json serializer:
# file: json.py
def custom_json_encoder(o):
if isinstance(o, pydantic.BaseModel):
res = o.dict()
return res['__root__'] if '__root__' in res else res| from typing import cast | |
| import logging | |
| import json | |
| import urllib.request | |
| import http.client | |
| import urllib.parse | |
| logger = logging.getLogger(__name__) | |
| import re | |
| PASSWORD_MIN_LENGTH = 8 | |
| PASSWORD_MAX_LENGTH = 128 | |
| PASSWORD_MIN_UNIQUE_CHARS = 5 | |
| PASSWORD_MAX_REPEATED_CHARS = 3 | |
| MAX_CONTINUOUS_INCREASING_OR_DECREASING_SEQUENCES = 3 | |
| class PasswordValidationError(Exception): |
| sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| PREFIX=${PREFIX:-~/.local} | |
| mkdir -p $PREFIX/bin $PREFIX/lib | |
| curl -L https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.36/swagger-codegen-cli-3.0.36.jar \ | |
| -o $PREFIX/lib/swagger-codegen-cli.jar | |
| echo '#!/usr/bin/env bash' > $PREFIX/bin/swagger-codegen-cli |
| from functools import wraps | |
| import asyncio | |
| def get_event_loop(): | |
| try: | |
| return asyncio.get_event_loop() | |
| except RuntimeError as e: | |
| if "There is no current event loop in thread" in str(e): | |
| loop = asyncio.new_event_loop() |
| def camel_case_to_snake_case(s: str, use_fat: bool = False) -> str: | |
| """ | |
| >>> camel_case_to_snake_case("ProcedureContextStatus") | |
| "procedure_context_status" | |
| >>> camel_case_to_snake_case("ProcedureContextStatus", use_fat=True) | |
| "PROCEDURE_CONTEXT_STATUS" | |
| """ | |
| chars = [s[0].upper() if use_fat else s[0].lower()] | |
| for c in s[1:]: | |
| if c in ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'): |
| from functools import wraps | |
| import asyncio | |
| def get_event_loop(): | |
| try: | |
| return asyncio.get_event_loop() | |
| except RuntimeError as e: | |
| if "There is no current event loop in thread" in str(e): | |
| loop = asyncio.new_event_loop() |
| #!/usr/bin/env bash | |
| # Mainly used with GitLab CI/CD | |
| # Original source link of this file: | |
| # https://gist.github.com/wonderbeyond/434d3622c2db3d5ff00b4ba4a2a667bc | |
| set -euo pipefail | |
| export POETRY_HOME=~/poetry | |
| command -v curl > /dev/null || apt-get install -y curl |
| """Thanks to https://gist.github.com/butla/2d9a4c0f35ea47b7452156c96a4e7b12""" | |
| import socket | |
| import time | |
| def wait_port_ready(port: int, host: str = 'localhost', timeout: float = 5.0): | |
| """ | |
| Wait until a port starts accepting TCP connections. |