Best Python code snippet using autotest_python
urls.py
Source:urls.py  
1from django.conf.urls import patterns, include, url2from django.contrib import admin3urlpatterns = patterns('',4	5    # Route for built-in authentication with our own custom login page6    url(r'^loginandregister$', 'django.contrib.auth.views.login', {'template_name':'foodchaser/registerandlogin.html'}, name='login'),7    # Route to logout a user and send them back to the login page8    url(r'^logout$', 'django.contrib.auth.views.logout_then_login'),9    url(r'^register$', 'foodchaser.views.register', name='register'),10    url(r'^userhome$', 'foodchaser.views.userhome', name='home'),11    url(r'^trial$', 'foodchaser.views.trial'),12    url(r'^recommend$', 'foodchaser.views.recommendpage', name='recommend'),13    url(r'^menuplanner$', 'foodchaser.views.menuplanner', name='menuplanner'),14    # any token produced by the default_token_generator15    url(r'^confirm-registration/(?P<username>[a-zA-Z0-9_@\+\-]+)/(?P<token>[a-z0-9\-]+)$', 'foodchaser.views.confirm_registration', name='confirm'),16    url(r'^add_recipe$', 'foodchaser.handle_recipe.add_recipe', name='add_recipe'),17    url(r'^confirm-reset-password/(?P<username>[a-zA-Z0-9_@\+\-]+)/(?P<new_password>[a-zA-Z0-9_@\+\- ]+)/(?P<token>[a-z0-9\-]+)$', 'foodchaser.views.confirm_resetpassword', name='confirmpassword'),18    url(r'^changepassword$', 'foodchaser.views.change_password'),19    url(r'^recipebox_maindish$', 'foodchaser.handle_recipe.recipebox_maindish', name='recipebox_maindish'),20	21    url(r'^recipe_view/(?P<id>\d+)$', 'foodchaser.handle_recipe.recipe_view', name='recipe_view'),22	23    url(r'^search$', 'foodchaser.handle_recipe.search', name='search'),24    url(r'^recipe/photo/(?P<id>\d+)$', 'foodchaser.views.get_recipe_picture'),25                       26    url(r'^step/photo/(?P<id>\d+)$', 'foodchaser.views.get_step_picture'),27    url(r'^rate$', 'foodchaser.handle_recipe.rate', name='rate'),28    url(r'^comment$', 'foodchaser.handle_recipe.comment', name='comment'),29    url(r'^settings$', 'foodchaser.views.settings_page', name='settings'),30    url(r'^virtual_restaurant$', 'foodchaser.views.virtual_restaurant', name='virtual_restaurant'),31    url(r'^virtual_restaurant_menu$', 'foodchaser.views.virtual_restaurant_menu', name='virtual_restaurant_menu'),32    url(r'^favorites$', 'foodchaser.views.get_favorites', name='favorites'),33    url(r'^add_favorite/(?P<id>\d+)$', 'foodchaser.views.add_favorite', name='add_favorite'),34    url(r'^preference$', 'foodchaser.views.preference', name='preference'),35    url(r'^add-dislike$', 'foodchaser.views.add_dislike', name='dislike'),36    37    url(r'^edit/(?P<id>\d+)$', 'foodchaser.handle_recipe.edit', name='edit'),38    url(r'^save_planner$', 'foodchaser.views.save_planner', name='save_planner'),39    url(r'^get_planner$', 'foodchaser.views.get_planner', name='get_planner'),40    41    url(r'^delete/(?P<id>\d+)$', 'foodchaser.handle_recipe.delete', name='delete'),42    url(r'^changemyprofile$', 'foodchaser.views.changemyprofile'),43    url(r'^leftover$', 'foodchaser.views.use_leftover', name='leftover'),44    url(r'^suggest-leftover$', 'foodchaser.views.suggest_leftover', name='suggest_leftover')...sanitize_xml.py
Source:sanitize_xml.py  
...6count = 07doc = xml.dom.minidom.Document()8oldjob = xml.dom.minidom.parseString(open(sys.argv[1]).read()).getElementsByTagName('job')[0]9newjob = doc.createElement('job')10def handle_recipe(element, node):11    global count12    new_r = doc.createElement(element)13    new_r.setAttribute('result', node.getAttribute('result'))14    new_r.setAttribute('status', node.getAttribute('status'))15    new_r.setAttribute('whiteboard', '')16    new_dr = doc.createElement('distroRequires')17    new_dn = doc.createElement('distro_name')18    new_dn.setAttribute('op','=')19    new_dn.setAttribute('value','BlueShoeLinux5-5')20    new_dr.appendChild(new_dn)21    new_r.appendChild(new_dr)22    new_r.appendChild(doc.createElement('hostRequires'))23    for child in node.childNodes:24        if child.nodeName == 'guestrecipe':25            new_r.appendChild(handle_recipe('guestrecipe', child))26        if child.nodeName == 'task':27            new_t = doc.createElement('task')28            if child.getAttribute('name') not in tasks:29                tasks[child.getAttribute('name')] = '/fake/Task/task%s' % count30                count += 131            new_t.setAttribute('name', tasks[child.getAttribute('name')])32            new_t.setAttribute('result', child.getAttribute('result'))33            new_t.setAttribute('status', child.getAttribute('status'))34            new_r.appendChild(new_t)35    return new_r36    37newjob.setAttribute('result', oldjob.getAttribute('result'))38newjob.setAttribute('status', oldjob.getAttribute('status'))39newjob.appendChild(doc.createElement('whiteboard'))40for old_rs in oldjob.getElementsByTagName('recipeSet'):41    new_rs = doc.createElement('recipeSet')42    for child in old_rs.childNodes:43        if child.nodeName == 'recipe':44            new_r = handle_recipe('recipe', child)45            new_rs.appendChild(new_r)46    newjob.appendChild(new_rs)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
