﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20757	A more Object-Oriented URLResolver	Flavio Curella		"Currently, the `RegexURLResolver` is populated using tuples.

Because of that, code that tries to inspect the resolver will end up containg awkward indexing like this (semplified code for clarity's sake):

{{{
def get_urlformat(urlname):
    """"""
    Given a URL name, returns the URL as a string suitable for string.format.

    Example::

    urlpatterns = patterns('',
        url(r'^extra/(?P<extra>\w+)/$', empty_view, name=""named-url2""),
    )

    >>> get_urlformat('named-url2')
    'extra/%(extra)s/'
    """"""

    resolver = get_resolver()
    return resolver.reverse_dict[urlname][0][0][0]
}}}

My proposal is to replace tuples with a tuple-like object whose elements can be accessed by using attribute names. That way, the above method could become:
{{{
def get_urlformat(urlname):
    """"""
    Given a URL name, returns the URL as a string suitable for string.format.

    Example::

    urlpatterns = patterns('',
        url(r'^extra/(?P<extra>\w+)/$', empty_view, name=""named-url2""),
    )

    >>> get_urlformat('named-url2')
    'extra/%(extra)s/'
    """"""

    resolver = get_resolver()
    urlbit = resolver.reverse_dict[urlname].urlbits[0]
    return urlbit.format
}}}

I realize this is mostly aesthetic, and there could be performance implications since the URLResolver is probably the most hit codepath, so I appreciate every kind of opinion.

The attached patch is still a draft, it definitely needs more extensive test coverage, but it's a start to get the idea."	New feature	new	Core (URLs)	dev	Normal			flavio.curella@… Ülgen Sarıkavak	Accepted	0	0	0	0	0	0
