Skip to content

Refactor filename processing optimization#1242

Merged
AndreyNikiforov merged 14 commits intoicloud-photos-downloader:masterfrom
AndreyNikiforov:refactor/filename-processing-optimization
Sep 2, 2025
Merged

Refactor filename processing optimization#1242
AndreyNikiforov merged 14 commits intoicloud-photos-downloader:masterfrom
AndreyNikiforov:refactor/filename-processing-optimization

Conversation

@AndreyNikiforov
Copy link
Copy Markdown
Collaborator

No description provided.

AndreyNikiforov and others added 11 commits September 1, 2025 11:21
Update compile_tzlc.py to perform case insensitive comparison when
checking if timezone/locale compatibility test outputs match expected
content. This makes the compatibility tests more robust by handling
variations in capitalization that may occur across different systems.

Before: content not in expected_content (case sensitive)
After: content.lower() not in [c.lower() for c in expected_content] (case insensitive)

This prevents false negatives when version strings have different
capitalization (e.g., "Version:1.32.0" vs "version:1.32.0").

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…omposition

- Add string utility functions in src/foundation/string_utils.py
- Add predicate composition utilities in src/foundation/predicates.py
- Refactor lp_filename_concatinator to use functional composition
- Update authentication functions to use strip and strip_and_lower utilities
- Improve parse_mfa_provider with functional lookup pattern instead of if/elif chain
- Fix cross-platform path issues in issue icloud-photos-downloader#1220 test
- Separate pure transformations from I/O operations for better testability

All tests pass (201 passed, 3 skipped) with strict mypy validation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Remove empty else blocks that Pylance flagged as statically false conditions.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Refactor folder structure checks using compose(eq("none"), lower)
- Update password input handling with strip and strip_and_lower utilities
- Improve file extension checks with compose(endswith(...), lower)
- Enhance XMP sidecar logic with functional predicates
- Add tuple support to endswith utility for multiple extensions
- Replace imperative string checks with point-free composition

All 201 tests pass with strict mypy validation maintained.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
… composition

- Add replace_extension utility for filename transformations
- Refactor lp_filename_* functions to use functional composition patterns
- Extract pure validation functions from I/O operations in authentication
- Consolidate duplicate string utilities and improve import organization
- Separate side-effectful operations from pure business logic
- Enhance testability through functional decomposition

All tests pass, strict mypy validation successful, and code follows
point-free style patterns throughout high-priority areas.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Replace mock_lp_filename_generator with real lp_filename_concatinator function
- Replace simple_lp_filename_generator with lp_filename_original (identical functionality)
- Eliminate code duplication while maintaining identical behavior
- Tests continue to pass with the real functions instead of duplicated logic

Both simple_lp_filename_generator and lp_filename_original had identical logic:
just replace any file extension with .MOV for live photo handling.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…ssion

Add centralized connection error handling at the HTTP session level to provide
consistent error messages and behavior for all iCloud API requests.

Key changes:
- Add PyiCloudConnectionErrorException for standardized connection errors
- Implement handle_connection_error decorator to catch ConnectionError,
  TimeoutError, Timeout, and NewConnectionError
- Apply wrapper at PyiCloudSession.request() level for universal coverage
- Update core_single_run error handling to include new exception type
- Remove redundant connection error handling block in base.py

Testing:
- Add comprehensive integration test suite with real HTTP server
- Test all four connection exception types with mocking and real network conditions
- Update existing authentication tests to work with new session-level handling
- All 61 tests pass with new 7 integration tests added

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…sers

Replace generic "Invalid email/password combination." with actual exception
messages to provide better diagnostic information to users.

Changes:
- Use actual exception message instead of hardcoded generic message
- Apply to both logger output and WebUI error display
- Preserve original exception handling flow and error chaining

Benefits:
- Users see specific errors like "Invalid authentication token" or
  "Failed to initiate srp authentication" instead of generic message
- Better troubleshooting with actionable error information
- Maintains security as original messages are already user-safe

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…d parameters

• Create filename_policies.py with create_filename_builder() factory using partial_2_1
• Replace 12 instances of duplicated filename building code with single function
• Remove None optionality from file_match_policy and filename_cleaner parameters
• Eliminate redundant parameters from download_media function
• Fix parameter order bugs in delete function calls
• Update test assertions to match new function signatures

Performance improvements:
- Pre-configured filename builders eliminate repeated parameter passing
- No runtime None checks in hot paths with required parameters
- Better type safety with guaranteed non-None values
- Reduced function complexity by removing defensive programming branches

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
• Add explicit desired_item_type parameter to make function intent clearer
• Move photo parameter to last position for better partial application
• Replace reverse logic inference with direct desired type logic
• Update function calls to pass explicit AssetItemType.IMAGE/MOVIE values

Benefits:
- Clearer function signature expressing "skip message for desired type"
- No more reverse logic assumptions in implementation
- Better parameter ordering for functional composition
- More explicit and maintainable code

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
AndreyNikiforov and others added 3 commits September 1, 2025 22:18
• Change socket bind from ("", 0) to ("localhost", 0) in test helper
• Addresses security scanner warning about binding to all interfaces
• No functional change - test still finds available port correctly
• Follows security best practice of explicit interface binding

This fixes a false positive security warning while maintaining the same
test functionality for finding available ports.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…handling

- Use tempfile.gettempdir() instead of hardcoded '/tmp/' paths
- Ensures test compatibility across Windows, macOS, and Linux platforms
- Fixes FileNotFoundError on Windows systems

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Upgrade pytest-cov from 5.0.0 to 6.2.1 for Python 3.13 and coverage 7.x compatibility
- Remove coveralls==3.3.1 dependency as it's unused and conflicts with coverage 7.x
- Eliminates Python 3.13 deprecation warning: "co_lnotab is deprecated, use co_lines instead"
- Project uses local coverage reports only, no external coverage service integration

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@AndreyNikiforov AndreyNikiforov merged commit 52e1fcd into icloud-photos-downloader:master Sep 2, 2025
773 of 774 checks passed
@AndreyNikiforov AndreyNikiforov deleted the refactor/filename-processing-optimization branch September 2, 2025 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants