コード例 #1
0
ファイル: views.py プロジェクト: Blake-Johnson/cs373-wcdb
def xml(request):
	'''
	An XML string is generated if the file does not exist
		or if the file is outdated, or it is loaded from the cache file
		if the file is not outdated
	'''
	path = XML_CACHE_PATH
	if not os.path.isdir(os.path.dirname(path)):
		os.mkdir(os.path.dirname(path))
	try:
		xml_info = open(XML_CACHE_PATH, 'r+')
		date_created = datetime.datetime.strptime(xml_info.readline(), '%m-%d-%Y %H:%M:%S\n')
		# For this project XML is not expected to go > 2 MB
		xml = xml_info.read(2097152)
		if date_created + datetime.timedelta(hours=1) < datetime.datetime.now() or xml == '':
			xml_info.close()
			raise OutdatedException('The file ' + XML_CACHE_PATH + ' is outdated.')
	except:
		xml_info = open(XML_CACHE_PATH, 'w')
		xml_info.write(datetime.datetime.strftime(datetime.datetime.now(), '%m-%d-%Y %H:%M:%S') + '\n')
		xml = to_xml.convert()
		xml_info.write(xml.encode('utf8'))
	xml_info.close()
	return HttpResponse(content=xml, mimetype='application/xml')
コード例 #2
0
	def test_export_validation(self):
		xml = to_xml.convert()
		ret = parseAndValidateXmlInputString(inputText=xml, xsdText=XSD)
		self.assertTrue(not not ret)
コード例 #3
0
	def test_export(self):
		# just a sanity check to make sure we're working w/ the correct data
		self.assertEqual(len(Event.objects.all()), 1)

		# the real test
		self.assertEqual(to_xml.convert().strip(), XML['initial_data'])
コード例 #4
0
ファイル: xml.py プロジェクト: Blake-Johnson/cs373-wcdb
	def handle(self, *args, **options):
		s = convert()
		sys.stdout.write(s if sys.stdout.isatty() else s.encode('UTF-8'))