MobileBlur

Check-in [b28babbbb4]
Login
Overview
SHA1:b28babbbb4b9a08e90f00cab9cefa4baae552a88
Date: 2011-11-22 23:56:55
User: spiffy
Comment:Somehow routes.py never got added to the repo
Timelines: family | ancestors | descendants | both | develop
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2011-11-29
05:23
[fe10ff441d] Fixed story list to omit stories below the intelligence threshold (user: spiffy, tags: develop)
2011-11-22
23:56
[b28babbbb4] Somehow routes.py never got added to the repo (user: spiffy, tags: develop)
23:54
[ecb326adfb] Made the site a ton prettier (user: spiffy, tags: develop, v0.3)
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Added routes.py version [b42c3be42e].

            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 = 'mobileblur'    # 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  +
           45  +# Error-handling redirects all HTTP errors (status codes >= 400) to a specified
           46  +# path.  If you wish to use error-handling redirects, uncomment the tuple
           47  +# below.  You can customize responses by adding a tuple entry with the first
           48  +# value in 'appName/HTTPstatusCode' format. ( Only HTTP codes >= 400 are
           49  +# routed. ) and the value as a path to redirect the user to.  You may also use
           50  +# '*' as a wildcard.
           51  +#
           52  +# The error handling page is also passed the error code and ticket as
           53  +# variables.  Traceback information will be stored in the ticket.
           54  +#
           55  +# routes_onerror = [
           56  +#     (r'init/400', r'/init/default/login')
           57  +#    ,(r'init/*', r'/init/static/fail.html')
           58  +#    ,(r'*/404', r'/init/static/cantfind.html')
           59  +#    ,(r'*/*', r'/init/error/index')
           60  +# ]
           61  +
           62  +# specify action in charge of error handling
           63  +#
           64  +# error_handler = dict(application='error',
           65  +#                      controller='default',
           66  +#                      function='index')
           67  +
           68  +# In the event that the error-handling page itself returns an error, web2py will
           69  +# fall back to its old static responses.  You can customize them here.
           70  +# ErrorMessageTicket takes a string format dictionary containing (only) the
           71  +# "ticket" key.
           72  +
           73  +# error_message = '<html><body><h1>%s</h1></body></html>'
           74  +# 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>'
           75  +
           76  +# specify a list of apps that bypass args-checking and use request.raw_args
           77  +#
           78  +#routes_apps_raw=['myapp']
           79  +#routes_apps_raw=['myapp', 'myotherapp']
           80  +
           81  +def __routes_doctest():
           82  +    '''
           83  +    Dummy function for doctesting routes.py.
           84  +
           85  +    Use filter_url() to test incoming or outgoing routes;
           86  +    filter_err() for error redirection.
           87  +
           88  +    filter_url() accepts overrides for method and remote host:
           89  +        filter_url(url, method='get', remote='0.0.0.0', out=False)
           90  +
           91  +    filter_err() accepts overrides for application and ticket:
           92  +        filter_err(status, application='app', ticket='tkt')
           93  +
           94  +    >>> import os
           95  +    >>> import gluon.main
           96  +    >>> from gluon.rewrite import regex_select, load, filter_url, regex_filter_out, filter_err, compile_regex
           97  +    >>> regex_select()
           98  +    >>> load(routes=os.path.basename(__file__))
           99  +
          100  +    >>> os.path.relpath(filter_url('http://domain.com/favicon.ico'))
          101  +    'applications/examples/static/favicon.ico'
          102  +    >>> os.path.relpath(filter_url('http://domain.com/robots.txt'))
          103  +    'applications/examples/static/robots.txt'
          104  +    >>> filter_url('http://domain.com')
          105  +    '/init/default/index'
          106  +    >>> filter_url('http://domain.com/')
          107  +    '/init/default/index'
          108  +    >>> filter_url('http://domain.com/init/default/fcn')
          109  +    '/init/default/fcn'
          110  +    >>> filter_url('http://domain.com/init/default/fcn/')
          111  +    '/init/default/fcn'
          112  +    >>> filter_url('http://domain.com/app/ctr/fcn')
          113  +    '/app/ctr/fcn'
          114  +    >>> filter_url('http://domain.com/app/ctr/fcn/arg1')
          115  +    "/app/ctr/fcn ['arg1']"
          116  +    >>> filter_url('http://domain.com/app/ctr/fcn/arg1/')
          117  +    "/app/ctr/fcn ['arg1']"
          118  +    >>> filter_url('http://domain.com/app/ctr/fcn/arg1//')
          119  +    "/app/ctr/fcn ['arg1', '']"
          120  +    >>> filter_url('http://domain.com/app/ctr/fcn//arg1')
          121  +    "/app/ctr/fcn ['', 'arg1']"
          122  +    >>> filter_url('HTTP://DOMAIN.COM/app/ctr/fcn')
          123  +    '/app/ctr/fcn'
          124  +    >>> filter_url('http://domain.com/app/ctr/fcn?query')
          125  +    '/app/ctr/fcn ?query'
          126  +    >>> filter_url('http://otherdomain.com/fcn')
          127  +    '/app/ctr/fcn'
          128  +    >>> regex_filter_out('/app/ctr/fcn')
          129  +    '/ctr/fcn'
          130  +    >>> filter_url('https://otherdomain.com/app/ctr/fcn', out=True)
          131  +    '/ctr/fcn'
          132  +    >>> filter_url('https://otherdomain.com/app/ctr/fcn/arg1//', out=True)
          133  +    '/ctr/fcn/arg1//'
          134  +    >>> filter_url('http://otherdomain.com/app/ctr/fcn', out=True)
          135  +    '/fcn'
          136  +    >>> filter_url('http://otherdomain.com/app/ctr/fcn?query', out=True)
          137  +    '/fcn?query'
          138  +    >>> filter_url('http://otherdomain.com/app/ctr/fcn#anchor', out=True)
          139  +    '/fcn#anchor'
          140  +    >>> filter_err(200)
          141  +    200
          142  +    >>> filter_err(399)
          143  +    399
          144  +    >>> filter_err(400)
          145  +    400
          146  +    >>> filter_url('http://domain.com/welcome', app=True)
          147  +    'welcome'
          148  +    >>> filter_url('http://domain.com/', app=True)
          149  +    'myapp'
          150  +    >>> filter_url('http://domain.com', app=True)
          151  +    'myapp'
          152  +    >>> compile_regex('.*http://otherdomain.com.* (?P<any>.*)', '/app/ctr\g<any>')[0].pattern
          153  +    '^.*http://otherdomain.com.* (?P<any>.*)$'
          154  +    >>> compile_regex('.*http://otherdomain.com.* (?P<any>.*)', '/app/ctr\g<any>')[1]
          155  +    '/app/ctr\\\\g<any>'
          156  +    >>> compile_regex('/$c/$f', '/init/$c/$f')[0].pattern
          157  +    '^.*?:https?://[^:/]+:[a-z]+ /(?P<c>\\\\w+)/(?P<f>\\\\w+)$'
          158  +    >>> compile_regex('/$c/$f', '/init/$c/$f')[1]
          159  +    '/init/\\\\g<c>/\\\\g<f>'
          160  +    '''
          161  +    pass
          162  +
          163  +if __name__ == '__main__':
          164  +    import doctest
          165  +    doctest.testmod()
          166  +