%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/share/hplip/base/__pycache__/
Upload File :
Create Path :
Current File : //usr/share/hplip/base/__pycache__/ldif.cpython-312.pyc

�

=	fWA���dZdZgd�ZddlmZmZmZddlZddlZddl	Z		ddl
mZddl
�d	Zd
ZedzezZedzezd
zZej$dez�Zde�zZdddd�Zdddd�Zgd�ZiZeD]Zdee<�	dZej$e�Zd�Zd�Zd�ZGd�d�Z d%d�Z!Gd�d�Z"Gd �d!e"�Z#Gd"�d#e"�Z$d&d$�Z%y#e$r	ddl
mZY��wxYw)'a
ldif - generate and parse LDIF data (see RFC 2849)
written by Michael Stroeder <michael@stroeder.com>

See http://python-ldap.sourceforge.net for details.

$Id: ldif.py,v 1.3 2008/02/11 16:35:43 dwelch Exp $

Python compability note:
Tested with Python 2.0+, but should work with Python 1.5.2+.

The python-ldap package is distributed under Python-style license.

Standard disclaimer:
   This software is made available by the author(s) to the public for free
   and "as is".  All users of this free software are solely and entirely
   responsible for their own choice and use of this software for their
   own purposes.  By using this software, each user agrees that the
   author(s) shall not be liable for damages of any kind in relation to
   its use or performance. The author(s) do not warrant that this software
   is fit for any purpose.

Note: This file is part of the python-ldap package. For the complete
  python-ldap package, please visit: http://sourceforge.net/projects/python-ldap/
  
  It has been modified for use in HPLIP.

z0.5.5)�ldif_pattern�AttrTypeandValueLDIF�
CreateLDIF�	ParseLDIF�
LDIFWriter�
LDIFParser�LDIFRecordList�LDIFCopy�)�urllib2_request�
urllib2_parse�
urllib2_error�N)�StringIO)�*z[\w;.]+(;[\w_-]+)*z(([^,]|\\,)+|".*?")z	[ ]*=[ ]*z
([ ]*,[ ]*z)*[ ]*z^%s$z>^((dn(:|::) %(dn_pattern)s)|(%(attrtype_pattern)s(:|::) .*)$)+�)�add�delete�replacerrr)rr
r)rr�modify�modrdnu"(^(|
|
| |:|<)|[

€-ÿ]+|[ ]+$)c�n�|dk(rytj|�}|dk7xr|jd�|k(S)z%
    returns 1 if s is a LDAP DN
    �r
Nr)�dn_regex�match�group)�s�rms  �/usr/share/hplip/base/ldif.py�is_dnrQs7��	�"�u��	����	�B�
�t�8�&������Q��&�c�0�tj|�duS)zK
    returns 1 if s has to be base-64 encoded because of special chars
    N)�safe_string_re�search)rs r�needs_base64r$[s���$�$�Q�'�4�/�/r c�B�t|D�cgc]}|df��c}�Scc}w)zR
    return a dictionary with all items of l being the keys of the dictionary
    N)�dict)�l�is  r�	list_dictr)bs!���A�&�q�!�T��&�'�'��&s�c�6�eZdZdZd	d�Zd�Zd�Zd�Zd�Zd�Z	y)
rz�
    Write LDIF entry or change records to file object
    Copy LDIF input to a file output object containing all data retrieved
    via URLs
    Nc��||_ttxsgD�cgc]}|j���c}�|_||_||_d|_ycc}w)aI
        output_file
            file object for output
        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
        rN)�_output_filer)�
bases64_attrs�lower�
_base64_attrs�_cols�	_line_sep�records_written)�self�output_file�base64_attrs�cols�line_sep�as      r�__init__zLDIFWriter.__init__psK��(���&�M�<O�R�'Q�a����	�'Q�R�����
�!��� ����(Rs�Ac	��t|�}||jkrA|jj|�|jj|j�y|j}|jj|dt||j��|jj|j�||kr�|jjd�|jj||t|||jzdz
��|jj|j�||jzdz
}||kr��y)z?
        Write string line as one or more folded lines
        r� r
