
    g                        d dl 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d dlZd dlZd dl	Z	d dl
mZ dag ad$dZd%dZ G d de      Z ej$                  d      Zd Z ej$                  d	      Zd
 Z ej$                  d      Zd Zd Zd Zd Zd Z G d d      Z G 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 Z&d Z'd Z( G d d       Z)d*d!Z*d" Z+d# Z,y)+    N)ElementTreec                     t        d| ddg|dg      a|,t        |t              r|j	                         }t        |      ayy)a  
    Configure nltk's java interface, by letting nltk know where it can
    find the Java binary, and what extra options (if any) should be
    passed to Java when it is run.

    :param bin: The full path to the Java binary.  If not specified,
        then nltk will search the system for a Java binary; and if
        one is not found, it will raise a ``LookupError`` exception.
    :type bin: str
    :param options: A list of options that should be passed to the
        Java binary when it is called.  A common value is
        ``'-Xmx512m'``, which tells Java binary to increase
        the maximum heap size to 512 megabytes.  If no options are
        specified, then do not modify the options list.
    :type options: list(str)
    javaJAVAHOME	JAVA_HOMEzjava.exe)env_varsverbosebinary_namesN)find_binary	_java_bin
isinstancestrsplitlist_java_options)binoptionsr	   s      C/var/www/openai/venv/lib/python3.12/site-packages/nltk/internals.pyconfig_javar      sO    $ k* \I gs#mmoGW     c                    t         j                  t         j                  t         j                  d}|j	                  ||      }|j	                  ||      }|j	                  ||      }t        | t              rt        d      t        
t                t        |t              r|g}nt        |      }t        j                  j                  j                  |      }t        |       } d|g| z   } t        gt        z   | z   } t        j                   | |||      }|s|S |j#                         \  }}|j$                  dk7  r+t'        t)        |             t+        dt        |       z         ||fS )aa  
    Execute the given java command, by opening a subprocess that calls
    Java.  If java has not yet been configured, it will be configured
    by calling ``config_java()`` with no arguments.

    :param cmd: The java command that should be called, formatted as
        a list of strings.  Typically, the first string will be the name
        of the java class; and the remaining strings will be arguments
        for that java class.
    :type cmd: list(str)

    :param classpath: A ``':'`` separated list of directories, JAR
        archives, and ZIP archives to search for class files.
    :type classpath: str

    :param stdin: Specify the executed program's
        standard input file handles, respectively.  Valid values are ``subprocess.PIPE``,
        an existing file descriptor (a positive integer), an existing
        file object, 'pipe', 'stdout', 'devnull' and None.  ``subprocess.PIPE`` indicates that a
        new pipe to the child should be created.  With None, no
        redirection will occur; the child's file handles will be
        inherited from the parent.  Additionally, stderr can be
        ``subprocess.STDOUT``, which indicates that the stderr data
        from the applications should be captured into the same file
        handle as for stdout.

    :param stdout: Specify the executed program's standard output file
        handle. See ``stdin`` for valid values.

    :param stderr: Specify the executed program's standard error file
        handle. See ``stdin`` for valid values.


    :param blocking: If ``false``, then return immediately after
        spawning the subprocess.  In this case, the return value is
        the ``Popen`` object, and not a ``(stdout, stderr)`` tuple.

    :return: If ``blocking=True``, then return a tuple ``(stdout,
        stderr)``, containing the stdout and stderr outputs generated
        by the java command if the ``stdout`` and ``stderr`` parameters
        were set to ``subprocess.PIPE``; or None otherwise.  If
        ``blocking=False``, then return a ``subprocess.Popen`` object.

    :raise OSError: If the java command returns a nonzero return code.
    )pipestdoutdevnullzcmd should be a list of stringsz-cp)stdinr   stderrr   zJava command failed : )
