mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-21 13:53:15 -07:00
Fix PEP8 whitespace violations
This commit is contained in:
parent
e490f97a05
commit
52c6096b6a
14 changed files with 237 additions and 225 deletions
|
@ -19,6 +19,7 @@ try:
|
|||
except ImportError:
|
||||
import simplejson as json
|
||||
|
||||
|
||||
class UTorrentClient(object):
|
||||
|
||||
def __init__(self, base_url, username, password):
|
||||
|
@ -27,7 +28,7 @@ class UTorrentClient(object):
|
|||
self.password = password
|
||||
self.opener = self._make_opener('uTorrent', base_url, username, password)
|
||||
self.token = self._get_token()
|
||||
#TODO refresh token, when necessary
|
||||
# TODO refresh token, when necessary
|
||||
|
||||
def _make_opener(self, realm, base_url, username, password):
|
||||
'''uTorrent API need HTTP Basic Auth and cookie support for token verify.'''
|
||||
|
@ -60,25 +61,25 @@ class UTorrentClient(object):
|
|||
return self._action(params)
|
||||
|
||||
def start(self, *hashes):
|
||||
params = [('action', 'start'),]
|
||||
params = [('action', 'start'), ]
|
||||
for hash in hashes:
|
||||
params.append(('hash', hash))
|
||||
return self._action(params)
|
||||
|
||||
def stop(self, *hashes):
|
||||
params = [('action', 'stop'),]
|
||||
params = [('action', 'stop'), ]
|
||||
for hash in hashes:
|
||||
params.append(('hash', hash))
|
||||
return self._action(params)
|
||||
|
||||
def pause(self, *hashes):
|
||||
params = [('action', 'pause'),]
|
||||
params = [('action', 'pause'), ]
|
||||
for hash in hashes:
|
||||
params.append(('hash', hash))
|
||||
return self._action(params)
|
||||
|
||||
def forcestart(self, *hashes):
|
||||
params = [('action', 'forcestart'),]
|
||||
params = [('action', 'forcestart'), ]
|
||||
for hash in hashes:
|
||||
params.append(('hash', hash))
|
||||
return self._action(params)
|
||||
|
@ -94,8 +95,8 @@ class UTorrentClient(object):
|
|||
def setprops(self, hash, **kvpairs):
|
||||
params = [('action', 'setprops'), ('hash', hash)]
|
||||
for k, v in iteritems(kvpairs):
|
||||
params.append( ("s", k) )
|
||||
params.append( ("v", v) )
|
||||
params.append(("s", k))
|
||||
params.append(("v", v))
|
||||
|
||||
return self._action(params)
|
||||
|
||||
|
@ -111,7 +112,7 @@ class UTorrentClient(object):
|
|||
|
||||
form = MultiPartForm()
|
||||
if filepath is not None:
|
||||
file_handler = open(filepath,'rb')
|
||||
file_handler = open(filepath, 'rb')
|
||||
else:
|
||||
file_handler = StringIO(bytes)
|
||||
|
||||
|
@ -124,19 +125,19 @@ class UTorrentClient(object):
|
|||
self._action(params)
|
||||
|
||||
def remove(self, *hashes):
|
||||
params = [('action', 'remove'),]
|
||||
params = [('action', 'remove'), ]
|
||||
for hash in hashes:
|
||||
params.append(('hash', hash))
|
||||
return self._action(params)
|
||||
|
||||
def removedata(self, *hashes):
|
||||
params = [('action', 'removedata'),]
|
||||
params = [('action', 'removedata'), ]
|
||||
for hash in hashes:
|
||||
params.append(('hash', hash))
|
||||
return self._action(params)
|
||||
|
||||
def _action(self, params, body=None, content_type=None):
|
||||
#about token, see https://github.com/bittorrent/webui/wiki/TokenSystem
|
||||
# about token, see https://github.com/bittorrent/webui/wiki/TokenSystem
|
||||
url = self.base_url + '?token=' + self.token + '&' + urlencode(params)
|
||||
request = Request(url)
|
||||
|
||||
|
|
|
@ -42,29 +42,28 @@ class MultiPartForm(object):
|
|||
|
||||
# Add the form fields
|
||||
parts.extend(
|
||||
[ part_boundary,
|
||||
'Content-Disposition: form-data; name="%s"' % name,
|
||||
'',
|
||||
value,
|
||||
]
|
||||
[part_boundary,
|
||||
'Content-Disposition: form-data; name="%s"' % name,
|
||||
'',
|
||||
value,
|
||||
]
|
||||
for name, value in self.form_fields
|
||||
)
|
||||
)
|
||||
|
||||
# Add the files to upload
|
||||
parts.extend(
|
||||
[ part_boundary,
|
||||
'Content-Disposition: file; name="%s"; filename="%s"' % \
|
||||
(field_name, filename),
|
||||
'Content-Type: %s' % content_type,
|
||||
'',
|
||||
body,
|
||||
]
|
||||
[part_boundary,
|
||||
'Content-Disposition: file; name="%s"; filename="%s"' % (field_name, filename),
|
||||
'Content-Type: %s' % content_type,
|
||||
'',
|
||||
body,
|
||||
]
|
||||
for field_name, filename, content_type, body in self.files
|
||||
)
|
||||
)
|
||||
|
||||
# Flatten the list and add closing boundary marker,
|
||||
# then return CR+LF separated data
|
||||
flattened = list(itertools.chain(*parts))
|
||||
flattened.append('--' + self.boundary + '--')
|
||||
flattened.append('')
|
||||
return '\r\n'.join(flattened)
|
||||
return '\r\n'.join(flattened)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue