| 349 | # This is a hack to get namespaced URLs to reverse when the base |
| 350 | # has named parameters (may work for positional, but not tested at all). |
| 351 | pattern = prefix |
| 352 | possibility = normalize(pattern) # The magical regex reverse function! |
| 353 | # Below copied from _populate above and slightly altered |
| 354 | for result, params in possibility: |
| 355 | copy_args = [v for v in args] |
| 356 | copy_kwargs = kwargs.copy() |
| 357 | if args: |
| 358 | if len(args) < len(params): |
| 359 | continue |
| 360 | # Pop arguments to ensure the right number are passed on to the |
| 361 | # resolver. |
| 362 | unicode_args = [force_unicode(copy_args.pop(0)) for v in params] |
| 363 | candidate = result % dict(zip(params, unicode_args)) |
| 364 | else: |
| 365 | if not set(params).issubset(set(kwargs.keys())): |
| 366 | continue |
| 367 | # Pop arguments to ensure the right number are passed on to the |
| 368 | # resolver. |
| 369 | unicode_kwargs = dict([(k, force_unicode(copy_kwargs.pop(k))) for k in params]) |
| 370 | candidate = result % unicode_kwargs |
| 371 | if re.search(u'^%s' % pattern, candidate, re.UNICODE): |
| 372 | prefix = candidate |
| 373 | else: |
| 374 | raise NoReverseMatch( |
| 375 | "Reverse for '%s' with arguments '%s' and keyword arguments\ |
| 376 | '%s' not found." % (pattern, args, kwargs)) |
| 377 | |