diff options
author | Marc Abramowitz <marc@marc-abramowitz.com> | 2016-03-07 18:52:36 -0800 |
---|---|---|
committer | Marc Abramowitz <marc@marc-abramowitz.com> | 2016-03-07 18:52:36 -0800 |
commit | cc83e06efff71b81ca5a3ac6df65775971181295 (patch) | |
tree | d52fa3f1a93730f263c2c5ac8266de8e5fb12abf /tests/cgiapp_data | |
download | paste-git-tox_coverage.tar.gz |
tox.ini: Measure test coveragetox_coverage
Diffstat (limited to 'tests/cgiapp_data')
-rwxr-xr-x | tests/cgiapp_data/error.cgi | 3 | ||||
-rwxr-xr-x | tests/cgiapp_data/form.cgi | 69 | ||||
-rwxr-xr-x | tests/cgiapp_data/ok.cgi | 5 | ||||
-rwxr-xr-x | tests/cgiapp_data/stderr.cgi | 8 |
4 files changed, 85 insertions, 0 deletions
diff --git a/tests/cgiapp_data/error.cgi b/tests/cgiapp_data/error.cgi new file mode 100755 index 0000000..e11c766 --- /dev/null +++ b/tests/cgiapp_data/error.cgi @@ -0,0 +1,3 @@ +#!/usr/bin/env python + +print('hey you!') diff --git a/tests/cgiapp_data/form.cgi b/tests/cgiapp_data/form.cgi new file mode 100755 index 0000000..c4c562d --- /dev/null +++ b/tests/cgiapp_data/form.cgi @@ -0,0 +1,69 @@ +#!/usr/bin/env python + +from __future__ import print_function + +import cgi +import six + +print('Content-type: text/plain') +print('') + +if six.PY3: + # Python 3: cgi.FieldStorage keeps some field names as unicode and some as + # the repr() of byte strings, duh. + + class FieldStorage(cgi.FieldStorage): + + def _key_candidates(self, key): + yield key + + try: + # assume bytes, coerce to str + try: + yield key.decode(self.encoding) + except UnicodeDecodeError: + pass + except AttributeError: + # assume str, coerce to bytes + try: + yield key.encode(self.encoding) + except UnicodeEncodeError: + pass + + def __getitem__(self, key): + + superobj = super(FieldStorage, self) + + error = None + + for candidate in self._key_candidates(key): + if isinstance(candidate, bytes): + # ouch + candidate = repr(candidate) + try: + return superobj.__getitem__(candidate) + except KeyError as e: + if error is None: + error = e + + # fall through, re-raise the first KeyError + raise error + + def __contains__(self, key): + superobj = super(FieldStorage, self) + + for candidate in self._key_candidates(key): + if superobj.__contains__(candidate): + return True + return False + +else: # PY2 + + FieldStorage = cgi.FieldStorage + + +form = FieldStorage() + +print('Filename: %s' % form['up'].filename) +print('Name: %s' % form['name'].value) +print('Content: %s' % form['up'].file.read()) diff --git a/tests/cgiapp_data/ok.cgi b/tests/cgiapp_data/ok.cgi new file mode 100755 index 0000000..d03f0b9 --- /dev/null +++ b/tests/cgiapp_data/ok.cgi @@ -0,0 +1,5 @@ +#!/usr/bin/env python +print('Content-type: text/html; charset=UTF-8') +print('Status: 200 Okay') +print('') +print('This is the body') diff --git a/tests/cgiapp_data/stderr.cgi b/tests/cgiapp_data/stderr.cgi new file mode 100755 index 0000000..d2520b6 --- /dev/null +++ b/tests/cgiapp_data/stderr.cgi @@ -0,0 +1,8 @@ +#!/usr/bin/env python +from __future__ import print_function +import sys +print('Status: 500 Server Error') +print('Content-type: text/html') +print() +print('There was an error') +print('some data on the error', file=sys.stderr) |