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

Contents of /trunk/harmonious/_dispatcher.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, 3 months ago) by port001
File MIME type: text/x-python
File size: 3381 byte(s)
Convert Header to Id
1 __id__ = '$Id$'
2 __version__ = '$Revision: $'
3 __modulename__ = 'Dispatcher'
4
5 import os
6 import re
7 import sys
8
9 from harmonious import harm
10 from harmonious._pathfilter import PathFilter
11 from harmonious._response import Response
12
13 class ImportError(Exception): pass
14 class ValueError(Exception): pass
15
16 class Dispatcher:
17
18 def __init__(self):
19
20 self.__domain_module = None
21
22 def __send_response(self):
23
24 headers = harm.response.get_headers()
25
26 harm.request._baseRequest.send_response(harm.request.path_status)
27
28 for key in headers.keys():
29
30 print "Sending header: ", key, headers[key]
31 harm.request._baseRequest.send_header(key, headers[key])
32
33 harm.request._baseRequest.end_headers()
34 print "Headers sent"
35
36 harm.request._baseRequest.wfile.write(harm.response.get_body())
37 print "Body sent"
38
39 def __error_500(self):
40
41 from harmonious.server.responders.responder500 import Responder500
42
43 responder500 = Responder500()
44 harm.response.add_responder(responder500)
45
46 def __error_403(self):
47
48 from harmonious.server.responders.responder403 import Responder403
49
50 responder403 = Responder403()
51 harm.response.add_responder(responder403)
52
53 def __error_404(self):
54
55 from harmonious.server.responders.responder404 import Responder404
56
57 responder404 = Responder404()
58 harm.response.add_responder(responder404)
59
60 def __error_501(self):
61
62 from harmonious.server.responders.responder501 import Responder501
63
64 responder501 = Responder501()
65 harm.response.add_responder(responder501)
66
67 def dispatch(self):
68
69 print "DISPATCH"
70
71 PathFilter(domain_map).perform()
72 harm.response = Response()
73
74 print "PATH:", harm.request.path
75 print "ABS_PATH:", harm.request.abs_path
76 print "FILE:", harm.request.file
77 print "PATH_STATUS:", harm.request.path_status
78
79 if harm.request.path_status == 404:
80
81 self.__error_404()
82
83 elif harm.request.path_status == 403:
84
85 self.__error_403()
86
87 elif harm.request.path_status == 501:
88
89 self.__error_501()
90
91 elif harm.request.path_status == 200:
92
93 call_page = ''
94
95 if harm.request.queries.has_key('page'):
96
97 if hasattr(harm._domain_map[harm.request.path][harm.request.file], harm.request.queries['page']):
98
99 call_page = harm.request.queries['page']
100
101 else:
102
103 self.__error_404()
104 else:
105
106 # Find the default page
107 for method in dir(harm._domain_map[harm.request.path][harm.request.file]):
108
109 try:
110
111 default = getattr(getattr(harm._domain_map[harm.request.path][harm.request.file], method), 'default')
112 except AttributeError:
113
114 default = False
115
116 if default == True:
117
118 call_page = method
119
120 if call_page != '':
121
122 try:
123
124 getattr(harm._domain_map[harm.request.path][harm.request.file], call_page)()
125 except:
126
127 self.__error_500()
128 else:
129
130 self.__error_500()
131
132 else:
133
134 self.__error_500()
135
136 self.__send_response()

Properties

Name Value
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.20