Commits

Erik Svensson  committed 13f9eb0

Cleaning lint suggestions.

  • Participants
  • Parent commits 26b8828

Comments (0)

Files changed (5)

 transmissionrpc requires:
 
  * Python >= 2.6
- * Six >= 1.2.0, https://pypi.python.org/pypi/six/
+ * Six >= 1.1.0, https://pypi.python.org/pypi/six/
 
 Install
 -------

File doc/index.rst

 transmissionrpc has the following dependencies.
 
  * Python >= 2.6
- * Six >= 1.2.0, https://pypi.python.org/pypi/six/
+ * Six >= 1.1.0, https://pypi.python.org/pypi/six/
 
 Report a problem
 ----------------

File transmissionrpc/client.py

         )
     )
 
+
+
+def parse_torrent_id(arg):
+    """Parse an torrent id or torrent hashString."""
+    torrent_id = None
+    try:
+        # handle index
+        torrent_id = int(arg)
+    except ValueError:
+        pass
+    if torrent_id is None:
+        # handle hashes
+        try:
+            int(arg, 16)
+            torrent_id = arg
+        except ValueError:
+            pass
+    return torrent_id
+
 """
 Torrent ids
 
                     LOGGER.info('Server responded with 409, trying to set session-id.')
                     if request_count > 1:
                         raise TransmissionError('Session ID negotiation failed.', error)
-                    sessionId = None
+                    session_id = None
                     for key in list(error.headers.keys()):
                         if key.lower() == 'x-transmission-session-id':
-                            sessionId = error.headers[key]
-                            self.session_id = sessionId
+                            session_id = error.headers[key]
+                            self.session_id = session_id
                             headers = {'x-transmission-session-id': str(self.session_id)}
-                    if sessionId is None:
+                    if session_id is None:
                         debug_httperror(error)
                         raise TransmissionError('Unknown conflict.', error)
                 else:
 
         return results
 
-    def _parse_id(self, arg):
-        torrent_id = None
-        try:
-            # handle index
-            torrent_id = int(arg)
-        except ValueError:
-            pass
-        if torrent_id is None:
-            # handle hashes
-            try:
-                int(arg, 16)
-                torrent_id = arg
-            except ValueError:
-                pass
-        return torrent_id
-
     def _format_ids(self, args):
         """
         Take things and make them valid torrent identifiers
                 if len(item) == 0:
                     continue
                 addition = None
-                torrent_id = self._parse_id(item)
+                torrent_id = parse_torrent_id(item)
                 if torrent_id is not None:
                     addition = [torrent_id]
                 if not addition:
             self.session = Session(self, data)
 
     def _update_server_version(self):
+        """Decode the Transmission version string, if available."""
         if self.server_version is None:
             version_major = 1
             version_minor = 30
         warnings.warn('reannounce has been deprecated, please use reannounce_torrent instead.', DeprecationWarning)
         self.reannounce_torrent(ids, timeout)
 
-    def get_torrent(self, id, arguments=None, timeout=None):
+    def get_torrent(self, torrent_id, arguments=None, timeout=None):
         """
         Get information for torrent with provided id.
         ``arguments`` contains a list of field names to be returned, when None
         """
         if not arguments:
             arguments = self.torrent_get_arguments
-        torrent_id = self._parse_id(id)
+        torrent_id = parse_torrent_id(torrent_id)
         if torrent_id is None:
             raise ValueError("Invalid id")
         result = self._request('torrent-get', {'fields': arguments}, torrent_id, require_ids=True, timeout=timeout)

File transmissionrpc/session.py

         """
         Update the session data from a Transmission JSON-RPC arguments dictionary
         """
-        fields = None
         if isinstance(other, dict):
             for key, value in iteritems(other):
                 self._fields[key.replace('-', '_')] = Field(value, False)
     peer_port = property(_get_peer_port, _set_peer_port, None, "Peer port. This is a mutator.")
 
     def _get_pex_enabled(self):
