AlkantarClanX12

Your IP : 3.149.23.123


Current Path : /opt/alt/python310/lib64/python3.10/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/__pycache__/nntplib.cpython-310.opt-1.pyc

o

6��f?��	@s>dZddlZddlZddlZddlZddlZzddlZWney'dZYnwdZddl	m
ZddlmZgd�Z
dZGd	d
�d
e�ZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZdZdZhd�Zgd�Zddd�ZdZe�dgd��Ze�dgd ��Zd!d"�Z
d#d$�ZdZd%d&�Z dZd'd(�Z!d[d)d*�Z"er�d+d,�Z#Gd-d.�d.�Z$er�Gd/d0�d0e$�Z%e
�&d0�e'd1k�r�ddl(Z(e(j)d2d3�Z*e*j+d4d5d6d7d8�e*j+d9d:d;d<d8�e*j+d=d>d?e,d@eefdA�e*j+dBdCdDe,dEdA�e*j+dFdGdHddIdJ�e*�-�Z.e.j/Z/e.j�se/d?k�reZ/e$e.j0e/dK�Z1ne/d?k�r&eZ/e%e.j0e/dK�Z1e1�2�Z3dLe3v�r:e1�4�e1�5e.j5�\Z6Z7Z8Z9Z:e;dMe:dNe7dOe8dPe9�dQdR�Z<e=e,e9�e.j>dS�Z8e1�?e8e9�\Z6Z@e@D]-\ZAZBe
eBdT��CdUdS�dZDe
eBdV�ZEe,eBd�ZFe;dW�GeAe<eDdX�e<eEdY�eF���qie1�H�dSdS)\a�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.
�NFT)�
decode_header)�_GLOBAL_DEFAULT_TIMEOUT)�NNTP�	NNTPError�NNTPReplyError�NNTPTemporaryError�NNTPPermanentError�NNTPProtocolError�
NNTPDataErrorric@seZdZdZdd�ZdS)rz%Base class for all nntplib exceptionscGs>tj|g|�R�z|d|_WdStyd|_YdSw)NrzNo response given)�	Exception�__init__�response�
IndexError)�self�args�r�./opt/alt/python310/lib64/python3.10/nntplib.pyrbs�zNNTPError.__init__N)�__name__�
__module__�__qualname__�__doc__rrrrrr`src@�eZdZdZdS)rzUnexpected [123]xx replyN�rrrrrrrrri�rc@r)rz
4xx errorsNrrrrrrmrrc@r)rz
5xx errorsNrrrrrrqrrc@r)r	z"Response does not begin with [1-5]Nrrrrrr	urr	c@r)r
zError in response dataNrrrrrr
yrr
�wi3>Z222Z101Z282Z230�215Z224Z100Z225Z231Z221�211Z220)�subject�from�datez
message-idZ
references�:bytes�:linesr r!)�bytes�lines�
�	GroupInfo)�group�last�first�flag�ArticleInfo)Znumber�
message_idr#cCsJg}t|�D]\}}t|t�r|�|�|pd��q|�|�qd�|�S)zvTakes a unicode string representing a munged header value
    and decodes it as a (possibly non-ASCII) readable value.�ascii�)�_email_decode_header�
isinstancer"�append�decode�join)Z
header_str�parts�v�encrrrr�s

rcCs�g}|D]0}|ddkr|dd��d�\}}}d|}n|�d�\}}}|��}t�||�}|�|�qt}t|�t|�krCtd��|dt|��|krQtd��|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�getr0�_DEFAULT_OVERVIEW_FMT�lenr
)r#�fmt�line�name�_�suffix�defaultsrrr�_parse_overview_fmt�s
rDcCs�tt�}g}|D]]}i}|�d�^}}t|�}t|�D]B\}	}
|	t|�kr&q||	}|�d�}|	|krW|sW|d}
|
rK|
dt|
����|
krKtd��|
rU|
t|
�d�nd}
|
|||	<q|�||f�q|S)zZParse the response to an OVER or XOVER command according to the
    overview format `fmt`.�	r6z: Nz?OVER/XOVER response doesn't include names of additional headers)	r=r<�split�int�	enumerate�
startswithr9r
r0)r#r>Zdata_process_funcZ
n_defaultsZoverviewr?ZfieldsZarticle_number�tokens�i�tokenZ
field_nameZis_metadata�hrrr�_parse_overview�s&
rNcCs�|dur|dd�}|dd�}t|dd��}t|dd��}t|dd��}t|dd��}t|dd��}t|dd��}|dkrI|d7}n|d	krQ|d
7}t�||||||�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)rG�datetime)�date_str�time_strZhoursZminutesZseconds�yearZmonthZdayrrr�_parse_datetime�s
rYcCsVt|tj�s	d}nd�|�}|j}|r!|d}d�||�}||fSd�||�}||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.
    Z000000z({0.hour:02d}{0.minute:02d}{0.second:02d}rTz{0:02d}{1.month:02d}{1.day:02d}z{0:04d}{1.month:02d}{1.day:02d})r/rU�formatrX)ZdtZlegacyrW�yrVrrr�_unparse_datetime�s

�r\cCs|durt��}|j||d�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)Zserver_hostname)�sslZ_create_stdlib_contextZwrap_socket)�sock�contextZhostnamerrr�_encrypt_onsr`c@seZdZdZdZeddddefdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�ZeZdd�Zdd�Zdidd�Zdd�Zdjdd�Zd d!�Zdjd"d#�Zdjd$d%�Zd&d'�Zd(d)�Zd*d+�Zdd,�d-d.�Zdd,�d/d0�Zdjdd,�d1d2�Zd3d4�Zd5d6�Zd7d8�Z d9d:�Z!dd,�d;d<�Z"d=d>�Z#d?d@�Z$djdAdB�Z%dCdD�Z&dEdF�Z'djdGdH�Z(djdd,�dIdJ�Z)djdd,�dKdL�Z*djdd,�dMdN�Z+dOdP�Z,dd,�dQdR�Z-dd,�dSdT�Z.dd,�dUdV�Z/dWdX�Z0dYdZ�Z1d[d\�Z2d]d^�Z3d_d`�Z4dadb�Z5dkdcdd�Z6dedf�Z7e8�rdjdgdh�Z9dSdS)lrzutf-8�surrogateescapeNFcCs|||_||_|�|�|_d|_z|j�d�|_|�|�|s |r*|�|||�WdSWdS|jr8|j��|j���)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)rrcrd�user�password�
readermode�usenetrc�timeoutrrrr8s
�

