Merge pull request #2331 from fuzeman/feature/dev_rtorrent
rTorrent Downloader - fixes to scgi on Python 2.6
This commit is contained in:
@@ -71,7 +71,7 @@ class rTorrent(Downloader):
|
||||
group.set_command()
|
||||
group.disable()
|
||||
except MethodError, err:
|
||||
log.error('Unable to set group options: %s', err.message)
|
||||
log.error('Unable to set group options: %s', err.msg)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@@ -115,6 +115,11 @@ class RTorrent:
|
||||
|
||||
return self._client_version_tuple
|
||||
|
||||
def _update_rpc_methods(self):
|
||||
self._rpc_methods = self._get_conn().system.listMethods()
|
||||
|
||||
return self._rpc_methods
|
||||
|
||||
def _get_rpc_methods(self):
|
||||
""" Get list of raw RPC commands
|
||||
|
||||
@@ -122,10 +127,7 @@ class RTorrent:
|
||||
@rtype: list
|
||||
"""
|
||||
|
||||
if self._rpc_methods == []:
|
||||
self._rpc_methods = self._get_conn().system.listMethods()
|
||||
|
||||
return(self._rpc_methods)
|
||||
return(self._rpc_methods or self._update_rpc_methods())
|
||||
|
||||
def get_torrents(self, view="main"):
|
||||
"""Get list of all torrents in specified view
|
||||
@@ -317,6 +319,8 @@ class RTorrent:
|
||||
assert view is not None, "view parameter required on non-persistent groups"
|
||||
p.group.insert('', name, view)
|
||||
|
||||
self._update_rpc_methods()
|
||||
|
||||
def get_group(self, name):
|
||||
assert name is not None, "group name required"
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
# rtorrent_xmlrpc
|
||||
# (c) 2011 Roger Que <alerante@bellsouth.net>
|
||||
#
|
||||
# Modified portions:
|
||||
# (c) 2013 Dean Gardiner <gardiner91@gmail.com>
|
||||
#
|
||||
# Python module for interacting with rtorrent's XML-RPC interface
|
||||
# directly over SCGI, instead of through an HTTP server intermediary.
|
||||
# Inspired by Glenn Washburn's xmlrpc2scgi.py [1], but subclasses the
|
||||
@@ -78,13 +81,28 @@
|
||||
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
# OF THIS SOFTWARE.
|
||||
|
||||
import httplib
|
||||
import re
|
||||
import socket
|
||||
import urllib
|
||||
import xmlrpclib
|
||||
import errno
|
||||
|
||||
|
||||
class SCGITransport(xmlrpclib.Transport):
|
||||
# Added request() from Python 2.7 xmlrpclib here to backport to Python 2.6
|
||||
def request(self, host, handler, request_body, verbose=0):
|
||||
#retry request once if cached connection has gone cold
|
||||
for i in (0, 1):
|
||||
try:
|
||||
return self.single_request(host, handler, request_body, verbose)
|
||||
except socket.error, e:
|
||||
if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE):
|
||||
raise
|
||||
except httplib.BadStatusLine: #close after we sent request
|
||||
if i:
|
||||
raise
|
||||
|
||||
def single_request(self, host, handler, request_body, verbose=0):
|
||||
# Add SCGI headers to the request.
|
||||
headers = {'CONTENT_LENGTH': str(len(request_body)), 'SCGI': '1'}
|
||||
@@ -97,7 +115,7 @@ class SCGITransport(xmlrpclib.Transport):
|
||||
try:
|
||||
if host:
|
||||
host, port = urllib.splitport(host)
|
||||
addrinfo = socket.getaddrinfo(host, port, socket.AF_INET,
|
||||
addrinfo = socket.getaddrinfo(host, int(port), socket.AF_INET,
|
||||
socket.SOCK_STREAM)
|
||||
sock = socket.socket(*addrinfo[0][:3])
|
||||
sock.connect(addrinfo[0][4])
|
||||
|
||||
Reference in New Issue
Block a user