예제 #1
0
 def _set(self, key: str, value: Any, commit: bool = False) -> None:
     key = key.replace("-", "_")
     current_field = self._fields.get(key)
     if current_field is None:
         self._fields[key] = Field(value, True)
     else:
         if current_field.value != value:
             self._fields[key] = Field(value, True)
     if commit:
         self._commit(key, value)
예제 #2
0
 def upload_limit(self, limit: Optional[int]) -> None:
     """Upload limit in Kbps or None."""
     if isinstance(limit, int):
         self._fields["uploadLimited"] = Field(True, True)
         self._fields["uploadLimit"] = Field(limit, True)
         self._push()
     elif limit is None:
         self._fields["uploadLimited"] = Field(False, True)
         self._push()
     else:
         raise ValueError("Not a valid limit")
예제 #3
0
 def seed_idle_mode(self, mode: Union[str, int]) -> None:
     """
     Set the seed ratio mode. Can be one of ``global``, ``single`` or ``unlimited``, or ``0``, ``1``, ``2``.
     """
     if isinstance(mode, str):
         self._fields["seedIdleMode"] = Field(IDLE_LIMIT[mode], True)
         self._push()
     elif isinstance(mode, int):
         self._fields["seedIdleMode"] = Field(IDLE_LIMIT[mode], True)
         self._push()
     else:
         raise ValueError("Not a valid limit")
예제 #4
0
 def _update_fields(self, other: Union[Dict[str, Any], "Session"]) -> None:
     """
     Update the session data from a Transmission JSON-RPC arguments dictionary
     """
     if isinstance(other, dict):
         for key, value in other.items():
             self._fields[key.replace("-", "_")] = Field(value, False)
     elif isinstance(other, Session):
         for key in list(other._fields.keys()):
             self._fields[key] = Field(other._fields[key].value, False)
     else:
         raise ValueError("Cannot update with supplied data")
예제 #5
0
 def seed_ratio_mode(self, mode: Union[str, int]) -> None:
     """
     Set the seed ratio mode.
     Can be one of ``'global'``, ``'single'`` or ``'unlimited'``, or ``0``, ``1``, ``2``.
     """
     if isinstance(mode, str):
         self._fields["seedRatioMode"] = Field(RATIO_LIMIT[mode], True)
         self._push()
     elif isinstance(mode, int):
         self._fields["seedRatioMode"] = Field(mode, True)
         self._push()
     else:
         raise ValueError("Not a valid limit")
예제 #6
0
 def pex_enabled(self, enabled: bool) -> None:
     """Enable/disable peer exchange."""
     if isinstance(enabled, bool):
         self._fields["pex_enabled"] = Field(enabled, True)
         self._push()
     else:
         raise TypeError("Not a valid type")
예제 #7
0
 def seed_ratio_limit(self, limit: Union[int, float]) -> None:
     """
     Set the seed ratio limit as float.
     """
     if isinstance(limit, (int, float)) and limit >= 0.0:
         self._fields["seedRatioLimit"] = Field(float(limit), True)
         self._push()
     else:
         raise ValueError("Not a valid limit")
예제 #8
0
 def seed_idle_limit(self, limit: int) -> None:
     """
     Set the seed idle limit in minutes.
     """
     if isinstance(limit, int):
         self._fields["seedIdleLimit"] = Field(limit, True)
         self._push()
     else:
         raise ValueError("Not a valid limit")
예제 #9
0
 def peer_limit(self, limit: int) -> None:
     """
     Set the peer limit.
     """
     if isinstance(limit, int):
         self._fields["peer_limit"] = Field(limit, True)
         self._push()
     else:
         raise ValueError("Not a valid limit")
예제 #10
0
 def queue_position(self, position: str) -> None:
     """Queue position"""
     if self._rpc_version() >= 14:
         if isinstance(position, int):
             self._fields["queuePosition"] = Field(position, True)
             self._push()
         else:
             raise ValueError("Not a valid position")
     else:
         pass
예제 #11
0
 def priority(self, priority: str) -> None:
     if isinstance(priority, str):
         self._fields["bandwidthPriority"] = Field(PRIORITY[priority], True)
         self._push()