| 1 |
""" |
|---|
| 2 |
Copyright (c) 2004, CherryPy Team (team@cherrypy.org) |
|---|
| 3 |
All rights reserved. |
|---|
| 4 |
|
|---|
| 5 |
Redistribution and use in source and binary forms, with or without modification, |
|---|
| 6 |
are permitted provided that the following conditions are met: |
|---|
| 7 |
|
|---|
| 8 |
* Redistributions of source code must retain the above copyright notice, |
|---|
| 9 |
this list of conditions and the following disclaimer. |
|---|
| 10 |
* Redistributions in binary form must reproduce the above copyright notice, |
|---|
| 11 |
this list of conditions and the following disclaimer in the documentation |
|---|
| 12 |
and/or other materials provided with the distribution. |
|---|
| 13 |
* Neither the name of the CherryPy Team nor the names of its contributors |
|---|
| 14 |
may be used to endorse or promote products derived from this software |
|---|
| 15 |
without specific prior written permission. |
|---|
| 16 |
|
|---|
| 17 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|---|
| 18 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|---|
| 19 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|---|
| 20 |
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
|---|
| 21 |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|---|
| 22 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|---|
| 23 |
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|---|
| 24 |
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|---|
| 25 |
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|---|
| 26 |
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 27 |
|
|---|
| 28 |
------------------------------------------------------------------------------- |
|---|
| 29 |
|
|---|
| 30 |
Helper script for debugging CherryPy ticket #107 and #78 |
|---|
| 31 |
|
|---|
| 32 |
Todos: |
|---|
| 33 |
* get documentation in here |
|---|
| 34 |
* if possible, have the tests be evaluated automagically |
|---|
| 35 |
* do something with the output on the console, as this can be |
|---|
| 36 |
handles quite easily. |
|---|
| 37 |
* insert a full blown list of examples, and prefereble, insert |
|---|
| 38 |
them all by hand, and make each url a: "should crash, should |
|---|
| 39 |
move to another location, should run" kinda thing. (this also |
|---|
| 40 |
allows for easily automating the test) |
|---|
| 41 |
* once done, it's an extensive and comprehensive list of all |
|---|
| 42 |
mappings CherryPy can do. |
|---|
| 43 |
|
|---|
| 44 |
""" |
|---|
| 45 |
__version__ = "0.1-20050414" |
|---|
| 46 |
__authors__ = ["Remco Boema"] |
|---|
| 47 |
__license__ = "The BSD License, see http://www.opensource.org/licenses/bsd-license.php" |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
try: |
|---|
| 51 |
|
|---|
| 52 |
import fixpath |
|---|
| 53 |
except: |
|---|
| 54 |
pass |
|---|
| 55 |
from cherrypy import cpg |
|---|
| 56 |
import sys |
|---|
| 57 |
|
|---|
| 58 |
def concat(*p): |
|---|
| 59 |
return " ".join([str(x) for x in p]) |
|---|
| 60 |
_ = concat |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
class ObjWithParamIndex(object): |
|---|
| 64 |
def __init__(self): |
|---|
| 65 |
self.exposed = True |
|---|
| 66 |
self.testurls = ['','/','/index','/index?param=value','/param/value','/?invalidname=value','to/many/params'] |
|---|
| 67 |
def __call__(self): |
|---|
| 68 |
pass |
|---|
| 69 |
|
|---|
| 70 |
def index(self,param): |
|---|
| 71 |
print 'parameterized index:( param:',`param`,')' |
|---|
| 72 |
return _('parameterized index:( param:',`param`,')') |
|---|
| 73 |
index.exposed = True |
|---|
| 74 |
|
|---|
| 75 |
class ObjWithPlainIndex(object): |
|---|
| 76 |
def __init__(self): |
|---|
| 77 |
self.exposed = True |
|---|
| 78 |
self.testurls = ['','/','/index','/index?param=value','/param/value','/?invalidname=value','to/many/params'] |
|---|
| 79 |
def __call__(self): |
|---|
| 80 |
pass |
|---|
| 81 |
|
|---|
| 82 |
def index(self,param): |
|---|
| 83 |
print 'plain index:( )' |
|---|
| 84 |
return 'plain index:( )' |
|---|
| 85 |
index.exposed = True |
|---|
| 86 |
|
|---|
| 87 |
class Root(object): |
|---|
| 88 |
def _cpOnError(self): |
|---|
| 89 |
try: |
|---|
| 90 |
raise |
|---|
| 91 |
except Exception, e: |
|---|
| 92 |
print >>sys.stderr, 'Raised: ',str(e) |
|---|
| 93 |
raise |
|---|
| 94 |
|
|---|
| 95 |
def __init__(self): |
|---|
| 96 |
self.objWithParamIndex = ObjWithParamIndex() |
|---|
| 97 |
self.objWithPlainIndex = ObjWithPlainIndex() |
|---|
| 98 |
self.recursive = self |
|---|
| 99 |
|
|---|
| 100 |
def paramless(self): |
|---|
| 101 |
print 'paramless( )' |
|---|
| 102 |
return _('paramless( )') |
|---|
| 103 |
paramless.exposed = True |
|---|
| 104 |
|
|---|
| 105 |
def test1(self,str): |
|---|
| 106 |
print 'test1( str:',`str`,')' |
|---|
| 107 |
return _('test1( str:',`str`,')') |
|---|
| 108 |
test1.exposed = True |
|---|
| 109 |
test1.testurls = ['/a','?str=somestring'] |
|---|
| 110 |
|
|---|
| 111 |
def test2(self,*p): |
|---|
| 112 |
print 'test2( *p:',`p`,')' |
|---|
| 113 |
return _('test2( *p:',`p`,')') |
|---|
| 114 |
test2.exposed = True |
|---|
| 115 |
|
|---|
| 116 |
def test3(self,x='valuex'): |
|---|
| 117 |
print 'test3( x=valuex:',`x`,')' |
|---|
| 118 |
return _('test3( x=valuex:',`x`,')') |
|---|
| 119 |
test3.exposed = True |
|---|
| 120 |
test3.testurls = ['/x','?x=value','/x/y','/x/y?bla=pir'] |
|---|
| 121 |
|
|---|
| 122 |
def test4(self,**kwp): |
|---|
| 123 |
print 'test4( **kwp:',`kwp`,')' |
|---|
| 124 |
return _('test4( **kwp:',`kwp`,')') |
|---|
| 125 |
test4.exposed = True |
|---|
| 126 |
|
|---|
| 127 |
def test5(self,*p,**kwp): |
|---|
| 128 |
print 'test5( *p:',`p`,', **kwp:',`kwp`,')' |
|---|
| 129 |
return _('test5( *p:',`p`,', **kwp:',`kwp`,')') |
|---|
| 130 |
test5.exposed = True |
|---|
| 131 |
|
|---|
| 132 |
def default(self,*p,**kwp): |
|---|
| 133 |
print 'ROOT.DEFAULT( *p:',`p`,', **kwp:',`kwp`,')' |
|---|
| 134 |
return _('ROOT.DEFAULT( *p:',`p`,', **kwp:',`kwp`,')') |
|---|
| 135 |
default.exposed = True |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
def TEST(self): |
|---|
| 139 |
header = """ |
|---|
| 140 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|---|
| 141 |
<html xmlns="Testinghttp://www.w3.org/1999/xhtml"><head><title>Testing</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /></head> |
|---|
| 142 |
<body>""" |
|---|
| 143 |
iframe = """<br>Iframe: for %s:<br><iframe src="%s" width="500" height="200">no iframes?</iframe>""" |
|---|
| 144 |
footer = """ |
|---|
| 145 |
</body> |
|---|
| 146 |
</html> |
|---|
| 147 |
""" |
|---|
| 148 |
defaultTests = ['','/','/someparam','?some=param','/?some=other','/some?other=param'] |
|---|
| 149 |
urls = [] |
|---|
| 150 |
def addUrls(obj,root): |
|---|
| 151 |
"Don't you just _love_ introspection? :)" |
|---|
| 152 |
for name,value in [(x,getattr(obj,x)) for x in dir(obj) if callable(getattr(obj,x))]: |
|---|
| 153 |
if not hasattr(value,'exposed'): continue |
|---|
| 154 |
if name== 'TEST': continue |
|---|
| 155 |
testUrls = getattr(value,'testurls',[]) |
|---|
| 156 |
testUrls.extend(defaultTests) |
|---|
| 157 |
for testurl in testUrls: |
|---|
| 158 |
urls.append('%s%s%s' % (root,name,testurl)) |
|---|
| 159 |
addUrls(self,'/') |
|---|
| 160 |
|
|---|
| 161 |
return header+"".join([iframe % (url,url) for url in urls]) + footer |
|---|
| 162 |
TEST.exposed = True |
|---|
| 163 |
|
|---|
| 164 |
cpg.root = Root() |
|---|
| 165 |
|
|---|
| 166 |
if __name__=='__main__': |
|---|
| 167 |
try: |
|---|
| 168 |
import os.path, sys |
|---|
| 169 |
cpg.server.start(configMap = {'socketPort': 80, |
|---|
| 170 |
'threadPool':1, |
|---|
| 171 |
'socketQueueSize':1, |
|---|
| 172 |
'sessionStorageType':'ram' |
|---|
| 173 |
} |
|---|
| 174 |
) |
|---|
| 175 |
except Exception,e: |
|---|
| 176 |
try: |
|---|
| 177 |
import os.path, sys |
|---|
| 178 |
cpg.server.start(configDict = {'socketPort': 80, |
|---|
| 179 |
'threadPool':1, |
|---|
| 180 |
'socketQueueSize':1, |
|---|
| 181 |
'sessionStorageType':'ram' |
|---|
| 182 |
} |
|---|
| 183 |
) |
|---|
| 184 |
except Exception, e: |
|---|
| 185 |
print 'Error: ',str(e) |
|---|
| 186 |
raw_input('hit enter') |
|---|
| 187 |
|
|---|