Commits

Erik Svensson committed da873e8

Fixed spelling errors.
Cleanup.

  • Participants
  • Parent commits 82d5b04

Comments (0)

Files changed (7)

 NOTE: You might need administrator privileges to install python modules.
 
 The setup program will take care of the simplejson requirement. Please refer to
-the Transmission documenation on how to install Transmission.
+the Transmission documentation on how to install Transmission.
 
 Developer
 =========

doc/reference/transmissionrpc.rst

 -----------
 
 Many functions in Client takes torrent id. A torrent id can either be id or
-hashString. When suppling multiple id's it is possible to use a list mixed
+hashString. When supplying multiple id's it is possible to use a list mixed
 with both id and hashString.
 
 Timeouts

transmissionrpc/client.py

 # Copyright (c) 2008-2011 Erik Svensson <erik.public@gmail.com>
 # Licensed under the MIT license.
 
-import os, re, time
-import warnings
-import httplib, urllib2, urlparse, base64
+import re, time
+import urllib2, urlparse, base64
 
 try:
     import json
                 password = urlo.password
             elif urlo.username or urlo.password:
                 LOGGER.warning('Either user or password missing, not using authentication.')
-        if http_handler == None:
+        if http_handler is None:
             self.http_handler = DefaultHTTPHandler()
         else:
             if hasattr(http_handler, 'set_authentication') and hasattr(http_handler, 'request'):
         Query Transmission through HTTP.
         """
         headers = {'x-transmission-session-id': str(self.session_id)}
+        result = {}
         request_count = 0
-        if timeout == None:
+        if timeout is None:
             timeout = self._query_timeout
         while True:
             LOGGER.debug(json.dumps({'url': self.url, 'headers': headers, 'query': query, 'timeout': timeout}, indent=2))
                 else:
                     debug_httperror(error)
                     raise TransmissionError('Request failed.', error)
-            request_count = request_count + 1
+            request_count += 1
         return result
 
     def _request(self, method, arguments=None, ids=None, require_ids=False, timeout=None):
         """
         if not isinstance(method, (str, unicode)):
             raise ValueError('request takes method as string')
-        if arguments == None:
+        if arguments is None:
             arguments = {}
         if not isinstance(arguments, dict):
             raise ValueError('request takes arguments as dict')
         """
         ids = []
 
-        if args == None:
+        if args is None:
             pass
         elif isinstance(args, (int, long)):
             ids.append(args)
                 if not addition:
                     raise ValueError(u'Invalid torrent id, \"%s\"' % item)
                 ids.extend(addition)
-        elif isinstance(args, (list)):
+        elif isinstance(args, list):
             for item in args:
                 ids.extend(self._format_ids(item))
         else:
         self.session.update(data)
 
     def _update_server_version(self):
-        if self.server_version == None:
+        if self.server_version is None:
             version_major = 1
             version_minor = 30
             version_changeset = 0
             version_parser = re.compile('(\d).(\d+) \((\d+)\)')
             if hasattr(self.session, 'version'):
                 match = version_parser.match(self.session.version)
-                if (match):
+                if match:
                     version_major = int(match.group(1))
                     version_minor = int(match.group(2))
                     version_changeset = match.group(3)
         """
         Get the Transmission RPC version. Trying to deduct if the server don't have a version value.
         """
-        if self.protocol_version == None:
+        if self.protocol_version is None:
             # Ugly fix for 2.20 - 2.22 reporting rpc-version 11, but having new arguments
-            if (self.server_version and (self.server_version[0] == 2 and self.server_version[1] in [20, 21, 22])):
+            if self.server_version and (self.server_version[0] == 2 and self.server_version[1] in [20, 21, 22]):
                 self.protocol_version = 12
             # Ugly fix for 2.12 reporting rpc-version 10, but having new arguments
-            elif (self.server_version and (self.server_version[0] == 2 and self.server_version[1] == 12)):
+            elif self.server_version and (self.server_version[0] == 2 and self.server_version[1] == 12):
                 self.protocol_version = 11
             elif hasattr(self.session, 'rpc_version'):
                 self.protocol_version = self.session.rpc_version
         ``priority_normal``   1 -               A list of file id's that should have normal priority.
         ===================== ===== =========== =============================================================
         """
-        if uri == None:
+        if uri is None:
             raise ValueError('add_uri requires a URI.')
         # there has been some problem with T's built in torrent fetcher,
         # use a python one instead
-        parseduri = urlparse.urlparse(uri)
+        parsed_uri = urlparse.urlparse(uri)
         torrent_data = None