subprocessPIPESTDOUTDEVNULLgetr   r   	TypeErrorr   r   r   ospathpathsepjoinr   Popencommunicate
returncodeprint_decode_stdoutdataOSError)	cmd	classpathr   r   r   blockingsubprocess_output_dict
classpathsps	            r   r   r   ?   sL   ` ##%% #&&ue4E#''7F#''7F#s9::  )S![
)_
$$Z0I s)C)
s
"C+
%
+C 	E&HA}}VV 	||q ().S9::Fr   c                       e Zd ZdZd Zd Zy)	ReadErrorz
    Exception raised by read_* functions when they fail.
    :param position: The index in the input string where an error occurred.
    :param expected: What was expected when an error occurred.
    c                 N    t         j                  | ||       || _        || _        y N)
ValueError__init__expectedposition)selfr9   r:   s      r   r8   zReadError.__init__   s"    D(H5  r   c                 :    d| j                    d| j                   S )Nz	Expected z at )r9   r:   r;   s    r   __str__zReadError.__str__   s    4==/dmm_==r   N)__name__
__module____qualname____doc__r8   r>    r   r   r4   r4      s    !
>r   r4   z[uU]?[rR]?(\"\"\"|\'\'\'|\"|\')c                    t         j                  | |      }|st        d|      |j                  d      }t	        j
                  d|z        }|j                         }	 |j                  | |      }|st        d|      |j                  d      dk(  r|j                         dz   }nnJ	 t        | ||j                                |j                         fS # t        $ r}t        d|      |d}~ww xY w)	a  
    If a Python string literal begins at the specified position in the
    given string, then return a tuple ``(val, end_position)``
    containing the value of the string literal and the position where
    it ends.  Otherwise, raise a ``ReadError``.

    :param s: A string that will be checked to see if within which a
        Python string literal exists.
    :type s: str

    :param start_position: The specified beginning position of the string ``s``
        to begin regex matching.
    :type start_position: int

    :return: A tuple containing the matched string literal evaluated as a
        string and the end position of the string literal.
    :rtype: tuple(str, int)

    :raise ReadError: If the ``_STRING_START_RE`` regex doesn't return a
        match in ``s`` at ``start_position``, i.e., open quote. If the
        ``_STRING_END_RE`` regex doesn't return a match in ``s`` at the
        end of the first match, i.e., close quote.
    :raise ValueError: If an invalid string (i.e., contains an invalid
        escape sequence) is passed into the ``eval``.

    :Example:

    >>> from nltk.internals import read_str
    >>> read_str('"Hello", World!', 0)
    ('Hello', 7)

    z
open quote   z\\|%szclose quoter   \zvalid escape sequenceN)
_STRING_START_REmatchr4   grouprecompileendsearchevalr7   )sstart_positionm	quotemark_STRING_END_REr:   rH   es           r   read_strrU      s    D 	q.1An55
I ZZ9 45NuuwH
%%a2M844;;q>T!yy{QH HAnuyy{34eiikAA H/@aGHs   *+C 	C1C,,C1z-?\d+c                     t         j                  | |      }|st        d|      t        |j	                               |j                         fS )al  
    If an integer begins at the specified position in the given
    string, then return a tuple ``(val, end_position)`` containing the
    value of the integer and the position where it ends.  Otherwise,
    raise a ``ReadError``.

    :param s: A string that will be checked to see if within which a
        Python integer exists.
    :type s: str

    :param start_position: The specified beginning position of the string ``s``
        to begin regex matching.
    :type start_position: int

    :return: A tuple containing the matched integer casted to an int,
        and the end position of the int in ``s``.
    :rtype: tuple(int, int)

    :raise ReadError: If the ``_READ_INT_RE`` regex doesn't return a
        match in ``s`` at ``start_position``.

    :Example:

    >>> from nltk.internals import read_int
    >>> read_int('42 is the answer', 0)
    (42, 2)

    integer)_READ_INT_RErH   r4   intrI   rL   rO   rP   rQ   s      r   read_intr[      sA    : 	1n-A	>22qwwy>1557""r   z-?(\d*)([.]?\d*)?c                 T   t         j                  | |      }|r"|j                  d      s|j                  d      st        d|      |j                  d      r)t	        |j                               |j                         fS t        |j                               |j                         fS )a  
    If an integer or float begins at the specified position in the
    given string, then return a tuple ``(val, end_position)``
    containing the value of the number and the position where it ends.
    Otherwise, raise a ``ReadError``.

    :param s: A string that will be checked to see if within which a
        Python number exists.
    :type s: str

    :param start_position: The specified beginning position of the string ``s``
        to begin regex matching.
    :type start_position: int

    :return: A tuple containing the matched number casted to a ``float``,
        and the end position of the number in ``s``.
    :rtype: tuple(float, int)

    :raise ReadError: If the ``_READ_NUMBER_VALUE`` regex doesn't return a
        match in ``s`` at ``start_position``.

    :Example:

    >>> from nltk.internals import read_number
    >>> read_number('Pi is 3.14159', 6)
    (3.14159, 13)

    rE      number)_READ_NUMBER_VALUErH   rI   r4   floatrL   rY   rZ   s      r   read_numberra     s|    : 	  N3AQWWQZ1771:.11wwqzQWWY((1779~quuw&&r   c                 D   t        | t        j                        rw| j                  j                  a| j
                  }t        | j                  j                        D cg c]  }||j                  v r|j                  |   ! }}t        |      dkD  S t        d      c c}w )a  
    :return: True if ``method`` overrides some method with the same
        name in a base class.  This is typically used when defining
        abstract base classes or interfaces, to allow subclasses to define
        either of two related methods:

        >>> class EaterI:
        ...     '''Subclass must define eat() or batch_eat().'''
        ...     def eat(self, food):
        ...         if overridden(self.batch_eat):
        ...             return self.batch_eat([food])[0]
        ...         else:
        ...             raise NotImplementedError()
        ...     def batch_eat(self, foods):
        ...         return [self.eat(food) for food in foods]

    :type method: instance method
    rE   zExpected an instance method.)
r   types
MethodType__self__	__class__r?   _mro__dict__lenr"   )methodnameclsfuncss       r   
overriddenrn   @  s    & &%**+0I0I0U FOO556
6s||# LL6 	 

 5zA~677
s   $Bc                     t        | t              r| j                  S | g}| j                  D ]  }|j	                  t        |              |S )aY  
    Return the method resolution order for ``cls`` -- i.e., a list
    containing ``cls`` and all its base classes, in the order in which
    they would be checked by ``getattr``.  For new-style classes, this
    is just cls.__mro__.  For classic classes, this can be obtained by
    a depth-first left-to-right traversal of ``__bases__``.
    )r   type__mro__	__bases__extendrg   )rl   mrobases      r   rg   rg   _  sB     #t{{eMMDJJtDz" "
r   c                 R   d}| j                   r^| j                   j                         dz   | _         t        j                  d| j                   j	                               }|rt        |      }nd| _         | xj                   t        j                  d| d| ||dz         z  c_         y)	z4Add an epytext @field to a given object's docstring. 

z(?<=\n)[ ]+(?!\s)@:     initial_indentsubsequent_indentN)rB   rstriprJ   findall
expandtabsmintextwrapfill)objfieldmessageindentindentss        r   _add_epytext_fieldr   v  s    F {{kk((*V3**13;;3I3I3KL\F KK8==
E7"WI 6/ Kr   c                       fd}|S )a$  
    A decorator used to mark functions as deprecated.  This will cause
    a warning to be printed the when the function is used.  Usage:

        >>> from nltk.internals import deprecated
        >>> @deprecated('Use foo() instead')
        ... def bar(x):
        ...     print(x/10)

    c                 (    d j                    d dt        j                  dd      z    fd}|j                  j	                   j                          j                   |_          j
                  |_        d|_        t        |d       |S )	Nz	Function z() has been deprecated.  
  r|   c                  L    t        j                  t        d        | i |S )Nr]   category
stacklevel)warningswarnDeprecationWarning)argskwargsfuncmsgs     r   newFuncz.deprecated.<locals>.decorator.<locals>.newFunc  s$    MM#(:qI(((r   T
deprecated)r?   r   r   rh   updaterB   __deprecated__r   )r   r   r   r   s   ` @r   	decoratorzdeprecated.<locals>.decorator  s    $--(A'KX]]3ttTT	)
 	.==,,!%7L':r   rC   )r   r   s   ` r   r   r     s    " r   c                       e Zd ZdZd Zy)
Deprecateda  
    A base class used to mark deprecated classes.  A typical usage is to
    alert users that the name of a class has changed:

        >>> from nltk.internals import Deprecated
        >>> class NewClassName:
        ...     pass # All logic goes here.
        ...
        >>> class OldClassName(Deprecated, NewClassName):
        ...     "Use NewClassName instead."

    The docstring of the deprecated class will be used in the
    deprecation warning message.
    c                    d }t        |       D ]  }t        |j                  v s|} n |sJ d       |j                  xs dj	                         }t        j                  dd|      }t        j                  dd|      }d|j                  z  }| |k7  r|d| j                  z  z  }| d| }dt        j                  |d	d	
      z   }t        j                  |t        d       t        j                  |       S )Nz-Unable to determine which base is deprecated.rw   z\A\s*@deprecated:z(?m)^\s*zClass %sz (base class for %s)z has been deprecated.  r   r{   r|   r]   r   )rg   r   rr   rB   striprJ   subr?   r   r   r   r   r   object__new__)rl   r   r   dep_clsru   docrk   r   s           r   r   zDeprecated.__new__  s    IDT^^+  GGGw oo+ff)34ff["c*G,,,'>*S\\99D-cU3X]]3vQWXXc$61E~~c""r   N)r?   r@   rA   rB   r   rC   r   r   r   r     s    #r   r   c                       e Zd ZdZddZd Zy)CounterzE
    A counter that auto-increments each time its value is read.
    c                     || _         y r6   _value)r;   initial_values     r   r8   zCounter.__init__  s	    #r   c                 D    | xj                   dz  c_         | j                   S NrE   r   r=   s    r   r!   zCounter.get  s    q{{r   N)r   )r?   r@   rA   rB   r8   r!   rC   r   r   r   r     s    $r   r   c           
   #     K   | g|xs g z   }t        | t              sJ t        |t              rJ t        |t              rJ t        |t              r|j                         }d}|D ]  }t        j                  j                  | |      }	t        j                  j                  |	      r|rt        d|  d|	 d       d}|	 t        j                  j                  |      r|rt        d|  d| d       d}| t        j                  j                  | d|      }	t        j                  j                  |	      s|rt        d|  d|	 d       d}|	  |D ]X  }
