ok

Mini Shell

Direktori : /opt/alt/python311/lib64/python3.11/__pycache__/
Upload File :
Current File : //opt/alt/python311/lib64/python3.11/__pycache__/nntplib.cpython-311.pyc

�

�f����dZddlZddlZddlZddlZddlZddlZ	ddlZdZn
#e	$rdZYnwxYwddl
mZddlm
Z
gd�Zejed�	��d
ZGd�de��ZGd
�de��ZGd�de��ZGd�de��ZGd�de��ZGd�de��ZdZdZhd�Zgd�Zddd�ZdZejdgd ���Z ejd!gd"���Z!d#�Zd$�Z"dWd%�Z#dWd&�Z$dXd'�Z%erd(�Z&Gd)�d*��Z'er#Gd+�d,e'��Z(e�)d,��ed-k�r,ddl*Z*e*j+d.�/��Z,e,�-d0d1d2d3�4��e,�-d5d6d7d8�4��e,�-d9d:d;e.d<e�d=e�d>��?��e,�-d@dAdBe.dC�?��e,�-dDdEdFddG�H��e,�/��Z0e0j1Z1e0jse1d;kreZ1e'e0j2e1�I��Z3ne1d;kreZ1e(e0j2e1�I��Z3e3�4��Z5dJe5vre3�6��e3�7e0j7��\Z8Z9Z:Z;Z<e=dKe<dLe9dMe:dNe;��dO�Z>e?e.e;��e0j@z
dPz��Z:e3�Ae:e;��\Z8ZBeBD]�\ZCZDeeDdQ���EdRdP��dZFeeDdS��ZGe.eDd��ZHe=dT�IeCe>eFdU��e>eGdV��eH������e3�J��dSdS)Ya�An NNTP client class based on:
- RFC 977: Network News Transfer Protocol
- RFC 2980: Common NNTP Extensions
- RFC 3977: Network News Transfer Protocol (version 2)

Example:

>>> from nntplib import NNTP
>>> s = NNTP('news')
>>> resp, count, first, last, name = s.group('comp.lang.python')
>>> print('Group', name, 'has', count, 'articles, range', first, 'to', last)
Group comp.lang.python has 51 articles, range 5770 to 5821
>>> resp, subs = s.xhdr('subject', '{0}-{1}'.format(first, last))
>>> resp = s.quit()
>>>

Here 'resp' is the server response line.
Error responses are turned into exceptions.

To post an article from a file:
>>> f = open(filename, 'rb') # file containing article, including header
>>> resp = s.post(f)
>>>

For descriptions of all methods, read the comments in the code below.
Note that all arguments and return values representing article numbers
are strings, not numbers, since they are rarely used for calculations.
�NTF)�
decode_header)�_GLOBAL_DEFAULT_TIMEOUT)�NNTP�	NNTPError�NNTPReplyError�NNTPTemporaryError�NNTPPermanentError�NNTPProtocolError�
NNTPDataErrorr)��
)�removeic��eZdZdZd�ZdS)rz%Base class for all nntplib exceptionsc�v�tj|g|�R�	|d|_dS#t$rd|_YdSwxYw)NrzNo response given)�	Exception�__init__�response�
IndexError)�self�argss  �./opt/alt/python311/lib64/python3.11/nntplib.pyrzNNTPError.__init__esW����4�'�$�'�'�'�'�	0� ��G�D�M�M�M���	0�	0�	0�/�D�M�M�M�M�	0���s�
#�8�8N)�__name__�
__module__�__qualname__�__doc__r��rrrcs)������/�/�0�0�0�0�0rrc��eZdZdZdS)rzUnexpected [123]xx replyN�rrrrrrrrrls������"�"��Drrc��eZdZdZdS)rz
4xx errorsNrrrrrrp����������Drrc��eZdZdZdS)r	z
5xx errorsNrrrrr	r	tr!rr	c��eZdZdZdS)r
z"Response does not begin with [1-5]Nrrrrr
r
xs������,�,��Drr
c��eZdZdZdS)rzError in response dataNrrrrrr|s������ � ��Drr�wi3>�100�101�211�215�220�221�222�224�225�230�231�282)�subject�from�datez
message-id�
references�:bytes�:linesr6r7)�bytes�lines�
�	GroupInfo)�group�last�first�flag�ArticleInfo)�number�
message_idr9c��g}t|��D]Z\}}t|t��r+|�|�|pd�����E|�|���[d�|��S)zvTakes a unicode string representing a munged header value
    and decodes it as a (possibly non-ASCII) readable value.�ascii�)�_email_decode_header�
isinstancer8�append�decode�join)�
header_str�parts�v�encs    rrr�s|��
�E�&�z�2�2�����3��a����	��L�L����#�.��1�1�2�2�2�2��L�L��O�O�O�O�
�7�7�5�>�>�rc���g}|D]�}|ddkr'|dd��d��\}}}d|z}n|�d��\}}}|���}t�||��}|�|����t
}t
|��t
|��krtd���|dt
|���|krtd���|S)z�Parse a list of string representing the response to LIST OVERVIEW.FMT
    and return a list of header/metadata names.
    Raises NNTPDataError if the response is not compliant
    (cf. RFC 3977, section 8.4).r�:�Nz$LIST OVERVIEW.FMT response too shortz*LIST OVERVIEW.FMT redefines default fields)�	partition�lower�_OVERVIEW_FMT_ALTERNATIVES�getrH�_DEFAULT_OVERVIEW_FMT�lenr)r9�fmt�line�name�_�suffix�defaultss       r�_parse_overview_fmtr^�s���

