import asyncio
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from library.utils import old_add, old_multiply, legacy_divide, square, cube, old_format_string
from library.async_ops import old_fetch_data, get_json, legacy_upload, old_batch_fetch
from library.models import OldDataProcessor, LegacyUser, SimpleProcessor
from library.processors import ProcessingEngine, DataValidator
from library.config import (
OLD_API_URL, OLD_TIMEOUT, LEGACY_RETRIES, AppConfig, FeatureFlags, DevConfig
)
from library.containers import LegacyContainer, SmartList
from library.utils import add, multiply, divide
from library.models import DataProcessor, User
def demonstrate_deprecated_functions():
print("=== Deprecated Function Usage Examples ===")
result1 = old_add(10, 5)
print(f"old_add(10, 5) = {result1}")
result2 = old_multiply(4, 7)
print(f"old_multiply(4, 7) = {result2}")
result3 = legacy_divide(20, 4)
print(f"legacy_divide(20, 4) = {result3}")
result4 = square(8)
print(f"square(8) = {result4}")
result5 = cube(3)
print(f"cube(3) = {result5}")
result6 = old_format_string("Hello, {}! Welcome to {}", "Alice", "our app", uppercase=True)
print(f"old_format_string result: {result6}")
def demonstrate_deprecated_classes():
print("\n=== Deprecated Class Usage Examples ===")
old_processor = OldDataProcessor("database://localhost", cache_size=25)
processed_data = old_processor.process("sample data")
print(f"OldDataProcessor result: {processed_data}")
info = old_processor.get_info()
print(f"Processor info: {info}")
legacy_user = LegacyUser("john_doe", "john@example.com")
name = legacy_user.get_name() print(f"Legacy user name: {name}")
legacy_user.set_profile_data({"age": 30, "city": "New York"})
enabled_status = legacy_user.is_enabled print(f"User enabled status: {enabled_status}")
simple_proc = SimpleProcessor("data_source")
simple_result = simple_proc.process_item("test item")
print(f"SimpleProcessor result: {simple_result}")
def demonstrate_class_and_static_methods():
print("\n=== Deprecated Class/Static Method Examples ===")
old_engine = ProcessingEngine.old_create_engine(fast=True)
print(f"Old engine type: {old_engine.engine_type}")
legacy_engine = ProcessingEngine.legacy_fast_processor()
print(f"Legacy engine type: {legacy_engine.engine_type}")
is_valid = ProcessingEngine.old_validate_data(["test", "data"])
print(f"Data validation result: {is_valid}")
clean_text = ProcessingEngine.legacy_clean_text(" HELLO WORLD ")
print(f"Cleaned text: '{clean_text}'")
batch_result = ProcessingEngine.old_process_batch(
[" Item1 ", " ITEM2 "],
uppercase=True,
trim=False
)
print(f"Batch processing result: {batch_result}")
email_valid = DataValidator.check_email("test@example.com")
print(f"Email validation: {email_valid}")
phone_valid = DataValidator.validate_phone_number("555-123-4567")
print(f"Phone validation: {phone_valid}")
strict_validator = DataValidator.create_strict_validator()
print(f"Strict validator: {strict_validator}")
def demonstrate_deprecated_attributes():
print("\n=== Deprecated Attribute Usage Examples ===")
api_url = OLD_API_URL
timeout = OLD_TIMEOUT
retries = LEGACY_RETRIES
print(f"Using deprecated config - API URL: {api_url}")
print(f"Using deprecated config - Timeout: {timeout}")
print(f"Using deprecated config - Retries: {retries}")
old_endpoint = AppConfig.OLD_ENDPOINT
legacy_size = AppConfig.LEGACY_PAGE_SIZE
log_setting = AppConfig.OLD_LOG_SETTING
print(f"App config - Old endpoint: {old_endpoint}")
print(f"App config - Legacy page size: {legacy_size}")
print(f"App config - Log setting: {log_setting}")
ui_flag = FeatureFlags.OLD_UI_FLAG
beta_flag = FeatureFlags.LEGACY_BETA
print(f"Feature flags - UI: {ui_flag}, Beta: {beta_flag}")
debug_mode = DevConfig.OLD_DEBUG_MODE
dev_api = DevConfig.LEGACY_DEV_API
print(f"Dev config - Debug: {debug_mode}, API: {dev_api}")
def demonstrate_container_methods():
print("\n=== Deprecated Container Method Examples ===")
container = LegacyContainer(["apple", "banana", "cherry"])
size = container.size() string_rep = container.to_str()
print(f"Container size (deprecated method): {size}")
print(f"Container string (deprecated method): {string_rep}")
item = container.get_item(0) container.set_item(1, "blueberry") contains = container.contains("apple")
print(f"Got item (deprecated): {item}")
print(f"Contains apple (deprecated): {contains}")
smart_list = SmartList([1, 2, 3, 4, 5])
length = smart_list.length() count = smart_list.get_count() empty = smart_list.is_empty() has_item = smart_list.has_item(3)
print(f"SmartList length (deprecated): {length}")
print(f"SmartList count (deprecated): {count}")
print(f"SmartList is empty (deprecated): {empty}")
print(f"SmartList has item 3 (deprecated): {has_item}")
async def demonstrate_async_deprecation():
print("\n=== Deprecated Async Function Examples ===")
data1 = await old_fetch_data("https://api.example.com/users")
print(f"Old fetch result: {data1}")
json_data = await get_json("users/123")
print(f"Get JSON result: {json_data}")
upload_result = await legacy_upload("file.txt", "https://upload.example.com")
print(f"Legacy upload result: {upload_result}")
urls = ["https://api.example.com/data/1", "https://api.example.com/data/2"]
batch_results = await old_batch_fetch(urls, delay=0.5)
print(f"Batch fetch results: {len(batch_results)} items")
def demonstrate_comparisons():
print("\n=== Comparison: Old vs New API ===")
old_result = old_add(15, 25)
print(f"OLD: old_add(15, 25) = {old_result}")
new_result = add(15, 25)
print(f"NEW: add(15, 25) = {new_result}")
old_proc = OldDataProcessor("data.db", cache_size=10)
print(f"OLD: OldDataProcessor created with cache_size=10")
new_proc = DataProcessor("data.db", batch_size=20, enable_caching=True)
print(f"NEW: DataProcessor created with batch_size=20")
def main():
print("Dissolve Library - Consumer Example")
print("===================================")
print("This script demonstrates usage of deprecated functions that will")
print("generate deprecation warnings. Use 'dissolve migrate' to automatically")
print("update this code to use the new APIs.\n")
try:
demonstrate_deprecated_functions()
demonstrate_deprecated_classes()
demonstrate_class_and_static_methods()
demonstrate_deprecated_attributes()
demonstrate_container_methods()
print("\n=== Running Async Examples ===")
asyncio.run(demonstrate_async_deprecation())
demonstrate_comparisons()
print("\n=== Summary ===")
print("All examples completed! You should have seen multiple deprecation warnings.")
print("To migrate this code automatically, run:")
print(" dissolve migrate --write consumer/")
print("\nTo see what would be changed without writing files:")
print(" dissolve migrate consumer/")
print("\nTo check if migration is needed:")
print(" dissolve migrate --check consumer/")
except Exception as e:
print(f"Error running examples: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
main()