|
t        j                  v s|rd}t        j                  |
    t        j                  |
   j                  t        j                        D ]  }t        j                  j                  |      r|rt        d|  d| d       d}| |D ]  }t        j                  j                  ||      }	t        j                  j                  |	      r|rt        d|  d|	 d       d}|	 t        j                  j                  |d|      }	t        j                  j                  |	      s|rt        d|  d|	 d       d}|	   [ |D ]O  }|D ]H  }t        j                  j                  ||      }	t        j                  j                  |	      sCd}|	 J Q t        j                  dk(  r|D ]  }	 t        j                  d	|gt        j                  t        j                  
      }|j                         \  }}t        |      j!                         }|j#                  |      r9t        j                  j%                  |      r|rt        d|  d| d       d}|  |s]d| z  }|r|d|d   z  z  }|dz  }|r |dz  }|dj                  d |D              z  }|r|d|  d| dz  }d}t-        d| d| d|       y# t&        t(        t*        f$ r  w xY w# w xY ww)a  
    Search for a file to be used by nltk.

    :param filename: The name or path of the file.
    :param env_vars: A list of environment variable names to check.
    :param file_names: A list of alternative file names to check.
    :param searchpath: List of directories to search.
    :param url: URL presented to user for download help.
    :param verbose: Whether or not to print path when a file is found.
    F[Found rz   ]Tfiler   posixwhich)r   r   zSNLTK was unable to find the %s file!
