%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/names/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/names/__pycache__/authority.cpython-312.pyc

�

Ϫ�f)A���dZddlZddlZddlmZddlmZmZmZddl	m
Z
ddlmZm
Z
ddlmZdd�ZGd	�d
ej"�ZGd�de�ZGd
�de�Zy)z
Authoritative resolvers.
�N)�defer)�common�dns�error)�failure)�execfile�nativeString)�FilePathc��tjd�}tjd�}	tjj|�s)t
|d�5}|j|dz�ddd�tj|�t
|�5}|j�j�\}}ddd�|k(xrt�dzxsd}t
|d�5}|jd||fz�ddd�|d	|fzz}|S#1swY��xYw#tj|�wxYw#1swY�~xYw#1swY�FxYw)
a�
    Return a monotonically increasing (across program runs) integer.

    State is stored in the given file.  If it does not exist, it is
    created with rw-/---/--- permissions.

    This manipulates process-global state by calling C{os.umask()}, so it isn't
    thread-safe.

    @param filename: Path to a file that is used to store the state across
        program runs.
    @type filename: L{str}

    @return: a monotonically increasing number
    @rtype: L{str}
    z%Y%m%d��wz 0N�rz%s %dz%02d)�time�strftime�os�umask�path�exists�open�write�readline�split�int)�filename�serial�o�f�
serialFile�
lastSerial�zoneIDs       �9/usr/lib/python3/dist-packages/twisted/names/authority.py�	getSerialr"s)��"�]�]�8�
$�F�
�����A���w�w�~�~�h�'��h��$�
'�������
�&�
'�	�����	
�h��;�:�'�0�0�2�8�8�:��
�F�;��F�"�
9��V��q��
>�Q�F�	
�h��	�5�
�����F�F�#3�3�4�5��v��	�)�
*�F��M�
'�
'��	������;�;��
5�5�s;�+D�D
�,D�"D3�#D?�
D�D�D0�3D<�?Ec��eZdZdZej
ejejfZejejfZdZdZ
d�Zd�Zd�Zd�Zd
d�Zdd�Zd	�Zy)�
FileAuthoritya�
    An Authority that is loaded from a file.

    This is an abstract class that implements record search logic. To create
    a functional resolver, subclass it and override the L{loadFile} method.

    @ivar _ADDITIONAL_PROCESSING_TYPES: Record types for which additional
        processing will be done.

    @ivar _ADDRESS_TYPES: Record types which are useful for inclusion in the
        additional section generated during additional processing.

    @ivar soa: A 2-tuple containing the SOA domain name as a L{bytes} and a
        L{dns.Record_SOA}.

    @ivar records: A mapping of domains (as lowercased L{bytes}) to records.
    @type records: L{dict} with L{bytes} keys
    Nc�r�tjj|�|j|�i|_y�N)r�ResolverBase�__init__�loadFile�_cache��selfrs  r!r(zFileAuthority.__init__Vs)�����$�$�T�*��
�
�h�����c��||_yr&)�__dict__)r,�states  r!�__setstate__zFileAuthority.__setstate__[s	����
r-c��y)ab
        Load DNS records from a file.

        This method populates the I{soa} and I{records} attributes. It must be
        overridden in a subclass. It is called once from the initializer.

        @param filename: The I{filename} parameter that was passed to the
        initilizer.

        @returns: L{None} -- the return value is ignored
        N�r+s  r!r)zFileAuthority.loadFile^s�r-c
