o
    iό                  
   @   s.  d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dZd	eeeZ
dd	lZdd	lZdd	lZdd	lZdd	lZdd	lZG d
d deZi ddgddgdg dddgddgddgdg ddg dddgdddgddgddgdddgdddgdddgd ddgd!dged"d#fd$gd%gd&ZG d'd( d(eZed)ejZd*d+ Zeji ddg ddd	d	d	f
d,d)Zd-ZG d.d/ d/eZd	ad0d1 Zze W n e y   d2d3 ZY nw ze! W n e y   d9d4d5Z!Y nw d9d6d7Z"e#d8krej$d Z%e&e"ej$ d	S d	S ):a  
    Preprocess a file.

    Command Line Usage:
        preprocess [<options>...] <infile>

    Options:
        -h, --help      Print this help and exit.
        -V, --version   Print the version info and exit.
        -v, --verbose   Give verbose output for errors.

        -o <outfile>    Write output to the given file instead of to stdout.
        -f, --force     Overwrite given output file. (Otherwise an IOError
                        will be raised if <outfile> already exists.
        -D <define>     Define a variable for preprocessing. <define>
                        can simply be a variable name (in which case it
                        will be true) or it can be of the form
                        <var>=<val>. An attempt will be made to convert
                        <val> to an integer so "-D FOO=0" will create a
                        false value.
        -I <dir>        Add an directory to the include path for
                        #include directives.

        -k, --keep-lines    Emit empty lines for preprocessor statement
                        lines and skipped output lines. This allows line
                        numbers to stay constant.
        -s, --substitute    Substitute defines into emitted lines. By
                        default substitution is NOT done because it
                        currently will substitute into everything, e.g.,
                        program strings.
        -c, --content-types-path <path>
                        Specify a path to a content.types file to assist
                        with filetype determination. See the
                        `_gDefaultContentTypes` string in this file for
                        details on its format.

    Module Usage:
        from preprocess import preprocess
        preprocess(infile, outfile=sys.stdout, defines={}, force=0,
                   keepLines=0, includePath=[], substitute=0,
                   contentType=None)

    The <infile> can be marked up with special preprocessor statement lines
    of the form:
        <comment-prefix> <preprocessor-statement> <comment-suffix>
    where the <comment-prefix/suffix> are the native comment delimiters for
    that file type.


    Examples
    --------

    HTML (*.htm, *.html) or XML (*.xml, *.kpf, *.xul) files:

        <!-- #if FOO -->
        ...
        <!-- #endif -->

    Python (*.py), Perl (*.pl), Tcl (*.tcl), Ruby (*.rb), Bash (*.sh),
    or make ([Mm]akefile*) files:

        # #if defined('FAV_COLOR') and FAV_COLOR == "blue"
        ...
        # #elif FAV_COLOR == "red"
        ...
        # #else
        ...
        # #endif

    C (*.c, *.h), C++ (*.cpp, *.cxx, *.cc, *.h, *.hpp, *.hxx, *.hh),
    Java (*.java), PHP (*.php) or C# (*.cs) files:

        // #define FAV_COLOR 'blue'
        ...
        /* #ifndef FAV_COLOR */
        ...
        // #endif

    Fortran 77 (*.f) or 90/95 (*.f90) files:

        C     #if COEFF == 'var'
              ...
        C     #endif

    And other languages.


    Preprocessor Syntax
    -------------------

    - Valid statements:
        #define <var> [<value>]
        #undef <var>
        #ifdef <var>
        #ifndef <var>
        #if <expr>
        #elif <expr>
        #else
        #endif
        #error <error string>
        #include "<file>"
        #include "<file>" fromto: from-regex@to-regex
        #include "<file>" fromto_: from-regex@to-regex
        #include <var>
      where <expr> is any valid Python expression.

    - About #include with from/to regex: fromto: means that the line
      with to-regex is not inclued, while fromto_: means that it is
      included. Note that from-regex and to-regex must be valid
      regular expressions. The to-regex can be left out (but the
      @ delimiter must be kept), meaning that everything from from-regex
      to the end of the file is included.

    - The expression after #if/elif may be a Python statement. It is an
      error to refer to a variable that has not been defined by a -D
      option or by an in-content #define.

    - Special built-in methods for expressions:
        defined(varName)    Return true if given variable is defined.


    Tips
    ----

    A suggested file naming convention is to let input files to
    preprocess be of the form <basename>.p.<ext> and direct the output
    of preprocess to <basename>.<ext>, e.g.:
        preprocess -o foo.py foo.p.py
    The advantage is that other tools (esp. editors) will still
    recognize the unpreprocessed file as the original language.
    cmp)map)str)range)object)   r   r   .Nc                   @   s   e Zd ZdddZdd ZdS )PreprocessErrorNc                 C   s2   t || _|| _|| _|| _t| |||| d S N)r   errmsgfilelinenoline	Exception__init__)selfr   r   r   r    r   N/var/www/Credit_scoring_API/venv310/lib/python3.10/site-packages/preprocess.pyr      s
   