z
NNTP.__init__cCs^d|_|��|_d|_|��d|_|r'd|jvr'|��|js'd|_|��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)rrmrrrrh[s
	
zNNTP._base_initcCs|S�Nr�rrrr�	__enter__}szNNTP.__enter__c	sf�fdd�}|�r1zz���WnttfyYnwW|�r&���dSdS|�r0���wwdS)Ncs
t�d�S)Nrf)�hasattrrr{rr�<lambda>�s
zNNTP.__exit__.<locals>.<lambda>)�quit�OSError�EOFError�_close)rrZis_connectedrr{r�__exit__�s��
�
��z
NNTP.__exit__cCs<|dur
|s
td��t�d||j|j�t�|j|jf|�S)Nz0Non-blocking socket (timeout=0) is not supportedznntplib.connect)�
ValueError�sys�auditrcrd�socketZcreate_connection)rrorrrre�szNNTP._create_socketcCs|jrtdt|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*)rq�print�reprrsr{rrr�
getwelcome�szNNTP.getwelcomec	Cs�|jdurAd|_d|_z|��\}}Wnttfy#i|_Y|jSw||_d|vr5ttt|d��|_d|vrAd�	|d�|_|jS)z�Get the server capabilities, as read by __init__().
        If the CAPABILITIES command is not supported, an empty dict is
        returned.Nr7ZVERSIONZIMPLEMENTATION� )
rt�nntp_versionZnntp_implementation�capabilitiesrr�max�maprGr2)r�resp�capsrrrru�s
	�zNNTP.getcapabilitiescCs
