
    ?d                         d Z ddlmZmZmZ ddlZddlZddlZddlZddl	Z	e	j                  j                  dk\  rddlmZ nddlmZ d Zedk(  r e        yy)	a.  
This script reads input from a unified diff and reformats all the changed
lines. This is useful to reformat all the lines touched by a specific patch.
Example usage for git/svn users:

  git diff -U0 --no-color --relative HEAD^ | yapf-diff -i
  svn diff --diff-cmd=diff -x-U0 | yapf-diff -p0 -i

It should be noted that the filename contained in the diff is used unmodified
to determine the source file to update. Users calling this script directly
should be careful to ensure that the path in the diff is correct relative to the
current working directory.
    )absolute_importdivisionprint_functionN   )StringIO)BytesIOc            	         t        j                  t        t         j                        } | j	                  ddddd       | j	                  dd	d
dd       | j	                  ddd d       | j	                  dddd       | j	                  dddd       | j	                  dd       | j	                  ddd       | j                         }d }i }t        j                  D ]I  }t        j                  d|j                  z  |      }|r|j                  d       }|=|j                  $t        j                  d!|j                  z  |      s4mt        j                  d!|j                  z  |t        j                        st        j                  d"|      }|st!        |j                  d            }d}|j                  d#      rt!        |j                  d#            }|d$k(  r||z   dz
  }|j#                  |g       j%                  d%t'        |      d&z   t'        |      z   g       L |j)                         D ]  \  }}	|j*                  r&|j,                  rt/        d'j1                  |             |j2                  |g}
|j*                  r|
j5                  d       |
j%                  |	       |j6                  r|
j%                  d|j6                  g       t9        j:                  |
t8        j<                  d t8        j<                  d()      }|j?                         \  }}|j@                  d$k7  rt        jB                  |j@                         |j*                  r#tE        |      5 }|jG                         }d d d        tI        |      jG                         }tK        jL                  |||d*d+      }d,jO                  |      }tQ        |      d$kD  st        jR                  jU                  |        y # 1 sw Y   xY w)-N)descriptionformatter_classz-iz
--in-place
store_trueFz1apply edits to files instead of displaying a diff)actiondefaulthelpz-pz--prefixNUM   z.strip the smallest prefix containing P slashes)metavarr   r   z--regexPATTERNzScustom pattern selecting file paths to reformat (case sensitive, overrides -iregex)z--iregexz.*\.(py)zXcustom pattern selecting file paths to reformat (case insensitive, overridden by -regex)z-vz	--verbosez'be more verbose, ineffective without -i)r   r   z--stylea  specify formatting style: either a style name (for example "pep8" or "google"), or the name of a file with style settings. The default is pep8 unless a .style.yapf or setup.cfg file located in one of the parent directories of the source file (or current directory for stdin))r   z--binaryyapfz"location of binary to use for yapf)r   r   z^\+\+\+\ (.*?/){%s}(\S*)   z^%s$z^@@.*\+(\d+)(,(\d+))?r   r   z--lines-zFormatting {}T)stdoutstderrstdinuniversal_newlinesz(before formatting)z(after formatting) )+argparseArgumentParser__doc__RawDescriptionHelpFormatteradd_argument
parse_argssysr   researchprefixgroupregexmatchiregex
IGNORECASEint
setdefaultextendstritemsin_placeverboseprintformatbinaryappendstyle
subprocessPopenPIPEcommunicate
returncodeexitopen	readlinesr   difflibunified_diffjoinlenr   write)parserargsfilenamelines_by_fileliner(   
start_line
line_countend_linelinescommandpr   r   fcodeformatted_codediffdiff_strings                      F/usr/lib/python3/dist-packages/yapf/third_party/yapf_diff/yapf_diff.pymainrU   )   s   ""8+O+OQ&
>  @ 	
;  = 	,	  - 	1	  2 	
4	  6
 	   	&'K  M				$ (-ii >dII1DKK?FEQhzzXXftzz)84XXft{{*HbmmDII.5Eu{{1~&jj	QQ(
	qj(1,hx,33c*o+c(m;
<>->4 ',,. &oh}}O""8,-{{H%G}}nnTNN5zznni,-oo	!A ]]_NFF||q	hhq||==> Q{{}'113n!!$("79MOdGGDMk	[	A	

%7&( s   +O;;P	__main__)r   
__future__r   r   r   r   r?   r#   r7   r"   version_infomajorior   r   rU   __name__     rT   <module>r^      sW    A @   	  
Q$d&N z& r]   