zPreprocessError.__init__c                 C   sb   d}| j d ur|| j d 7 }| jd ur|t| jd 7 }| j d us&| jd ur*|d7 }|| j7 }|S )N : )r   r   r   r   )r   sr   r   r   __str__   s   


zPreprocessError.__str__NNN)__name__
__module____qualname__r   r   r   r   r   r   r
      s    
r
   Python#r   PerlPHP)z/*z*/z//r   r   RubyTclZShellXML))z<!--z-->r#   r$   HTMLMakefile
JavaScriptr#   r$   CSSCzC++JavazC#IDLTextz^[a-zA-Z*$]\s*r   )!r   )%r   )FortranTeXc                   @   s   e Zd Zed\ZZZZZde	j
fddZdd Zdd Zd	d
 Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ ZdS )%_Logger   Nc                 C   sP   || _ |d u r| j| _n|| _t|tkr t|d| _d| _d S || _d| _d S )Nw   r   )_nameWARNleveltypebytesopenstream_opennedStream)r   namer:   ZstreamOrFileNamer   r   r   r      s   


z_Logger.__init__c                 C   s   | j r
| j  d S d S r   )r?   r>   closer   r   r   r   __del__   s   z_Logger.__del__c                 C   s   | j S r   r:   rB   r   r   r   getLevel   s   z_Logger.getLevelc                 C   s
   || _ d S r   rD   r   r:   r   r   r   setLevel      
z_Logger.setLevelc              
   C   s*   | j d| jd| jd| jd| jdi}|| S )NDEBUGINFOr9   ERRORCRITICAL)rI   rJ   r9   rK   rL   )r   r:   ZlevelNameMapr   r   r   _getLevelName   s   z_Logger._getLevelNamec                 C   s
   || j kS r   rD   rF   r   r   r   	isEnabled   rH   z_Logger.isEnabledc                 C      |  | jS r   )rN   rI   rB   r   r   r   isDebugEnabled       z_Logger.isDebugEnabledc                 C   rO   r   )rN   rJ   rB   r   r   r   isInfoEnabled   rQ   z_Logger.isInfoEnabledc                 C   rO   r   )rN   r9   rB   r   r   r   isWarnEnabled   rQ   z_Logger.isWarnEnabledc                 C   rO   r   )rN   rK   rB   r   r   r   isErrorEnabled   rQ   z_Logger.isErrorEnabledc                 C   rO   r   )rN   FATALrB   r   r   r   isFatalEnabled   rQ   z_Logger.isFatalEnabledc                 G   sP   || j k rd S d| j| | f }|||  d }| j| | j  d S )Nz%s: %s: 
)r:   r8   rM   lowerr>   writeflush)r   r:   msgargsmessager   r   r   log   s   
z_Logger.logc                 G      | j | j|g|R   d S r   )r^   rI   r   r[   r\   r   r   r   debug      z_Logger.debugc                 G   r_   r   )r^   rJ   r`   r   r   r   info  rb   z_Logger.infoc                 G   r_   r   )r^   r9   r`   r   r   r   warn  rb   z_Logger.warnc                 G   r_   r   )r^   rK   r`   r   r   r   error  rb   z_Logger.errorc                 G   r_   r   )r^   rL   r`   r   r   r   fatal  rb   z_Logger.fatal)r   r   r   r   rI   rJ   r9   rK   rL   sysstderrr   rC   rE   rG   rM   rN   rP   rR   rS   rT   rV   r^   ra   rc   rd   re   rf   r   r   r   r   r4      s&    	r4   
preprocessc              
      s   zt | d fddi }W nJ tyX } z>t|}|drA|drA|tdtd  }| d| dkr@|d||f 7 }n	|d	rJd