Use software specific configuration parametersz# or set the %s environment variabler   .

  Searched in:rw   c              3   &   K   | ]	  }d |z    ywz	
    - %sNrC   .0ds     r   	<genexpr>z!find_file_iter.<locals>.<genexpr>j       @Z<!+Z   z

  For more information on z, see:
    <>K===========================================================================rx   r   N)r   r   r   r#   r$   r&   isfiler*   environr%   rk   r   r'   r   r(   r+   r   endswithexistsKeyboardInterrupt
SystemExitr,   LookupError)filenamer   
searchpath
file_namesurlr	   finding_diryieldedalternativepath_to_fileenv_varenv_dir	directoryr2   r   r   r$   r   divs                      r   find_file_iterr     s    & z/R0Jh$$$*c****c***(C >>#G "ww||Hk:77>>,'zL>;<G77>>+&zK=:;Gww||HfkB77>>,'zL>;<G' ", bjj jj))::g.44RZZ@77>>'*zG9A>?"G!M#-K#%77<<#ELww~~l3"!GH:R~Q"GH"&**
 $&77<<#LLww~~l3"!GH:R~Q"GH"&**# $. A D  	%K77<<	;?Lww~~l+""	 &   
ww'%K$$k*%??%??
 "#)&1779==-"''..2FzD6;<"GJ # && ')12 	
 88A;FFCs
''C277@Z@@@C3H:]3%qQQCDRuBse455  &z7;  sF   D:Q=4Q2D#QA*Q"Q$B,P2A"Q2QQQQc           
      4    t        t        | |||||            S r6   nextr   r   r   r   r   r   r	   s         r   	find_filer   q  s#     x:z3P r   c                 8    t        t        | |||||d            S )NT)r   r   r   s         r   find_dirr   y  s)     h
