
    uYf                     T    d dl Z d dlZd dlmZ d dlmZ d dlmZ d Z G d de      Zy)    N)List)Optional)Tuplec                 h   d}| j                  d      }|dkD  xr |t        |       dz
  k7  }||rdndz  }| d   dk(  }| j                  d      }d}d}t        |      }|D ]  \  }	}
|r|t	        j
                  |
      z  }d}$|
dk(  rd	},|
d
k(  r|	dz   t        |      k  rw||	dz      d
k(  rl|	dk(  }|	dkD  xr ||	dz
     dk(  }|	dz   t        |      k(  }|	dz   t        |      k  xr ||	dz      dk(  }|s|r"|s|r|dz  }t        |d       t        |d       |dz  }|
dk(  r|dz  }|
dk(  rd	}||
z  }|
dk(  r#|r||
z  }d}|t	        j
                  |
      z  }|t	        j
                  |
      z  } |rt        dj                  |             ||rdndz  }t	        j                  |      S )a	  
    source https://github.com/sbdchd/codeowners/blob/c95e13d384ac09cfa1c23be1a8601987f41968ea/codeowners/__init__.py

    Copyright (c) 2019-2020 Steve Dignam

    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    "Software"), to deal in the Software without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:

    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

    ported from https://github.com/hmarr/codeowners/blob/d0452091447bd2a29ee508eebc5a79874fb5d4ff/match.go#L33

    MIT License

    Copyright (c) 2020 Harry Marr
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.
     /   z\Az(?:\A|/)F\T*r      z.*Nz[^/]*?z[^/][]z1unterminated character class in pattern {pattern})patternz(?:\Z|/))
findlenstrip	enumeratereescapenext
ValueErrorformatcompile)r   regex	slash_posanchoredmatches_dirpattern_trimmedin_char_classescapediteratorichleft_anchoredleading_slashright_anchoredtrailing_slashs                  [/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/ddtrace/internal/codeowners.pypath_to_regexr+      s   ^ ES!I2~?)s7|a/?"?H	hUK/E"+$KmmC(OMG)H "#2RYYr]"EG:G3Y1us?++A0F#0M !Q !A G/!a%*@C*G!"Q#o*>!>!"Q_)=!=!_/RSVWRWBX\_B_!]>TME4(4(WE3YVOE3Y MRKE3Y %2&RYYr]"EE"#H LSS\cSdee	KS[0E::e    c                   0    e Zd ZdZdZddZd	dZd Zd Zy)

CodeownerszMProvide interface to parse CODEOWNERS file and match a given path against it.)
CODEOWNERSz.github/CODEOWNERSzdocs/CODEOWNERSz.gitlab/CODEOWNERSNc                 n    |xs | j                  |      }||| _        g | _        | j                          y)zInitialize Codeowners object.

        :param path: path to CODEOWNERS file otherwise try to use any from known locations
        N)locationpathpatternsparse)selfr2   cwds      r*   __init__zCodeowners.__init__z   s4     )t}}S)DI

r,   c                     |xs t        j                         }| j                  D ]E  }t         j                  j	                  ||      }t         j                  j                  |      sC|c S  t        d      )z+Return the location of the CODEOWNERS file.zCODEOWNERS file not found)osgetcwdKNOWN_LOCATIONSr2   joinisfiler   )r5   r6   r1   r2   s       r*   r1   zCodeowners.location   s`      RYY[,, 	H77<<X.Dww~~d#	 455r,   c                    t        | j                        5 }g }|j                         D ]  }|j                         }|dk(  r|j	                  d      r+|j	                  d      r|j                  d      rN|j	                  d      r|j                  d      rq|j                         }t        |      dk  r|d   }|	 t        |      }|d	d D cg c]  }|s|	 }}|s|j                  ||f        |j                          || _        ddd       y# t        t        f$ r Y w xY wc c}w # 1 sw Y   yxY w)
z6Parse CODEOWNERS file and store the lines and regexes.r   #r   r   z^[r   r   Nr
   )openr2   	readlinesr   
startswithendswithsplitr   r+   r   
IndexErrorappendreverser3   )	r5   fr3   lineelementsr2   r   ownerownerss	            r*   r4   zCodeowners.parse   s@    $))_ $	%H 3zz|2:??3'??3'DMM#,>??4(T]]3-?::<x=1${<+D1G .6ab\CEU%CC& 12?3B $DMI$	% $	%4 #J/  D;$	% $	%sB   B+D5DD5D0D0 1D5D-)D5,D--D55D>c                     | j                   D ]  \  }}|j                  |      s|c S  t        dj                  |            )zReturn code owners for a given path.

        :param path: path to check
        :return: list of file code owners identified by the given path
        zno code owners found for {path})r2   )r3   searchKeyErrorr   )r5   r2   r   rL   s       r*   ofzCodeowners.of   sH      $}} 	OGV~~d#	 8??T?JKKr,   )NN)N)	__name__
__module____qualname____doc__r;   r7   r1   r4   rP    r,   r*   r.   r.   p   s"    WO
6'%R
Lr,   r.   )	r9   r   typingr   r   r   r+   objectr.   rU   r,   r*   <module>rX      s+    	 	   ePSL SLr,   