io_utils.py
python_old/pytest-workshop/pytest-workshop-solutions/src/io_utils.py
from typing import List
import os
import logging
import requests
log = logging.getLogger(__name__)
def write_lines(path, lines: List[str]) -> None:
with open(path, "w", encoding="utf-8") as f:
for line in lines:
f.write(line + "\n")
def read_lines(path):
with open(path, "r", encoding="utf-8") as f:
return [line.rstrip("\n") for line in f]
def get_api_key() -> str:
return os.environ.get("API_KEY", "")
def greet(name: str) -> None:
print(f"Hello, {name}!")
log.info("Greeted %s", name)
def fetch_json(url: str):
# Network call is mocked in tests; no real I/O occurs.
return requests.get(url, timeout=5).json()
Bài viết liên quan
01_classical_caesar_cipher.py
01_classical_caesar_cipher.py — python source code from the python old learning materials (python_old/Cryptography/01_classical_caesar_cipher.py).
Đọc bài viết →02_classical_monoalphabetic.py
02_classical_monoalphabetic.py — python source code from the python old learning materials (python_old/Cryptography/02_classical_monoalphabetic.py).
Đọc bài viết →03_classical_rail_fence.py
03_classical_rail_fence.py — python source code from the python old learning materials (python_old/Cryptography/03_classical_rail_fence.py).
Đọc bài viết →04_frequency_analysis.py
04_frequency_analysis.py — python source code from the python old learning materials (python_old/Cryptography/04_frequency_analysis.py).
Đọc bài viết →05_cryptographic_hashing.py
05_cryptographic_hashing.py — python source code from the python old learning materials (python_old/Cryptography/05_cryptographic_hashing.py).
Đọc bài viết →06_password_hashing.py
06_password_hashing.py — python source code from the python old learning materials (python_old/Cryptography/06_password_hashing.py).
Đọc bài viết →