CodeVetter · Repo Unpack · Behavior traces
pallets/werkzeug
The investigation followed development startup, URL creation and persistence, short-link resolution, multipart parsing, file serving, and test-client execution through their actual call sites. Each trace records execution order and meaningful failure branches. These are source-level walkthroughs, not runtime observations. The Redis-backed example provides the clearest complete application flow.
- Startup: Shortly.create_app constructs Shortly, optionally wraps wsgi_app with SharedDataMiddleware, then its __main__ block calls run_simple with debugger and reloader enabled.
- Server startup continues through run_simple → optional DebuggedApplication → make_server → socket inheritance and WERKZEUG_SERVER_FD assignment → run_with_reloader or serve_forever; threaded plus multiple processes is rejected.
- Create-link flow: Shortly.__call__ → wsgi_app → Request → dispatch_request → bind_to_environ → match → on_new_url; valid POST input calls insert_url and redirects to details, while an invalid scheme re-renders the form.
- Persistence flow: insert_url first reads reverse-url:<url>; an existing mapping is reused, otherwise Redis INCR last-url-id → base36_encode → SET url-target:<id> → SET reverse-url:<url> establishes the new mapping.
- Follow-link flow: routing calls on_follow_short_link → Redis GET target → NotFound if absent, otherwise INCR click-count → redirect; dispatch_request turns NotFound into error_404 and Response emits the final WSGI output.
- Upload flow: Request.form → _load_form_data → _parse_form_data → FormDataParser.parse → _parse_multipart → MultiPartParser.parse → MultipartDecoder events; files become FileStorage and parser failures close streams through its context manager.
- Download flow: send_from_directory → safe_join → regular-file check → send_file → open/stat → wrap_file and Response → apply_conditions → apply_range; conditional-processing errors close the response before propagating.
- Test-client flow: Client.open obtains a Request from EnvironBuilder, calls Client.run_wsgi_app to attach and update cookies, constructs TestResponse, and optionally follows redirects while closing intermediate responses and detecting loops.