else:
form.append('Content-Disposition: form-data; name="%s"' % name)
form.append('')
- form.append(str(value))
+ if isinstance(value, unicode):
+ value = value.encode("utf-8")
+ else:
+ value = str(value)
+ assert isinstance(value, str)
+ form.append(value)
form.append(sep)
form[-1] += "--"
body = "\r\n".join(form) + "\r\n"
def test_POST_upload_unicode(self):
filename = u"n\u00e9wer.txt" # n e-acute w e r . t x t
- target_url = self.public_url + "/foo/" + filename.encode("utf-8")
d = self.POST(self.public_url + "/foo", t="upload",
file=(filename, self.NEWFILE_CONTENTS))
fn = self._foo_node
d.addCallback(lambda res:
self.failUnlessChildContentsAre(fn, filename,
self.NEWFILE_CONTENTS))
+ target_url = self.public_url + "/foo/" + filename.encode("utf-8")
+ d.addCallback(lambda res: self.GET(target_url))
+ d.addCallback(lambda contents: self.failUnlessEqual(contents,
+ self.NEWFILE_CONTENTS,
+ contents))
+ return d
+
+ def test_POST_upload_unicode_named(self):
+ filename = u"n\u00e9wer.txt" # n e-acute w e r . t x t
+ d = self.POST(self.public_url + "/foo", t="upload",
+ name=filename,
+ file=("overridden", self.NEWFILE_CONTENTS))
+ fn = self._foo_node
+ d.addCallback(self.failUnlessURIMatchesChild, fn, filename)
+ d.addCallback(lambda res:
+ self.failUnlessChildContentsAre(fn, filename,
+ self.NEWFILE_CONTENTS))
+ target_url = self.public_url + "/foo/" + filename.encode("utf-8")
d.addCallback(lambda res: self.GET(target_url))
d.addCallback(lambda contents: self.failUnlessEqual(contents,
self.NEWFILE_CONTENTS,
req = IRequest(ctx)
charset = get_arg(req, "_charset", "utf-8")
contents = req.fields["file"]
+ assert contents.filename is None or isinstance(contents.filename, str)
name = get_arg(req, "name")
name = name or contents.filename
if name is not None:
if not name:
# this prohibts empty, missing, and all-whitespace filenames
raise WebError("upload requires a name")
+ assert isinstance(name, str)
name = name.decode(charset)
if "/" in name:
raise WebError("name= may not contain a slash", http.BAD_REQUEST)