Ticket #4: #2-#4.patch
-
_cpHTTPTools.py
old new 65 65 cpg.request.paramMap[key] = value 66 66 cpg.request.path = cpg.request.path[:i] 67 67 68 cpg.request.trailingSlash = False 68 69 if cpg.request.path and cpg.request.path[-1] == '/': 69 70 cpg.request.path = cpg.request.path[:-1] # Remove trailing '/' if any 71 cpg.request.trailingSlash = True 70 72 71 73 def parsePostData(rfile): 72 74 # Read request body and put it in data … … 353 355 searchedPathList = [] 354 356 myPath = '' 355 357 bestKnownDefaultMethod = None 358 trailingSlash = True 356 359 # Successively get objects from the path: 'root', then 'a' then 'b' 357 360 for pathItem in pathList: 358 361 previousObj = obj … … 366 369 367 370 # if found object has a default method, remember it for later 368 371 default = getattr(obj, 'default', None) 369 if default: 370 # TODO: check if default is callable? 372 if default and callable(default) and getattr(default, 'exposed', None): 371 373 bestKnownDefaultMethod = default 372 374 bestKnownDefaultMethodMyPath = '/'.join(searchedPathList[1:]) 373 375 … … 375 377 break 376 378 377 379 # TODO: the following code could probably be KISSed somewhat. 378 380 381 # root_a_b exists 382 root_a_b = objList[-1] 383 379 384 if len(objList) == len(pathList): 380 # root_a_b exists381 root_a_b = objList[-1]382 383 385 # Try root.a.b.index() 384 386 root_a_b_dot_index = getattr(root_a_b, 'index', None) 385 387 if root_a_b_dot_index and getattr(root_a_b_dot_index, 'exposed', None): 386 myPath = '/'.join( pathList[1:])388 myPath = '/'.join(searchedPathList[1:]) 387 389 func = root_a_b_dot_index 388 else: 389 # Try root.a.b.default() 390 root_a_b_dot_default = getattr(root_a_b, 'default', None) 391 if root_a_b_dot_default and getattr(root_a_b_dot_default, 'exposed', None): 392 # XXX: I don't think this ever gets called? 393 myPath = 'root_a_b_dot_default' 394 func = root_a_b_dot_default 395 elif callable(root_a_b) and getattr(root_a_b, 'exposed', None): 396 # We use root.a.b() 397 myPath = '/'.join(pathList[1:-1]) 398 func = root_a_b 390 391 if func == None: 392 # Try root.a.b() 393 if callable(root_a_b) and getattr(root_a_b, 'exposed', None): 394 myPath = '/'.join(searchedPathList[1:-1]) 395 func = root_a_b 396 trailingSlash = False 399 397 400 398 if func == None: 401 399 # None of these exist: use the default method we found earlier … … 415 413 myPath = '/' + myPath 416 414 417 415 cpg.request.objectPath = myPath 418 cpg.request.virtualPath = cpg.request.path[len(myPath)-1:] 419 cpg.response.body = func(**(cpg.request.paramMap)) 416 cpg.request.virtualPath = "/".join(pathList[len(searchedPathList):]) 417 418 if cpg.request.virtualPath: trailingSlash = False 419 420 # Redirect to canonical URL 421 print cpg.request.path, trailingSlash, cpg.request.trailingSlash 422 if cpg.request.path and (trailingSlash != cpg.request.trailingSlash): 423 if trailingSlash: 424 redirect(wfile, "/" + cpg.request.path + "/") 425 else: 426 redirect(wfile, "/" + cpg.request.path) 427 428 cpg.response.body = func(*(pathList[len(searchedPathList):]), **(cpg.request.paramMap)) 420 429 421 430 _cpUtil.getSpecialFunction('_cpInitResponse')() 422 431 … … 448 457 449 458 if cpg.response.sendResponse: sendResponse(wfile) 450 459 460 def redirect(wfile, url): 461 cpg.response.headerMap["Status"] = "301 Moved Permanently" 462 cpg.response.headerMap["Location"] = url 463 cpg.response.body = '''Moved <a href="%s">here</a>.''' % url 464 sendResponse(wfile) 451 465 452 466 def generateSessionId(): 453 467 s = ''

