HEX
Server: LiteSpeed
System: Linux s882.use1.mysecurecloudhost.com 4.18.0-553.27.1.lve.el8.x86_64 #1 SMP Fri Nov 8 15:09:45 UTC 2024 x86_64
User: airservicecom (4307)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: //lib64/python3.6/site-packages/__pycache__/ldif.cpython-36.pyc
3

�`a6O�@sbdZddlmZdZdddddd	d
gZddlZddlmZmZdd
l	m
Z
ddlZddlm
Z
mZdZdZedeZededZededZejde�Zde�Zddddd�Zddddd�Zddd d!gZiZxeD]Zdee<q�Wd"d#�Zd$Zeje�Zd%d&�Z Gd'd�d�Z!d.d)d�Z"Gd*d�d�Z#Gd+d	�d	e#�Z$Gd,d
�d
e#�Z%d/d-d�Z&dS)0zc
ldif - generate and parse LDIF data (see RFC 2849)

See https://www.python-ldap.org/ for details.
�)�unicode_literalsz3.3.1�ldif_pattern�
CreateLDIF�	ParseLDIF�
LDIFWriter�
LDIFParser�LDIFRecordList�LDIFCopyN)�	b64encode�	b64decode)�StringIO)�urlparse�urlopenz[\w;.-]+(;[\w_-]+)*z(([^,]|\\,)+|".*?")z	[ ]*=[ ]*z([ ]*\+[ ]*z)*[ ]*z
([ ]*,[ ]*z^%s$z>^((dn(:|::) %(dn_pattern)s)|(%(attrtype_pattern)s(:|::) .*)$)+���)�add�delete�replace�	incrementrrrr)rrrr�modifyZmodrdncCs,|dkrdStj|�}|dko*|jd�|kS)z!
  returns 1 if s is a LDAP DN
  �rNr)�dn_regex�match�group)�sZrm�r�/usr/lib64/python3.6/ldif.py�is_dn8s
rs (^(|
|
| |:|<)|[

�-�]+|[ ]+$)cCsdd�|D�S)zN
  return a dictionary with all items of l being the keys of the dictionary
  cSsi|]
}d|�qS)Nr)�.0�irrr�
<dictcomp>Iszlist_dict.<locals>.<dictcomp>r)�lrrr�	list_dictEsr#c@sJeZdZdZddd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dS)rz�
  Write LDIF entry or change records to file object
  Copy LDIF input to a file output object containing all data retrieved
  via URLs
  N�L�
cCs4||_tdd�|pgD��|_||_||_d|_dS)aB
    output_file
        file object for output; should be opened in *text* mode
    base64_attrs
        list of attribute types to be base64-encoded in any case
    cols
        Specifies how many columns a line may have before it's
        folded into many lines.
    line_sep
        String used as line separator
    cSsg|]}|j��qSr)�lower)r�arrr�
<listcomp>`sz'LDIFWriter.__init__.<locals>.<listcomp>rN)�_output_filer#�
_base64_attrs�_cols�_last_line_sep�records_written)�self�output_file�base64_attrs�cols�line_seprrr�__init__Ss
zLDIFWriter.__init__cCs�t|�}||jkr.|jj|�|jj|j�n�|j}|jj|dt||j���|jj|j�xX||kr�|jjd�|jj||t|||jd���|jj|j�||jd}q`WdS)z7
    Write string line as one or more folded lines
    r� rN)�lenr+r)�writer,�min)r.�lineZline_len�posrrr�
_unfold_lineses

$zLDIFWriter._unfold_linescCs|j�|jkptj|�dk	S)z�
    returns 1 if attr_value has to be base-64 encoded because
    of special chars or because attr_type is in self._base64_attrs
    N)r&r*�safe_string_re�search)r.�	attr_type�
attr_valuerrr�_needs_base64_encodingzsz!LDIFWriter._needs_base64_encodingcCsZ|j||�r<t|�jd�}|jdd�}|jdj||g��n|jdj||jd�g��dS)z�
    Write a single attribute type/value pair

    attr_type
          attribute type (text)
    attr_value
          attribute value (bytes)
    �asciir%rz:: z: N)r?r
�decoderr:�join)r.r=r>Zencodedrrr�_unparseAttrTypeandValue�s	z#LDIFWriter._unparseAttrTypeandValuecCs8x2t|j��D]"\}}x|D]}|j||�qWqWdS)z3
    entry
        dictionary holding an entry
    N)�sorted�itemsrC)r.�entryr=�valuesr>rrr�_unparseEntryRecord�s
zLDIFWriter._unparseEntryRecordc	Cs�t|d�}|dkrd}n|dkr(d}ntd|��|jd|jd��x�|D]�}|dkrb|\}}n2|dkr�|\}}}|jt||jd��ntd	��|r�x|D]}|j||�q�W|dkrL|jjd
|j�qLWdS)zP
    modlist
        list of additions (2-tuple) or modifications (3-tuple)
    rrrrrz modlist item of wrong length: %d�
changetyper@z'Subsequent modlist item of wrong length�-N)r5�
ValueErrorrC�encode�
MOD_OP_STRr)r6r,)	r.ZmodlistZmod_lenrI�modZmod_typeZmod_valsZmod_opZmod_valrrr�_unparseChangeRecord�s(




zLDIFWriter._unparseChangeRecordcCsp|jd�}|jd|�t|t�r,|j|�n&t|t�rB|j|�ntdt|���|j	j
|j�|jd|_dS)z�
    dn
          string-representation of distinguished name
    record
          Either a dictionary holding the LDAP entry {attrtype:record}
          or a list with a modify list like for LDAPObject.modify().
    zutf-8�dnz8Argument record must be dictionary or list instead of %srN)
rLrC�
isinstance�dictrH�listrOrK�reprr)r6r,r-)r.rP�recordrrr�unparse�s	


zLDIFWriter.unparse)Nr$r%)�__name__�
__module__�__qualname__�__doc__r3r:r?rCrHrOrVrrrrrLs
	r$cCsDtjdtdd�t�}t|||d�}|j||�|j�}|j�|S)a�
  Create LDIF single formatted record including trailing empty line.
  This is a compatibility function.

  dn
        string-representation of distinguished name
  record
        Either a dictionary holding the LDAP entry {attrtype:record}
        or a list with a modify list like for LDAPObject.modify().
  base64_attrs
        list of attribute types to be base64-encoded in any case
  cols
        Specifies how many columns a line may have before it's
        folded into many lines.
  zhldif.CreateLDIF() is deprecated. Use LDIFWriter.unparse() instead. It will be removed in python-ldap 3.1r)�category�
stacklevelr%)�warnings�warn�DeprecationWarningrrrV�getvalue�close)rPrUr0r1�fZldif_writerrrrrr�sc@sdeZdZdZddd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zddd�Zdd�Z
dS)rz�
  Base class for a LDIF parser. Applications should sub-class this
  class and override method handle() to implement something meaningful.

  Public class attributes:

  records_read
        Counter for records processed so far
  Nrr%cCs�||_t|jjd�t�|_||_tdd�|p.gD��|_tdd�|pFgD��|_||_	d|_
d|_d|_d|_
ijtd�|_t|_y|j�|_Wntk
r�d|_YnXdS)a
    Parameters:
    input_file
        File-object to read the LDIF input from
    ignored_attr_types
        Attributes with these attribute type names will be ignored.
    max_entries
        If non-zero specifies the maximum number of entries to be
        read from f.
    process_url_schemes
        List containing strings with URLs schemes to process with urllib.
        An empty list turns off all URL processing and the attribute
        is ignored completely.
    line_sep
        String used as line separator
    rcSsg|]}|j��qSr)r&)rrrrrr(sz'LDIFParser.__init__.<locals>.<listcomp>cSsg|]}|j��qSr)r&)rr'rrrr(sNr)�_input_filerQ�read�bytes�_file_sends_bytes�_max_entriesr#�_process_url_schemes�_ignored_attr_typesr,�version�line_counter�byte_counter�records_read�fromkeys�CHANGE_TYPES�changetype_counterr�
_b64decode�	_readline�
_last_line�EOFError)r.�
input_file�ignored_attr_types�max_entries�process_url_schemesr2rrrr3�s zLDIFParser.__init__cCsdS)zw
    Process a single content LDIF record. This method should be
    implemented by applications using LDIFParser.
    Nr)r.rPrFrrr�handle(szLDIFParser.handlecCs~|jj�}|jr|jd�}|jd|_|jt|�|_|s>dS|dd�dkrZ|dd�S|dd�dkrv|dd	�S|SdS)
Nzutf-8rrz
r%���rz���r{)rc�readlinerfrArkrlr5)r.rrrrrr/s

zLDIFParser._readlinecCsn|jdkrtd|j|jf��|jg}|j�}x.|r\|ddkr\|j|dd��|j�}q0W||_dj|�S)zG
    Unfold several folded lines with trailing space into one line
    Nz%EOF reached after %d lines (%d bytes)rr4rr)rsrtrkrlrr�appendrB)r.Zunfolded_linesZ	next_linerrrr:@s
zLDIFParser._unfold_linesc	Cs\|j�}x|r$|ddkr$|j�}q
W|s.dS|dkr:dSy|jd�}Wn2tk
rz}ztdt|���WYdd}~XnX|d|�}|||d�}|dkr�||dd�j�}|jd	�}n�|d
kr�||dd�}|jd�}|j|�}nf|dk�r>||dd�j�}d}|j�rTt	|�}|d|jk�rTt
|�j�}n||d
d�jd	�}||fS)z�
    Parse a single attribute type and value pair from one or
    more lines of LDIF data

    Returns attr_type (text) and attr_value (bytes)
    r�#NrJ�:zno value-spec in %srz: zutf-8z::r@z:<r)NN)rJN)r:�indexrKrT�lstriprLrq�striprhr
rrd)	r.Z
unfolded_lineZ	colon_pos�er=Z
value_specr>Zurl�urrr�_next_key_and_valueQs:"

zLDIFParser._next_key_and_valuecCsZ|j}y.|�\}}x|dkr0|dkr0|�\}}qWWntk
rPd\}}YnX||fS)z�
    Consume empty lines until first non-empty line.
    Must only be used between full records!

    Returns non-empty key-value-tuple.
    N)NN)r�rt)r.�next_key_and_value�k�vrrr�_consume_empty_lines�s
zLDIFParser._consume_empty_linescCsx|j}y4|j�\}}|dkr8t|jd��|_|j�\}}Wntk
rNdSX�x |dkon|jsr|j|jk�rr|dkr�td|j	t
|�f��|jd�}t|�s�td|j	t
|�f��|}i}|�\}}x�|dk�rJ|j�|j
k�ry||j|�Wn tk
�r|g||<YnXy|�\}}Wq�tk
�rFd	\}}Yq�Xq�W|j||�|jd|_|j�\}}qTWdS)
z8
    Continuously read and parse LDIF entry records
    rjr@NrPz;Line %d: First line of record does not start with "dn:": %szutf-8z6Line %d: Not a valid string-representation for dn: %s.r)NN)r�r��intrArjrtrgrmrKrkrTrr&rir}�KeyErrorry)r.r�r�r�rPrFrrr�parse_entry_records�s@

zLDIFParser.parse_entry_recordscCs|j�S)zM
    Invokes LDIFParser.parse_entry_records() for backward compatibility
    )r�)r.rrr�parse�szLDIFParser.parsecCsgpd}dS)z�
    Process a single LDIF record representing a single modify operation.
    This method should be implemented by applications using LDIFParser.
    Nr)r.rP�modops�controlsrrr�
handle_modify�szLDIFParser.handle_modifyc!Cs4|j}|j�\}}|dkr0t|�|_|j�\}}�x�|dkoN|jsR|j|jk�r.|dkrptd|jt|�f��|j	d�}t
|�s�td|jt|�f��|}|�\}}g}x||dko�|dk�r&|j	d�}y|jdd�\}}}Wn*tk
�rd}|jdd	�\}}YnX|j|||f�|�\}}q�Wd}	|d
k�rh|j	d�}|t
k�rZtdt|���|}	|�\}}|	dk�r�g}
�y�x|dk�r�yt|}Wn,tk
�r�td
|jt|�f��YnX|j	d�}|}g}
y|�\}}Wntk
�rd\}}YnXxH||k�rJ|
j|�y|�\}}Wntk
�rDd\}}YnX�qW|
j|||
�p\df�|�\}}|dk�r~|�\}}�q~WWntk
�r�d\}}YnX|
�r�|j||
|�nx|dk�r�|�\}}�q�W|j�\}}y|j|	d	|j|	<Wn tk
�rd	|j|	<YnX|jd	|_q4WdS)NrjrPz;Line %d: First line of record does not start with "dn:": %szutf-8z6Line %d: Not a valid string-representation for dn: %s.Zcontrolr4rrrIzInvalid changetype: %srz"Line %d: Invalid mod-op string: %srJ)NN)NN)NN)r�r�r�rjrgrmrKrkrTrAr�splitr}�valid_changetype_dict�MOD_OP_INTEGERr�rtr�rp)r.r�r�r�rPr�Zcontrol_typeZcriticalityZ
control_valuerIr�ZmodopZmodattrZ	modvaluesrrr�parse_change_records�s�












zLDIFParser.parse_change_records)NrNr%)N)rWrXrYrZr3ryrrr:r�r�r�r�r�r�rrrrr�s	
'06
c@s,eZdZdZd
dd�Zdd�Zddd	�ZdS)rz�
  Collect all records of a LDIF file. It can be a memory hog!

  Records are stored in :attr:`.all_records` as a single list
  of 2-tuples (dn, entry), after calling :meth:`.parse`.
  NrcCs"tj|||||�g|_g|_dS)N)rr3�all_records�all_modify_changes)r.rurvrwrxrrrr3JszLDIFRecordList.__init__cCs|jj||f�dS)zS
    Append a single record to the list of all records (:attr:`.all_records`).
    N)r�r})r.rPrFrrrryUszLDIFRecordList.handlecCsgpd}|jj|||f�dS)z�
    Process a single LDIF record representing a single modify operation.
    This method should be implemented by applications using LDIFParser.
    N)r�r})r.rPr�r�rrrr�[szLDIFRecordList.handle_modify)NrN)N)rWrXrYrZr3ryr�rrrrrBs
c@s"eZdZdZd
dd�Zdd	�ZdS)r	zM
  Copy LDIF input to LDIF output containing all data retrieved
  via URLs
  Nrr$r%c		Cs&tj|||||�t||||�|_dS)z=
    See LDIFParser.__init__() and LDIFWriter.__init__()
    N)rr3r�_output_ldif)	r.rur/rvrwrxr0r1r2rrrr3js	zLDIFCopy.__init__cCs|jj||�dS)z2
    Write single LDIF record to output file.
    N)r�rV)r.rPrFrrrryvszLDIFCopy.handle)NrNNr$r%)rWrXrYrZr3ryrrrrr	ds
cCs.tjdtdd�t|||dd�}|j�|jS)zL
  Parse LDIF records read from file.
  This is a compatibility function.
  zildif.ParseLDIF() is deprecated. Use LDIFRecordList.parse() instead. It will be removed in python-ldap 3.1r)r[r\r)rvrwrx)r]r^r_rr�r�)rbZignore_attrsZ
maxentriesZldif_parserrrrr}s)Nr$)Nr)'rZZ
__future__r�__version__�__all__�re�base64r
r�iorr]Zldap.compatr
rZattrtype_patternZattrvalue_patternZattrtypeandvalue_patternZrdn_patternZ
dn_pattern�compiler�varsrr�rMror��crZSAFE_STRING_PATTERNr;r#rrrrr	rrrrr�<module>sT




T"