JWRV	
 r   c              #   H   K   t        |xs | |||||      E d{    y7 w)a  
    Search for a file to be used by nltk.

    :param name: The name or path of the file.
    :param path_to_bin: The user-supplied binary location (deprecated)
    :param env_vars: A list of environment variable names to check.
    :param file_names: A list of alternative file names to check.
    :param searchpath: List of directories to search.
    :param url: URL presented to user for download help.
    :param verbose: Whether or not to print path when a file is found.
    N)r   rk   path_to_binr   r   r
   r   r	   s          r   find_binary_iterr     s,     ( tXz<g  s   " "c                 6    t        t        | ||||||            S r6   )r   r   r   s          r   r   r     s(     +x\3	
 r   c              #   
  K   t        | t              sJ t        |t              rJ t        |t              r|j                         }d}dgt        |      z   }|7t        j
                  j                  |      rd}| nt        d|  d|       |D ]	  }|t        j                  v s|dk(  rt        j                  d   }	|	j                  t        j
                  j                        D ]  }
t        j
                  j                  |
      }
t        j
                  j                  |
      rXt        j
                  j                  |
      }|rt        j                  | |      s|s|| k(  r|rt        d|  d|
 d	       d}|
 t        j
                  j                  |
      s|sxt        j
                  j                  t        j
                  j!                  |
|             s|rt        d|  d|
 d	       d}t        j
                  j!                  |
|        4t	        j"                  |
      D ]o  }t        j                  | |      s|r0t        d| dt        j
                  j!                  |
|      d	       d}t        j
                  j!                  |
|       q  t        j
                  j                  t        j                  |         t        j
                  j                        rfd