|  }t| d  d d}~ww t	d| |  |S )zEvaluate the given expression string with the given context.

    WARNING: This runs eval() on a user string. This is unsafe.
    Zdefinedc                    s   |  v S r   r   )vdefinesr   r   <lambda>  s    z_evaluate.<locals>.<lambda>zname 'z' is not definedzdefined(%s)z< (perhaps you want "defined('%s')" instead of "defined(%s)")zinvalid syntaxzinvalid syntax: '%s'__FILE____LINE__Nzevaluate %r -> %s (defines=%r))
evalr   r   
startswithendswithlenfindr
   r^   ra   )exprrl   rvexr[   ZvarNamer   rk   r   	_evaluate  s$   
ry   c           2      C   st	  t | tr| \} }}}nd\}}}|
du rg }
td| |||||||
	 tjtj| }||
v r3	 |
tj|  |du rW|	pDt	 }|
| }|du rWd}td| | zt| }W n tyl   td|| f w g d}g }|D ]6}|D ]1\}}t|dr|j}nd	t| }||7 }t|dr||j7 }n	|d
t| 7 }|| qyqudd |D }t| d}| }|durd}d}tt|D ]&}t||| r|}|dkr|dkrt||| r|r|n|d } nq|dkr||d }n|||d  }|  t |ttfr,|r&tj|r&t|d t| t|d}n|}| |d< td\}}|ddfg} d}!|D ]I}"|!d7 }!td|!|" |!|d< |D ]}#|#|"}$|$rb nqVd}$|$r!|$ d}%td|%|  |%dkr| r| d d |ks|$ dd\}&}'|'du rd}'n|'|v r||' }'nzt!|'i i }'W n   Y |'||&< n^|%dkr| r| d d |ks|$ d}&z||&= W nA ty   Y n7w n4|%dkr| r| d d |ksd|$" v r|$ d}&||& }(n:|$ d}(d })}*d |$" v r9|$ d d!\})}*|)d"krd#}nd$}z	|*#d%\}}W n t$y8   td&|) w |rTt%t&|td'D ]}+||+ },|('|+t|,}(qDtj(| g| D ]}-tjtj)|-|(}.tj|.rs n
q]td(|(|f |)dur|.|||f}.t*|.||||||||	|
d)
}ny|%d*v r|%d+kr|$ d,}/n|%d-krd.|$ d, }/n|%d/krd0|$ d, }/z/| r| d d |kr| |ddf nt+|/|r| |ddf n| |ddf W n  ty   td1|% |d |d |"w |%d2krt|$ d,}/zP| d d r#td3|d |d |"| d d r2|ddf| d< n-| dd rJ| d4 d |krJ|ddf| d< nt+|/|rX|ddf| d< n|ddf| d< W n t,ys   td5|d |d |"w |%d6krzB| d d rtd7|d |d |"| d d r|ddf| d< n| dd r| d4 d |kr|ddf| d< n|ddf| d< W nU t,y   td8|d |d |"w |%d9krz| -  W n6 t,y   td:|d |d |"w |%d;kr| r| d d |ks|$ d;}0td<|0 |d |d |"td=|  |r|.d> qBzY| d d |krYtd?| d d   |"}1|rSt%t&|td'D ]}+||+ },|1'|+t|,}1qC|.|1 n|rmtd@| d d   |.d> ntdA| d d   W qB t,y   tdB|d |d w t| dkrtdC|d |d t| dk rtdD|d |d ||kr|  |S )Ea  Preprocess the given file.

    "infile" is the input path, either a string (the whole file),
        or a tuple (filename, from_, to_, last_to_line) that defines
        the lines in filename from from_ to to_, but not include to_
        if last_to_line is False. from_ and to_ are treated as
        regular expressions.
    "outfile" is the output path or stream (default is sys.stdout).
    "defines" is a dictionary of defined variables that will be
        understood in preprocessor statements. Keys must be strings and,
        currently, only the truth value of any key's value matters.
    "force" will overwrite the given outfile if it already exists. Otherwise
        an IOError will be raise if the outfile already exists.
    "keepLines" will cause blank lines to be emitted for preprocessor lines
        and content lines that would otherwise be skipped.
    "includePath" is a list of directories to search for given #include
        directives. The directory of the file being processed is presumed.
    "substitute", if true, will allow substitution of defines into emitted
        lines. (NOTE: This substitution will happen to anything, e.g.,
        within program strings, and this may not be what you expect!)
    "include_substitute", if true, will allow substitution of defines into
        #include statements.
    "contentType" can be used to specify the content type of the input
        file. It not given, it will be guessed.
    "contentTypesRegistry" is an instance of ContentTypesRegistry. If not specified
        a default registry will be created.
    "__preprocessedFiles" (for internal use only) is used to ensure files
        are not recusively preprocessed.

    Returns the modified dictionary of defines or raises PreprocessError if
    there was some problem.
    r   Nz}preprocess(infile=%r, outfile=%r, defines=%r, force=%r, keepLines=%r, includePath=%r, contentType=%r, __preprocessedFiles=%r)r/   z(defaulting content type for '%s' to '%s'z?don't know comment delimiters for content type '%s' (file '%s'))z0#\s*(?P<op>if|elif|ifdef|ifndef)\s+(?P<expr>.*?)z#\s*(?P<op>else|endif)z"#\s*(?P<op>error)\s+(?P<error>.*?)z7#\s*(?P<op>define)\s+(?P<var>[^\s]*?)(\s+(?P<val>.+?))?z$#\s*(?P<op>undef)\s+(?P<var>[^\s]*?)zL#\s*(?P<op>include) +"(?P<fname>.*?)" +(?P<fromto>fromto_?):\s+(?P<part>.+
)z&#\s*(?P<op>include)\s+"(?P<fname>.*?)"z&#\s*(?P<op>include)\s+(?P<var>[^\s]+?)patternz	^\s*%s\s*z	\s*%s\s*$c                 S   s   g | ]}t |qS r   )recompile).0pr   r   r   
<listcomp>  s    zpreprocess.<locals>.<listcomp>rrn   r   r7   i  r6   ro   r   r   zline %d: %rrp   opz%r stmt (states: %r)ZdefinevarvalZundefincludefnamefromtopartZfromto_TF@z3Wrong syntax, need #include %s: from-regex@to-regex)keyz7could not find #include'd file "%s" on include path: %r)contentTypesRegistry__preprocessedFiles)ififdefifndefr   rv   r   zdefined('%s')r   znot defined('%s')z%use of undefined variable in #%s stmtelifz+illegal #elif after #else in same #if blockz##elif stmt without leading #if stmtelsez+illegal #else after #else in same #if blockz##else stmt without leading #if stmtendifz##endif stmt without leading #ifstmtre   z#error: z
states: %rrW   zemit line (%s)zkeep blank line (%s)zskip line (%s)z#superfluous #endif before this linezunterminated #if blockz)superfluous #endif on or before this line)/
isinstancetupler^   rc   ospathnormpathabspathappendgetDefaultContentTypesRegistrygetContentTyperd   _commentGroupsKeyErrorr
   hasattrrz   r{   escaper=   	readlinesr   rt   searchrA   r   r<   existschmodremovera   matchgrouprq   	groupdictsplit
ValueErrorreversedsortedreplacedirnamejoinri   ry   
IndexErrorpoprY   )2infileoutfilerl   force	keepLinesincludePath
substituteinclude_substitutecontentTyper   r   Zfrom_Zto_Zlast_to_lineZ	absInfileregistryZcgsZstmtspatternsstmtZcprefixZcsuffixrz   ZstmtResZfinlinesZ	from_lineZto_lineiZfoutZSKIPZEMITZstatesZlineNumr   ZstmtRer   r   r   r   fr   r   r@   valuedr   rv   re   sliner   r   r   ri   /  s  
%


	


























 
 