||_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)rq)r�levelrrr�set_debuglevel�s
zNNTP.set_debuglevelcCsHt�d||�|t}|jdkrtdt|��|j�|�|j��dS)zfInternal: send one line to the server, appending CRLF.
        The `line` must be a bytes-like object.znntplib.putliner7z*put*N)	r�r��_CRLFrqr�r�rf�write�flush�rr?rrr�_putline�s
z
NNTP._putlinecCs2|jr
tdt|��|�|j|j�}|�|�dS)zkInternal: send one command to the server (through _putline()).
        The `line` must be a unicode string.z*cmd*N)rqr�r��encode�encoding�errorsr�r�rrr�_putcmd�szNNTP._putcmdTcCs�|j�td�}t|�tkrtd��|jdkrtdt|��|s"t�|rB|dd�t	kr4|dd�}|S|dd�t	vrB|dd�}|S)z�Internal: return one line from the server, stripping _CRLF.
        Raise EOFError if the connection is closed.
        Returns a bytes object.r7z
line too longz*get*rRN���)
rf�readline�_MAXLINEr=r
rqr�r�r�r�)rZ
strip_crlfr?rrr�_getline�s
�z
NNTP._getlinecCsl|��}|jrtdt|��|�|j|j�}|dd�}|dkr$t|��|dkr,t|��|dvr4t	|��|S)z�Internal: get a response from the server.
        Raise various errors if the response indicates an error.
        Returns a unicode string.z*resp*Nr7�4�5Z123)
r�rqr�r�r1r�r�rrr	)rr��crrrrr�sz
NNTP._getrespcCs�d}zot|ttf�rt|d�}}|��}|dd�tvr!t|��g}|durJdtdf}	|�d�}||vr8n|�	d�rC|dd�}|�
|�q.nd}	|��}||krVn|�	d�ra|dd�}|�|�qMW|rn|��||fS|ry|��ww)	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�wb��.s.
r7Fs..)
r/�strr"�openrr�	_LONGRESPrr�r�rIr�r0rj)rrfZ
openedFiler�r#Zterminatorsr?�
terminatorrrr�_getlongresp�sF	


�

��	�
�zNNTP._getlongrespcCs|�|�|��S)zWInternal: send a command and get the response.
        Same return value as _getresp().)r�rrr�rrr�	_shortcmds
zNNTP._shortcmdcCs|�|�|�|�S)zoInternal: send a command and get the response plus following text.
        Same return value as _getlongresp().�r�r�)rr?rfrrr�_longcmds