+        """Is peer exchange enabled?"""
         return self._fields['pex_enabled'].value
 
     def _set_pex_enabled(self, enabled):
+        """Enable/disable peer exchange."""
         if isinstance(enabled, bool):
             self._fields['pex_enabled'] = Field(enabled, True)
             self._push()
         else:
             raise TypeError("Not a valid type")
 
-    pex_enabled = property(_get_pex_enabled, _set_pex_enabled, None, "Enable PEX. This is a mutator.")
+    pex_enabled = property(_get_pex_enabled, _set_pex_enabled, None, "Enable peer exchange. This is a mutator.")

File transmissionrpc/torrent.py

 
 from six import integer_types, string_types, text_type, iteritems
 
+
+def get_status_old(code):
+    """Get the torrent status using old status codes"""
+    mapping = {
+        (1<<0): 'check pending',
+        (1<<1): 'checking',
+        (1<<2): 'downloading',
+        (1<<3): 'seeding',
+        (1<<4): 'stopped',
+    }
+    return mapping[code]
+
+def get_status_new(code):
+    """Get the torrent status using new status codes"""
+    mapping = {
+        0: 'stopped',
+        1: 'check pending',
+        2: 'checking',
+        3: 'download pending',
+        4: 'downloading',
+        5: 'seed pending',
+        6: 'seeding',
+    }
+    return mapping[code]
+
 class Torrent(object):
     """
     Torrent is a class holding the data received from Transmission regarding a bittorrent transfer.
             raise ValueError('Torrent requires an id')
         self._fields = {}
         self._update_fields(fields)
-        self._incoming_pending= False
-        self._outgoing_pending= False
+        self._incoming_pending = False
+        self._outgoing_pending = False
         self._client = client
 
-    def _getNameString(self, codec=None):
+    def _get_name_string(self, codec=None):
+        """Get the name"""
         if codec is None:
             codec = sys.getdefaultencoding()
         name = None
 
     def __repr__(self):
         tid = self._fields['id'].value
-        name = self._getNameString()
+        name = self._get_name_string()
         if isinstance(name, str):
             return '<Torrent %d \"%s\">' % (tid, name)
         else:
             return '<Torrent %d>' % (tid)
 
     def __str__(self):
-        name = self._getNameString()
+        name = self._get_name_string()
         if isinstance(name, str):
             return 'Torrent \"%s\"' % (name)
         else:
             raise AttributeError('No attribute %s' % name)
 
     def _rpc_version(self):
+        """Get the Transmission RPC API version."""
         if self._client:
             return self._client.rpc_version
         return 2
             raise ValueError('Cannot update with supplied data')
         self._incoming_pending = False
     
-    def _status_old(self, code):
-        mapping = {
-            (1<<0): 'check pending',
-            (1<<1): 'checking',
-            (1<<2): 'downloading',
-            (1<<3): 'seeding',
-            (1<<4): 'stopped',
-        }
-        return mapping[code]
-    
-    def _status_new(self, code):
-        mapping = {
-            0: 'stopped',
-            1: 'check pending',
-            2: 'checking',
-            3: 'download pending',
-            4: 'downloading',
-            5: 'seed pending',
-            6: 'seeding',
-        }
-        return mapping[code]
-    
     def _status(self):
+        """Get the torrent status"""
         code = self._fields['status'].value
         if self._rpc_version() >= 14:
-            return self._status_new(code)
+            return get_status_new(code)
         else:
-            return self._status_old(code)
+            return get_status_old(code)
 
     def files(self):
         """
     upload_limit = property(_get_upload_limit, _set_upload_limit, None, "Upload limit in Kbps or None. This is a mutator.")
 
     def _get_queue_position(self):
+        """Get the queue position for this torrent."""
         if self._rpc_version() >= 14:
             return self._fields['queuePosition'].value
         else:
             return 0
 
     def _set_queue_position(self, position):
+        """Set the queue position for this torrent."""
         if self._rpc_version() >= 14:
             if isinstance(position, integer_types):
                 self._fields['queuePosition'] = Field(position, True)