a	  
    # Default file types understood by "preprocess.py".
    #
    # Format is an extension of 'mime.types' file syntax.
    #   - '#' indicates a comment to the end of the line.
    #   - a line is:
    #       <filetype> [<pattern>...]
    #     where,
    #       <filetype>'s are equivalent in spirit to the names used in the Windows
    #           registry in HKCR, but some of those names suck or are inconsistent;
    #           and
    #       <pattern> is a suffix (pattern starts with a '.'), a regular expression
    #           (pattern is enclosed in '/' characters), a full filename (anything
    #           else).
    #
    # Notes on case-sensitivity:
    #
    # A suffix pattern is case-insensitive on Windows and case-sensitive
    # elsewhere.  A filename pattern is case-sensitive everywhere. A regex
    # pattern's case-sensitivity is defined by the regex. This means it is by
    # default case-sensitive, but this can be changed using Python's inline
    # regex option syntax. E.g.:
    #         Makefile            /^(?i)makefile.*$/   # case-INsensitive regex

    Python              .py
    Python              .pyw
    Perl                .pl
    Ruby                .rb
    Tcl                 .tcl
    XML                 .xml
    XML                 .kpf
    XML                 .xul
    XML                 .rdf
    XML                 .xslt
    XML                 .xsl
    XML                 .wxs
    XML                 .wxi
    HTML                .htm
    HTML                .html
    XML                 .xhtml
    Makefile            /^[Mm]akefile.*$/
    PHP                 .php
    JavaScript          .js
    CSS                 .css
    C++                 .c       # C++ because then we can use //-style comments
    C++                 .cpp
    C++                 .cxx
    C++                 .cc
    C++                 .h
    C++                 .hpp
    C++                 .hxx
    C++                 .hh
    IDL                 .idl
    Text                .txt
    Fortran             .f
    Fortran             .f90
    Shell               .sh
    Shell               .csh
    Shell               .ksh
    Shell               .zsh
    Java                .java
    C#                  .cs
    TeX                 .tex

    # Some Komodo-specific file extensions
    Python              .ksf  # Fonts & Colors scheme files
    Text                .kkf  # Keybinding schemes files
