
    siR%                         S r SSKrSSKJr  SSKJrJr  SSKJr  SSK	J
r
  SSKJr  S	S
KJrJrJr  \" \5      r\R&                  R(                  rS r\\R&                  l         " S S\5      rS rS rS rS rS rg)a  Defines FTP transport adapter for CondaSession (requests.Session).

Taken from requests-ftp (https://github.com/Lukasa/requests-ftp/blob/master/requests_ftp/ftp.py).

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
    N)	b64decode)BytesIOStringIO)	getLogger   )urlparse)AuthenticationError   )BaseAdapterResponsedispatch_hookc                 \    [        U 5      u  pU R                  R                  5       S   nX4$ )Nr   )_old_makepasvsockgetpeername)selfhostports      Flib/python3.13/site-packages/conda/gateways/connection/adapters/ftp.py_new_makepasvr   %   s-    t$JD99  "1%D:    c                   V   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	 rS
 rSrU =r$ )
FTPAdapter.   z3A Requests Transport Adapter that handles FTP urls.c                    > [         TU ]  5         U R                  U R                  U R                  U R                  S.U l        g )N)LISTRETRNLSTGET)super__init__listretrnlst
func_table)r   	__class__s    r   r!   FTPAdapter.__init__1   s5     IIIIII99	
r   c                    U R                  U5      nU R                  U5      u  pEnUR                  SS5      n[        U[        5      (       d  Sn[
        R                  " 5       U l        U R                  R                  XEU5        Ub#  U R                  R                  US   US   5        OU R                  R                  5         U R                  UR                     " Xa5      nU$ )zCSends a PreparedRequest object over FTP. Returns a response object.timeoutN
   r      )!get_username_password_from_headerget_host_and_path_from_urlget
isinstanceintftplibFTPconnconnectloginr%   method)	r   requestkwargsauthr   r   pathr)   resps	            r   sendFTPAdapter.send>   s     55g>  ::7CD **Y-'3''G JJL			$g.IIOODGT!W-IIOO w~~.t= r   c                     g)zDispose of any internal state.N )r   s    r   closeFTPAdapter.close[   s     	r   c                    [        5       nUR                  Ul        U R                  R	                  U5        U R                  R                  S[        U5      5      n[        X#U5      nU R                  R                  5         U$ )z0Executes the FTP LIST command on the given path.r   r   r@   release_connr3   cwd
retrbinarydata_callback_factorybuild_text_responser   r:   r7   datacoderesponses         r   r"   FTPAdapter.list`   sf    z
 !JJ		dyy##F,A$,GH 'wd; 			r   c                     [        5       nUR                  Ul        U R                  R	                  SU-   [        U5      5      n[        X#U5      nU R                  R                  5         U$ )z0Executes the FTP RETR command on the given path.zRETR )r   r@   rD   r3   rF   rG   build_binary_responserI   s         r   r#   FTPAdapter.retrt   sX    y !JJyy##GdN4I$4OP(= 			r   c                    [        5       nUR                  Ul        U R                  R	                  U5        U R                  R                  S[        U5      5      n[        X#U5      nU R                  R                  5         U$ )z0Executes the FTP NLST command on the given path.r   rC   rI   s         r   r$   FTPAdapter.nlst   sf    z !JJ		dyy##F,A$,GH 'wd; 			r   c                     UR                   R                  S5      nU(       aU  UR                  5       SS nUS   S:w  a  [        S5      eUS   n[	        U5      nUR                  S5      nUS   nUS   nXx4$ g)	zGiven a PreparedRequest object, reverse the process of adding HTTP
Basic auth to obtain the username and password. Allows the FTP adapter
to piggyback on the basic auth notation without changing the control
flow.
AuthorizationNr
   r   Basicz$Invalid form of Authentication used.r+   :)headersr.   splitr	   r   )	r   r7   auth_headerencoded_componentsencodeddecoded