N)�lenr0r,�writer1�min)r3�line�line_len�poss    r�_unfoldLDIFLinezLDIFWriter._unfoldLDIFLine�s��
�t�9���T�Z�Z�����#�#�D�)����#�#�D�N�N�3�	��*�*�C����#�#�D��3�x����+D�$E�F����#�#�D�N�N�3��h�,��!�!�'�'��,��!�!�'�'��S��X�s�4�:�:�~�a�?O�1P�(Q�R��!�!�'�'����7��$�*�*�n�Q�&��	�h�,�
	r c	�"�|j�|jvst|�rF|jdj	|tj|�jdd�g��y|jdj	||g��y)z�
        Write a single attribute type/value pair

        attr_type
              attribute type
        attr_value
              attribute value
        z:: �
rz: N)r.r/r$rB�join�base64�encodestringr)r3�	attr_type�
attr_values   r�_unparseAttrTypeandValuez#LDIFWriter._unparseAttrTypeandValue�s}���?�?��� 2� 2�2��
�#�� � ����Y��8K�8K�J�8W�8_�8_�`d�fh�8i�,j�!k�l�	�
� � ����I�z�+B�!C�D�r c��t|j��dd}|j�|D]}||D]}|j||��� y)z?
        entry
            dictionary holding an entry
        N)�list�keys�sortrJ)r3�entry�
attr_typesrHrIs     r�_unparseEntryRecordzLDIFWriter._unparseEntryRecord�sZ��
�%�*�*�,�'��*�
�����#�	E�I�#�I�.�
E�
��-�-�i��D�
E�	Er c��t|d�}|dk(rd}n|dk(rd}ntd��|jd|�|D]�}|dk(r|\}}n0|dk(r |\}}}|jt||�ntd��|r|D]}|j||��|dk(s�_|jjd	|jz���y
)z\
        modlist
            list of additions (2-tuple) or modifications (3-tuple)
        rrr�rzmodlist item of wrong length�
changetypez'Subsequent modlist item of wrong length�-N)r<�
ValueErrorrJ�
MOD_OP_STRr,r=r1)	r3�modlist�mod_lenrT�mod�mod_type�mod_vals�mod_op�mod_vals	         r�_unparseChangeRecordzLDIFWriter._unparseChangeRecord�s���
�g�a�j�/���A�:��J�
�a�Z�!�J��;�<�<��%�%�l�J�?��	<�C���z�%(�"��(��!��-0�*���(��-�-�j��.@�(�K� �!J�K�K��'�E�G��1�1�(�G�D�E���z��!�!�'�'��D�N�N�(:�;�	<r c�>�|sy|jd|�t|t�r|j|�n-t|t�r|j|�nt
d��|jj|j�|jdz|_
y)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().
        N�dnz*Argument record must be dictionary or listr
)rJ�
isinstancer&rQrLr_rVr,r=r1r2)r3ra�records   r�unparsezLDIFWriter.unparse�s������%�%�d�B�/��f�d�#��$�$�V�,�
���
%��%�%�f�-��I�J�J���������/�#�3�3�A�5���r )N�LrD)
�__name__�
__module__�__qualname__�__doc__r9rBrJrQr_rd�r rrris&���!�$�*�"	E�<�6r rc��t�}t|||d�}|j||�|j�}|j	�|S)a
    Create LDIF single formatted record including trailing empty line.
    This is a compability function. Use is deprecated!

    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.
    rD)rrrd�getvalue�close)rarcr5r6�f�ldif_writerrs       rrr�sD�� 	�
