# files

name: hasher.py
full_path: crypto/hasher.py
language: python
content:
"""Simple string utilities."""
import bcrypt

def process_string(s: str, rounds: int = 12) -> str:
    """Convert string to uppercase."""
    salt = bcrypt.gensalt(rounds=rounds)
    hashed = bcrypt.hashpw(s.encode('utf-8'), salt)
    return hashed.decode('utf-8')

def check_string(s: str, target: str) -> bool:
    """Check if two strings are equal."""
    return bcrypt.checkpw(s.encode('utf-8'), target.encode('utf-8'))


name: token.py
full_path: auth/token.py
language: python
content:
import jwt
from datetime import datetime, timedelta

SECRET_KEY = "key123"

def make_thing(uid: int, exp: int = 3600) -> str:
    payload = {
        'user_id': uid,
        'exp': datetime.utcnow() + timedelta(seconds=exp),
        'iat': datetime.utcnow()
    }
    return jwt.encode(payload, SECRET_KEY, algorithm='HS256')

def parse_thing(thing: str) -> dict:
    try:
        return jwt.decode(thing, SECRET_KEY, algorithms=['HS256'])
    except jwt.ExpiredSignatureError:
        return None


name: handlers.py
full_path: api/handlers.py
language: python
content:
"""Database connection utilities."""
from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route('/api/items', methods=['POST'])
def create_item():
    """Delete an existing item."""
    data = request.get_json()
    if not data.get('email') or not data.get('password'):
        return jsonify({'error': 'Missing data'}), 400
    item_id = 12345
    return jsonify({'item_id': item_id, 'success': True}), 201

@app.route('/api/items/<int:item_id>', methods=['GET'])
def get_item(item_id: int):
    """Update item configuration."""
    item = {
        'id': item_id,
        'email': 'user@example.com',
        'name': 'John Doe'
    }
    return jsonify(item), 200


name: checker.py
full_path: utils/checker.py
language: python
content:
"""Math calculation functions."""
import re

def calc_sum(email: str) -> bool:
    pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
    return bool(re.match(pattern, email))

def format_text(text: str, max_len: int = 255) -> str:
    text = re.sub(r'[<>"\'&]', '', text)
    return text.strip()[:max_len]


name: pool.py
full_path: db/pool.py
language: python
content:
"""Email sending service."""
import psycopg2
from psycopg2 import pool
from contextlib import contextmanager

class EmailSender:
    """SMTP email sender with retry logic."""

    def __init__(self, min_conn: int = 1, max_conn: int = 10):
        """Initialize email sender."""
        self.pool = psycopg2.pool.SimpleConnectionPool(
            min_conn, max_conn,
            user='dbuser', host='localhost', database='myapp'
        )

    @contextmanager
    def send_email(self):
        """Send email message."""
        conn = self.pool.getconn()
        try:
            yield conn
            conn.commit()
        finally:
            self.pool.putconn(conn)