componentsusernamepasswords	            r   r,   ,FTPAdapter.get_username_password_from_header   s     oo))/: "-!2!2!4Ra!8!!$/)*PQQ,Q/  (G !s+J!!}H!!}H'' r   c                     UR                   n[        U5      nUR                  nUS   S:X  a  USS nUR                  nUR                  =(       d    SnXVU4$ )zGiven a PreparedRequest object, split the URL in such a manner as to
determine the host and the path. This is a separate method to wrap some
of urlparse's craziness.
r   /r+   N)urlr   r:   hostnamer   )r   r7   rc   parsedr:   r   r   s          r   r-   %FTPAdapter.get_host_and_path_from_url   sY    
 kk#{{ 7c>8D{{aD!!r   )r3   r%   )__name__
__module____qualname____firstlineno____doc__r!   r<   r@   r"   r#   r$   r,   r-   __static_attributes____classcell__)r&   s   @r   r   r   .   s3    =
:
("$<" "r   r   c                    ^  U 4S jnU$ )zReturns a callback suitable for use by the FTP library. This callback
will repeatedly save data into the variable provided to this function. This
variable should be a file-like structure.
c                 (   > TR                  U 5        g )N)write)rJ   variables    r   callback'data_callback_factory.<locals>.callback   s    tr   r?   )rq   rr   s   ` r   rG   rG      s     Or   c                     [        XUS5      $ )z"Build a response for textual data.asciibuild_responser7   rJ   rK   s      r   rH   rH      s    'w77r   c                     [        XUS5      $ )z4Build a response for data whose encoding is unknown.Nrv   rx   s      r   rO   rO      s    't44r   c                     [        5       nX4l        Xl        U R                  Ul        Xl        [        U5      Ul        UR                  R                  S5        [        SU R                  U5      nU$ )zYBuilds a response object from the data returned by ftplib, using the
specified encoding.
r   rL   )
r   encodingrawrc   r7   "get_status_code_from_code_responsestatus_codeseekr   hooks)r7   rJ   rK   r{   rL   s        r   rw   rw      sc     zH  L;;HL=dCH LLa ZAHOr   c                     U R                  S5       Vs/ s H  o(       d  M  UPM     snS   n[        UR                  5       S   5      n[        U SS 5      nX4:w  a  [        R                  SU UU5        U$ s  snf )au  Handle complicated code response, even multi-lines.

We get the status code in two ways:
- extracting the code from the last valid line in the response
- getting it from the 3 first digits in the code
After a comparison between the two values,
we can safely set the code or raise a warning.
Examples:
    - get_status_code_from_code_response('200 Welcome') == 200
    - multi_line_code = '226-File successfully transferred\n226 0.000 seconds'
      get_status_code_from_code_response(multi_line_code) == 226
    - multi_line_with_code_conflicts = '200-File successfully transferred\n226 0.000 seconds'
      get_status_code_from_code_response(multi_line_with_code_conflicts) == 226
For more detail see RFC 959, page 36, on multi-line responses:
    https://www.ietf.org/rfc/rfc959.txt
    "Thus the format for multi-line replies is that the first line
     will begin with the exact required reply code, followed
     immediately by a Hyphen, "-" (also known as Minus), followed by
     text.  The last line will begin with the same code, followed
     immediately by Space <SP>, optionally some text, and the Telnet
     end-of-line code."

r   N   zZFTP response status code seems to be inconsistent.
Code received: %s, extracted: %s and %s)rX   r0   logwarning)rK   linelast_valid_line_from_codestatus_code_from_last_linestatus_code_from_first_digitss        r   r}   r}      s    . 37**T2B K2B$d2B KB O!$%>%D%D%Fq%I!J$'RaM!!B6&)	
 &% !Ls
   
A7A7)rk   r1   base64r   ior   r   loggingr   
common.urlr   
exceptionsr	    r   r   r   rg   r   r2   makepasvr   r   r   rG   rH   rO   rw   r}   r?   r   r   <module>r      sz   "      # . 3 3
 

## $

 W" W"t	8
5
,"&r   