�A��Q��d�D�9�K�����F�#�	�
�
��A��G�G�I��Hr c�:�eZdZdZd�Z		d	d�Zd�Zd�Zd�Zd�Z	y)
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
    c�B�|jd�jd�S)zQ
        Strip trailing line separators from s, but no other whitespaces
        rD�
)�strip)r3rs  r�
_stripLineSepzLDIFParser._stripLineSeps���w�w�t�}�"�"�4�(�(r Nc��||_||_t|xsgD�cgc]}|j���c}�|_t|xsgD�cgc]}|j���c}�|_||_d|_ycc}wcc}w)aK
        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
        rN)�_input_file�_max_entriesr)r.�_process_url_schemes�_ignored_attr_typesr1�records_read)r3�
input_file�ignored_attr_types�max_entries�process_url_schemesr7rr8s        rr9zLDIFParser.__init__sv��$&���'���$-�CV�C\�Z\�.^�Q�q�w�w�y�.^�$_��!�#,�BT�BZ�XZ�-\�A�a�g�g�i�-\�#]�� �!�������/_��-\s�A>�Bc��y)z�
        Process a single content LDIF record. This method should be
        implemented by applications using LDIFParser.
        Nrj�r3rarOs   r�handlezLDIFParser.handle1s�r c��|j|j�g}|jj�|_|jr}|jddk(rk|j	|j|jdd��|jj�|_|jr|jddk(r�kdj|�S)zO
        Unfold several folded lines with trailing space into one line
        rr;r
Nr)rt�_linerv�readline�appendrE)r3�unfolded_liness  rrBzLDIFParser._unfoldLDIFLine7s��� �-�-�d�j�j�9�;���%�%�.�.�0��
��j�j�T�Z�Z��]�c�1��!�!�$�"4�"4�T�Z�Z���^�"D�E��)�)�2�2�4�D�J��j�j�T�Z�Z��]�c�1��w�w�~�&�&r c��|j�}|r#|ddk(r|j�}|r	|ddk(r�|r
|dk(s|dk(ry	|jd�}|d|}|||d	z}|d
k(rtj||d	zd�}||fS|dk(rq||d	zdj�}d}|jrItj|�}|d|jvr#tj|�j�}||fS|d
k(s|dk(rd}||fS||d	zdj�}||fS#t$rtj	d|z�YywxYw)zj
        Parse a single attribute type and value pair from one or
        more lines of LDIF data
        r�#rDz
)NN�:zMalformed line: %s)rrrz::Nz:<z:
r)rB�indexrV�log�errorrF�decodestringrsrxr�urlparser�urlopen�read�lstrip)r3�
unfolded_line�	colon_posrH�
value_specrI�url�us        r�_parseAttrTypeandValuez!LDIFParser._parseAttrTypeandValueDs����,�,�.�
��
�a� 0�C� 7� �0�0�2�M��
�a� 0�C� 7��
�� 5��&�9P��	�%�+�+�C�0�I�"�!�I�.�	�#�9�Y�q�[�9�
��t���,�,�]�9�Q�;�<�-H�I�J�"�*�$�$���
��	�!���-�3�3�5�C��J��(�(�!�*�*�3�/���Q�4�4�4�4�4�!0�!8�!8��!=�!B�!B�!D�J��*�$�$�
��
 �J��$4��J�
�*�$�$�'�y��{�|�4�;�;�=�J��*�$�$��=�	��I�I�*�]�:�;��		�s�D&�&!E
�	E
c��|jj�|_|j�r�|jr|j|jk�r�d}d}d}d}i}|j�\}}|��=|��:|j
�}tjt|��dt|����|r|s|j�\}}�Z|dk(r2|�td��t|�stdt|�z��|}n�|dk(r|�d}n�|dk(rJ|�td	��|�td
��|j
�tvrtdt|�z��|}n=|�;|j
�|jvr||vr||j|�n|g||<|j�\}}|�|���:|r'|j||�|xjdz
c_|jr)|js���|j|jkr���y)z9
        Continously read and parse LDIF records
        Nz ---> raz*Two lines starting with dn: in one record.z8No valid string-representation of distinguished name %s.�versionr