z
NNTP._longcmdcs.��|���|�\}}|�fdd�|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.
        csg|]
}|��j�j��qSr)r1r�r���.0r?r{rr�
<listcomp>+s�z'NNTP._longcmdstring.<locals>.<listcomp>r�)rr?rfr��listrr{r�_longcmdstring$s

�zNNTP._longcmdstringcCs`z|jWSty
Ynwz	|�d�\}}Wnty&tdd�}Ynwt|�}||_|S)zqInternal: get the overview format. Queries the server if not
        already done, else returns the cached value.zLIST OVERVIEW.FMTN)Z_cachedoverviewfmt�AttributeErrorr�rr<rD)rr�r#r>rrr�_getoverviewfmt.s��zNNTP._getoverviewfmtcCsdd�|D�S)NcSsg|]}t|����qSr)r%rFr�rrrr�Asz#NNTP._grouplist.<locals>.<listcomp>r)rr#rrr�
_grouplist?szNNTP._grouplistcCs8i}|�d�\}}|D]}|��^}}|||<q||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'] })
        ZCAPABILITIES)r�rF)rr�r�r#r?r@rJrrrr�Cs
zNNTP.capabilities)rfcCsbt|tjtjf�std�|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}'rOzNEWGROUPS {0} {1})r/rUr�	TypeErrorrZ�	__class__rr\r�r�r�)rrrfrVrW�cmdr�r#rrr�	newgroupsQs
�zNNTP.newgroupscCsRt|tjtjf�std�|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�rOzNEWNEWS {0} {1} {2})
r/rUrr�rZr�rr\r�r�)rr&rrfrVrWr�rrr�newnewsas
�zNNTP.newnewscCs4|dur	d|}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 ZLIST)r�r�)r�
group_patternrf�commandr�r#rrrr�qs

z	NNTP.listcCs�t�d�}|�d|�\}}|�d�s|�d|�\}}i}|D]}|�|���}|r=|�dd�\}	}
|s9|
S|
||	<q |rD||fSdS)Nz^(?P<group>[^ 	]+)[ 	]+(.*)$zLIST NEWSGROUPS rzXGTITLE r7rOr-)�re�compiler�rI�search�stripr&)rr�Z
return_allZline_patr�r#�groupsZraw_line�matchr@Zdescrrr�_getdescriptions�s 

�zNNTP._getdescriptionscC�|�|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&rrr�description�szNNTP.descriptioncCr�)z'Get descriptions for a range of groups.Tr�)rr�rrr�descriptions�szNNTP.descriptionscCs�|�d|�}|�d�st|��|��}d}}}t|�}|dkr@|d}|dkr@|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 rrr7rOr�rP)r�rIrrFr=r9rG)rr@r��words�countr(r'�nrrrr&�s

z
NNTP.groupcC�|�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
        ZHELP)r�)rrfrrr�help�sz	NNTP.helpcCs8|�d�s	t|��|��}t|d�}|d}|||fS)z_Internal: parse the response line of a STAT, NEXT, LAST,
        ARTICLE, HEAD or BODY command.Z22r7rO)rIrrFrG)rr�r��art_numr+rrr�
_statparse�s

zNNTP._statparsecCs|�|�}|�|�S)z/Internal: process a STAT, NEXT or LAST command.)r�r�)rr?r�rrr�_statcmd�s

z
NNTP._statcmdcCs|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}ZSTAT)r�rZ)r�message_specrrr�stat�s	
z	NNTP.statcC�
|�d�S)z;Process a NEXT command.  No arguments.  Return as for STAT.ZNEXT�r�r{rrr�next��
z	NNTP.nextcCr�)z;Process a LAST command.  No arguments.  Return as for STAT.ZLASTr�r{rrrr'�r�z	NNTP.lastcCs0|�||�\}}|�|�\}}}|t|||�fS)z2Internal: process a HEAD, BODY or ARTICLE command.)r�r�r*)rr?rfr�r#r�r+rrr�_artcmd�szNNTP._artcmdcC�$|dur
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}ZHEAD�rZr��rr�rfr�rrr�head��z	NNTP.headcCr�)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}ZBODYr�r�rrr�bodyr�z	NNTP.bodycCr�)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}ZARTICLEr�r�rrr�articler�zNNTP.articlecCr�)zYProcess a SLAVE command.  Returns:
        - resp: server response if successful
        ZSLAVE)r�r{rrr�slave!s
z
NNTP.slavecsDt�d��|�d�||�|�\}}�fdd��|�fdd�|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}cs��|�}|r
|�dd�S|S)Nr7rO)r�r&)r?�m)�patrr�
remove_number2s
z NNTP.xhdr.<locals>.remove_numbercsg|]}�|��qSrrr�)r�rrr�5szNNTP.xhdr.<locals>.<listcomp>)r�r�r�rZ)rZhdrr�rfr�r#r)r�r�r�xhdr's
	z	NNTP.xhdrcCs.|�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�rZr�rN)r�start�endrfr�r#r>rrr�xover7s
	�z
NNTP.xoverc	Csxd|jvrdnd}t|ttf�r|\}}|d�||pd�7}n
|dur)|d|}|�||�\}}|��}|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
        ZOVERZXOVERz {0}-{1}r-Nr�)rtr/�tupler�rZr�r�rN)	rr�rfr�r�r�r�r#r>rrr�overEsz	NNTP.overcCsb|�d�}|�d�st|��|��}t|�dkrt|��|d}t|�dkr*t|��|t|d�fS)z�Process the DATE command.
        Returns:
        - resp: server response if successful
        - date: datetime object
        ZDATEZ111rOr7�N)r�rIrrFr=r
rY)rr��elemrrrrr`s

z	NNTP.datecCs�|�|�}|�d�st|��t|ttf�r|��}|D]}|�t�s)|�	d�t}|�d�r2d|}|j
�|�q|j
�d�|j
��|�
�S)N�3r$r�s.
)r�rIrr/r"�	bytearray�
splitlines�endswithr��rstriprfr�r�rr)rr��fr�r?rrr�_postqs




