#NEWLINE# def replace_urlpattern( urlpatterns , replacement ) : #NEWLINE# #INDENT# "Delete the old urlpattern, and add a new one.\n\n    parameters:\n        urlpatterns: list\n        replacement: an `django.conf.urls.defaults.url` object.\n\n    example:\n\n        replacement = url(r'^accounts/login/', 'my.site.login_signup', {}, name='auth_login'))\n        replace_urlpattern(urlpatterns, replacement)\n    " #NEWLINE# found = False #NEWLINE# ix = 0 #NEWLINE# if ( hasattr ( replacement , 'name' ) and replacement . name ) : #NEWLINE# #INDENT# name = replacement . name #NEWLINE# regex = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# name = None #NEWLINE# regex = replacement . regex . pattern #NEWLINE# #UNINDENT# while ( ( not found ) and ( ix < len ( urlpatterns ) ) ) : #NEWLINE# #INDENT# pattern = urlpatterns [ ix ] #NEWLINE# if hasattr ( pattern , 'url_patterns' ) : #NEWLINE# #INDENT# found = replace_urlpattern ( pattern . url_patterns , replacement ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( name and hasattr ( pattern , 'name' ) ) : #NEWLINE# #INDENT# if ( pattern . name == name ) : #NEWLINE# #INDENT# del urlpatterns [ ix ] #NEWLINE# urlpatterns . append ( replacement ) #NEWLINE# found = True #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( pattern . regex . pattern == regex ) : #NEWLINE# #INDENT# del urlpatterns [ ix ] #NEWLINE# urlpatterns . append ( replacement ) #NEWLINE# found = True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not found ) : #NEWLINE# #INDENT# ix += 1 #NEWLINE# #UNINDENT# #UNINDENT# return found