<s> import warnings <EOL> import six <EOL> if six . PY2 : <EOL> from cStringIO import StringIO as BytesIO <EOL> else : <EOL> from io import BytesIO <EOL> from w3lib . util import unicode_to_str <EOL> def encode_multipart ( data ) : <EOL> r"""<STR_LIT>""" <EOL> warnings . warn ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> DeprecationWarning <EOL> ) <EOL> boundary = '<STR_LIT>' <EOL> sep_boundary = b'<STR_LIT>' + boundary . encode ( '<STR_LIT:ascii>' ) <EOL> end_boundary = sep_boundary + b'<STR_LIT>' <EOL> body = BytesIO ( ) <EOL> for key , value in data . items ( ) : <EOL> title = u'<STR_LIT>' % key <EOL> if type ( value ) != type ( [ ] ) : <EOL> value = [ value ] <EOL> for value in value : <EOL> if type ( value ) is tuple : <EOL> title += u'<STR_LIT>' % value [ <NUM_LIT:0> ] <EOL> value = value [ <NUM_LIT:1> ] <EOL> else : <EOL> value = unicode_to_str ( value ) <EOL> body . write ( sep_boundary ) <EOL> body . write ( title . encode ( '<STR_LIT:utf-8>' ) ) <EOL> body . write ( b"<STR_LIT>" ) <EOL> body . write ( value ) <EOL> body . write ( end_boundary ) <EOL> body . write ( b"<STR_LIT:\r\n>" ) <EOL> return body . getvalue ( ) , boundary </s>