z
NNTP._postcCr�)z�Process a POST command.  Arguments:
        - data: bytes object, iterable or file containing the article
        Returns:
        - resp: server response if successfulZPOST)r�)r�datarrr�post�sz	NNTP.postcCs|�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})r�rZ)rr+r�rrr�ihave�sz
NNTP.ihavecCsBz|jr|j��|`W|j��dSW|j��dS|j��wrz)rfrjr^r{rrrr��s
�zNNTP._closecCs$z|�d�}W|��|S|��w)zdProcess a QUIT command and close the socket.  Returns:
        - resp: server response if successfulZQUIT)r�r�)rr�rrrr�s

�z	NNTP.quitcCs�|jrtd��|s|std��z|r,|s,ddl}|��}|�|j�}|r,|d}|d}Wn	ty6Ynw|s;dS|�d|�}|�d�r]|sMt|��|�d|�}|�d�s]t	|��d|_
|��|jryd	|j
vr{|�
�d|_
|��dSdSdS)
NzAlready logged in.z7At least one of `user` and `usenetrc` must be specifiedrrOzauthinfo user Z381zauthinfo pass Z281rp)ryr��netrcZauthenticatorsrcr�r�rIrrrtrurvrw)rrkrlrnr�ZcredentialsZauthr�rrrri�sD���

�z
NNTP.loginc
Csbz	|�d�|_WdStyYdSty0}z|j�d�r$d|_n�WYd}~dSd}~ww)Nzmode readerZ480T)r�rsrrr
rIrv)r�errrrw�s���zNNTP._setreadermodecCsz|jrtd��|jrtd��|�d�}|�d�r9|j��t|j||j	�|_|j�
d�|_d|_d|_|��dSt
d��)	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.�STARTTLSZ382rbTNzTLS failed to start.)rxr�ryr�rIrfrjr`r^rcrgrtrur)rr_r�rrr�starttls�s


z
NNTP.starttls)Trz)NNT):rrrr�r��	NNTP_PORTrrrhr|r�rer�rur��debugr�r�r�rrr�r�r�r�r�r�r�r�r�r�r�r�r�r&r�r�r�r�r�r'r�r�r�r�r�r�r�r�rr�r�r�r�rrirw�	_have_sslr�rrrrr(st

�#"		

.







	
	)
�rcs8eZdZedddddef�fdd�	Z�fdd�Z�ZS)�NNTP_SSLNFc			s"||_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)	rrcrdrkrlr�rmrnro�r�rrr�s�zNNTP_SSL.__init__cs4t��|�}zt||j|j�}W|S|���rz)r�rer`r�rcrj)rror^rrrres�zNNTP_SSL._create_socket)rrr�
NNTP_SSL_PORTrrre�
__classcell__rrrrr��s�r��__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�z#NNTP port number (default: %s / %s))r�typer�z-nz
--nb-articles�
z2number of articles to fetch (default: %(default)s)z-Sz--ssl�
store_truezuse NNTP over SSL)�actionrr�)rcrdr�ZGroupZhaszarticles, range�tocCs$t|�|kr|d|d�d}|S)NrPz...)r=)�sZlimrrr�cut3srr7r�<rz{:7} {:20} {:42} ({})��*rz)F)Irr�r��collectionsrUr�r]�ImportErrorr�Zemail.headerrr.r�__all__r�rrrrrr	r
r�rr�r<r:r��
namedtupler%r*rDrNrYr\r`rr�r0r�argparse�ArgumentParser�parser�add_argumentrG�
parse_argsrrdZserverr
rur�r�r&r�r�r(r'r@r�rr�Znb_articlesr�Z	overviewsZartnumr�rFZauthorrr#rZrrrrr�<module>s�A�
	���


S


�
�
���



��