rTz/Read changetype: before getting valid dn: line.z2Two lines starting with changetype: in one record.zchangetype value %s is invalid.)rvr�r�rwrzr�r.r��debug�reprrVr�valid_changetype_dictryr�r�)r3r�rarT�modoprOrHrIs        r�parsezLDIFParser.parseus���%�%�.�.�0��
��j�j��$�$��(9�(9�$�:K�:K�(K��G��B��J��E��E�$(�$?�$?�$A�!�I�z��'�J�,B�%�O�O�-�	��	�	�$�y�/�4�
�;K�L�M� �
�,0�,G�,G�,I�)�I�z����$��~�(�)U�V�V� ��,�(�)c�gk�lv�gw�)x�y�y�#�B��)�+��
��G��,�.��z�(�)Z�[�[�!�-�(�)]�^�^�%�+�+�-�1F�F�(�)J�d�S]�N^�)_�`�`�!+�J��+��_�_�&�d�.F�.F�F�!�E�)��i�(�/�/�
�;�*4���i�(�)-�(C�(C�(E�%�	�:�Y�'�J�,B�\����B��&��!�!�Q�&�!�{�j�j��$�$��(9�(9�$�:K�:K�(K�|	r )NrNrD)
rfrgrhrirtr9r�rBr�r�rjr rrrs/���)�7;�8<��2�'�/%�bEr rc�"�eZdZdZ		dd�Zd�Zy)rzt
    Collect all records of LDIF input into a single list.
    of 2-tuples (dn, entry). It can be a memory hog!
    Nc�D�tj|||||�g|_y)z�
        See LDIFParser.__init__()

        Additional Parameters:
        all_records
            List instance for storing parsed records
        N)rr9�all_records)r3r{r|r}r~s     rr9zLDIFRecordList.__init__�s$��	���D�*�.@�+�Ob�c���r c�>�|jj||f�y)zD
        Append single record to dictionary of all records.
        N)r�r�r�s   rr�zLDIFRecordList.handle�s��	
������U��,r )NrN�rfrgrhrir9r�rjr rrr�s���
7;�+/�
�-r rc�$�eZdZdZ			dd�Zd�Zy)r	zS
    Copy LDIF input to LDIF output containing all data retrieved
    via URLs
    Nc	�\�tj|||||�t||||�|_y)zE
        See LDIFParser.__init__() and LDIFWriter.__init__()
        N)rr9r�_output_ldif)	r3r{r4r|r}r~r5r6r7s	         rr9zLDIFCopy.__init__�s/��	���D�*�.@�+�Ob�c�&�{�L�$��Q��r c�<�|jj||�y)z:
        Write single LDIF record to output file.
        N)r�rdr�s   rr�zLDIFCopy.handle�s��	
���!�!�"�e�,r )NrNNrerDr�rjr rr	r	�s���
DH�>B��R�-r r	c�X�t|||d��}|j�|jS)zc
    Parse LDIF records read from file.
    This is a compability function. Use is deprecated!
    r)r|r}r~)rr�r�)rn�ignore_attrs�
maxentries�ldif_parsers    rrr�s/��
!��|��A�7�K������"�"�"r )Nre)Nr)&ri�__version__�__all__�sixext.movesrrr
rF�re�types�ior�ImportError�g�attrtype_pattern�attrvalue_pattern�rdn_pattern�
dn_pattern�compiler�varsr�MOD_OP_INTEGERrW�CHANGE_TYPESr��c�SAFE_STRING_PATTERNr"rr$r)rrrrr	rrjr r�<module>r�sK���:��
��H�G�
�	�����(��*����-�0A�A���]�*�[�8�9�D�
�
�R�Z�Z���+�
,��O�RV�RX�X��	
�A����

�X���
�5����	�"�A�!��!��"�I������/�0��'�0�(�}�}�@
�0y�y�x-�Z�-�2-�z�-�,#��s
����s�C�C�C

Zerion Mini Shell 1.0