/[glsr]/trunk/harmonious/_pathfilter.py
Gentoo

Contents of /trunk/harmonious/_pathfilter.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (show annotations) (download) (as text)
Thu Jun 16 00:41:45 2005 UTC (9 years, 1 month ago) by port001
File MIME type: text/x-python
File size: 2419 byte(s)
Convert Header to Id
1 __id__ = '$Id$'
2 __version__ = '$Revision: $'
3 __modulename__ = 'PathFilter'
4
5 import os
6
7 from harmonious import harm
8
9 class PathFilter:
10
11 def __init__(self, domain_map):
12
13 self.__domain_map = domain_map
14
15 def perform(self):
16
17 self.__normalise()
18 harm.request.path_status = self.__get_file_status()
19
20 def __normalise(self):
21
22 path_slash = False
23
24 harm.request._unlock('abs_path')
25 harm.request._unlock('path')
26
27 # os.path.normcase will cut off trailing '/'s; we want to keep them.
28 if harm.request.path[-1] == '/':
29
30 path_slash = True
31
32 harm.request.path = os.path.normcase(os.path.normpath(harm.request.path))
33 harm.request.abs_path = os.path.normcase(os.path.normpath(harm.request.abs_path))
34
35 if path_slash == True:
36
37 if harm.request.path != '/':
38
39 harm.request._unlock('path')
40 harm.request.path = "%s/" % harm.request.path
41
42 harm.request._unlock('abs_path')
43 harm.request.abs_path = "%s/" % harm.request.abs_path
44
45 if os.path.isdir(harm.request.abs_path):
46
47 if harm.request.path[-1] != '/':
48
49 harm.request._unlock('abs_path')
50 harm.request._unlock('path')
51
52 harm.request.path = "%s/" % harm.request.path
53 harm.request.abs_path = "%s/" % harm.request.abs_path
54
55 if len(harm.request.queries) > 0 or harm.request.fragment != '':
56
57 harm.request._unlock('file')
58
59 harm.request.file = 'index.py'
60 else:
61
62 harm.request._unlock('path')
63 harm.request._unlock('abs_path')
64 harm.request._unlock('file')
65
66 harm.request.file = os.path.basename(harm.request.path)
67 harm.request.path = harm.request.path.rstrip(os.path.basename(harm.request.path))
68 harm.request.abs_path = "%s%s" % (harm.config.server['DomainPath'], harm.request.path)
69
70 def __get_file_status(self):
71
72 if os.path.exists(os.path.join(harm.request.abs_path, harm.request.file)):
73
74 if os.path.isdir(os.path.join(harm.request.abs_path, harm.request.file)):
75 return 501
76
77 try:
78 open(os.path.join(harm.request.abs_path, harm.request.file), 'r')
79 except:
80 return 403
81
82 return 200
83
84 else:
85
86 return 404

Properties

Name Value
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.20