def test_signed_Indico_request_creation(self): """urlutils - test creation of signed Indico requests""" signed_Indico_request_url = create_Indico_request_url("https://indico.cern.ch", "categ", "", [1, 7], "xml", {'onlypublic': 'yes', 'order': 'title', 'from': 'today', 'to': 'tomorrow'}, '00000000-0000-0000-0000-000000000000', '00000000-0000-0000-0000-000000000000', _timestamp=1234) # Are we at least acccessing correct base url? self.assert_(signed_Indico_request_url.startswith("https://indico.cern.ch/export/categ/1-7.xml?")) # Check parameters self.assertEqual(parse_qs(signed_Indico_request_url)["order"], ['title']) self.assertEqual(parse_qs(signed_Indico_request_url)["timestamp"], ['1234']) # Check signature exists and is correct self.assertEqual(parse_qs(signed_Indico_request_url)["signature"], ['e984e0c683e36ce3544372f23a397fd2400f4954'])
def _update_seminars(indico_baseurl, indico_what, indico_loc, indico_id, indico_onlypublic, indico_from, indico_to, indico_key, indico_sig, indico_credential_path, cached_filename): """ helper function that gets the xml data source from CERN Indico and creates a dedicated xml file in the cache for easy use in the widget. """ if indico_credential_path: indico_key, indico_sig = get_indico_credentials(indico_credential_path) url = create_Indico_request_url(indico_baseurl, indico_what, indico_loc, indico_id, 'xml', {'onlypublic': indico_onlypublic, 'from': indico_from, 'to': indico_to}, indico_key, indico_sig) default_timeout = socket.getdefaulttimeout() socket.setdefaulttimeout(2.0) try: try: indico_xml = WEBJOURNAL_OPENER.open(url) except: return finally: socket.setdefaulttimeout(default_timeout) xml_file_handler = minidom.parseString(indico_xml.read()) seminar_xml = ['<Indico_Seminars time="%s">' % time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()), ] agenda_items = xml_file_handler.getElementsByTagName("conference") for item in agenda_items: seminar_xml.extend(["<seminar>", ]) try: start_date = item.getElementsByTagName("startDate")[0].firstChild.toxml(encoding="utf-8") start_time = start_date[11:16] except: start_time = "" seminar_xml.extend(["<start_time>%s</start_time>" % start_time, ]) try: category = item.getElementsByTagName("category")[0].firstChild.toxml(encoding="utf-8") category = category.split("/")[-1] category = category.replace("&", "") category = category.replace("nbsp;", "") category = category.replace(" ", "") except: category = "" seminar_xml.extend(["<category>%s</category>" % category, ]) try: title = item.getElementsByTagName("title")[0].firstChild.toxml(encoding="utf-8") except: title = "" seminar_xml.extend(["<title>%s</title>" % title, ]) try: url = item.getElementsByTagName("url")[0].firstChild.toxml(encoding="utf-8") except: url = "#" seminar_xml.extend(["<url>%s</url>" % url, ]) try: speaker = item.getElementsByTagName("fullName")[0].firstChild.toxml(encoding="utf-8") except: speaker = "" seminar_xml.extend(["<speaker>%s</speaker>" % speaker, ]) try: room = item.getElementsByTagName("room")[0].firstChild.toxml(encoding="utf-8") except: room = "" seminar_xml.extend(["<room>%s</room>" % room, ]) try: location = item.getElementsByTagName("location")[0].firstChild.toxml(encoding="utf-8") except: location = "" seminar_xml.extend(["<location>%s</location>" % location, ]) seminar_xml.extend(["</seminar>", ]) seminar_xml.extend(["</Indico_Seminars>", ]) # write the created file to cache fptr = open("%s/%s" % (CFG_CACHEDIR, cached_filename), "w") fptr.write("\n".join(seminar_xml)) fptr.close()
def _update_seminars(indico_baseurl, indico_what, indico_loc, indico_id, indico_onlypublic, indico_from, indico_to, indico_key, indico_sig, indico_credential_path, cached_filename): """ helper function that gets the xml data source from CERN Indico and creates a dedicated xml file in the cache for easy use in the widget. """ if indico_credential_path: indico_key, indico_sig = get_indico_credentials(indico_credential_path) url = create_Indico_request_url(indico_baseurl, indico_what, indico_loc, indico_id, 'xml', {'onlypublic': indico_onlypublic, 'from': indico_from, 'to': indico_to}, indico_key, indico_sig) default_timeout = socket.getdefaulttimeout() socket.setdefaulttimeout(2.0) try: try: indico_xml = WEBJOURNAL_OPENER.open(url) except: return finally: socket.setdefaulttimeout(default_timeout) xml_file_handler = minidom.parseString(indico_xml.read()) seminar_xml = ['<Indico_Seminars time="%s">' % time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()), ] agenda_items = xml_file_handler.getElementsByTagName("conference") for item in agenda_items: seminar_xml.extend(["<seminar>", ]) for childNode in item.childNodes: if childNode.tagName == "startDate": key = "start_time" value = childNode.firstChild.toxml(encoding="utf-8") value = value and value[11:16] or "" seminar_xml.extend(["<%s>%s</%s>" % (key, value, key), ]) continue #if childNode.tagName == "endDate": # continue if childNode.tagName == "creator": for extraChildNode in childNode.getElementsByTagName("fullName"): key = "creator" value = extraChildNode.firstChild.toxml(encoding="utf-8") seminar_xml.extend(["<%s>%s</%s>" % (key, value, key), ]) # Only get the first childNode break continue #if childNode.tagName == "hasAnyProtection": # continue #if childNode.tagName == "roomFullname": # continue #if childNode.tagName == "modificationDate": # continue #if childNode.tagName == "timezone": # continue if childNode.tagName == "category": key = "category" value = childNode.firstChild.toxml(encoding="utf-8") value = value.split("/")[-1].replace("&", "").replace("nbsp;", "").replace(" ", "") seminar_xml.extend(["<%s>%s</%s>" % (key, value, key), ]) continue if childNode.tagName == "title": key = "title" value = childNode.firstChild.toxml(encoding="utf-8") seminar_xml.extend(["<%s>%s</%s>" % (key, value, key), ]) continue if childNode.tagName == "location": key = "location" value = childNode.firstChild.toxml(encoding="utf-8") seminar_xml.extend(["<%s>%s</%s>" % (key, value, key), ]) continue #if childNode.tagName == "type": # continue #if childNode.tagName == "categoryId": # continue #if childNode.tagName == "description": # continue #if childNode.tagName == "roomMapURL": # continue #if childNode.tagName == "material": # continue #if childNode.tagName == "visibility": # continue #if childNode.tagName == "address": # continue #if childNode.tagName == "creationDate": # continue if childNode.tagName == "room": key = "room" value = childNode.firstChild.toxml(encoding="utf-8") seminar_xml.extend(["<%s>%s</%s>" % (key, value, key), ]) continue if childNode.tagName == "chairs": for extraChildNode in childNode.getElementsByTagName("fullName"): key = "chair" value = extraChildNode.firstChild.toxml(encoding="utf-8") seminar_xml.extend(["<%s>%s</%s>" % (key, value, key), ]) # Only get the first childNode break continue if childNode.tagName == "url": key = "url" value = childNode.firstChild.toxml(encoding="utf-8") seminar_xml.extend(["<%s>%s</%s>" % (key, value, key), ]) continue seminar_xml.extend(["</seminar>", ]) seminar_xml.extend(["</Indico_Seminars>", ]) # write the created file to cache fptr = open("%s/%s" % (CFG_CACHEDIR, cached_filename), "w") fptr.write("\n".join(seminar_xml)) fptr.close()
def _update_seminars(indico_baseurl, indico_what, indico_loc, indico_id, indico_onlypublic, indico_from, indico_to, indico_key, indico_sig, indico_credential_path, cached_filename): """ helper function that gets the xml data source from CERN Indico and creates a dedicated xml file in the cache for easy use in the widget. """ if indico_credential_path: indico_key, indico_sig = get_indico_credentials(indico_credential_path) url = create_Indico_request_url(indico_baseurl, indico_what, indico_loc, indico_id, 'xml', { 'onlypublic': indico_onlypublic, 'from': indico_from, 'to': indico_to }, indico_key, indico_sig) default_timeout = socket.getdefaulttimeout() socket.setdefaulttimeout(2.0) try: try: indico_xml = WEBJOURNAL_OPENER.open(url) except: return finally: socket.setdefaulttimeout(default_timeout) xml_file_handler = minidom.parseString(indico_xml.read()) seminar_xml = [ '<Indico_Seminars time="%s">' % time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()), ] agenda_items = xml_file_handler.getElementsByTagName("conference") for item in agenda_items: seminar_xml.extend([ "<seminar>", ]) for childNode in item.childNodes: if childNode.tagName == "startDate": key = "start_time" value = childNode.firstChild.toxml(encoding="utf-8") value = value and value[11:16] or "" seminar_xml.extend([ "<%s>%s</%s>" % (key, value, key), ]) continue #if childNode.tagName == "endDate": # continue if childNode.tagName == "creator": for extraChildNode in childNode.getElementsByTagName( "fullName"): key = "creator" value = extraChildNode.firstChild.toxml(encoding="utf-8") seminar_xml.extend([ "<%s>%s</%s>" % (key, value, key), ]) # Only get the first childNode break continue #if childNode.tagName == "hasAnyProtection": # continue #if childNode.tagName == "roomFullname": # continue #if childNode.tagName == "modificationDate": # continue #if childNode.tagName == "timezone": # continue if childNode.tagName == "category": key = "category" value = childNode.firstChild.toxml(encoding="utf-8") value = value.split("/")[-1].replace("&", "").replace( "nbsp;", "").replace(" ", "") seminar_xml.extend([ "<%s>%s</%s>" % (key, value, key), ]) continue if childNode.tagName == "title": key = "title" value = childNode.firstChild.toxml(encoding="utf-8") seminar_xml.extend([ "<%s>%s</%s>" % (key, value, key), ]) continue if childNode.tagName == "location": key = "location" value = childNode.firstChild.toxml(encoding="utf-8") seminar_xml.extend([ "<%s>%s</%s>" % (key, value, key), ]) continue #if childNode.tagName == "type": # continue #if childNode.tagName == "categoryId": # continue #if childNode.tagName == "description": # continue #if childNode.tagName == "roomMapURL": # continue #if childNode.tagName == "material": # continue #if childNode.tagName == "visibility": # continue #if childNode.tagName == "address": # continue #if childNode.tagName == "creationDate": # continue if childNode.tagName == "room": key = "room" value = childNode.firstChild.toxml(encoding="utf-8") seminar_xml.extend([ "<%s>%s</%s>" % (key, value, key), ]) continue if childNode.tagName == "chairs": for extraChildNode in childNode.getElementsByTagName( "fullName"): key = "chair" value = extraChildNode.firstChild.toxml(encoding="utf-8") seminar_xml.extend([ "<%s>%s</%s>" % (key, value, key), ]) # Only get the first childNode break continue if childNode.tagName == "url": key = "url" value = childNode.firstChild.toxml(encoding="utf-8") seminar_xml.extend([ "<%s>%s</%s>" % (key, value, key), ]) continue seminar_xml.extend([ "</seminar>", ]) seminar_xml.extend([ "</Indico_Seminars>", ]) # write the created file to cache fptr = open("%s/%s" % (CFG_CACHEDIR, cached_filename), "w") fptr.write("\n".join(seminar_xml)) fptr.close()
def _update_seminars(indico_baseurl, indico_what, indico_loc, indico_id, indico_onlypublic, indico_from, indico_to, indico_key, indico_sig, indico_credential_path, cached_filename): """ helper function that gets the xml data source from CERN Indico and creates a dedicated xml file in the cache for easy use in the widget. """ if indico_credential_path: indico_key, indico_sig = get_indico_credentials(indico_credential_path) url = create_Indico_request_url(indico_baseurl, indico_what, indico_loc, indico_id, 'xml', { 'onlypublic': indico_onlypublic, 'from': indico_from, 'to': indico_to }, indico_key, indico_sig) default_timeout = socket.getdefaulttimeout() socket.setdefaulttimeout(2.0) try: try: indico_xml = urlopen(url) except: return finally: socket.setdefaulttimeout(default_timeout) xml_file_handler = minidom.parseString(indico_xml.read()) seminar_xml = [ '<Indico_Seminars time="%s">' % time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()), ] agenda_items = xml_file_handler.getElementsByTagName("conference") for item in agenda_items: seminar_xml.extend([ "<seminar>", ]) try: start_date = item.getElementsByTagName( "startDate")[0].firstChild.toxml(encoding="utf-8") start_time = start_date[11:16] except: start_time = "" seminar_xml.extend([ "<start_time>%s</start_time>" % start_time, ]) try: category = item.getElementsByTagName( "category")[0].firstChild.toxml(encoding="utf-8") category = category.split("/")[-1] category = category.replace("&", "") category = category.replace("nbsp;", "") category = category.replace(" ", "") except: category = "" seminar_xml.extend([ "<category>%s</category>" % category, ]) try: title = item.getElementsByTagName("title")[0].firstChild.toxml( encoding="utf-8") except: title = "" seminar_xml.extend([ "<title>%s</title>" % title, ]) try: url = item.getElementsByTagName("url")[0].firstChild.toxml( encoding="utf-8") except: url = "#" seminar_xml.extend([ "<url>%s</url>" % url, ]) try: speaker = item.getElementsByTagName( "fullName")[0].firstChild.toxml(encoding="utf-8") except: speaker = "" seminar_xml.extend([ "<speaker>%s</speaker>" % speaker, ]) try: room = item.getElementsByTagName("room")[0].firstChild.toxml( encoding="utf-8") except: room = "" seminar_xml.extend([ "<room>%s</room>" % room, ]) try: location = item.getElementsByTagName( "location")[0].firstChild.toxml(encoding="utf-8") except: location = "" seminar_xml.extend([ "<location>%s</location>" % location, ]) seminar_xml.extend([ "</seminar>", ]) seminar_xml.extend([ "</Indico_Seminars>", ]) # write the created file to cache fptr = open("%s/%s" % (CFG_CACHEDIR, cached_filename), "w") fptr.write("\n".join(seminar_xml)) fptr.close()