c                   @   s4   e Zd ZdZdddZdd ZdddZd	d
 ZdS )ContentTypesRegistryzA class that handles determining the filetype of a given path.

    Usage:
        >>> registry = ContentTypesRegistry()
        >>> registry.getContentType("foo.py")
        "Python"
    Nc                 C   s   || _ |   d S r   )contentTypesPaths_load)r   r   r   r   r   r     s   zContentTypesRegistry.__init__c                 C   s   ddl m}m}m} i | _i | _i | _| t ||t	d}||r4t
d|  | t|d  | jp8g D ]}t
d|  | t|d  q9d S )Nr   )r   r   r   zcontent.typeszload content types file: `%r'r   )Zos.pathr   r   r   	suffixMapregexMapfilenameMap_loadContentType_gDefaultContentTypes__file__r^   ra   r=   readr   )r   r   r   r   ZlocalContentTypesPathr   r   r   r   r     s   
zContentTypesRegistry._loadc           	   	   C   s   | dD ]x}|  }tt|D ]}|| d dkr$||d=  nq|s(q|d |dd }}|sG|d dkrA|dd }td| |D ]3}|dr`tjd	rZ|	 }|| j
|< qI|d
rw|d
rw|| jt|dd < qI|| j|< qIqdS )zReturn the registry for the given content.types file.

        The registry is three mappings:
            <suffix> -> <content type>
            <regex> -> <content type>
            <filename> -> <content type>
        r   r    Nr7   rn   rW   zBbogus content.types line, there must be one or more patterns: '%s'r	   win/)
