~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/urls/__init__.py

  • Committer: William Grant
  • Date: 2009-07-02 12:40:11 UTC
  • mto: (1294.4.2 ui-the-third)
  • mto: This revision was merged to the branch mainline in revision 1353.
  • Revision ID: grantw@unimelb.edu.au-20090702124011-wjpwbnkgde0xyl1w
Allow routes that take infinitely many arguments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import sys
22
22
 
23
23
ROOT = object() # Marker object for the root.
 
24
INF = object()
24
25
 
25
26
class RoutingError(Exception):
26
27
    pass
250
251
                # The first path segment is the route identifier, so we skip
251
252
                # it when identifying arguments.
252
253
                lastseg = todo[0]
253
 
                args = todo[1:argc + 1]
254
 
                todo = todo[argc + 1:]
 
254
                if argc is INF:
 
255
                    args = todo[1:]
 
256
                    todo = []
 
257
                else:
 
258
                    args = todo[1:argc + 1]
 
259
                    todo = todo[argc + 1:]
255
260
            else:
256
261
                # Attempt traversal directly (with no intermediate segment)
257
262
                # as a last resort.
258
263
                if None in names:
259
264
                    route, argc = names[None]
260
265
                    lastseg = None
261
 
                    args = todo[:argc]
262
 
                    todo = todo[argc:]
 
266
                    if argc is INF:
 
267
                        args = todo
 
268
                        todo = []
 
269
                    else:
 
270
                        args = todo[:argc]
 
271
                        todo = todo[argc:]
263
272
                else:
264
273
                    raise NotFound(obj, todo[0])
265
274
 
266
 
            if len(args) != argc:
 
275
            if argc is not INF and len(args) != argc:
267
276
                # There were too few path segments left. Die.
268
277
                raise InsufficientPathSegments(obj, lastseg, len(args))
269
278