t	        j"                        D        nf}|D ]|  }t        j
                  j                  |      s#t        j
                  j                  |      }|rt        j                  | |      s	|r]|| k(  sc|rt        d|  d| d	       d}| ~  |D ]  }|rt	        j"                  |      D ]q  }t        j
                  j!                  ||      }t        j
                  j                  |      r*t        j                  | |      r|rt        d| d| d	       d}| s t        j
                  j!                  ||       }t        j
                  j                  |      s|rt        d|  d| d	       d}|  |s|d| z  }|r|d|d   z  z  }t%        j&                  |dz   dd      }|r |dz  }|dj!                  d |D              z  }|r|dj)                  | |      z  }d}t        d| d| d|       yw)a  
    Search for a jar that is used by nltk.

    :param name_pattern: The name of the jar file
    :param path_to_jar: The user-supplied jar location, or None.
    :param env_vars: A list of environment variable names to check
                     in addition to the CLASSPATH variable which is
                     checked by default.
    :param searchpath: List of directories to search.
    :param is_regex: Whether name is a regular expression.
    F	CLASSPATHNTzCould not find z jar file at r   rz   r   c              3   ^   K   | ]$  }t         j                  j                  |       & y wr6   )r#   r$   r&   )r   path_to_jarjar_envs     r   r   z find_jar_iter.<locals>.<genexpr>  s(      +>K Wk:+>s   *-zNLTK was unable to find %s!z  Set the %s environment variabler   r   r   r|   r   rw   c              3   &   K   | ]	  }d |z    ywr   rC   r   s     r   r   z find_jar_iter.<locals>.<genexpr>0  r   r   z.

  For more information, on {}, see:
    <{}>r   rx   r   )r   r   r   r   r#   r$   r   r   r   r%   
expanduserbasenamerJ   rH   r*   isdirr&   listdirr   r   format)name_patternr   r   r   r   r	   is_regexr   r   r.   cpr   	file_namejar_iterr   r   r   r   s                    @r   find_jar_iterr     sY    * lC(((*c***(C >>#G }tH~-H 77>>+&G!,}[MJ 
 bjj +%JJ{3	#//"''//:B++B/Bww~~b)#%77#3#3B#7$ "x @$,\1I& %~Rt1&E F&*G"$Hww}}R('!ww~~bggll2|.LM#*$)GL>B4q*I$J*.&(ggll2|&D D .0ZZ^	#%88L)#D'.(- 1=02R0K-.)* /3G*,'',,r9*E$E .</ ;J '',,RZZ-@A ww}}W-	+-::g+>
 "  $,Kww~~k2#%77#3#3K#@$ "x @$,\1I& %~R}A&N O&*G"-- $,e @  	JJy1 ggll9h?77>>+.xxh7"!GH:R}A"FG!! 2 '',,y,?Kww~~k*GL>K=BC!!!  $ +l:5CCCmmC#IddS''C277@Z@@@CFMM C DRuBse455 s;   B'T+C;T'?T'A(TC1T9T<TC/T2BTc                 6    t        t        | ||||||            S r6   )r   r   )r   r   r   r   r   r	   r   s          r   find_jarr   :  s(     +xS'8	
 r   c                     t        j                  |       D cg c]A  \  }}}t        j                  |d      D ]"  }t         j                  j                  ||      $ C c}}}}S c c}}}}w )Nz*.jar)r#   walkfnmatchfilterr$   r&   )path_to_jarsrootdirnames	filenamesr   s        r   find_jars_within_pathr   J  s`     *,)>)>%D(Iy':H 	T8$: 	%)>  s   AA'
c                     t        | t              s| S t        t        j                  dt        j                               }|| j                         S | j                  |      S )z/Convert data read from stdout/stderr to unicodeencoding)r   bytesgetattrsys
__stdout__localegetpreferredencodingdecode)
stdoutdatar   s     r   r+   r+   R  sS    j%(s~~z63N3N3PQH  ""X&&r   c                     t         j                  }t         j                  D cg c]	  }|dvs| c}t         _        t        |       }|t         _        |S c c}w )a  
    When python is run from within the nltk/ directory tree, the
    current directory is included at the beginning of the search path.
    Unfortunately, that means that modules within nltk can sometimes
    shadow standard library modules.  As an example, the stdlib
    'inspect' module will attempt to import the stdlib 'tokenize'
    module, but will instead end up importing NLTK's 'tokenize' module
    instead (causing the import to fail).
    )rw   r   )r  r$   
