File: //usr/local/lib/python3.10/site-packages/setuptools/command/__pycache__/upload_docs.cpython-310.pyc
o
��iF � @ s� d Z ddlmZ ddlmZ ddlmZ ddlZddlZddl Z ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlmZ ddlmZ d d
lmZ dd� ZG d
d� de�ZdS )z|upload_docs
Implements a Distutils 'upload_docs' subcommand (upload documentation to
sites other than PyPi such as devpi).
� )�standard_b64encode)�log)�DistutilsOptionErrorN� )�metadata)�SetuptoolsDeprecationWarning� )�uploadc C s | � dd�S )Nzutf-8�surrogateescape)�encode)�s� r
�I/usr/local/lib/python3.10/site-packages/setuptools/command/upload_docs.py�_encode s r c @ s� e Zd ZdZdZdddej fddgZejZdd � Zd
efgZ dd� Z
d
d� Zdd� Zdd� Z
edd� �Zedd� �Zdd� ZdS )�upload_docszhttps://pypi.python.org/pypi/z;Upload documentation to sites other than PyPi such as devpizrepository=�rzurl of repository [default: %s])z
show-responseNz&display full response text from server)zupload-dir=Nzdirectory to uploadc C s t | jd u otjddd��S )Nzdistutils.commands�build_sphinx)�group�name)�bool�
upload_dirr �entry_points��selfr
r
r �
has_sphinx0 s
�zupload_docs.has_sphinxr c C s t �| � d | _d | _d S )N)r �initialize_optionsr �
target_dirr r
r
r r 8 s
zupload_docs.initialize_optionsc C s� t �d� t�| � | jd u r0| �� r!| �d�}t|j�d | _ n| �d�}t
j�|j
d�| _ n | �d� | j| _ | �d| j � d S )NzWUpload_docs command is deprecated. Use Read the Docs (https://readthedocs.org) instead.r �html�build�docsr zUsing upload directory %s)r �warnr �finalize_optionsr r Zget_finalized_command�dictZbuilder_target_dirsr �os�path�joinZ
build_baseZensure_dirname�announce)r r r r
r
r r! = s �
zupload_docs.finalize_optionsc C s� t �|d�}zP| �| j� t�| j�D ]<\}}}|| jkr(|s(d}t|| j ��|D ]$}tj�||�}|t | j�d � �
tjj�} tj�| |�}
|�||
� q*qW |�
� d S |�
� w )N�wz'no files found in upload directory '%s')�zipfile�ZipFileZmkpathr r# �walkr r$ r% �len�lstrip�sep�write�close)r �filename�zip_file�root�dirs�files�tmplr �fullZrelative�destr
r
r �create_zipfileN s ��
zupload_docs.create_zipfilec C s| t �dt� | �� D ]}| �|� q
t�� }| jj� � }t
j�|d| �}z| �
|� | �|� W t�|� d S t�|� w )Nziupload_docs is deprecated and will be removed in a future version. Use tools like httpie or curl instead.z%s.zip)�warningsr r Zget_sub_commands�run_command�tempfile�mkdtemp�distributionr �get_namer# r$ r% r8 �upload_file�shutil�rmtree)r �cmd_nameZtmp_dirr r1 r
r
r �run^ s �
zupload_docs.runc c s� � | \}}d| }t |t�s|g}|D ]3}t |t�r'|d|d 7 }|d }nt|�}|V t|�V dV |V |rF|dd � dkrFdV qd S ) Nz*
Content-Disposition: form-data; name="%s"z; filename="%s"r r s
����
�
)�
isinstance�list�tupler )�item�sep_boundary�key�values�title�valuer
r
r �_build_partr s$ �
��zupload_docs._build_partc C sn d}d|� d� }|d }|df}tj| j|d�}t||�� �}tj�|�}t�||�} d| }
d� | �|
fS ) z=
Build up the MIME payload for the POST data
z3--------------GHSKFJDLGDS7543FJKLFHRE75642756743254s
--�asciis --rF )rK z multipart/form-data; boundary=%s� )
r � functools�partialrP �map�items� itertools�chain�
from_iterabler% )�cls�data�boundaryrK Zend_boundaryZ end_itemsZbuilderZpart_groups�partsZ
body_items�content_typer
r
r �_build_multipart� s �zupload_docs._build_multipartc
C sT t |d��}|�� }W d � n1 sw Y | jj}d|�� tj�|�|fd�}t| j d | j
�}t|��d�}d| }| �
|�\}} d| j }
| �|
tj� tj�| j�\}}}
}}}|sf|sf|rhJ �|dkrstj�|�}n|d kr~tj�|�}ntd
| ��d}z-|�� |�d|
� | }|�d
|� |�dtt|��� |�d|� |�� |� |� W n t!j"y� } z| �t|�tj#� W Y d }~d S d }~ww |�$� }|j%dkr�d|j%|j&f }
| �|
tj� n0|j%dk�r|�'d�}|d u r�d|�� }d| }
| �|
tj� nd|j%|j&f }
| �|
tj#� | j(�r(t)d|�� d� d S d S )N�rbZ
doc_upload)z:actionr �content�:rQ zBasic zSubmitting documentation to %s�http�httpszunsupported schema � �POSTzContent-typezContent-length�
Authorization�� zServer response (%s): %si- ZLocationzhttps://pythonhosted.org/%s/zUpload successful. Visit %szUpload failed (%s): %szK---------------------------------------------------------------------------)*�open�readr= r r>