Back to index

python3.2  3.2.2
Classes | Functions | Variables
test.test_cgi Namespace Reference

Classes

class  HackedSysModule
class  ComparableException
class  CgiTests

Functions

def do_test
def norm
def first_elts
def first_second_elts
def gen_result
def test_main

Variables

list parse_strict_test_cases
string BOUNDARY = "---------------------------721837373350705526688164684"
string POSTDATA
string POSTDATA_NON_ASCII

Function Documentation

def test.test_cgi.do_test (   buf,
  method 
)

Definition at line 33 of file test_cgi.py.

00033 
00034 def do_test(buf, method):
00035     env = {}
00036     if method == "GET":
00037         fp = None
00038         env['REQUEST_METHOD'] = 'GET'
00039         env['QUERY_STRING'] = buf
00040     elif method == "POST":
00041         fp = BytesIO(buf.encode('latin-1')) # FieldStorage expects bytes
00042         env['REQUEST_METHOD'] = 'POST'
00043         env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
00044         env['CONTENT_LENGTH'] = str(len(buf))
00045     else:
00046         raise ValueError("unknown method: %s" % method)
00047     try:
00048         return cgi.parse(fp, env, strict_parsing=1)
00049     except Exception as err:
00050         return ComparableException(err)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_cgi.first_elts (   list)

Definition at line 101 of file test_cgi.py.

00101 
00102 def first_elts(list):
00103     return [p[0] for p in list]

Definition at line 104 of file test_cgi.py.

00104 
00105 def first_second_elts(list):
00106     return [(p[0], p[1][0]) for p in list]

def test.test_cgi.gen_result (   data,
  environ 
)

Definition at line 107 of file test_cgi.py.

00107 
00108 def gen_result(data, environ):
00109     encoding = 'latin-1'
00110     fake_stdin = BytesIO(data.encode(encoding))
00111     fake_stdin.seek(0)
00112     form = cgi.FieldStorage(fp=fake_stdin, environ=environ, encoding=encoding)
00113 
00114     result = {}
00115     for k, v in dict(form).items():
00116         result[k] = isinstance(v, list) and form.getlist(k) or v.value
00117 
00118     return result

Here is the caller graph for this function:

def test.test_cgi.norm (   seq)

Definition at line 98 of file test_cgi.py.

00098 
00099 def norm(seq):
00100     return sorted(seq, key=repr)

Here is the call graph for this function:

Definition at line 383 of file test_cgi.py.

00383 
00384 def test_main():
00385     run_unittest(CgiTests)

Here is the call graph for this function:


Variable Documentation

string test.test_cgi.BOUNDARY = "---------------------------721837373350705526688164684"

Definition at line 352 of file test_cgi.py.

Definition at line 51 of file test_cgi.py.

Initial value:
00001 """-----------------------------721837373350705526688164684
00002 Content-Disposition: form-data; name="id"
00003 
00004 1234
00005 -----------------------------721837373350705526688164684
00006 Content-Disposition: form-data; name="title"
00007 
00008 
00009 -----------------------------721837373350705526688164684
00010 Content-Disposition: form-data; name="file"; filename="test.txt"
00011 Content-Type: text/plain
00012 
00013 Testing 123.
00014 
00015 -----------------------------721837373350705526688164684
00016 Content-Disposition: form-data; name="submit"
00017 
00018  Add\x20
00019 -----------------------------721837373350705526688164684--
00020 """

Definition at line 354 of file test_cgi.py.

Initial value:
00001 """-----------------------------721837373350705526688164684
00002 Content-Disposition: form-data; name="id"
00003 
00004 \xe7\xf1\x80
00005 -----------------------------721837373350705526688164684
00006 """

Definition at line 375 of file test_cgi.py.