mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-19 21:03:14 -07:00
update utorrent client. Fixes #1138
This commit is contained in:
parent
ccd89d5403
commit
454db6fe6a
2 changed files with 77 additions and 71 deletions
|
@ -1,10 +1,12 @@
|
|||
# coding=utf-8
|
||||
# code copied from http://www.doughellmann.com/PyMOTW/urllib2/
|
||||
|
||||
from email.generator import _make_boundary as make_boundary
|
||||
import itertools
|
||||
import mimetools
|
||||
import mimetypes
|
||||
|
||||
from cStringIO import StringIO
|
||||
import urllib
|
||||
import urllib2
|
||||
|
||||
class MultiPartForm(object):
|
||||
"""Accumulate the data to be used when posting a form."""
|
||||
|
@ -12,11 +14,11 @@ class MultiPartForm(object):
|
|||
def __init__(self):
|
||||
self.form_fields = []
|
||||
self.files = []
|
||||
self.boundary = make_boundary()
|
||||
self.boundary = mimetools.choose_boundary()
|
||||
return
|
||||
|
||||
def get_content_type(self):
|
||||
return 'multipart/form-data; boundary={0}'.format(self.boundary)
|
||||
return 'multipart/form-data; boundary=%s' % self.boundary
|
||||
|
||||
def add_field(self, name, value):
|
||||
"""Add a simple field to the form data."""
|
||||
|
@ -38,32 +40,33 @@ class MultiPartForm(object):
|
|||
# Once the list is built, return a string where each
|
||||
# line is separated by '\r\n'.
|
||||
parts = []
|
||||
part_boundary = '--{boundary}'.format(boundary=self.boundary)
|
||||
part_boundary = '--' + self.boundary
|
||||
|
||||
# Add the form fields
|
||||
parts.extend(
|
||||
[part_boundary,
|
||||
'Content-Disposition: form-data; name="{0}"'.format(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="{0}"; filename="{1}"'.format(field_name, filename),
|
||||
'Content-Type: {0}'.format(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('--{boundary}--'.format(boundary=self.boundary))
|
||||
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