diff options
| author | Gael Pasgrimaud <gael@gawel.org> | 2013-01-28 15:39:41 +0100 |
|---|---|---|
| committer | Gael Pasgrimaud <gael@gawel.org> | 2013-01-28 15:39:41 +0100 |
| commit | 6f5a2a2ddd18f95cb1c65958a37fd116051b85aa (patch) | |
| tree | 25fcfd318227b1bb7cb54d1c2d78ccee1f425f0d /webtest/forms.py | |
| parent | 683e9ce5e3360aabf7e1d68c6c3bbc5a9e1d715e (diff) | |
| download | webtest-6f5a2a2ddd18f95cb1c65958a37fd116051b85aa.tar.gz | |
improve Upload
Diffstat (limited to 'webtest/forms.py')
| -rw-r--r-- | webtest/forms.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/webtest/forms.py b/webtest/forms.py index 46a2438..bf0e52d 100644 --- a/webtest/forms.py +++ b/webtest/forms.py @@ -3,13 +3,28 @@ __doc__ = """Helpers to fill and submit forms""" from webtest.compat import OrderedDict from webtest import utils import re +import os class Upload(object): - """A file to upload""" - def __init__(self, filename, file_content=None): + """A file to upload:: + + >>> Upload('filename.txt', 'data') + <Upload "filename.txt"> + >>> Upload(__file__) + <Upload "forms.py"> + """ + def __init__(self, filename, content=None): self.filename = filename - self.file_content = file_content + self.content = content + if content is None and os.path.isfile(filename): + self.filename = os.path.basename(filename) + fd = open(filename, 'rb') + self.content = fd.read() + fd.close() + + def __repr__(self): + return '<Upload "%s">' % self.filename class Field(object): |
