
    x
h                        d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	m
Z
mZmZmZmZ d dlmZ d dlZd dlZd dlZd dlmZmZmZmZ d dlmZmZmZ d dlmZmZm Z m!Z! d dl"m#Z#m$Z$ d d	l%m&Z& d d
l'm(Z(m)Z) d dl*m+Z+m,Z,  e-ej.        /                                          Z0ee1e2f         Z3ee3ee3         df         Z4dZ5 G d de          Z6d(dZ7d)dZ8d*dZ9 G d d          Z: ed          Z;d+d!Z<d,d$Z=d-d'Z>dS ).    )annotationsN)AnyBinaryIOIterableListTypeVarUnion)quote)LiteralSelf	TypedDict
deprecated)DEFAULT_TIMEOUTLOGGER	RpcMethod)TransmissionAuthErrorTransmissionConnectErrorTransmissionErrorTransmissionTimeoutError)SessionSessionStatsTorrent)Group_Timeout)_try_read_torrentget_torrent_argumentsx-transmission-session-idc                  .    e Zd ZU ded<   ded<   ded<   dS )ResponseDatar   	argumentsinttagstrresultN)__name__
__module____qualname____annotations__     P/var/www/html/mejor/venv/lib/python3.11/site-packages/transmission_rpc/client.pyr    r    %   s+         NNNHHHKKKKKr+   r    sstr | pathlib.Pathreturnr$   c                    t          | t          j                  r2|                                 rt	          |           S t          d          t	          |           S )NzDusing relative `pathlib.Path` as remote path is not supported in v4.)
isinstancepathlibPathis_absoluter$   
ValueError)r-   s    r,   ensure_location_strr6   +   sS    !W\"" 
==?? 	q66MR
 
 	
 q66Mr+   raw_torrent_id	int | strc                
   t          | t                    r	| dk    r| S nTt          | t                    r?t          |           dk    st	          |           t
          z
  rt          d|  d          | S t          |  d          )Nr   (   ztorrent ids z; is not valid torrent id, should be a hex str for sha1 hashz is not valid torrent id)r1   r"   r$   lenset
_hex_charsr5   )r7   s    r,   _parse_torrent_idr>   7   s    .#&& Q!! 	NC	(	( ~"$$^)<)<z)I$wNwwwxxx
@@@
A
AAr+   argsr   str | list[str | int]c                "   | g S t          | t                    rt          |           gS t          | t                    r| dk    r| S t          |           gS t          | t          t
          f          rd | D             S t          d|            )Nrecently-activec                ,    g | ]}t          |          S r*   )r>   ).0items     r,   
