-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnsapytest.py
More file actions
80 lines (56 loc) · 1.95 KB
/
nsapytest.py
File metadata and controls
80 lines (56 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# An example of NSAPy
# June 11 1997 Gregory Trubetskoy <grisha@ispol.com>
"""
Minimally, all you need is:
import nsapy
class RequestHandler( nsapy.RequestHandler ):
def Content( self ):
return 'Hello World!'
"""
import nsapy
import string
class RequestHandler( nsapy.RequestHandler ):
def Content( self ):
# uncomment this to see redirection!
#self.redirect = "http://www.python.org/"
s = """<html><head><title>NSAPY!</title></head>\n
<body bgcolor="#ffffc0">
<h1>Some things you can see in nsapy:</h1>
"""
s = s + '<h2> Parameter Block </h2>\n'
s = s + '<blockquote>'
s = s + pblock_table( self.pb )
s = s + '</blockquote>'
s = s + '<h2> Session Data </h2>\n'
s = s + '<blockquote>'
s = s + "<h3>DNS</h3>\n"
s = s + "%s <br>\n" % self.sn.session_dns()
s = s + "<h3>Client Data</h3>\n"
s = s + pblock_table( self.sn.client() )
s = s + '</blockquote>'
s = s + '<h2> Request Data </h2>\n'
s = s + '<blockquote>'
s = s + "<h3> Parameter Block </h3>\n"
s = s + pblock_table( self.rq.reqpb )
s = s + "<h3> Request Headers </h3>\n"
# NOTE! Netscape documentation sais you're
# not supposed to access "headers" directly,
# instead, do something like ( to get "user-agent" )
# >>> ua = self.rq.request_header("user-agent", self.sn)
# ( P.S. but I don't care! )
s = s + pblock_table( self.rq.headers )
s = s + "<h3> Server Headers </h3>\n"
s = s + pblock_table( self.rq.srvhdrs )
s = s + "<h3> Request Variables </h3>\n"
s = s + pblock_table( self.rq.vars )
s = s + '</blockquote>'
return s
# convert a block to an HTML table
def pblock_table( pblock ):
s = '\n<table border=1 cellpadding=3>\n'
l = string.split( pblock.pblock2str(), '"' )
for n in range( 1, len( l ), 2 ):
s = s + '<tr><td align=center>%s</td><td align=center>%s</td></tr>\n' \
% ( l[n-1][:-1], l[n] )
s = s + '\n</table>\n'
return s