�C�������7�c�>�>�"�1�2�2�h�0�0��5�5�O�D�!�V���:�D�D�#�n�n�S�1�1�O�D�!�V��z�z�|�|��)�-�-�d�D�9�9���
�
�4�����$�H�
�3�x�x�#�h�-�-����B�C�C�C�
�>�C��M�M�>��h�&�&��H�I�I�I��Jrc�(�tt��}g}|D]�}i}|�d��^}}t|��}t	|��D]�\}	}
|	t|��kr�||	}|�d��}|	|kr`|s^|dz}
|
r<|
dt|
������|
krtd���|
r|
t|
��d�nd}
|
|||	<��|�||f����|S)zZParse the response to an OVER or XOVER command according to the
    overview format `fmt`.�	rPz: Nz?OVER/XOVER response doesn't include names of additional headers)	rWrV�split�int�	enumerate�
startswithrSrrH)r9rX�data_process_func�
n_defaults�overviewrY�fields�article_number�tokens�i�token�
field_name�is_metadata�hs              r�_parse_overviewrp�sD���*�+�+�J��H��2�2����"&�*�*�T�"2�"2�����^�,�,��!�&�)�)�	#�	#�H�A�u��C��H�H�}�}���Q��J�$�/�/��4�4�K��J���{����%���G�U�7�C��F�F�7�^�1�1�3�3�q�8�8�'�)F�G�G�G�*/�9��c�!�f�f�g�g���T��"�F�3�q�6�N�N������0�1�1�1�1��Orc��|�|dd�}|dd�}t|dd���}t|dd���}t|dd���}t|dd���}t|dd���}t|dd���}|dkr|dz
}n|d	kr|d
z
}tj||||||��S)z�Parse a pair of (date, time) strings, and return a datetime object.
    If only the date is given, it is assumed to be date and time
    concatenated together (e.g. response to the DATE command).
    Ni�������������Fi��dil)rb�datetime)�date_str�time_str�hours�minutes�seconds�year�month�days        r�_parse_datetimer��s���
���B�C�C�=���C�R�C�=�����!�����E��(�1�Q�3�-� � �G��(�1�2�2�,���G��x����}���D����B��� � �E�

�h�r�s�s�m�
�
�C��b�y�y������	
����������T�5�#�u�g�w�G�G�Grc���t|tj��sd}nd�|��}|j}|r|dz}d�||��}nd�||��}||fS)aPFormat a date or datetime object as a pair of (date, time) strings
    in the format required by the NEWNEWS and NEWGROUPS commands.  If a
    date object is passed, the time is assumed to be midnight (00h00).

    The returned representation depends on the legacy flag:
    * if legacy is False (the default):
      date has the YYYYMMDD format and time the HHMMSS format
    * if legacy is True:
      date has the YYMMDD format and time the HHMMSS format.
    RFC 3977 compliant servers should understand both formats; therefore,
    legacy is only needed when talking to old servers.
    �000000z({0.hour:02d}{0.minute:02d}{0.second:02d}rwz{0:02d}{1.month:02d}{1.day:02d}z{0:04d}{1.month:02d}{1.day:02d})rGrx�formatr~)�dt�legacyrz�yrys     r�_unparse_datetimer�s����b�(�+�,�,�I����=�D�D�R�H�H��
��A�
�C�
��G��4�;�;�A�r�B�B���4�;�;�A�r�B�B���X��rc�Z�|�tj��}|�||���S)z�Wrap a socket in SSL/TLS. Arguments:
        - sock: Socket to wrap
        - context: SSL context to use for the encrypted connection
        Returns:
        - sock: New, encrypted socket.
        N)�server_hostname)�ssl�_create_stdlib_context�wrap_socket)�sock�context�hostnames   r�_encrypt_onr�s0���?��0�2�2�G��"�"�4��"�B�B�Brc��eZdZdZdZeddddefd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�ZeZd
�Zd�Zd8d�Zd�Zd9d�Zd�Zd9d�Zd9d�Zd�Zd�Zd�Zdd�d�Zdd�d�Zd9dd�d�Zd�Zd�Zd�Z d �Z!dd�d!�Z"d"�Z#d#�Z$d9d$�Z%d%�Z&d&�Z'd9d'�Z(d9dd�d(�Z)d9dd�d)�Z*d9dd�d*�Z+d+�Z,dd�d,�Z-dd�d-�Z.dd�d.�Z/d/�Z0d0�Z1d1�Z2d2�Z3d3�Z4d4�Z5d:d5�Z6d6�Z7e8rd9d7�Z9dSdS);rzutf-8�surrogateescapeNFc��||_||_|�|��|_d|_	|j�d��|_|�|��|s|r|�|||��dSdS#|jr|j���|j����xYw)a,Initialize an instance.  Arguments:
        - host: hostname to connect to
        - port: port to connect to (default the standard NNTP port)
        - user: username to authenticate with
        - password: password to use with username
        - readermode: if true, send 'mode reader' command after
                      connecting.
        - usenetrc: allow loading username and password from ~/.netrc file
                    if not specified explicitly
        - timeout: timeout (in seconds) used for socket connections

        readermode is sometimes necessary if you are connecting to an
        NNTP server on the local machine and intend to call
        reader-specific commands, such as `group'.  If you get
        unexpected NNTPPermanentErrors, you might need to set
        readermode.
        N�rwb)	�host�port�_create_socketr��file�makefile�
