@@ -249,17 +249,24 @@ function extractPythonLandmarks(lines: string[]): Candidate[] {
249249
250250function pythonRoute ( lines : string [ ] , index : number ) : { method : string ; path : string ; handler ?: string ; signature : string ; endLine : number } | undefined {
251251 const trimmed = lines [ index ] . trim ( ) ;
252+ const handlerPattern = '([A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)?(?:\\([^)]*\\))?)' ;
252253 const decorator = trimmed . match ( / ^ @ \w + (?: \. \w + ) * \. ( g e t | p o s t | p u t | p a t c h | d e l e t e | r o u t e ) \( \s * [ ' " ] ( [ ^ ' " ] + ) [ ' " ] / ) ;
253254 if ( decorator ) return { method : decorator [ 1 ] . toUpperCase ( ) , path : decorator [ 2 ] , signature : trimmed , endLine : index + 1 } ;
254255
255- const addRoute = trimmed . match ( / (?: \w + \. ) ? r o u t e r \. a d d _ ( g e t | p o s t | p u t | p a t c h | d e l e t e | r o u t e ) \( \s * [ ' " ] ( [ ^ ' " ] + ) [ ' " ] \s * (?: , \s * ( [ A - Z a - z _ ] \w * (?: \. [ A - Z a - z _ ] \w * ) ? ) ) ? / ) ;
256+ const genericAddRoute = trimmed . match ( new RegExp ( `(?:\\w+\\.)?router\\.add_route\\(\\s*['"]([^'"]+)['"]\\s*,\\s*['"]([^'"]+)['"]\\s*,\\s*${ handlerPattern } ` ) ) ;
257+ if ( genericAddRoute ) return { method : genericAddRoute [ 1 ] . toUpperCase ( ) , path : genericAddRoute [ 2 ] , handler : genericAddRoute [ 3 ] , signature : trimmed , endLine : index + 1 } ;
258+
259+ const addRoute = trimmed . match ( new RegExp ( `(?:\\w+\\.)?router\\.add_(get|post|put|patch|delete)\\(\\s*['"]([^'"]+)['"]\\s*(?:,\\s*${ handlerPattern } )?` ) ) ;
256260 if ( addRoute ) return { method : addRoute [ 1 ] . toUpperCase ( ) , path : addRoute [ 2 ] , handler : addRoute [ 3 ] , signature : trimmed , endLine : index + 1 } ;
257261
258- const webRoute = trimmed . match ( / \b w e b \. ( g e t | p o s t | p u t | p a t c h | d e l e t e | r o u t e ) \( \s * [ ' " ] ( [ ^ ' " ] + ) [ ' " ] \s * (?: , \s * ( [ A - Z a - z _ ] \w * (?: \. [ A - Z a - z _ ] \w * ) ? ) ) ? / ) ;
262+ const genericWebRoute = trimmed . match ( new RegExp ( `\\bweb\\.route\\(\\s*['"]([^'"]+)['"]\\s*,\\s*['"]([^'"]+)['"]\\s*,\\s*${ handlerPattern } ` ) ) ;
263+ if ( genericWebRoute ) return { method : genericWebRoute [ 1 ] . toUpperCase ( ) , path : genericWebRoute [ 2 ] , handler : genericWebRoute [ 3 ] , signature : trimmed , endLine : index + 1 } ;
264+
265+ const webRoute = trimmed . match ( new RegExp ( `\\bweb\\.(get|post|put|patch|delete)\\(\\s*['"]([^'"]+)['"]\\s*(?:,\\s*${ handlerPattern } )?` ) ) ;
259266 if ( webRoute ) return { method : webRoute [ 1 ] . toUpperCase ( ) , path : webRoute [ 2 ] , handler : webRoute [ 3 ] , signature : trimmed , endLine : index + 1 } ;
260267
261268 const windowText = lines . slice ( index , Math . min ( lines . length , index + 8 ) ) . map ( ( line ) => line . trim ( ) ) . join ( ' ' ) ;
262- const multilineWeb = windowText . match ( / \ bw e b \. ( g e t | p o s t | p u t | p a t c h | d e l e t e | r o u t e ) \( \ s* [ ' " ] ( [ ^ ' " ] + ) [ ' " ] \s * , \s * ( [ A - Z a - z _ ] \w * (?: \. [ A - Z a - z _ ] \w * ) ? ) / ) ;
269+ const multilineWeb = windowText . match ( new RegExp ( `\\ bweb\\ .(get|post|put|patch|delete)\\(\\ s*['"]([^'"]+)['"]\\ s*,\\s* ${ handlerPattern } ` ) ) ;
263270 if ( multilineWeb ) return { method : multilineWeb [ 1 ] . toUpperCase ( ) , path : multilineWeb [ 2 ] , handler : multilineWeb [ 3 ] , signature : windowText , endLine : Math . min ( lines . length , index + 8 ) } ;
264271
265272 return undefined ;
0 commit comments