-        if parseduri.scheme in ['file', 'ftp', 'ftps', 'http', 'https']:
+        if parsed_uri.scheme in ['file', 'ftp', 'ftps', 'http', 'https']:
             torrent_file = urllib2.urlopen(uri)
             torrent_data = base64.b64encode(torrent_file.read())
         if torrent_data:
     def get_files(self, ids=None, timeout=None):
         """
     	Get list of files for provided torrent id(s). If ids is empty,
-    	information for all torrents are fetched. This function returns a dictonary
+    	information for all torrents are fetched. This function returns a dictionary
     	for each requested torrent id holding the information about the files.
 
     	::

transmissionrpc/error.py

 
 class TransmissionError(Exception):
     """
-	This exception is raised when there has occured an error related to
+	This exception is raised when there has occurred an error related to
 	communication with Transmission. It is a subclass of Exception.
     """
     def __init__(self, message='', original=None):
         Exception.__init__(self)
-        self.message = message
+        self._message = message
         self.original = original
 
     def __str__(self):
 
 class HTTPHandlerError(Exception):
     """
-	This exception is raised when there has occured an error related to
+	This exception is raised when there has occurred an error related to
 	the HTTP handler. It is a subclass of Exception.
     """
     def __init__(self, httpurl=None, httpcode=None, httpmsg=None, httpheaders=None, httpdata=None):
         Exception.__init__(self)
         self.url = ''
         self.code = 600
-        self.message = ''
+        self._message = ''
         self.headers = {}
         self.data = ''
         if isinstance(httpurl, (str, unicode)):
         if isinstance(httpcode, (int, long)):
             self.code = httpcode
         if isinstance(httpmsg, (str, unicode)):
-            self.message = httpmsg
-        if isinstance(httpheaders, (dict)):
+            self._message = httpmsg
+        if isinstance(httpheaders, dict):
             self.headers = httpheaders
         if isinstance(httpdata, (str, unicode)):
             self.data = httpdata
 
     def __repr__(self):
-        return '<HTTPHandlerError %d, %s>' % (self.code, self.message)
+        return '<HTTPHandlerError %d, %s>' % (self.code, self._message)
 
     def __str__(self):
-        return '<HTTPHandlerError %d, %s>' % (self.code, self.message)
+        return 'HTTPHandlerError %d: %s' % (self.code, self._message)
 
     def __unicode__(self):
-        return u'<HTTPHandlerError %d, %s>' % (self.code, self.message)
+        return u'HTTPHandlerError %d: %s' % (self.code, self._message)

transmissionrpc/httphandler.py

             else:
                 response = urllib2.urlopen(request)
         except urllib2.HTTPError, error:
-            if error.fp == None:
+            if error.fp is None:
                 raise HTTPHandlerError(error.filename, error.code, error.msg, dict(error.hdrs))
             else:
                 raise HTTPHandlerError(error.filename, error.code, error.msg, dict(error.hdrs), error.read())
         except urllib2.URLError, error:
-            # urllib2.URLError documentation is absymal!
+            # urllib2.URLError documentation is horrendous!
             # Try to get the tuple arguments of URLError
             if hasattr(error.reason, 'args') and isinstance(error.reason.args, tuple) and len(error.reason.args) == 2:
                 raise HTTPHandlerError(httpcode=error.reason.args[0], httpmsg=error.reason.args[1])

transmissionrpc/torrent.py

 
 class Torrent(object):
     """
-    Torrent is a class holding the data raceived from Transmission regarding a bittorrent transfer.
-    All fetched torrent fields are accessable through this class using attributes.
+    Torrent is a class holding the data received from Transmission regarding a bittorrent transfer.
+    All fetched torrent fields are accessible through this class using attributes.
     This class has a few convenience properties using the torrent data.
     """
 
         self.client = client
 
     def _getNameString(self, codec=None):
-        if codec == None:
+        if codec is None:
             codec = sys.getdefaultencoding()
         name = None
         # try to find name
 
     def update(self, other):
         """
-        Update the torrent data from a Transmission JSON-RPC arguments dictinary
+        Update the torrent data from a Transmission JSON-RPC arguments dictionary
         """
         fields = None
         if isinstance(other, dict):

transmissionrpc/utils.py

 
 def format_timedelta(delta):
     """
-    Format datetime.timedelta into <days> <hours>:<mminutes>:<seconds>.
+    Format datetime.timedelta into <days> <hours>:<minutes>:<seconds>.
     """
     minutes, seconds = divmod(delta.seconds, 60)
     hours, minutes = divmod(minutes, 60)