splitlinesstripr   r   rt   r
   rr   rg   platformrX   r   rs   r   r{   r|   r   )	r   contentr   r   wordsr   r   r   rz   r   r   r   r     s0   

z%ContentTypesRegistry._loadContentTypec                 C   s   t j|}d}|s|| jv r| j| }td|| |sFd|v rFd|dd  }tj	dr4|
 }|| jv rF| j| }td||| |sd| j D ]\}}||rc|}td|||j  nqMt|d }|	d	rrd
}|S )zReturn a content type for the given path.

        @param path {str} The path of file for which to guess the
            content type.
        @returns {str|None} Returns None if could not determine the
            content type.
        Nz9Content type of '%s' is '%s' (determined from full path).r	   rn   r   z;Content type of '%s' is '%s' (determined from suffix '%s').z1Content type of '%s' is '%s' (matches regex '%s')rbs   <?xmlr'   )r   r   basenamer   r^   ra   r   rg   r   rr   rX   r   r   itemsr   rz   r=   r   )r   r   r   r   suffixregexctyper   r   r   r   r     s:   




z#ContentTypesRegistry.getContentTyper   )r   r   r   __doc__r   r   r   r   r   r   r   r   r     s    

r   c                   C   s   t d u rt a t S r   )_gDefaultContentTypesRegistryr   r   r   r   r   r   )  s   r   c                 c   s&    t | }|  |D ]}|V  qd S r   )listreverse)seqZrseqitemr   r   r   r   7  s   r   c                 #   s@    dd }|p| t | }| fdd |D ]}|V  qd S )Nc                 S   s   | S r   r   )xr   r   r   rm   B  s    zsorted.<locals>.<lambda>c                    s   t  |  |S r   r   )r   otherZkey_funcr   r   rm   E  s    )r   sort)r   r   identityZsseqr   r   r   r   r   A  s   r   c                 C   sl  | d u rt j} zt| dd  dg d\}}W n$ tjy< } zt jd|| f  t jd W Y d }~dS d }~ww t j}i }d}d}d}d}	g }
g }|D ]\}}|dv rat jt  dS |dv rpt jd	t   dS |d
v r{t	
t	j n|dkr|}|dv rd}qP|dkr|ddkr|dd\}}zt|}W n ty   Y nw |d }}|||< qP|dv rd}qP|dkr|
| qP|dv rd}qP|dv rd}	qP|dv r|| qPt|dkrt jd|   dS |d }zt|}t||||||
||	|d	 W d S  ty5 } z"t	 r dd l}|jt jd n
t jdt|  W Y d }~dS d }~ww )Nr7   zhVvo:D:fkI:sic:)helpversionverboser   z
keep-linesr   r   zcontent-types-path=z/preprocess: error: %s. Your invocation was: %s
zSee 'preprocess --help'.
r   )z-hz--help)z-Vz	--versionzpreprocess %s
)z-vz	--verbosez-o)z-fz--forcez-D=rn   )z-kz--keep-linesz-I)z-sz--substitute)z-iz--include_substitute)z-cz--content-types-pathz:preprocess: error: incorrect number of arguments: argv=%r
)r   )r   zpreprocess: error: %s
)rg   argvgetoptGetoptErrorrh   rY   stdoutr   __version__r^   rG   rI   ru   r   intr   r   rt   r   ri   r
   rP   	traceback	print_excr   )r   Zoptlistr\   r[   r   rl   r   r   r   r   r   r   optZoptargr   r   r   r   rx   r   r   r   r   mainL  s   



r   __main__r   )'r   Zpast.builtinsr   builtinsr   r   r   r   __version_info__r   r   r   rg   r   typesr{   pprintr   r
   r|   r   r4   r9   r^   ry   r   ri   r   r   r   r   r   	NameErrorr   r   r   r   r   exitr   r   r   r   <module>   s    	
7
  SEc


J
