File: 02_publisher.py.dpatch

package info (click to toggle)
libapache-mod-python 2%3A2.7.11-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,328 kB
  • ctags: 848
  • sloc: ansic: 2,785; python: 1,115; sh: 299; makefile: 285
file content (87 lines) | stat: -rw-r--r-- 3,088 bytes parent folder | download
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
81
82
83
84
85
86
87
#! /bin/sh /usr/share/dpatch/dpatch-run
## 02_publisher.py.dpatch by  <jeremie.corbier@resel.enst-bretagne.fr>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Adapted from a patch by Jeff Bailey which makes the publisher handler
## DP: default to adding /index to the end of a python file name, instead of
## DP: the server error which is the current default.

@DPATCH@
diff -urNad libapache-mod-python~/lib/python/mod_python/publisher.py libapache-mod-python/lib/python/mod_python/publisher.py
--- libapache-mod-python~/lib/python/mod_python/publisher.py	2006-08-01 10:20:11.000000000 +0200
+++ libapache-mod-python/lib/python/mod_python/publisher.py	2006-08-01 14:39:24.000000000 +0200
@@ -64,6 +64,7 @@
 import base64
 
 import new
+from types import *
 
 from types import *
 
@@ -81,14 +82,16 @@
 
     args = {}
 
-    # get the path PATH_INFO (everthing after script)
-    if not _req.subprocess_env.has_key("PATH_INFO"):
-        raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND
-    
-    func_path = _req.subprocess_env["PATH_INFO"][1:] # skip fist /
-    func_path = string.replace(func_path, "/", ".")
-    if func_path[-1] == ".":
-        func_path = func_path[:-1] 
+    func_path = ""
+    if req.path_info:
+        func_path = req.path_info[1:] # skip first /
+        func_path = func_path.replace("/", ".")
+        if func_path[-1:] == ".":
+            func_path = func_path[:-1]
+                                                                                
+    # default to 'index' if no path_info was given
+    if not func_path:
+        func_path = "index"
 
     # if any part of the path begins with "_", abort
     if func_path[0] == '_' or string.count(func_path, "._"):
@@ -122,6 +125,8 @@
 
     # import the script
     path, module_name =  os.path.split(_req.filename)
+    if not module_name:
+      module_name = "index"
 
     # get rid of the suffix
     module_name = suff_matcher.sub("", module_name)
@@ -249,7 +254,7 @@
     if found_auth:
 
         if not user:
-            s = 'Basic realm = "%s"' % realm
+            s = 'Basic realm="%s"' % realm
             req.err_headers_out["WWW-Authenticate"] = s
             raise apache.SERVER_RETURN, apache.HTTP_UNAUTHORIZED    
 
@@ -262,7 +267,7 @@
                 rc = __auth__
             
         if not rc:
-            s = 'Basic realm = "%s"' % realm
+            s = 'Basic realm="%s"' % realm
             req.err_headers_out["WWW-Authenticate"] = s
             raise apache.SERVER_RETURN, apache.HTTP_UNAUTHORIZED    
 
@@ -319,9 +324,13 @@
     def __init__(self, field):
 
         # steal all the file-like methods
-        for m in field.file.__methods__:
+        for m in self.sim_methods(field.file):
             self.__dict__[m] = getattr(field.file, m)
 
         self.headers = field.headers
         self.filename = field.filename
     
+    def sim_methods(self,obj):
+        from types import BuiltinMethodType #parte aggiunta
+        return filter(lambda s, t=obj:
+        type(getattr(t, s)) == BuiltinMethodType, dir(obj))