<listcomp>z&_parse_torrent_ids.<locals>.<listcomp>L   s!    999D!$''999r+   zInvalid torrent id )r1   r"   r>   r$   listtupler5   )r?   s    r,   _parse_torrent_idsrI   B   s    |	$ )!$''(($ )$$$K!$''(($u&& :99D9999
1411
2
22r+   c            1      X   e Zd ZddddddeedddZe ed          dd                        Ze ed          dd                        Z	e ed          dd                        Z
e ed          dd                        Ze ed           dd!                        Zedd#            Zej        dd&            Zej        dd'            Zedd)            Zddd,Z	 	 	 	 ddd6Zdd7Ze ed8          dd9                        Ze ed:          dd;                        Zdd=Z	 ddddddddddddd>ddQZdddTZdddVZdddWZdddXZdddYZdddZZ	 	 ddd]Z	 	 	 ddd_Z	 dddaZ 	 ddddddddddddddddddddddddddbddzZ!	 dd{d|ddZ"	 dddZ#dddZ$dddZ%dddZ&dddZ'dddZ(	 ddddddddddddddddddddddddddddddddddddddddddddddddd/ddZ)dddZ*dddZ+dddZ,dddZ-dddddddddZ.ddddZ/dddddńZ0ddǄZ1dd΄Z2dS )ClienthttpNz	127.0.0.1i#  /transmission/rpc)protocolusernamepasswordhostportpathtimeoutloggerrN   Literal['http', 'https']rO   
str | NonerP   rQ   r$   rR   r"   rS   rT   floatrU   logging.Loggerc               2   t          |t          j                  r|| _        nt	          d          || _        |rt          |pddd          nd}|rdt          |pddd          z   nd}|s|r| | dnd}	|dk    rd	}| d
|	 | d| | }
t          |
          | _        i | _	        d| _
        d| _        d| _        t          j                    | _        d| j        _        d| _        |                                  t'          | j                  | _        dS )z

        Parameters:
            protocol:
            username:
            password:
            host:
            port:
            path: rpc request target path, default ``/transmission/rpc``
            timeout:
            logger:
        z[logger must be instance of `logging.Logger`, default: logging.getLogger('transmission-rpc') z$-_.+!*'(),;&=utf8)safeencoding:@z/transmission/rM   z://0z	(unknown)   FN)r1   loggingLoggerrU   	TypeError_query_timeoutr
   r$   _url_Client__raw_session_Client__session_id_Client__server_version_Client__protocol_versionrequestsr   _http_session	trust_env_Client__semver_versionget_sessionr   _Client__torrent_get_arguments)selfrN   rO   rP   rQ   rR   rS   rT   rU   authurls              r,   __init__zClient.__init__Q   sa   0 fgn-- 	 DKKm   )0T\d5R.>PPPPbdZbj3x~24DvVVVVVhj,4II('H''''r###&D77d7D774777HH	-/%0')%-//',$ $'<T=T'U'U$$$r+   zdo not use internal propertyr/   c                    | j         S N)rg   rr   s    r,   rt   z
Client.url   s     yr+   zRdo not use internal property, use `get_torrent_arguments(rpc_version)` if you need	list[str]c                    | j         S rw   )rq   rx   s    r,   torrent_get_argumentszClient.torrent_get_arguments   s     ++r+   z:do not use internal property, use `.get_session()` insteaddict[str, Any]c                    | j         S rw   )rh   rx   s    r,   raw_sessionzClient.raw_session   s     !!r+   c                    | j         S rw   )ri   rx   s    r,   
session_idzClient.session_id   s       r+   zBdo not use internal property, use `.get_session().version` insteadc                    | j         S rw   )rj   rx   s    r,   server_versionzClient.server_version   s     $$r+   r   c                    | j         S )z7
        Get current timeout for HTTP queries.
        )rf   rx   s    r,   rT   zClient.timeout   s    
 ""r+   valueNonec                X   t          |t          t          f          rit          |          dk    rt	          d          |D ]-}t          |t
          t          f          st          d          .|d         |d         f| _        dS |t          | _        dS t          |          | _        dS )z/
        Set timeout for HTTP queries.
           z1timeout tuple can only include 2 numbers elementsz1element of timeout tuple can only be int or floatr      N)
r1   rH   rG   r;   r5   rX   r"   re   rf   r   )rr   r   vs      r,   rT   zClient.timeout   s    
 eeT]++ 
	/5zzQ !TUUU Y Y!!eS\22 Y#$WXXXY#(8U1X"6D]"1D"',,Dr+   c                    t           | _        dS )z>
        Reset the HTTP query timeout to the default.
        N)r   rf   rx   s    r,   rT   zClient.timeout   s    
 .r+   dict[str, str]c                    t           | j        iS rw   )_header_session_idri   rx   s    r,   _http_headerzClient._http_header   s    "D$566r+   query_Timeout | Nonec                   d}|| j         }	 |dk    rt          d          | j                            | j        | j        ||d           |dz  }	 | j                            | j        | j        ||          }nV# t          j	        j
        $ r}t          d	          |d}~wt          j	        j        $ r}t          d
|          |d}~ww xY w| j                            |j                   |j        dv r5| j                            |j        j                   t%          d|          t&          |j        v r|j        d         | _        |j        dk    r|j        S T)z2
        Query Transmission through HTTP.
        r   NT   z8too much request, try enable logger to see what happened)rt   headersdatarT   r   )r   jsonrT   z.timeout when connection to transmission daemonz&can't connect to transmission daemon: >       z transmission daemon require auth)originalr   i  )rT   r   rU   debugrg   r   rm   postrl   
exceptionsTimeoutr   ConnectionErrorr   textstatus_coderequestr   r   r   ri   )rr   r   rT   request_countres         r,   _http_queryzClient._http_query   s    ?lG"	!!'(bcccK9#0!&	    QM
f&++I -#	 ,   &. h h h./_``fgg&6 f f f./]XY/]/]^^deef Kaf%%%}
**!!!)"3444+,NYZ[[[[!QY..$%I.I$J!}##vE"	s$   (A: :CBC5CCFmethodr   r!   dict[str, Any] | Noneids_TorrentIDs | Nonerequire_idsboolc                p   t          |t                    st          d          |i }t          |t                    st          d          t	          |          }t          |          dk    r||d<   n|rt          d          ||d}t          j                    }	 | 	                    ||          }t          j                    |z
  }	| j
                            d|	           n6# t          j                    |z
  }	| j
                            d|	           w xY w	 t          j        |          }
n{# t          j        $ ri}| j
                            d	           | j
                            d
|           | j
                            d|           t!          d|||          |d}~ww xY w| j
                            t$          j                  r.| j
                            t          j        |
d                     d|
vrt!          d|||
|          |
d         dk    rt!          d|
d          d|||
|          |
d         }i }|t*          j        k    r|S |t*          j        k    rKd}d|v r	|d         }nd|v r|d         }|rt1          |          ||d         <   nt!          d|||
|          |t*          j        k    r| j                            |           nR|t*          j        k    rd|v r|d         S |S |t*          j        t*          j        t*          j        t*          j         fv r|S |S |S )zG
        Send json-rpc request to Transmission using http POST
        zrequest takes method as stringNz&request takes arguments should be dictr   r   zrequest require ids)r   r!   zhttp request took %.3f szError:zRequest: "%s"zHTTP data: "%s"z failed to parse response as json)r   argumentrawResponser   )indentr%   z3Query failed, response data missing without result.)r   r   responser   successzQuery failed with result "z".r!   ztorrent-addedztorrent-duplicatefieldsidzInvalid torrent-add response.zsession-stats)!r1   r$   re   dictrI   r;   r5   time	monotonicr   rU   r   r   loadsJSONDecodeError	exceptionr   isEnabledForrc   DEBUGdumpsr   
TorrentGet
TorrentAddr   
SessionGetrh   updater   PortTestBlocklistUpdate	FreeSpaceTorrentRenamePath)rr   r   r!   r   r   rT   r   start	http_dataelapsedr   errorresresultsrE   s                  r,   _requestzClient._request   s    &#&& 	><===I)T** 	FDEEE %%s88a<<"Ie 	42333!	::  	C((88In&&.GK8'BBBB n&&.GK8'BBBB	!%I!6!6DD# 	 	 	K!!(+++K!!/5999K!!"3Y???#26Icl  		 ;##GM22 	:Kdja8889994#E"%    >Y&&#?T(^???"%    ;Y)))JY)))D#%%?+$++./ 	&-T&:&:&:T
##'3!&! )    y+++%%c****y---#%%?++J%'	
 
 
 JJs%   C' '3DD3 3F+A$F&&F+c                    | j                             d          | _        | j         d         | _        | j         d         | _        dS )z5Decode the Transmission version string, if available.zrpc-version-semverversionzrpc-versionN)rh   getro   rj   rk   rx   s    r,   _update_server_versionzClient._update_server_versionS  sB     $ 2 6 67K L L $ 29 ="&"4]"Cr+   z-use .get_session().rpc_version_semver insteadc                    | j         S )zGet the Transmission daemon RPC version.

        .. deprecated:: 7.0.5
            Use ``.get_session().rpc_version_semver`` instead
        )ro   rx   s    r,   semver_versionzClient.semver_versionY  s     $$r+   z&use .get_session().rpc_version insteadc                    | j         S )zGet the Transmission daemon RPC version.

        .. deprecated:: 7.0.5
            Use ``.get_session().rpc_version`` instead
        )rk   rx   s    r,   rpc_versionzClient.rpc_versionc  s     &&r+   required_versionc                b    | j         |k     r#| j                            d| j         |           dS dS )zn
        Add a warning to the log if the Transmission RPC version is lower then the provided version.
        z[Using feature not supported by server. RPC version for server %d, feature introduced in %d.N)rk   rU   warning)rr   r   s     r,   _rpc_version_warningzClient._rpc_version_warningm  sK     "%555Km'      65r+   )download_dirfiles_unwantedfiles_wantedpaused
peer_limitpriority_highpriority_lowpriority_normalcookieslabelsbandwidthPrioritytorrent%BinaryIO | str | bytes | pathlib.Pathr   r   list[int] | Noner   r   bool | Noner   
int | Noner   r   r   r   r   Iterable[str] | Noner   r   c                  |t          d          ||                     d           t          |||||||	|
||t          t	          |                    d          }t          |          }|||d<   n|st          d          ||d<   t          t          |                     t          j
        ||                                                              S )	a  
        Add torrent to transfers list. ``torrent`` can be:

        - ``http://``, ``https://`` or  ``magnet:`` URL
        - torrent file-like object in **binary mode**
        - bytes of torrent content
        - ``pathlib.Path`` for local torrent file, will be read and encoded as base64.

        Warnings:
            base64 string or ``file://`` protocol URL are not supported in v4.

        Parameters:
            torrent:
                torrent to add
            timeout:
                request timeout
            bandwidthPriority:
                Priority for this transfer.
            cookies:
                One or more HTTP cookie(s).
            download_dir:
                The directory where the downloaded contents will be saved in.
            files_unwanted:
                A list of file id's that shouldn't be downloaded.
            files_wanted:
                A list of file id's that should be downloaded.
            paused:
                If ``True``, does not start the transfer when added.
                Magnet url will always start to downloading torrents.
            peer_limit:
                Maximum number of peers allowed.
            priority_high:
                A list of file id's that should have high priority.
            priority_low:
                A list of file id's that should have low priority.
            priority_normal:
                A list of file id's that should have normal priority.
            labels:
                Array of string labels.
                Add in rpc 17.
        Nz#add_torrent requires data or a URI.rb   )download-dirfiles-unwantedfiles-wantedr   
peer-limitpriority-highpriority-lowpriority-normalr   r   r   filenamezTorrent metadata is emptymetainforT   )r5   r   remove_unset_valuelist_or_none_single_str_as_listr   nextiterr   r   r   values)rr   r   rT   r   r   r   r   r   r   r   r   r   r   r   kwargstorrent_datas                   r,   add_torrentzClient.add_torrentx  s    t ?BCCC%%b)))!3 ,"0 , (!. ,#2%6"&':6'B'BCC "
 "
  )11!(F: > !<===!-F:Dy';VWUU\\^^__```r+   _TorrentIDsdelete_datac                R    |                      t          j        d|i|d|           dS )z
        remove torrent(s) with provided id(s).

        Local data will be removed by transmission daemon if ``delete_data`` is set to ``True``.
        zdelete-local-dataTr   N)r   r   TorrentRemove)rr   r   r   rT   s       r,   remove_torrentzClient.remove_torrent  s@     	# +. 	 	
 	
 	
 	
 	
r+   bypass_queuec                n    t           j        }|rt           j        }|                     |i |d|           dS )z$Start torrent(s) with provided id(s)Tr   N)r   TorrentStartTorrentStartNowr   )rr   r   r  rT   r   s        r,   start_torrentzClient.start_torrent  s<    ' 	/.Ffb#tW=====r+   c                    t           j        }|rt           j        }t          |                                 d           }|                     |i d |D             d|           dS )z-Start all torrents respecting the queue orderc                    | j         S rw   )queue_position)ts    r,   <lambda>z"Client.start_all.<locals>.<lambda>  s	    AQ r+   )keyc                    g | ]	}|j         
S r*   )r   rD   xs     r,   rF   z$Client.start_all.<locals>.<listcomp>  s    ,,,!,,,r+   Tr   r   rT   N)r   r  r  sortedget_torrentsr   )rr   r  rT   r   torrent_lists        r,   	start_allzClient.start_all  s~    ' 	/.Fd//117Q7QRRR,,|,,, 	 	
 	
 	
 	
 	
r+   c                N    |                      t          j        i |d|           dS )z#stop torrent(s) with provided id(s)Tr   N)r   r   TorrentStoprr   r   rT   s      r,   stop_torrentzClient.stop_torrent  s'    i+RdGLLLLLr+   c                N    |                      t          j        i |d|           dS )z%verify torrent(s) with provided id(s)Tr   N)r   r   TorrentVerifyr  s      r,   verify_torrentzClient.verify_torrent  s'    i-r3gNNNNNr+   c                N    |                      t          j        i |d|           dS )z)Reannounce torrent(s) with provided id(s)Tr   N)r   r   TorrentReannouncer  s      r,   reannounce_torrentzClient.reannounce_torrent  s'    i12sD'RRRRRr+   
torrent_id
_TorrentIDc                   |r"t          t          |          ddhz            }n| j        }t          |          }|t	          d          |                     t          j        d|i|d|          }|d         D ]F}|                    d          |k    s|                    d          |k    rt          |	          c S Gt          d
          )a  
        Get information for torrent with provided id.
        ``arguments`` contains a list of field names to be returned, when ``arguments=None`` (default),
        all fields are requested. See the Torrent class for more information.

        new argument ``format`` in rpc_version 16 is unnecessarily
        and this lib can't handle table response, So it's unsupported.

        Returns a Torrent object with the requested fields.

        Note:
            It's recommended that you only fetch arguments you need,
            this could improve response speed.

            For example, fetch all fields from transmission daemon with 1500 torrents would take ~5s,
            but is only ~0.2s if to fetch 6 fields.

        Parameters:
            torrent_id:
                torrent id can be an int or a torrent ``info_hash`` (``hashString`` property of the ``Torrent`` object).

            arguments:
                fetched torrent arguments, in most cases you don't need to set this,
                transmission-rpc will fetch all torrent fields it supported.

            timeout:
                requests timeout

        Raises:
            KeyError: torrent with given ``torrent_id`` not found
        r   
hashStringNz
Invalid idr   T)r   rT   torrentsr   zTorrent not found in result)rG   r<   rq   r>   r5   r   r   r   r   r   KeyError)rr   r  r!   rT   r%   r   s         r,   get_torrentzClient.get_torrent  s    J  	5S^^t\.BBCCII4I&z22
\*** y!  
 
 j) 	/ 	/G{{<((J66'++d:K:Kz:Y:Yg...... ;Z4555r+   list[Torrent]c                    |r"t          t          |          ddhz            }n| j        }d |                     t          j        d|i||          d         D             S )z
        Get information for torrents with provided ids. For more information see :py:meth:`Client.get_torrent`.

        Returns a list of Torrent object.
        r   r"  c                .    g | ]}t          |           S r   r   r  s     r,   rF   z'Client.get_torrents.<locals>.<listcomp>J  s3     
 
 
 1
 
 
r+   r   r   r#  rG   r<   rq   r   r   r   )rr   r   r!   rT   s       r,   r  zClient.get_torrents;  sx      	5S^^t\.BBCCII4I
 
]]9#7(I9NPS]d]eefpq
 
 
 	
r+   tuple[list[Torrent], list[int]]c                    |r"t          t          |          ddhz            }n| j        }|                     t          j        d|id|          }d |d         D             |d         fS )	aC  
        Get information for torrents for recently active torrent. If you want to get recently-removed
        torrents. you should use this method.

        Returns:
            active_torrents, removed_torrents
                list of recently active torrents and list of torrent-id of recently-removed torrents.
        r   r"  r   rB   r   c                .    g | ]}t          |           S r)  r   r  s     r,   rF   z7Client.get_recently_active_torrents.<locals>.<listcomp>a  s#    >>>aq!!!>>>r+   r#  removedr*  )rr   r!   rT   r%   s       r,   get_recently_active_torrentsz#Client.get_recently_active_torrentsO  sy      	5S^^t\.BBCCII4Iy3h	5JL]gnoo>>6*+=>>>y@QQQr+   )bandwidth_prioritydownload_limitdownload_limitedupload_limitupload_limitedr   r   honors_session_limitslocationr   r   r   r   r	  seed_idle_limitseed_idle_modeseed_ratio_limitseed_ratio_modetracker_addr   grouptracker_listtracker_replacetracker_remover0  r1  r2  r3  r4  Iterable[int] | Noner5  r6  r	  r7  r8  r9  float | Noner:  r;  r<  r=  Iterable[Iterable[str]] | Noner>   Iterable[tuple[int, str]] | Noner?  r   r   c                  ||                      d           ||                      d           ||                      d           t          i d|d|d|d|d|d	t          |          d
t          |	          d|
d|d|dt          |          dt          |          dt          |          d|d|d|d|||||t          t          |                    |dnd                    d |D                       |d          }|                    |           |r&|                     t          j        ||d|           dS t          d          )aj  Change torrent parameters for the torrent(s) with the supplied id's.

        Parameters:
            ids: torrent(s) to change.
            timeout: requesst timeout.
            honors_session_limits: true if session upload limits are honored.
            location: new location of the torrent's content
            peer_limit: maximum number of peers
            queue_position: position of this torrent in its queue [0...n)
            files_wanted: Array of file id to download.
            files_unwanted: Array of file id to not download.
            download_limit: maximum download speed (KBps)
            download_limited: true if ``download_limit`` is honored
            upload_limit: maximum upload speed (KBps)
            upload_limited: true if ``upload_limit`` is honored
            bandwidth_priority: Priority for this transfer.
            priority_high: list of file id to set high download priority
            priority_low: list of file id to set low download priority
            priority_normal: list of file id to set normal download priority
            seed_ratio_limit: Seed inactivity limit in minutes.
            seed_ratio_mode: Torrent seed ratio mode
                Valid options are :py:class:`transmission_rpc.RatioLimitMode`
            seed_idle_limit: torrent-level seeding ratio
            seed_idle_mode: Seed inactivity mode.
                Valid options are :py:class:`transmission_rpc.IdleMode`
            labels: Array of string labels. Add in rpc 16.
            group: The name of this torrent's bandwidth group. Add in rpc 17.
            tracker_list:
                A ``Iterable[Iterable[str]]``, each ``Iterable[str]`` for a tracker tier.

                Add in rpc 17.

                Example: ``[['https://tracker1/announce', 'https://tracker2/announce'],
                ['https://backup1.example.com/announce'], ['https://backup2.example.com/announce']]``.

            tracker_add:
                Array of string with announce URLs to add.

                Warnings:
                    since transmission daemon 4.0.0, this argument is deprecated, use ``tracker_list`` instead.

            tracker_remove:
                Array of ids of trackers to remove.

                Warnings:
                    since transmission daemon 4.0.0, this argument is deprecated, use ``tracker_list`` instead.

            tracker_replace:
                Array of (id, url) tuples where the announcement URL should be replaced.

                Warning:
                    since transmission daemon 4.0.0, this argument is deprecated, use ``tracker_list`` instead.

        Warnings:
            ``kwargs`` is for the future features not supported yet, it's not compatibility promising.
            It will be bypassed to request arguments **as-is**, the underline in the key will not be replaced, so you should use kwargs like ``{'a-argument': 'value'}``
        N   rb   r   downloadLimitdownloadLimiteduploadLimituploadLimitedr   r   honorsSessionLimitsr6  r   r   r   r   queuePositionseedIdleLimitseedIdleModeseedRatioLimitz

c              3  @   K   | ]}d                      |          V  dS )
N)join)rD   tiers     r,   	<genexpr>z(Client.change_torrent.<locals>.<genexpr>  s.      LvLvaeTYYW[__LvLvLvLvLvLvr+   )seedRatioMode
trackerAddtrackerRemovetrackerReplacer   trackerListr<  Tr   zNo arguments to set)
r   r   r   r   rQ  r   r   r   
TorrentSetr5   )rr   r   rT   r0  r1  r2  r3  r4  r   r   r5  r6  r   r   r   r   r	  r7  r8  r9  r:  r;  r   r<  r=  r>  r?  r   r?   s                                r,   change_torrentzClient.change_torrentc  s   p %%b)))#%%b)))%%b)))1#%7 "#3 |	
   !,~">"> \ : : &'< H j  m!<!< \ : : "<#@#@      !" !"2#$ "1)!/"1&':6'B'BCC'3';ttLvLviuLvLvLvAvAv1   
  
: 	F 	4MM).c4MQQQQQ2333r+   T)mover.   r[  c                   t          |          t          |          d}|                     t          j        ||d|           dS )z
        Move torrent data to the new location.

        See Also:
            `RPC Spec: moving-a-torrent <https://github.com/transmission/transmission/blob/main/docs/rpc-spec.md#36-moving-a-torrent>`_
        )r6  r[  Tr   N)r6   r   r   r   TorrentSetLocation)rr   r   r6  rT   r[  r?   s         r,   move_torrent_datazClient.move_torrent_data  sD     0994::NNi2D#tWUUUUUr+   nametuple[str, str]c                    |                      d           t          |          }|                                }|                     t          j        t          |          |d|d|          }|d         |d         fS )aZ  
        Warnings:
            This method can only be called on single torrent.

        Warnings:
            This is not the method to move torrent data directory,

        See Also:
            `RPC Spec: renaming-a-torrents-path <https://github.com/transmission/transmission/blob/main/docs/rpc-spec.md#37-renaming-a-torrents-path>`_
           )rS   r_  Tr   rS   r_  )r   r>   stripr   r   r   r6   )rr   r  r6  r_  rT   r%   s         r,   rename_torrent_pathzClient.rename_torrent_path  s    " 	!!"%%%&z22
zz||'(22DAA  
 
 f~vf~--r+   c                L    |                      t          j        |d|           dS )z
        Move transfer to the top of the queue.

        https://github.com/transmission/transmission/blob/main/docs/rpc-spec.md#46-queue-movement-requests
        Tr  N)r   r   QueueMoveTopr  s      r,   	queue_topzClient.queue_top  s(     	i,#4QXYYYYYr+   c                L    |                      t          j        |d|           dS )z
        Move transfer to the bottom of the queue.

        https://github.com/transmission/transmission/blob/main/docs/rpc-spec.md#46-queue-movement-requests
        Tr  N)r   r   QueueMoveBottomr  s      r,   queue_bottomzClient.queue_bottom!  s(     	i/SdT[\\\\\r+   c                L    |                      t          j        |d|           dS )zMove transfer up in the queue.Tr  N)r   r   QueueMoveUpr  s      r,   queue_upzClient.queue_up)  s&    i+$PWXXXXXr+   c                L    |                      t          j        |d|           dS )z Move transfer down in the queue.Tr  N)r   r   QueueMoveDownr  s      r,   
queue_downzClient.queue_down-  s&    i-3DRYZZZZZr+   r   c                    |                      t          j        |           |                                  t	          | j                  S )zU
        Get session parameters. See the Session class for more information.
        r   r   )r   r   r   r   r   rh   )rr   rT   s     r,   rp   zClient.get_session1  sC     	i*G<<<##%%%d01111r+   )/alt_speed_downalt_speed_enabledalt_speed_time_beginalt_speed_time_dayalt_speed_time_enabledalt_speed_time_endalt_speed_upblocklist_enabledblocklist_urlcache_size_mbdht_enableddefault_trackersr   download_queue_enableddownload_queue_size
encryptionidle_seeding_limitidle_seeding_limit_enabledincomplete_dirincomplete_dir_enabledlpd_enabledpeer_limit_globalpeer_limit_per_torrent	peer_portpeer_port_random_on_startpex_enabledport_forwarding_enabledqueue_stalled_enabledqueue_stalled_minutesrename_partial_filesscript_torrent_done_enabledscript_torrent_done_filenameseed_queue_enabledseed_queue_sizer9  seed_ratio_limitedspeed_limit_downspeed_limit_down_enabledspeed_limit_upspeed_limit_up_enabledstart_added_torrentstrash_original_torrent_filesutp_enabled$script_torrent_done_seeding_filename#script_torrent_done_seeding_enabledscript_torrent_added_enabledscript_torrent_added_filenamerr  rs  rt  ru  rv  rw  rx  ry  rz  r{  r|  r}  r~  r  r  4Literal['required', 'preferred', 'tolerated'] | Noner  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  r  r  c       /           ||dvrt          d          ||                     d           |-|                     d           |.|                     d           |/|                     d           |0|                     d           t          i d|d|d|d|d	|d
|d|d|	d|
d|d|d|d|d|d|d|d|i d|d|d|d|d|d|d|d|d|d|d |d!| d"|!d#|"d$|#d%|$d&|%|&|'|(|)|*|+|,||0|-|.|/|d'                    |          ndd(          }2|2                    |1           |2r$|                     t          j        |2|)           dS dS )*a&  
        Set session parameters.

        Parameters:
            timeout
                request timeout
            alt_speed_down:
                max global download speed (KBps)
            alt_speed_enabled:
                true means use the alt speeds
            alt_speed_time_begin:
                Time when alternate speeds should be enabled. Minutes after midnight.
            alt_speed_time_day:
                Enables alternate speeds scheduling these days.
            alt_speed_time_enabled:
                Enables alternate speeds scheduling.
            alt_speed_time_end:
                Time when alternate speeds should be disabled. Minutes after midnight.
            alt_speed_up:
                Alternate session upload speed limit (in Kib/s).
            blocklist_enabled:
                Enables the block list
            blocklist_url:
                Location of the block list. Updated with blocklist-update.
            cache_size_mb:
                The maximum size of the disk cache in MB
            default_trackers:
                list of default trackers to use on public torrents.
            dht_enabled:
                Enables DHT.
            download_dir:
                Set the session download directory.
            download_queue_enabled:
                Enables download queue.
            download_queue_size:
                Number of slots in the download queue.
            encryption:
                Set the session encryption mode, one of ``required``, ``preferred`` or ``tolerated``.
            idle_seeding_limit:
                The default seed inactivity limit in minutes.
            idle_seeding_limit_enabled:
                Enables the default seed inactivity limit
            incomplete_dir:
                The path to the directory of incomplete transfer data.
            incomplete_dir_enabled:
                Enables the incomplete transfer data directory,
                Otherwise data for incomplete transfers are stored in the download target.
            lpd_enabled:
                Enables local peer discovery for public torrents.
            peer_limit_global:
                Maximum number of peers.
            peer_limit_per_torrent:
                Maximum number of peers per transfer.
            peer_port:
                Peer port.
            peer_port_random_on_start:
                Enables randomized peer port on start of Transmission.
            pex_enabled:
                Allowing PEX in public torrents.
            port_forwarding_enabled:
                Enables port forwarding.
            queue_stalled_enabled:
                Enable tracking of stalled transfers.
            queue_stalled_minutes:
                Number of minutes of idle that marks a transfer as stalled.
            rename_partial_files:
                Appends ".part" to incomplete files

            seed_queue_enabled:
                Enables upload queue.
            seed_queue_size:
                Number of slots in the upload queue.
            seed_ratio_limit:
                Seed ratio limit. 1.0 means 1:1 download and upload ratio.
            seed_ratio_limited:
                Enables seed ration limit.
            speed_limit_down:
                Download speed limit (in Kib/s).
            speed_limit_down_enabled:
                Enables download speed limiting.
            speed_limit_up:
                Upload speed limit (in Kib/s).
            speed_limit_up_enabled:
                Enables upload speed limiting.
            start_added_torrents:
                Added torrents will be started right away.
            trash_original_torrent_files:
                The .torrent file of added torrents will be deleted.
            utp_enabled:
                Enables Micro Transport Protocol (UTP).
            script_torrent_done_enabled:
                Whether to call the "done" script.
            script_torrent_done_filename:
                Filename of the script to run when the transfer is done.
            script_torrent_added_filename:
                filename of the script to run
            script_torrent_added_enabled:
                whether or not to call the ``added`` script
            script_torrent_done_seeding_enabled:
                whether or not to call the ``seeding-done`` script
            script_torrent_done_seeding_filename:
                filename of the script to run

        Warnings:
            ``kwargs`` is pass the arguments not supported yet future, it's not compatibility promising.
            transmission-rpc will merge ``kwargs`` in rpc arguments **as-is**
        N)required	preferred	toleratedzInvalid encryption valuerb   zalt-speed-downzalt-speed-enabledzalt-speed-time-beginzalt-speed-time-dayzalt-speed-time-enabledzalt-speed-time-endzalt-speed-upzblocklist-enabledzblocklist-urlzcache-size-mbzdht-enabledr   zdownload-queue-enabledzdownload-queue-sizezidle-seeding-limit-enabledzidle-seeding-limitzincomplete-dirzincomplete-dir-enabledzlpd-enabledzpeer-limit-globalzpeer-limit-per-torrentzpeer-port-random-on-startz	peer-portzpex-enabledzport-forwarding-enabledzqueue-stalled-enabledzqueue-stalled-minuteszrename-partial-fileszscript-torrent-done-enabledzscript-torrent-done-filenamezseed-queue-enabledzseed-queue-sizerN  seedRatioLimitedrP  )speed-limit-downspeed-limit-down-enabledspeed-limit-upspeed-limit-up-enabledzstart-added-torrentsztrash-original-torrent-fileszutp-enabledr  zscript-torrent-added-filenamez$script-torrent-done-seeding-filenamez#script-torrent-done-seeding-enabledzscript-torrent-added-enabledzdefault-trackersr   )r5   r   r   rQ  r   r   r   
SessionSet)3rr   rT   rr  rs  rt  ru  rv  rw  rx  ry  rz  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  r9  r  r  r  r  r  r  r  r  r  r  r  r  r   r?   s3                                                      r,   set_sessionzClient.set_session9  s   B !j8^&^&^7888'%%b)))/;%%b))).:%%b)))'3%%b)))(4%%b)))10 .0#%60 '(<0 %&8	0
 )*@0 %&80 0 $%60  0  0 {0 0 )*@0 &':0 -.H0  %&8!0" !.#0 0$ )*@%0& {'0( $%6)0* )*@+0, ,-F-0. Y/00 {102 *+B304 ()>506 ()>708 '(<90: ./J;0< /0L=0> %&8?0@ "?A0B !"2C0D #$6E0 0F %5,D"0*@(<0L*(1N8\7Z0LCSC_DII.>$?$?$?ei_0 0 02 
 2 
h 	F 	GMM).gMFFFFF	G 	Gr+   c                n    |                      t          j        |          }|                    d          S )z6Update block list. Returns the size of the block list.r   zblocklist-size)r   r   r   r   rr   rT   r%   s      r,   blocklist_updatezClient.blocklist_update!  s-    y8'JJzz*+++r+   c                n    |                      t          j        |          }|                    d          S )zg
        Tests to see if your incoming peer port is accessible from the
        outside world.
        r   zport-is-open)r   r   r   r   r  s      r,   	port_testzClient.port_test&  s.    
 y17CCzz.)))r+   c                    |                      d           t          |          }|                     t          j        d|i|          }|d         |k    r|d         S dS )zS
        Get the amount of free space (in bytes) at the provided location.
        rb  rS   r   z
size-bytesN)r   r6   r   r   r   )rr   rS   rT   r%   s       r,   
free_spacezClient.free_space.  sc     	!!"%%%"4((!%y/BVTN\c!d!d&>T!!,''tr+   r   c                d    |                      t          j        |          }t          |          S )zGet session statisticsr   r   )r   r   r   r  s      r,   session_statszClient.session_stats9  s+    y5wGG6****r+   )rT   r5  r  r  r  r  c          	         |                      d           t          ||||||d          }|                     t          j        ||           dS )a  create or update a Bandwidth group.

        :param name: Bandwidth group name
        :param honors_session_limits: true if session upload limits are honored
        :param speed_limit_down_enabled: true means enabled
        :param speed_limit_down: 	max global download speed (KBps)
        :param speed_limit_up_enabled: 	true means enabled
        :param speed_limit_up: max global upload speed (KBps)
        :param timeout: request timeout
        rb   )r_  rJ  r  r  r  r  r   N)r   r   r   r   GroupSet)	rr   r_  rT   r5  r  r  r  r  r!   s	            r,   	set_groupzClient.set_group>  sf    , 	!!"%%%$6'<$4*@"0,D 	%
 	%
	 	i()WEEEEEr+   r   Group | Nonec                   |                      d           |                     t          j        d|i|          }|d         rt	          |d         d                   S d S )Nrb   r<  r   r   r   )r   r   r   GroupGetr   )rr   r_  rT   r%   s       r,   	get_groupzClient.get_groupb  s`    !!"%%%!%y/AGT?\c!d!d'? 	4w 23333tr+   list[str] | Nonedict[str, Group]c               z    i }|d|i}|                      t          j        ||          }d |d         D             S )Nr<  r   c                <    i | ]}|d          t          |          S )r_  r   )r   r  s     r,   
<dictcomp>z%Client.get_groups.<locals>.<dictcomp>r  s&    DDDq&	5???DDDr+   )r   r   r  )rr   r_  rT   payloadr%   s        r,   
get_groupszClient.get_groupsk  sI    oG!%y/A7T[!\!\DDF7ODDDDr+   r   c                    | S rw   r*   rx   s    r,   	__enter__zClient.__enter__t  s    r+   exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbtypes.TracebackType | Nonec                8    | j                                          d S rw   )rm   close)rr   r  r  r  s       r,   __exit__zClient.__exit__w  s     	  """""r+   )rN   rV   rO   rW   rP   rW   rQ   r$   rR   r"   rS   r$   rT   rX   rU   rY   )r/   r$   )r/   ry   )r/   r|   )r/   r   )r   r   r/   r   )r/   r   )r/   r   rw   )r   r|   rT   r   r/   r$   )NNFN)r   r   r!   r   r   r   r   r   rT   r   r/   r|   )r/   rW   )r/   r"   )r   r"   r/   r   )r   r   rT   r   r   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rW   r   r   r   r   r/   r   )FN)r   r   r   r   rT   r   r/   r   )r   r   r  r   rT   r   r/   r   )r  r   rT   r   r/   r   )r   r   rT   r   r/   r   )NN)r  r   r!   r   rT   r   r/   r   )NNN)r   r   r!   r   rT   r   r/   r&  )r!   r   rT   r   r/   r+  )8r   r   rT   r   r0  r   r1  r   r2  r   r3  r   r4  r   r   r@  r   r@  r5  r   r6  rW   r   r   r   r@  r   r@  r   r@  r	  r   r7  r   r8  r   r9  rA  r:  r   r;  r   r   r   r<  rW   r=  rB  r>  rC  r?  r@  r   r   r/   r   )
r   r   r6  r.   rT   r   r[  r   r/   r   )
r  r   r6  r$   r_  r$   rT   r   r/   r`  )rT   r   r/   r   )drT   r   rr  r   rs  r   rt  r   ru  r   rv  r   rw  r   rx  r   ry  r   rz  rW   r{  r   r|  r   r}  r   r   rW   r~  r   r  r   r  r  r  r   r  r   r  rW   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  rW   r  r   r  r   r9  rA  r  r   r  r   r  r   r  r   r  r   r  r   r  r   r  r   r  rW   r  r   r  r   r  rW   r   r   r/   r   )rT   r   r/   r   )rT   r   r/   r   )rS   r.   rT   r   r/   r   )rT   r   r/   r   )r_  r$   rT   r   r5  r   r  r   r  r   r  r   r  r   r/   r   )r_  r$   rT   r   r/   r  )r_  r  rT   r   r/   r  )r/   r   )r  r  r  r  r  r  r/   r   )3r&   r'   r(   r   r   ru   propertyr   rt   r{   r~   r   r   rT   setterdeleterr   r   r   r   r   r   r   r   r  r  r  r  r  r  r%  r  r/  rZ  r^  rd  rg  rj  rm  rp  rp   r  r  r  r  r  r  r  r  r  r  r*   r+   r,   rK   rK   P   sn        .4##'(!'1V 1V 1V 1V 1V 1Vf Z.//   0/ X Zdee, , , fe X, ZLMM" " " NM X" Z.//! ! ! 0/ X! ZTUU% % % VU X% # # # X# ^/ / / ^/  _. . . _. 7 7 7 X7) ) ) ) )\ ,0"&!#'f f f f fPD D D D Z?@@% % % A@ X% Z899' ' ' :9 X'	 	 	 	 $(Xa
 $(+/)-"!%*.)-,0"'+(,Xa Xa Xa Xa Xa Xat
 
 
 
 
> > > > >
 
 
 
 
M M M M MO O O O OS S S S S +/#'	86 86 86 86 86x #'*.#'	
 
 
 
 
* RVR R R R R. $(C4
 *.%)(,#'&*/3-1-1#!%.2-104%)&*%))-&*,0'+ 7;<@/39C4 C4 C4 C4 C4 C4R $(	V V V V V V V, $(. . . . .@Z Z Z Z Z] ] ] ] ]Y Y Y Y Y[ [ [ [ [2 2 2 2 2 $(fG &*)-+/)-.2)-#')-$($(#'15#'.2*.KO)-26%).2#'(,-1 $15#'/3-1,0,03737*.&*)-*.'+04%).2,048#';?;?4848efG fG fG fG fG fGP, , , , ,
* * * * *	 	 	 	 	+ + + + + $(-104'+.2%)"F "F "F "F "F "FH BF      EVZ E E E E E E   # # # # # #r+   rK   Tr   r   r  c                X    | | S t          | t                    r| gS t          |           S rw   )r1   r$   rG   r   s    r,   r   r     s0    y!S s
77Nr+   Iterable[T] | Nonelist[T] | Nonec                (    | d S t          |           S rw   )rG   r  s    r,   r   r     s    yt77Nr+   r   r|   c                >    d |                                  D             S )Nc                    i | ]
\  }}|||S rw   r*   )rD   r  r   s      r,   r  z&remove_unset_value.<locals>.<dictcomp>  s#    KKK:39JC9J9J9Jr+   )items)r   s    r,   r   r     s    KKKKKKr+   )r-   r.   r/   r$   )r7   r8   r/   r8   )r?   r   r/   r@   )r   r   r/   r  )r   r  r/   r  )r   r|   r/   r|   )?
__future__r   r   rc   r2   stringr   typestypingr   r   r   r   r   r	   urllib.parser
   rl   requests.authrequests.exceptionstyping_extensionsr   r   r   r   transmission_rpc.constantsr   r   r   transmission_rpc.errorr   r   r   r   transmission_rpc.sessionr   r   transmission_rpc.torrentr   transmission_rpc.typesr   r   transmission_rpc.utilsr   r   	frozenset	hexdigitslowerr=   r"   r$   r   r   r   r    r6   r>   rI   rK   r  r   r   r   r*   r+   r,   <module>r     s   " " " " " "       @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @                B B B B B B B B B B B B I I I I I I I I I I            ; : : : : : : : , , , , , , 2 2 2 2 2 2 2 2 K K K K K K K KYv'--//00
38_
JZ 0$670     9   	 	 	 	B B B B3 3 3 3m# m# m# m# m# m# m# m#`! GCLL      L L L L L Lr+   