#�K�||zD]�}|j|jvs�|jjj}|jj|j
�d�D]^}|j|jvs�tj||jtj|jxs||d�����`��y�w)aW
        Find locally known information that could be useful to the consumer of
        the response and construct appropriate records to include in the
        I{additional} section of that response.

        Essentially, implement RFC 1034 section 4.3.2 step 6.

        @param answer: A L{list} of the records which will be included in the
            I{answer} section of the response.

        @param authority: A L{list} of the records which will be included in
            the I{authority} section of the response.

        @param ttl: The default TTL for records for which this is not otherwise
            specified.

        @return: A generator of L{dns.RRHeader} instances for inclusion in the
            I{additional} section.  These instances represent extra information
            about the records in C{answer} and C{authority}.
        r3T��authN)
�type�_ADDITIONAL_PROCESSING_TYPES�payload�name�records�get�lower�TYPE�_ADDRESS_TYPESr�RRHeader�IN�ttl)r,�answer�	authorityrB�recordr:�recs       r!�_additionalRecordsz FileAuthority._additionalRecordsks�����*�y�(�	�F��{�{�d�?�?�?��~�~�*�*�/�/���<�<�+�+�D�J�J�L�"�=��C��x�x�4�#6�#6�6�!�l�l� �#�(�(�C�F�F�C�G�G�N�s�C�d����	�s�!C�A%C�
ACc�n�g}g}g}g}t|jdj|jdj�}	|jj|j
��}
|
�r/|
D�]q}|j�
|j}n|	}|jtjk(rq|j
�|jdj
�k7rC|jtj||jtj||d���nd|j|k(s|tjk(rB|jtj||jtj||d���|jtjk(s��0|jtj||jtj||d�����t|s|}|j!|||	�}
|r|j#|
�n|j#|
�|sb|s`|jtj|jdtj$tj|jdd���t'j(|||f�Stj*||jd�r;t'j,t/j0tj2|���St'j,t/j0t5j6|���S)a�
        Determine a response to a particular DNS query.

        @param name: The name which is being queried and for which to lookup a
            response.
        @type name: L{bytes}

        @param cls: The class which is being queried.  Only I{IN} is
            implemented here and this value is presently disregarded.
        @type cls: L{int}

        @param type: The type of records being queried.  See the types defined
            in L{twisted.names.dns}.
        @type type: L{int}

        @param timeout: All processing is done locally and a result is
            available immediately, so the timeout value is ignored.

        @return: A L{Deferred} that fires with a L{tuple} of three sets of
            response records (to comprise the I{answer}, I{authority}, and
            I{additional} sections of a DNS response) or with a L{Failure} if
            there is a problem processing the query.
        rrFr5T)�max�soa�minimum�expirer;r<r=rBr>r�NS�appendr@rA�ALL_RECORDS�CNAMErG�extend�SOAr�succeed�_isSubdomainOf�failr�Failure�AuthoritativeDomainErrorr�DomainError)r,r:�clsr7�timeout�cnames�resultsrD�
additional�default_ttl�domain_recordsrErB�additionalInformations              r!�_lookupzFileAuthority._lookup�sg��0�����	��
��$�(�(�1�+�-�-�t�x�x��{�/A�/A�B�����)�)�$�*�*�,�7���(�
���:�:�)� �*�*�C�%�C��;�;�#�&�&�(�T�Z�Z�\�T�X�X�a�[�=N�=N�=P�-P��$�$����T�6�;�;�����V�RW�X���[�[�D�(�D�C�O�O�,C��N�N����T�6�;�;�����V�RV�W���;�;�#�)�)�+��M�M����T�6�;�;�����V�RV�W��%
�*� ��%)�$;�$;���K�%�!�����4�5��!�!�"7�8��9�� � ��L�L������S�W�W�c�f�f�c�4�8�8�A�;�T���
�=�=�'�9�j�!A�B�B��!�!�$������4��z�z�'�/�/�#�2N�2N�t�2T�"U�V�V�
�z�z�'�/�/�%�2C�2C�D�2I�"J�K�Kr-c�"�tj|�}|jdj�|j�k(�r�t	|jdj
|jdj�}|jdj�|jdj}n|}tj|jdtjtj||jdd��g}|jj�D]�\}}|D]}}|j�
|j}	n|}	|jtjk7s�<|jtj||jtj|	|d������|j|d�tj |ddf�Stj"t%j&tj(|���S)NrrTr5r3)r�domainStringrJr=rIrKrLrBr@rRrAr;�itemsr>rNrrSrUrrVrX)
r,r:rZr^�soa_ttlr\�k�rrFrBs
          r!�
lookupZonezFileAuthority.lookupZone�s�������%���8�8�A�;����$�*�*�,�.��d�h�h�q�k�1�1�4�8�8�A�;�3E�3E�F�K��x�x��{���*��(�(�1�+�/�/��%������H�H�Q�K����#�&�&�'�4�8�8�A�;�T���G�
���*�*�,�	
���1���C��w�w�*�!�g�g��)���x�x�3�7�7�*�����L�L��C�H�H�c�f�f�c�3�T�R��
�	
�
�N�N�7�1�:�&��=�=�'�2�r�!2�3�3��z�z�'�/�/�#�/�/�$�*?�@�A�Ar-c��ggg}}}|D]M}|ds�	|j|dd�|j|dd�|j|dd��O|||fS)Nrr�)rQ)r,r\�ansr6�add�ress      r!�
_cbAllRecordszFileAuthority._cbAllRecords�so���R��3�T���	&�C��1�v��
�
�3�q�6�!�9�%����C��F�1�I�&��
�
�3�q�6�!�9�%�		&�
�D�#�~�r-r&)�
)�__name__�
__module__�__qualname__�__doc__rrP�MXrMr8�A�AAAAr?rJr;r(r1r)rGrarhrnr3r-r!r$r$;se���(%(�I�I�s�v�v�s�v�v�#>� ��e�e�S�X�X�&�N�
�C��G��
���<WL�rB�8r-r$c�"�eZdZdZd�Zd�Zd�Zy)�PySourceAuthorityzC
    A FileAuthority that is built up from Python source code.
    c�N�|j�i}}t|||�d|vrtd|z��i|_|dD]e}t	|dt