_base_init�login�close)rr�r��user�password�
readermode�usenetrc�timeouts        rrz
NNTP.__init__;s���(��	���	��'�'��0�0��	���	�		��	�*�*�5�1�1�D�I��O�O�J�'�'�'��
5�x�
5��
�
�4��8�4�4�4�4�4�
5�
5��	��y�
"��	���!�!�!��I�O�O�������s�AB�<Cc�(�d|_|���|_d|_|���d|_|r?d|jvr6|���|jsd|_|���d|_d|_dS)z~Partial initialization for the NNTP protocol.
        This instance method is extracted for supporting the test code.
        rNF�READER)	�	debugging�_getresp�welcome�_caps�getcapabilities�readermode_afterauth�_setreadermode�tls_on�
authenticated)rr�s  rr�zNNTP._base_init^s�������}�}�������
�������%*��!��	'�(�$�*�4�4����!�!�!��,�
'�!��
��$�$�&�&�&�
���#����rc��|S�Nr�rs r�	__enter__zNNTP.__enter__�s���rc����fd�}|��rs	����n#ttf$rYnwxYw|��r����dSdS#|��r����wwxYwdS)Nc�$��t�d��S)Nr�)�hasattrr�s�r�<lambda>zNNTP.__exit__.<locals>.<lambda>�s���w�t�V�4�4�r)�quit�OSError�EOFError�_close)rr�is_connecteds`  r�__exit__z
NNTP.__exit__�s����4�4�4�4���<�>�>�	"�
"��	�	�������X�&�
�
�
���
���� �<�>�>�"��K�K�M�M�M�M�M�"�"��<�<�>�>�"��K�K�M�M�M�M�"����
	"�	"s!�'�A �;�A �;�A � !Bc��|�|std���tjd||j|j��tj|j|jf|��S)Nz0Non-blocking socket (timeout=0) is not supportedznntplib.connect)�
ValueError�sys�auditr�r��socket�create_connection)rr�s  rr�zNNTP._create_socket�sS����w���O�P�P�P��	�#�T�4�9�d�i�@�@�@��'���D�I�(>��H�H�Hrc�b�|jr"tdt|j����|jS)z�Get the welcome message from the server
        (this is read and squirreled away by __init__()).
        If the response code is 200, posting is allowed;
        if it 201, posting is not allowed.z	*welcome*)r��print�reprr�r�s r�
getwelcomezNNTP.getwelcome�s-���>�A�5��d�4�<�.@�.@�A�A�A��|�rc�`�|j��d|_d|_	|���\}}||_d|vr-t	tt|d����|_d|vr d�|d��|_n#ttf$r
i|_YnwxYw|jS)z�Get the server capabilities, as read by __init__().
        If the CAPABILITIES command is not supported, an empty dict is
        returned.NrQ�VERSION�IMPLEMENTATION� )
r��nntp_version�nntp_implementation�capabilities�max�maprbrJr	r)r�resp�capss   rr�zNNTP.getcapabilities�s����:�� !�D��'+�D�$�
P�!�.�.�0�0�
��d�
"��
���$�$�),�C��T�)�_�,E�,E�(F�(F�D�%�#�t�+�+�/2�x�x��=M�8N�/O�/O�D�,���'�(:�;�
 �
 �
 ���
�
�
�
 �����z�s�B�B&�%B&c��||_dS)z�Set the debugging level.  Argument 'level' means:
        0: no debugging output (default)
        1: print commands and responses but not body text etc.
        2: also print raw lines read and sent before stripping CR/LFN)r�)r�levels  r�set_debuglevelzNNTP.set_debuglevel�s������rc��tjd||��|tz}|jdkrt	dt|����|j�|��|j���dS)zfInternal: send one line to the server, appending CRLF.
        The `line` must be a bytes-like object.znntplib.putlinerQz*put*N)	r�r��_CRLFr�r�r�r��write�flush�rrYs  r�_putlinez
NNTP._putline�sp��	�	�#�T�4�0�0�0��e�|���>�A���u�W�d�4�j�j�9�9�9��	��������	�������rc��|jrtdt|����|�|j|j��}|�|��dS)zkInternal: send one command to the server (through _putline()).
        The `line` must be a unicode string.z*cmd*N)r�r�r��encode�encoding�errorsr�r�s  r�_putcmdzNNTP._putcmd�sP���>�5�5��$�t�*�*�5�5�5��{�{�4�=�$�+�6�6���
�
�d�����rTc�p�|j�tdz��}t|��tkrt	d���|jdkrt
dt|����|st�|r9|dd�tkr|dd�}n|dd�tvr
|dd�}|S)z�Internal: return one line from the server, stripping _CRLF.
        Raise EOFError if the connection is closed.
        Returns a bytes object.rQz
line too longz*get*ruN���)
r��readline�_MAXLINErWrr�r�r�r�r�)r�
strip_crlfrYs   r�_getlinez
NNTP._getline�s����y�!�!�(�A�+�.�.���t�9�9�x�����0�0�0��>�A����'�4��:�:�&�&�&��#�8�^��	!��B�C�C�y�E�!�!��C�R�C�y����b�c�c��e�#�#��C�R�C�y���rc�D�|���}|jrtdt|����|�|j|j��}|dd�}|dkrt|���|dkrt|���|dvrt|���|S)z�Internal: get a response from the server.
        Raise various errors if the response indicates an error.
        Returns a unicode string.z*resp*NrQ�4�5�123)
r�r�r�r�rIr�r�rr	r
)rr��cs   rr�z
NNTP._getresp�s����}�}�����>�6�5��4��:�:�6�6�6��{�{�4�=�$�+�6�6����!��H����8�8�$�T�*�*�*���8�8�$�T�*�*�*��E�>�>�#�D�)�)�)��rc��d}	t|ttf��rt|d��x}}|���}|dd�t
vrt
|���g}|�]dtzdf}	|�d��}||vrn5|�	d��r
|dd�}|�
|���OnSd}	|���}||krn5|�	d��r
|dd�}|�|���P|r|���n#|r|���wwxYw||fS)	aPInternal: get a response plus following text from the server.
        Raise various errors if the response indicates an error.

        Returns a (response, lines) tuple where `response` is a unicode
        string and `lines` is a list of bytes objects.
        If `file` is a file-like object, it must be open in binary mode.
        N�wbr�.s.
rQFs..)
rG�strr8�openr��	_LONGRESPrr�r�rdr�rHr�)rr��
openedFiler�r9�terminatorsrY�
terminators        r�_getlongrespzNNTP._getlongresp�s����
� 	#��$��e��-�-�
5�$(��t�$4�$4�4�
�T��=�=�?�?�D��B�Q�B�x�y�(�(�$�T�*�*�*��E���#�e�|�V�4��%��=�=��/�/�D��{�*�*�����u�-�-�(�#�A�B�B�x���J�J�t�$�$�$�
%��
"�
�'��=�=�?�?�D��z�)�)�����u�-�-�(�#�A�B�B�x���L�L��&�&�&�
'��
#�� � �"�"�"����
#�� � �"�"�"�"�
#�����U�{�s�DD1�1E
c�T�|�|��|���S)zWInternal: send a command and get the response.
        Same return value as _getresp().)r�r�r�s  r�	_shortcmdzNNTP._shortcmds$��	
���T�����}�}���rc�V�|�|��|�|��S)zoInternal: send a command and get the response plus following text.
        Same return value as _getlongresp().�r�r�)rrYr�s   r�_longcmdz
NNTP._longcmd!s*��	
���T����� � ��&�&�&rc�~����|����|��\}}|�fd�|D��fS)z�Internal: send a command and get the response plus following text.
        Same as _longcmd() and _getlongresp(), except that the returned `lines`
        are unicode strings rather than bytes objects.
        c�P��g|]"}|��j�j����#Sr)rIr�r�)�.0rYrs  �r�
<listcomp>z'NNTP._longcmdstring.<locals>.<listcomp>.s;���(�(�(���k�k�$�-���=�=�(�(�(rr�)rrYr�r��lists`    r�_longcmdstringzNNTP._longcmdstring'sa���
	
���T�����&�&�t�,�,�
��d��(�(�(�(�"&�(�(�(�(�	(rc���	|jS#t$rYnwxYw	|�d��\}}t|��}n#t$rt
dd�}YnwxYw||_|S)zqInternal: get the overview format. Queries the server if not
        already done, else returns the cached value.zLIST OVERVIEW.FMTN)�_cachedoverviewfmt�AttributeErrorr�r^r	rV)rr�r9rXs    r�_getoverviewfmtzNNTP._getoverviewfmt1s���	��*�*���	�	�	��D�	����	-��-�-�.A�B�B�K�D�%�
&�e�,�,�C�C��	"�	+�	+�	+�'����*�C�C�C�	+����
#&����
s�	�
��A�A�Ac��d�|D��S)Nc�D�g|]}t|������Sr)r;ra)r�rYs  rr�z#NNTP._grouplist.<locals>.<listcomp>Ds%��;�;�;�T�	�4�:�:�<�<�(�;�;�;rr)rr9s  r�
_grouplistzNNTP._grouplistBs��;�;�U�;�;�;�;rc�~�i}|�d��\}}|D]}|���^}}|||<�||fS)a!Process a CAPABILITIES command.  Not supported by all servers.
        Return:
        - resp: server response if successful
        - caps: a dictionary mapping capability names to lists of tokens
        (for example {'VERSION': ['2'], 'OVER': [], LIST: ['ACTIVE', 'HEADERS'] })
        �CAPABILITIES)r�ra)rr�r�r9rYrZrjs       rr�zNNTP.capabilitiesFsU�����)�)�.�9�9���e��	 �	 �D� �J�J�L�L�M�D�6��D��J�J��T�z�r)r�c�j�t|tjtjf��s,td�|jj�����t||jdk��\}}d�||��}|�	||��\}}||�
|��fS)z�Process a NEWGROUPS command.  Arguments:
        - date: a date or datetime object
        Return:
        - resp: server response if successful
        - list: list of newsgroup names
        �Athe date parameter must be a date or datetime object, not '{:40}'rrzNEWGROUPS {0} {1})rGrxr4�	TypeErrorr��	__class__rr�r�r�r)rr4r�ryrz�cmdr�r9s        r�	newgroupszNNTP.newgroupsTs����$����
� >�?�?�	?���$�f�T�^�%<�=�=�?�?�
?�/�t�T�5F��5J�K�K���(�!�(�(��8�<�<���)�)�#�t�4�4���e��T�_�_�U�+�+�+�+rc�8�t|tjtjf��s,td�|jj�����t||jdk��\}}d�|||��}|�	||��S)z�Process a NEWNEWS command.  Arguments:
        - group: group name or '*'
        - date: a date or datetime object
        Return:
        - resp: server response if successful
        - list: list of message ids
        r	rrzNEWNEWS {0} {1} {2})
rGrxr4r
r�rrr�r�r�)rr<r4r�ryrzrs       r�newnewszNNTP.newnewsds����$����
� >�?�?�	?���$�f�T�^�%<�=�=�?�?�
?�/�t�T�5F��5J�K�K���(�#�*�*�5�(�H�E�E���"�"�3��-�-�-rc�v�|�d|z}nd}|�||��\}}||�|��fS)a@Process a LIST or LIST ACTIVE command. Arguments:
        - group_pattern: a pattern indicating which groups to query
        - file: Filename string or file object to store the result in
        Returns:
        - resp: server response if successful
        - list: list of (group, last, first, flag) (strings)
        NzLIST ACTIVE �LIST)r�r)r�
group_patternr��commandr�r9s      rr�z	NNTP.listtsK���$�$�}�4�G�G��G��)�)�'�4�8�8���e��T�_�_�U�+�+�+�+rc�x�tjd��}|�d|z��\}}|�d��s|�d|z��\}}i}|D]O}|�|�����}|r$|�dd��\}	}
|s|
cS|
||	<�P|r||fSdS)Nz^(?P<group>[^ 	]+)[ 	]+(.*)$zLIST NEWSGROUPS r)zXGTITLE rQrrrE)�re�compiler�rd�search�stripr<)rr�
return_all�line_patr�r9�groups�raw_line�matchrZ�descs           r�_getdescriptionszNNTP._getdescriptions�s����:�>�?�?���)�)�*<�}�*L�M�M���e����u�%�%�	J��-�-�j�=�.H�I�I�K�D�%����	$�	$�H��O�O�H�N�N�$4�$4�5�5�E��
$�"�[�[��A�.�.�
��d�!� ��K�K�K�#��t����	���<���2rc�.�|�|d��S)a�Get a description for a single group.  If more than one
        group matches ('group' is a pattern), return the first.  If no
        group matches, return an empty string.

        This elides the response code from the server, since it can
        only be '215' or '285' (for xgtitle) anyway.  If the response
        code is needed, use the 'descriptions' method.

        NOTE: This neither checks for a wildcard in 'group' nor does
        it check whether the group actually exists.F�r)rr<s  r�descriptionzNNTP.description�s���$�$�U�E�2�2�2rc�.�|�|d��S)z'Get descriptions for a range of groups.Tr!)rrs  r�descriptionszNNTP.descriptions�s���$�$�]�D�9�9�9rc��|�d|z��}|�d��st|���|���}dx}x}}t	|��}|dkrD|d}|dkr6|d}|dkr(|d}|dkr|d���}|t
|��t
|��t
|��|fS)aProcess a GROUP command.  Argument:
        - group: the group name
        Returns:
        - resp: server response if successful
        - count: number of articles
        - first: first article number
        - last: last article number
        - name: the group name
        zGROUP r(rrQrrrrs)r�rdrrarWrSrb)rrZr��words�countr>r=�ns        rr<z
NNTP.group�s����~�~�h��o�.�.�����u�%�%�	'� ��&�&�&��
�
���� � �� �����J�J���q�5�5��!�H�E��1�u�u��a����q�5�5� ��8�D��1�u�u�$�Q�x�~�~�/�/���S��Z�Z��U���S��Y�Y��<�<rc�.�|�d|��S)aProcess a HELP command. Argument:
        - file: Filename string or file object to store the result in
        Returns:
        - resp: server response if successful
        - list: list of strings returned by the server in response to the
                HELP command
        �HELP)r�)rr�s  r�helpz	NNTP.help�s���"�"�6�4�0�0�0rc��|�d��st|���|���}t|d��}|d}|||fS)z_Internal: parse the response line of a STAT, NEXT, LAST,
        ARTICLE, HEAD or BODY command.�22rQrr)rdrrarb)rr�r&�art_numrBs     r�
_statparsezNNTP._statparse�sX�����t�$�$�	'� ��&�&�&��
�
�����e�A�h�-�-���1�X�
��W�j�(�(rc�V�|�|��}|�|��S)z/Internal: process a STAT, NEXT or LAST command.)r�r/)rrYr�s   r�_statcmdz
NNTP._statcmd�s%���~�~�d�#�#�����t�$�$�$rc��|r(|�d�|����S|�d��S)a(Process a STAT command.  Argument:
        - message_spec: article number or message id (if not specified,
          the current article is selected)
        Returns:
        - resp: server response if successful
        - art_num: the article number
        - message_id: the message id
        zSTAT {0}�STAT)r1r�)r�message_specs  r�statz	NNTP.stat�s>���	)��=�=��!2�!2�<�!@�!@�A�A�A��=�=��(�(�(rc�,�|�d��S)z;Process a NEXT command.  No arguments.  Return as for STAT.�NEXT�r1r�s r�nextz	NNTP.next�����}�}�V�$�$�$rc�,�|�d��S)z;Process a LAST command.  No arguments.  Return as for STAT.�LASTr8r�s rr=z	NNTP.last�r:rc��|�||��\}}|�|��\}}}|t|||��fS)z2Internal: process a HEAD, BODY or ARTICLE command.)r�r/r@)rrYr�r�r9r.rBs       r�_artcmdzNNTP._artcmd�sH���m�m�D�$�/�/���e�$(�O�O�D�$9�$9�!��g�z��[��*�e�<�<�<�<rc�b�|�d�|��}nd}|�||��S)a0Process a HEAD command.  Argument:
        - message_spec: article number or message id
        - file: filename string or file object to store the headers in
        Returns:
        - resp: server response if successful
        - ArticleInfo: (article number, message id, list of header lines)
        NzHEAD {0}�HEAD�r�r>�rr4r�rs    r�headz	NNTP.head��8���#��#�#�L�1�1�C�C��C��|�|�C��&�&�&rc�b�|�d�|��}nd}|�||��S)a+Process a BODY command.  Argument:
        - message_spec: article number or message id
        - file: filename string or file object to store the body in
        Returns:
        - resp: server response if successful
        - ArticleInfo: (article number, message id, list of body lines)
        NzBODY {0}�BODYrArBs    r�bodyz	NNTP.bodyrDrc�b�|�d�|��}nd}|�||��S)a5Process an ARTICLE command.  Argument:
        - message_spec: article number or message id
        - file: filename string or file object to store the article in
        Returns:
        - resp: server response if successful
        - ArticleInfo: (article number, message id, list of article lines)
        NzARTICLE {0}�ARTICLErArBs    r�articlezNNTP.articles8���#��&�&�|�4�4�C�C��C��|�|�C��&�&�&rc�,�|�d��S)zYProcess a SLAVE command.  Returns:
        - resp: server response if successful
        �SLAVE)r�r�s r�slavez
NNTP.slave$s���~�~�g�&�&�&rc����tjd���|�d�||��|��\}}�fd��|�fd�|D��fS)aiProcess an XHDR command (optional server extension).  Arguments:
        - hdr: the header type (e.g. 'subject')
        - str: an article nr, a message id, or a range nr1-nr2
        - file: Filename string or file object to store the result in
        Returns:
        - resp: server response if successful
        - list: list of (nr, value) strings
        z^([0-9]+) ?(.*)
?zXHDR {0} {1}c�b����|��}|r|�dd��n|S)NrQrr)rr<)rY�m�pats  �r�
remove_numberz NNTP.xhdr.<locals>.remove_number5s-����	�	�$���A�$%�/�1�7�7�1�a�=�=�=�4�/rc�&��g|]
}�|����Srr)r�rYrRs  �rr�zNNTP.xhdr.<locals>.<listcomp>8s#���<�<�<�d�m�m�D�)�)�<�<�<r)rrr�r�)r�hdrr�r�r�r9rQrRs      @@r�xhdrz	NNTP.xhdr*sz�����j�-�.�.���)�)�.�*?�*?��S�*I�*I�4�P�P���e�	0�	0�	0�	0�	0��<�<�<�<�e�<�<�<�<�<rc��|�d�||��|��\}}|���}|t||��fS)aFProcess an XOVER command (optional server extension) Arguments:
        - start: start of range
        - end: end of range
        - file: Filename string or file object to store the result in
        Returns:
        - resp: server response if successful
        - list: list of dicts containing the response fields
        z
XOVER {0}-{1})r�r�rrp)r�start�endr�r�r9rXs       r�xoverz
NNTP.xover:sX���)�)�/�*@�*@���*L�*L�*.�0�0���e��"�"�$�$���_�U�C�0�0�0�0rc�(�d|jvrdnd}t|ttf��r!|\}}|d�||pd��z
}n
|�|dz|z}|�||��\}}|���}|t||��fS)a�Process an OVER command.  If the command isn't supported, fall
        back to XOVER. Arguments:
        - message_spec:
            - either a message id, indicating the article to fetch
              information about
            - or a (start, end) tuple, indicating a range of article numbers;
              if end is None, information up to the newest message will be
              retrieved
            - or None, indicating the current article number must be used
        - file: Filename string or file object to store the result in
        Returns:
        - resp: server response if successful
        - list: list of dicts containing the response fields

        NOTE: the "message id" form isn't supported by XOVER
        �OVER�XOVERz {0}-{1}rENr�)r�rG�tupler�r�r�rrp)	rr4r�rrWrXr�r9rXs	         r�overz	NNTP.overHs���"�$�*�,�,�f�f�'���l�U�D�M�2�2�	+�%�J�E�3��:�$�$�U�C�I�2�6�6�6�C�C�
�
%���)�l�*�C��)�)�#�t�4�4���e��"�"�$�$���_�U�C�0�0�0�0rc�X�|�d��}|�d��st|���|���}t	|��dkrt|���|d}t	|��dkrt|���|t
|d��fS)z�Process the DATE command.
        Returns:
        - resp: server response if successful
        - date: datetime object
        �DATE�111rrrQ�N)r�rdrrarWrr�)rr��elemr4s    rr4z	NNTP.datecs����~�~�f�%�%�����u�%�%�	'� ��&�&�&��z�z�|�|���t�9�9��>�>���%�%�%��A�w���t�9�9��?�?���%�%�%��_�T�4�0�0�0�0rc�B�|�|��}|�d��st|���t|tt
f��r|���}|D]m}|�t��s|�	d��tz}|�d��rd|z}|j
�|���n|j
�d��|j
���|�
��S)N�3r:r�s.
)r�rdrrGr8�	bytearray�
splitlines�endswithr��rstripr�r�r�r�)rr�fr�rYs     r�_postz
NNTP._postts����~�~�g�&�&�����s�#�#�	'� ��&�&�&��a�%��+�,�,�	������A�
�	"�	"�D��=�=��'�'�
4��{�{�7�+�+�e�3�����t�$�$�
#��d�{���I�O�O�D�!�!�!�!��	����!�!�!��	�������}�}���rc�.�|�d|��S)z�Process a POST command.  Arguments:
        - data: bytes object, iterable or file containing the article
        Returns:
        - resp: server response if successful�POST)rk)r�datas  r�postz	NNTP.post�s��
�z�z�&�$�'�'�'rc�T�|�d�|��|��S)aProcess an IHAVE command.  Arguments:
        - message_id: message-id of the article
        - data: file containing the article
        Returns:
        - resp: server response if successful
        Note that if the server refuses the article an exception is raised.z	IHAVE {0})rkr�)rrBrns   r�ihavez