__import__)moduleold_pathr   rQ   s       r   import_from_stdlibr  b  sI     xxH88:8aq	'98:CH6ACHH ;s
   	AAc                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd ZddZd Zd Zd Zy)ElementWrappera  
    A wrapper around ElementTree Element objects whose main purpose is
    to provide nicer __repr__ and __str__ methods.  In addition, any
    of the wrapped Element's methods that return other Element objects
    are overridden to wrap those values before returning them.

    This makes Elements more convenient to work with in
    interactive sessions and doctests, at the expense of some
    efficiency.
    c                 X    t        |t              r|S t        j                  t              S )z
        Create and return a wrapper around a given Element object.
        If ``etree`` is an ``ElementWrapper``, then ``etree`` is
        returned as-is.
        )r   r  r   r   )rl   etrees     r   r   zElementWrapper.__new__  s"     e^,L>>.11r   c                 l    t        |t              rt        j                  |      }|| j                  d<   y)a?  
        Initialize a new Element wrapper for ``etree``.

        If ``etree`` is a string, then it will be converted to an
        Element object using ``ElementTree.fromstring()`` first:

            >>> ElementWrapper("<test></test>")
            <Element "<?xml version='1.0' encoding='utf8'?>\n<test />">

        _etreeN)r   r   r   
fromstringrh   )r;   r  s     r   r8   zElementWrapper.__init__  s,     eS!**51E"'hr   c                     | j                   S )zD
        Return the Element object wrapped by this wrapper.
        r  r=   s    r   unwrapzElementWrapper.unwrap  s     {{r   c                     t        j                  | j                  d      j                  d      }t	        |      dkD  r1|j                  d      }t	        |      |z
  dkD  rd}|d d  d||d   }d|z  S )	Nutf8r   <   <   iz...z<Element %r>)r   tostringr  r  ri   rfind)r;   rO   rT   s      r   __repr__zElementWrapper.__repr__  sw      v>EEfMq6B;AA
b Sb6(#aeW%A!!r   c                 ~    t        j                  | j                  d      j                  d      j	                         S )zs
        :return: the result of applying ``ElementTree.tostring()`` to
        the wrapped Element object.
        r  r  )r   r  r  r  r   r=   s    r   r>   zElementWrapper.__str__  s1       v>EEfMTTV	
