o nnh@stdZddlmZddlZddlZddlZddlZddlm Z dd d Z Gd d d Z GdddZ GdddZ dS)z#Diff parsing functions and classes.) annotationsN)ApplicationErrorlines list[str]returnlist[FileDiff]cCs t|jS)zgParse the given diff lines and return a list of FileDiff objects representing the changes of each file.) DiffParserfiles)rr F/usr/local/lib/python3.10/dist-packages/ansible_test/_internal/diff.py parse_diffs r c@s2eZdZdZdddZdd d Zedd dZdS)FileDiffzParsed diff for a single file.old_pathstrnew_pathrNonecCs,t|dd|_t|dd|_g|_d|_dS)NF)newT)DiffSideoldrheadersbinary)selfrrr r r __init__s zFileDiff.__init__linecCs|j|dS)z;Append the given line to the list of headers for this file.N)rappend)rrr r r append_headerszFileDiff.append_headerboolcCs|jjo|jjS).True if the diff is complete, otherwise False.)r is_completerrr r r r szFileDiff.is_completeN)rrrrrrrrrrrr)__name__ __module__ __qualname____doc__rrpropertyrr r r r rs   rc@sHeZdZdZddd Zdd dZdddZedddZddddZ dS) rz1Parsed diff for a single 'side' of a single file.pathrrrrrcCsP||_||_|jr dnd|_d|_d|_g|_g|_g|_d|_d|_ d|_ dS)N+-Tr) r(rprefix eof_newlineexistsrlines_and_contextranges_next_line_number_lines_remaining _range_start)rr(rr r r r)s zDiffSide.__init__ line_startint line_countcCs||_||_d|_dS)z%Set the starting line and line count.rN)r0r1r2)rr3r5r r r set_start8s zDiffSide.set_startrcCs|jdkr td|j|f}|drn||jr(|j||js'|j|_ntd|j||jd8_|jr^|j rC|j}n |drN|jd}nd}|r^|j |j|fd|_|jd7_dS)zAppend the given line.rzDiff range overflow. zUnexpected diff content prefix.rN) r1 Exceptionr0 startswithr+rrr2r.rr/)rrentry range_endr r r r>s.        zDiffSide.appendcCs |jdkS)rr)r1r r r r ras zDiffSide.is_completeTcontextrcs$|rj}nj}fdd|DS)zIFormat the diff and return a list of lines, optionally including context.cs$g|]}dj|d|dfqS)z %s:%4d %srr)r().0rr r r ms$z)DiffSide.format_lines..)r.r)rr<rr r r format_linesfszDiffSide.format_linesN)r(rrrrr)r3r4r5r4rrr!r")T)r<rrr) r#r$r%r&rr6rr'rr?r r r r r&s   # rc@sVeZdZdZdddZddd Zdd d Zdd d ZdddZdddZ dddZ dS)r zParse diff lines.rrrrc Cs||_g|_|j|_d|_d|_d|_d|_|jD]?|_|jd7_z|Wn*tyS}zt d ||j|jp>d|jpBdt f}t| dd}~ww|j|_q|dS)Nrrz %s Line: %d Previous: %s Current: %s %s )rr process_startaction line_number previous_linerfiler8textwrapdedentstrip traceback format_excr complete_file)rrexmessager r r rss4    zDiffParser.__init__cCsF|td|j}|stdt|d|d|_|j|_ dS)zProcess a diff start line.zD^diff --git "?(?:a/)?(?P.*)"? "?(?:b/)?(?P.*)"?$zUnexpected diff start line.rrN) rKresearchrr8rgrouprEprocess_continuerBrmatchr r r rAs  zDiffParser.process_startcCsvtd|j}|s td|jjt|dpdt|d|jj t|dp,dt|d|j |_ dS) zProcess a diff range line.zg^@@ -((?P[0-9]+),)?(?P[0-9]+) \+((?P[0-9]+),)?(?P[0-9]+) @@zUnexpected diff range line. old_startr old_count new_start new_countN) rNrOrr8rErr6r4rPrprocess_contentrBrRr r r process_ranges (( zDiffParser.process_rangecCs<|jdr |dS|jdr|dS|dS)z+Process a diff start, range or header line.zdiff z@@ N)rr9rArYprocess_headerr r r r rQs     zDiffParser.process_continuecCsZ|jdr d|j_dS|jdkrd|jj_dS|jdkr$d|jj_dS|j|jdS)zProcess a diff header line.z Binary files Tz --- /dev/nullFz +++ /dev/nullN)rr9rErrr-rrr r r r rZs    zDiffParser.process_headercCs|jdkr5|jdrd|jj_d|jj_dS|jdr$d|jj_dS|jdr1d|jj_dStd|jjr?| dS|jdrW|jj |j|jj |jdS|jdrg|jj |jdS|jdrw|jj |jdStd) zProcess a diff content line.z\ No newline at end of filer7Fr*r)z&Unexpected previous diff content line.NzUnexpected diff content line.) rrDr9rErr,rr8rrQrr r r r rXs.         zDiffParser.process_contentcCs|jsdS|j|jdS)z0Complete processing of the current file, if any.N)rEr rr r r r rKszDiffParser.complete_fileN)rrrr)rr) r#r$r%r&rrArYrQrZrXrKr r r r r ps  % r )rrrr)r& __future__rrNrFrItypingtutilrr rrr r r r r s   J