NNTP.ihave�s&���z�z�+�,�,�Z�8�8�$�?�?�?rc��	|jr|j���|`|j���dS#|j���wxYwr�)r�r�r�r�s rr�zNNTP._close�sX��	��y�
��	���!�!�!��I��I�O�O�������D�I�O�O�������s	�"?�Ac��	|�d��}|���n#|���wxYw|S)zdProcess a QUIT command and close the socket.  Returns:
        - resp: server response if successful�QUIT)r�r�)rr�s  rr�z	NNTP.quit�s>��	��>�>�&�)�)�D��K�K�M�M�M�M��D�K�K�M�M�M�M�����s	�,�Ac���|jrtd���|s|std���	|rF|sDddl}|���}|�|j��}|r|d}|d}n#t
$rYnwxYw|sdS|�d|z��}|�d��rM|st|���|�d|z��}|�d��st|���d|_
|���|jr:d	|j
vr3|�
��d|_
|���dSdSdS)
NzAlready logged in.z7At least one of `user` and `usenetrc` must be specifiedrrrzauthinfo user �381zauthinfo pass �281r�)r�r��netrc�authenticatorsr�r�r�rdrr	r�r�r�r�)rr�r�r�rx�credentials�authr�s        rr�z
NNTP.login�s�����	3��1�2�2�2��	K�H�	K��I�K�K�
K�
		��
'��
'�����#�k�k�m�m��"�1�1�$�)�<�<���'���7�D�#�A�w�H����	�	�	��D�	�����	��F��~�~�.��5�6�6���?�?�5�!�!�	3��
3�$�T�*�*�*��~�~�&6��&A�B�B�����u�-�-�3�,�T�2�2�2���
��������$�	#����)C�)C����!�!�!��D�J�� � �"�"�"�"�"�		#�	#�)C�)Cs�AA4�4
B�Bc���	|�d��|_dS#t$rYdSt$r.}|j�d��rd|_n�Yd}~dSd}~wwxYw)Nzmode reader�480T)r�r�r	rrrdr�)r�es  rr�zNNTP._setreadermode�s���
	��>�>�-�8�8�D�L�L�L��!�	�	�	��D�D�!�	�	�	��z�$�$�U�+�+�
�,0��)�)��*�)�)�)�)�)�����	���s��
A"�	A"�#A�A"c���|jrtd���|jrtd���|�d��}|�d��r||j���t|j||j	��|_|j�
d��|_d|_d|_|���dStd���)	zzProcess a STARTTLS command. Arguments:
            - context: SSL context to use for the encrypted connection
            zTLS is already enabled.z+TLS cannot be started after authentication.�STARTTLS�382r�TNzTLS failed to start.)r�r�r�r�rdr�r�r�r�r�r�r�r�r)rr�r�s   r�starttlsz
NNTP.starttls�s����{�
<� �!:�;�;�;��!�
P� �!N�O�O�O��>�>�*�-�-�D����u�%�%�

8��	���!�!�!�'��	�7�D�I�F�F��	� �I�.�.�u�5�5��	�"���"��
��$�$�&�&�&�&�&�� 6�7�7�7r)Tr�)NNT):rrrr�r��	NNTP_PORTrrr�r�r�r�r�r�r��debugr�r�r�r�r�r�r�r�rrr�r
rr�rr"r$r<r+r/r1r5r9r=r>rCrGrJrMrUrYr^r4rkrorqr�r�r�r��	_have_sslr�rrrrr+s��������H�
�F�"+�$�� �5�0�!�!�!�!�F #� #� #�D���	"�	"�	"�I�I�I�������,���
�E�����������"��� ,�,�,�,�\���'�'�'�'�(�(�(�(����"<�<�<����'+�,�,�,�,�,� ,0�.�.�.�.�.� 
,�t�
,�
,�
,�
,�
,����.3�3�3�:�:�:�=�=�=�4 �1�1�1�1�1�)�)�)�%�%�%�
)�)�)�)�%�%�%�%�%�%�=�=�=�=�'�d�'�'�'�'�'�'�d�'�'�'�'�'�'��'�'�'�'�'�'�'�'�&*�=�=�=�=�=� )-�1�1�1�1�1�*.�1�1�1�1�1�61�1�1�"���*(�(�(�@�@�@�������'#�'#�'#�'#�R����8�	8�	8�	8�	8�	8�	8�8�8rrc�8��eZdZedddddef�fd�	Z�fd�Z�xZS)�NNTP_SSLNFc		�d��||_t���|||||||��dS)z�This works identically to NNTP.__init__, except for the change
            in default port and the `ssl_context` argument for SSL connections.
            N)�ssl_context�superr)
rr�r�r�r�r�r�r�r�rs
         �rrzNNTP_SSL.__init__�sB��� +�D���G�G���T�4��x��%�w�
0�
0�
0�
0�
0rc���t���|��}	t||j|j��}|S#|����xYwr�)r�r�r�r�r�r�)rr�r�rs   �rr�zNNTP_SSL._create_socketsU����7�7�)�)�'�2�2�D�
�"�4��)9�4�9�E�E��
���	
��
�
�������s�A�A)rrr�
NNTP_SSL_PORTrrr��
__classcell__)rs@rr�r��sh�������&3���$�#�e�3�		0�		0�		0�		0�		0�		0�	�	�	�	�	�	�	�	�	rr��__main__zJ        nntplib built-in demo - display the latest articles in a newsgroup)r"z-gz--groupzgmane.comp.python.generalz3group to fetch messages from (default: %(default)s))�defaultr+z-sz--serverz
news.gmane.ioz+NNTP server hostname (default: %(default)s)z-pz--portr�zNNTP port number (default: z / �))r��typer+z-nz
--nb-articles�
z2number of articles to fetch (default: %(default)s)z-Sz--ssl�
store_truezuse NNTP over SSL)�actionr�r+)r�r�r��Group�haszarticles, range�toc�L�t|��|kr|d|dz
�dz}|S)Nrsz...)rW)�s�lims  r�cutr�6s,���q�6�6�C�<�<��(�3��7�(��e�#�A��rrQr3�<r2z{:7} {:20} {:42} ({})��*r�)F)Krrr��collectionsrxr��warningsr�r��ImportError�email.headerrrFr�__all__�_deprecatedrr�rrrrr	r
rr�r�r�rVrTr��
namedtupler;r@r^rpr�r�r�rr�rH�argparse�ArgumentParser�parser�add_argumentrb�
parse_argsrr��serverr�r�r�r�r<r�r'r>r=rZr�r�r��nb_articlesrY�	overviews�artnumr^ra�authorr2r9r�r�rrr�<module>r�se����B
�	�	�	�
�
�
�
���������
�
�
�
�������J�J�J��I�I�������I�I�I�����
?�>�>�>�>�>�*�*�*�*�*�*�
�
�
�����X�g�.�.�.�.���0�0�0�0�0�	�0�0�0�	�	�	�	�	�Y�	�	�	�	�	�	�	�	��	�	�	�	�	�	�	�	��	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�I�	�	�	�
�	��
�

�

�

�	� O�O�O��
�
����	��"�K�"�;�#E�#E�#E�
G�
G�	�%�k�$�]�%F�%F�%F�H�H��
	�	�	����2����:H�H�H�H�,����4
�C�
C�
C�
C�K8�K8�K8�K8�K8�K8�K8�K8�\
�������4����.�N�N�:�����z����O�O�O�
$�X�
$�2N�O�O�O�F�
����i�1L�R��T�T�T�
����j�/�J��L�L�L�
����h����FO�i�i�Q^�Q^�Q^�_��a�a�a�
����o�r��Q��S�S�S�
����g�l�E�0��2�2�2������D��9�D��8�2��2�:�:��D��D�d�k��-�-�-����2�:�:� �D��H�$�+�D�1�1�1�������D��T���	�
�
����%&�W�W�T�Z�%8�%8�"�D�%���d�	�E�'�4���'8�%��t�L�L�L����

�C���D�	�	�D�,�,�q�0�1�1�E��g�g�e�T�*�*�O�D�)�!��������t�F�|�,�,�2�2�3��:�:�1�=���-��Y��0�0����D��N�#�#��
��%�,�,��c�c�&�"�o�o�s�s�7�B�'7�'7��@�@�	�	�	�	��F�F�H�H�H�H�H�a�s�#�-�-

Zerion Mini Shell 1.0