j�r||_|jj|dj�g�j|d��gy)N�zonezNo zone defined in rr)�setupConfigNamespacer�
ValueErrorr;�
isinstancer�
Record_SOArJ�
setdefaultr=rN)r,r�g�l�rrs     r!r)zPySourceAuthority.loadFile
s����(�(�*�B�1����1�a� ���?��2�X�=�>�>�����F�)�	E�B��"�Q�%����0�����L�L�#�#�B�q�E�K�K�M�2�6�=�=�b��e�D�	Er-c����fd�}|S)Nc�>��tj|��|i|��fSr&)rrc)r:�arg�kwr7s   �r!�wrapRecordFuncz4PySourceAuthority.wrapRecord.<locals>.wrapRecordFuncs#����$�$�T�*�D�#�,<��,<�=�=r-r3)r,r7r�s ` r!�
wrapRecordzPySourceAuthority.wrapRecords���	>��r-c��i}tjj�}|D�cgc]}|jd�s�|��c}D]4}t	t|�}|j|�}|||t
d�d<�6|Scc}w)N�Record_)rr/�keys�
startswith�getattrr��len)r,rgrd�xrEr7rs       r!r{z&PySourceAuthority.setupConfigNamespaces{�������!�!�#��"'�C�Q�1�<�<�	�+B�q�C�	,�F��3��'�D�����%�A�*+�A�f�S��^�%�&�'�	,����	Ds
�A<�A<N)rprqrrrsr)r�r{r3r-r!rxrxs���
E��r-rxc�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�
BindAuthorityz�
    An Authority that loads U{BIND zone files
    <https://en.wikipedia.org/wiki/Zone_file>}.

    Supports only C{$ORIGIN} and C{$TTL} directives.
    c��t|�}t|j�dz�|_|j	�jd�}|j
|�}|j|�}|j|�y)z}
        Load records from C{filename}.

        @param filename: file to read from
        @type filename: L{bytes}
        �.TN)	r
r	�basename�origin�
getContent�
splitlines�
stripComments�collapseContinuations�
parseLines)r,r�fp�liness    r!r)zBindAuthority.loadFile1si���h�
��#�2�;�;�=�4�#7�8����
�
��*�*�4�0���"�"�5�)���*�*�5�1������r-c�V�d�|D�cgc]}|j���c}D�Scc}w)z�
        Strip comments from C{lines}.

        @param lines: lines to work on
        @type lines: iterable of L{bytes}

        @return: C{lines} sans comments.
        c3�xK�|]2}|jd�dk(xr|xs|d|jd����4y�w)�;���N)�find)�.0�as  r!�	<genexpr>z.BindAuthority.stripComments.<locals>.<genexpr>KsA����
��
�F�F�4�L�B��$�1�9��.�A�F�F�4�L�(9�9�
�s�8:)�strip)r,r��bs   r!r�zBindAuthority.stripCommentsBs(��
�).�/�A�a�g�g�i�/�
�	
��/s�&c
�r�g}d}|D]�}|dk(rL|jd�dk(r|j|��.|j|d|jd��d}�T|jd�dk7r%|dxxd|d|jd�zz
cc<d}��|dxxd|zz
cc<��tdd�|D��S)	z�
        Transform multiline statements into single lines.

        @param lines: lines to work on
        @type lines: iterable of L{bytes}

        @return: iterable of continuous lines
        r�(r�Nr�)� c3�<K�|]}|j����y�wr&)r)r��lines  r!r�z6BindAuthority.collapseContinuations.<locals>.<genexpr>hs����8�d�T�Z�Z�\�8�s�)r�rN�filter)r,r�r�r0r�s     r!r�z#BindAuthority.collapseContinuationsPs���
�����	)�D���z��9�9�T�?�b�(��H�H�T�N��H�H�T�"3�D�I�I�d�O�4�5��E��9�9�T�?�b�(��b�E�T�D�):�4�9�9�T�?�$;�;�;�E��E��b�E�T�D�[�(�E�	)��d�8�a�8�9�9r-c��d}|j}i|_|D]j}|ddk(rtj|d�}�$|ddk(r|d}�2|ddk(rt	d��|ddk(rt	d	��|j|||��l||_y
)zs
        Parse C{lines}.

        @param lines: lines to work on
        @type lines: iterable of L{bytes}
        i0*rs$TTLrs$ORIGINs$INCLUDEz"$INCLUDE directive not implementeds	$GENERATEz#$GENERATE directive not implementedN)r�r;r�str2time�NotImplementedError�parseRecordLine)r,r�rBr�r�s     r!r�zBindAuthority.parseLinesjs�������������
	8�D��A�w�'�!��l�l�4��7�+���a��J�&��a����a��K�'�)�*N�O�O��a��L�(�)�*O�P�P��$�$�V�S�$�7�
	8���r-c��|jd�s|dz|ddz}n|dd}t|d|��d�}|r|||||�ytd|�d���)a
        Add a record to our authority.  Expand domain with origin if necessary.

        @param owner: origin?
        @type owner: L{bytes}

        @param ttl: time to live for the record
        @type ttl: L{int}

        @param domain: the domain for which the record is to be added
        @type domain: L{bytes}

        @param type: record type
        @type type: L{str}

        @param cls: record class
        @type cls: L{str}

        @param rdata: record data
        @type rdata: L{list} of L{bytes}
        r�Nr��class_z
Record class � not supported)�endswithr�r�)r,�ownerrBr7�domainrY�rdatars        r!�	addRecordzBindAuthority.addRecord�sh��,���t�$��d�]�U�3�B�Z�/�F��C�R�[�F��D�F�3�%�.�$�/���
�c�4���'�%�
�c�W�N�&K�L�Lr-c��ttdt|���d�}|rU||�}||_|jj|j
�g�j|�|dk(r
||f|_yytdt|��d���)a>
        Simulate a class IN and recurse into the actual class.

        @param ttl: time to live for the record
        @type ttl: L{int}

        @param type: record type
        @type type: str

        @param domain: the domain
        @type domain: bytes

        @param rdata:
        @type rdata: bytes
        r�NrRzRecord type r�)
r�rr	rBr;rr=rNrJr�)r,rBr7r�r�rErgs       r!�class_INzBindAuthority.class_IN�s��� ����T�(:�';�<�d�C������A��A�E��L�L�#�#�F�L�L�N�B�7�>�>�q�A��u�}�"�A�;����&��|�D�1�4�N�C��
r-c	��tjj�D�chc]}|jd���}}tjj�D�chc]}|jd���}}||z}d}	|}
|ddk(r|dd}|}
n$|dj�s|d|vr
|d}
|dd}|dj�s|d|vr|
}|}
n
|d}|dd}|d|vr1|d}	|dd}|dj�rKt
|d�}|dd}n7|dj�r$t
|d�}|dd}|d|vr
|d}	|dd}|d}|dd}
|j|
|t|�|t|	�|
�ycc}wcc}w)a�
        Parse a C{line} from a zone file respecting C{origin} and C{ttl}.

        Add resulting records to authority.

        @param origin: starting point for the zone
        @type origin: L{bytes}

        @param ttl: time to live for the record
        @type ttl: L{int}

        @param line: zone file line to parse; split by word
        @type line: L{list} of L{bytes}
        �asciisINr�@rN)	r�
QUERY_CLASSES�values�encode�QUERY_TYPES�isdigitrr�r	)r,r�rBr��qc�queryClasses�qt�
queryTypes�markersrYr�r�r7r�s              r!r�zBindAuthority.parseRecordLine�s���69�5F�5F�5M�5M�5O�P�r��	�	�'�*�P��P�36�?�?�3I�3I�3K�L�R�b�i�i��(�L�
�L���+��������7�d�?����8�D��E��a����"�t�A�w�g�'=���G�E����8�D���7�?�?���Q��7� 2��F��E��!�W�F����8�D���7�l�"��q�'�C����8�D��A�w��� ��$�q�'�l���A�B�x��
�!�W�_�_�
��d�1�g�,�C����8�D��A�w�,�&��1�g���A�B�x���A�w���Q�R������u�c�<��#5�v�|�C�?P�RW�X��MQ��Ls�E=�FN)rprqrrrsr)r�r�r�r�r�r�r3r-r!r�r�)s-����"
�:�4�6M�@�:5Yr-r�)z/tmp/twisted-names.serial)rsrr�twisted.internetr�
twisted.namesrrr�twisted.pythonr�twisted.python.compatrr	�twisted.python.filepathr
r"r'r$rxr�r3r-r!�<module>r�s\��
�

��"�,�,�"�8�,�$�NJ�F�'�'�J�Z�
��BNY�M�NYr-

Zerion Mini Shell 1.0