Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 175 lines (151 sloc) 6.863 kb
d421c13 @mdipierro initial commit
mdipierro authored
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # default_application, default_controller, default_function
5 # are used when the respective element is missing from the
6 # (possibly rewritten) incoming URL
7 #
8 default_application = 'init' # ordinarily set in base routes.py
9 default_controller = 'default' # ordinarily set in app-specific routes.py
10 default_function = 'index' # ordinarily set in app-specific routes.py
11
12 # routes_app is a tuple of tuples. The first item in each is a regexp that will
13 # be used to match the incoming request URL. The second item in the tuple is
14 # an applicationname. This mechanism allows you to specify the use of an
15 # app-specific routes.py. This entry is meaningful only in the base routes.py.
16 #
17 # Example: support welcome, admin, app and myapp, with myapp the default:
18
19
20 routes_app = ((r'/(?P<app>welcome|admin|app)\b.*', r'\g<app>'),
21 (r'(.*)', r'myapp'),
22 (r'/?(.*)', r'myapp'))
23
24 # routes_in is a tuple of tuples. The first item in each is a regexp that will
25 # be used to match the incoming request URL. The second item in the tuple is
26 # what it will be replaced with. This mechanism allows you to redirect incoming
27 # routes to different web2py locations
28 #
29 # Example: If you wish for your entire website to use init's static directory:
30 #
31 # routes_in=( (r'/static/(?P<file>[\w./-]+)', r'/init/static/\g<file>') )
32 #
33
34 routes_in = ((r'.*:/favicon.ico', r'/examples/static/favicon.ico'),
35 (r'.*:/robots.txt', r'/examples/static/robots.txt'),
36 ((r'.*http://otherdomain.com.* (?P<any>.*)', r'/app/ctr\g<any>')))
37
38 # routes_out, like routes_in translates URL paths created with the web2py URL()
39 # function in the same manner that route_in translates inbound URL paths.
40 #
41
42 routes_out = ((r'.*http://otherdomain.com.* /app/ctr(?P<any>.*)', r'\g<any>'),
43 (r'/app(?P<any>.*)', r'\g<any>'))
44
261ae74 router debug option, thanks Jonathan
Massimo DiPierro authored
45 # Specify log level for rewrite's debug logging
46 # Possible values: debug, info, warning, error, critical (loglevels),
47 # off, print (print uses print statement rather than logging)
48 # GAE users may want to use 'off' to suppress routine logging.
49 #
50 logging = 'debug'
51
d421c13 @mdipierro initial commit
mdipierro authored
52 # Error-handling redirects all HTTP errors (status codes >= 400) to a specified
53 # path. If you wish to use error-handling redirects, uncomment the tuple
54 # below. You can customize responses by adding a tuple entry with the first
55 # value in 'appName/HTTPstatusCode' format. ( Only HTTP codes >= 400 are
56 # routed. ) and the value as a path to redirect the user to. You may also use
57 # '*' as a wildcard.
58 #
59 # The error handling page is also passed the error code and ticket as
60 # variables. Traceback information will be stored in the ticket.
61 #
62 # routes_onerror = [
63 # (r'init/400', r'/init/default/login')
64 # ,(r'init/*', r'/init/static/fail.html')
65 # ,(r'*/404', r'/init/static/cantfind.html')
66 # ,(r'*/*', r'/init/error/index')
67 # ]
68
69 # specify action in charge of error handling
70 #
71 # error_handler = dict(application='error',
72 # controller='default',
73 # function='index')
74
75 # In the event that the error-handling page itself returns an error, web2py will
76 # fall back to its old static responses. You can customize them here.
77 # ErrorMessageTicket takes a string format dictionary containing (only) the
78 # "ticket" key.
79
80 # error_message = '<html><body><h1>%s</h1></body></html>'
81 # error_message_ticket = '<html><body><h1>Internal error</h1>Ticket issued: <a href="/admin/default/ticket/%(ticket)s" target="_blank">%(ticket)s</a></body></html>'
82
83 # specify a list of apps that bypass args-checking and use request.raw_args
84 #
85 #routes_apps_raw=['myapp']
86 #routes_apps_raw=['myapp', 'myotherapp']
87
88 def __routes_doctest():
89 '''
90 Dummy function for doctesting routes.py.
91
92 Use filter_url() to test incoming or outgoing routes;
93 filter_err() for error redirection.
94
95 filter_url() accepts overrides for method and remote host:
96 filter_url(url, method='get', remote='0.0.0.0', out=False)
97
98 filter_err() accepts overrides for application and ticket:
99 filter_err(status, application='app', ticket='tkt')
100
101 >>> import os
102 >>> import gluon.main
103 >>> from gluon.rewrite import regex_select, load, filter_url, regex_filter_out, filter_err, compile_regex
104 >>> regex_select()
105 >>> load(routes=os.path.basename(__file__))
106
107 >>> os.path.relpath(filter_url('http://domain.com/favicon.ico'))
108 'applications/examples/static/favicon.ico'
109 >>> os.path.relpath(filter_url('http://domain.com/robots.txt'))
110 'applications/examples/static/robots.txt'
111 >>> filter_url('http://domain.com')
112 '/init/default/index'
113 >>> filter_url('http://domain.com/')
114 '/init/default/index'
115 >>> filter_url('http://domain.com/init/default/fcn')
116 '/init/default/fcn'
117 >>> filter_url('http://domain.com/init/default/fcn/')
118 '/init/default/fcn'
119 >>> filter_url('http://domain.com/app/ctr/fcn')
120 '/app/ctr/fcn'
121 >>> filter_url('http://domain.com/app/ctr/fcn/arg1')
122 "/app/ctr/fcn ['arg1']"
123 >>> filter_url('http://domain.com/app/ctr/fcn/arg1/')
124 "/app/ctr/fcn ['arg1']"
125 >>> filter_url('http://domain.com/app/ctr/fcn/arg1//')
126 "/app/ctr/fcn ['arg1', '']"
127 >>> filter_url('http://domain.com/app/ctr/fcn//arg1')
128 "/app/ctr/fcn ['', 'arg1']"
129 >>> filter_url('HTTP://DOMAIN.COM/app/ctr/fcn')
130 '/app/ctr/fcn'
131 >>> filter_url('http://domain.com/app/ctr/fcn?query')
132 '/app/ctr/fcn ?query'
133 >>> filter_url('http://otherdomain.com/fcn')
134 '/app/ctr/fcn'
135 >>> regex_filter_out('/app/ctr/fcn')
136 '/ctr/fcn'
137 >>> filter_url('https://otherdomain.com/app/ctr/fcn', out=True)
138 '/ctr/fcn'
139 >>> filter_url('https://otherdomain.com/app/ctr/fcn/arg1//', out=True)
140 '/ctr/fcn/arg1//'
141 >>> filter_url('http://otherdomain.com/app/ctr/fcn', out=True)
142 '/fcn'
143 >>> filter_url('http://otherdomain.com/app/ctr/fcn?query', out=True)
144 '/fcn?query'
145 >>> filter_url('http://otherdomain.com/app/ctr/fcn#anchor', out=True)
146 '/fcn#anchor'
147 >>> filter_err(200)
148 200
149 >>> filter_err(399)
150 399
151 >>> filter_err(400)
152 400
153 >>> filter_url('http://domain.com/welcome', app=True)
154 'welcome'
155 >>> filter_url('http://domain.com/', app=True)
156 'myapp'
157 >>> filter_url('http://domain.com', app=True)
158 'myapp'
159 >>> compile_regex('.*http://otherdomain.com.* (?P<any>.*)', '/app/ctr\g<any>')[0].pattern
160 '^.*http://otherdomain.com.* (?P<any>.*)$'
161 >>> compile_regex('.*http://otherdomain.com.* (?P<any>.*)', '/app/ctr\g<any>')[1]
162 '/app/ctr\\\\g<any>'
163 >>> compile_regex('/$c/$f', '/init/$c/$f')[0].pattern
164 '^.*?:https?://[^:/]+:[a-z]+ /(?P<c>\\\\w+)/(?P<f>\\\\w+)$'
165 >>> compile_regex('/$c/$f', '/init/$c/$f')[1]
166 '/init/\\\\g<c>/\\\\g<f>'
167 '''
168 pass
169
170 if __name__ == '__main__':
171 import doctest
172 doctest.testmod()
173
d281acb @mdipierro fixws and 'new' button in grid query
mdipierro authored
174
Something went wrong with that request. Please try again.