Exemple #1
0
	def run(self):
		while not self.__should_stop:
			self.__sleep.sleep(self.__sleep_time)
			with TempDir() as temp_dir:
				tmp_file_path = os.path.join(temp_dir.get_path(), "tree.xml")
				with open(tmp_file_path, "w") as tmp_f:
					writer = XMLTreeWriter(tmp_f)
					self.__tree.get_lock().writer_acquire()
					try:
						sentinel = self.__tree.get_sentinel()
						writer.write(sentinel)
					finally:
						self.__tree.get_lock().writer_release()
				shutil.copyfile(tmp_file_path, self.__path)
Exemple #2
0
 def test_basic_write_and_read(self):
     (sentinel, schema_root) = self.__create_tree()
     out = StringIO.StringIO()
     writer = XMLTreeWriter(out)
     writer.write(sentinel)
     out_str = out.getvalue()
     in_ = StringIO.StringIO(out_str)
     reader = XMLTreeReader(in_)
     new_sentinel = StandardNode()
     reader.read(new_sentinel)
     self.assert_(
         subtrees_equal(schema_root, new_sentinel.get_child("root")))
     out2 = StringIO.StringIO()
     writer2 = XMLTreeWriter(out2)
     writer2.write(new_sentinel)
     out2_str = out2.getvalue()
     self.assertEqual(out_str, out2_str)
	def test_basic_write_and_read(self):
		(sentinel, schema_root) = self.__create_tree()
		out = StringIO.StringIO()
		writer = XMLTreeWriter(out)
		writer.write(sentinel)
		out_str = out.getvalue()
		in_ = StringIO.StringIO(out_str)
		reader = XMLTreeReader(in_)
		new_sentinel = StandardNode()
		reader.read(new_sentinel)
		self.assert_(subtrees_equal(schema_root, new_sentinel.get_child("root")))
		out2 = StringIO.StringIO()
		writer2 = XMLTreeWriter(out2)
		writer2.write(new_sentinel)
		out2_str = out2.getvalue()
		self.assertEqual(out_str, out2_str)