r   c                 .    t        | j                  |      S r6   )r  r  )r;   attribs     r   __getattr__zElementWrapper.__getattr__  s    t{{F++r   c                 0    t        | j                  ||      S r6   )setattrr  )r;   attrvalues      r   __setattr__zElementWrapper.__setattr__  s    t{{D%00r   c                 .    t        | j                  |      S r6   )delattrr  )r;   r&  s     r   __delattr__zElementWrapper.__delattr__  s    t{{D))r   c                 "    || j                   |<   y r6   r  )r;   indexelements      r   __setitem__zElementWrapper.__setitem__  s    $Er   c                     | j                   |= y r6   r  r;   r-  s     r   __delitem__zElementWrapper.__delitem__  s    KKr   c                 "    || j                   || y r6   r  )r;   startstopelementss       r   __setslice__zElementWrapper.__setslice__  s    "*E$r   c                 "    | j                   ||= y r6   r  )r;   r4  r5  s      r   __delslice__zElementWrapper.__delslice__  s    KKd
#r   c                 ,    t        | j                        S r6   )ri   r  r=   s    r   __len__zElementWrapper.__len__  s    4;;r   c                 2    t        | j                  |         S r6   )r  r  r1  s     r   __getitem__zElementWrapper.__getitem__  s    dkk%011r   c                 X    | j                   || D cg c]  }t        |       c}S c c}w r6   r  r  )r;   r4  r5  elts       r   __getslice__zElementWrapper.__getslice__  s,    /3{{5/FG/Fs#/FGGGs   'c                 R    | j                   D cg c]  }t        |       c}S c c}w r6   r?  )r;   r@  s     r   getchildrenzElementWrapper.getchildren  s#    /3{{;{s#{;;;s   $Nc                 F    d | j                   j                  |      D        S )Nc              3   2   K   | ]  }t        |        y wr6   )r  )r   r@  s     r   r   z-ElementWrapper.getiterator.<locals>.<genexpr>  s     L/Ks#/Ks   )r  getiterator)r;   tags     r   rF  zElementWrapper.getiterator  s    Lt{{/F/Fs/KLLr   c                 L    t        | j                  j                  ||            S r6   )r  r  makeelement)r;   rG  r"  s      r   rI  zElementWrapper.makeelement  s    dkk55c6BCCr   c                 V    | j                   j                  |      }||S t        |      S r6   )r  findr  r;   r$   r@  s      r   rK  zElementWrapper.find  s+    kkt$;J!#&&r   c                 p    | j                   j                  |      D cg c]  }t        |       c}S c c}w r6   )r  r   r  rL  s      r   r   zElementWrapper.findall  s0    /3{{/B/B4/HI/Hs#/HIIIs   3r6   )r?   r@   rA   rB   r   r8   r  r  r>   r#  r(  r+  r/  r2  r7  r9  r;  r=  rA  rC  rF  rI  rK  r   rC   r   r   r  r  x  so    		2("
,1*%+$ 2H<MD'Jr   r  c                 6   |j                   |j                  }}|rM|j                  }|d}|dk  rt        | t	        ||            \  }}nt        | t	        ||            \  }}|||fS |j                  dvr"t        d| j                  j                  z        |d}|t        |       }|dk  rt        dt        |       |z         }|dk  rt        dt        |       |z         }|dkD  r		 | |dz
      t        ||      }||fS # t        $ r t        |       }Y &w xY w)a   
    Given a slice, return the corresponding (start, stop) bounds,
    taking into account None indices and negative indices.  The
    following guarantees are made for the returned start and stop values:

      - 0 <= start <= len(sequence)
      - 0 <= stop <= len(sequence)
      - start <= stop

    :raise ValueError: If ``slice_obj.step`` is not None.
    :param allow_step: If true, then the slice object may have a
        non-None step.  If it does, then return a tuple
        (start, stop, step).
    rE   r   r   z)slices with steps are not supported by %s)r4  r5  stepslice_boundsslicer7   rf   r?   ri   max
IndexErrorr   )sequence	slice_obj
allow_stepr4  r5  rO  s         r   rP  rP    sB    ??INN4E ~~<D !8&xtU1CDKE4&xud1CDKE4dD   
y	(7(:L:L:U:UU
 	

 }|8} qyAs8}u,-ax1c(md*+
 ax	!TAX
 tE $;  	!x=D	!s   )D DDc                    t         j                  j                  |       syt        t         d      rt        j                  |       }t	        j
                  |j                        }|dz  ry|j                  t        j                         k(  r|dz  ry|j                  t        j                         gt        j                         z   v r|dz  ryyy)NFgetuidr]   T      )r#   r$   r   hasattrstatS_IMODEst_modest_uidrX  st_gidgetgid	getgroups)r$   statdataperms      r   is_writablere  A  s    77>>$ r8774=||H,,-%<__		+oo"))+!??dUl  r   c           
      x    t        dt        |      j                  d| dt        |      j                  d      )Nzunorderable types: z()  z())r"   rp   r?   )orderingabs      r   raise_unorderable_typesrk  a  s/    
7XtAw'7'7	9 r   )NNF)NNNNT)rC   rC   NNFF)rC   rC   NNF)NrC   rC   NNF)NrC   rC   NFF)F)-r   r  r#   rJ   r\  r   r  r   rc   r   	xml.etreer   r   r   r   r   r7   r4   rK   rG   rU   rX   r[   r_   ra   rn   rg   r   r   r   r   r   r   r   r   r   r   r   r   r+   r  r  rP  re  rk  rC   r   r   <module>rm     s     	 	   
    ! 	&@W~>
 >  2::@A 8Hv rzz(# #F  RZZ 45 #'V8>.*@)# )#b
 
( @6H NS NS 6 $ K6`  ' ,zJ zJD?N@r   