Anonymous avatar Anonymous committed 04c0753

Fixed restore_files(); added reset_files(); made these more flexible.

Comments (0)

Files changed (1)

 
 class FileWrapper(FileBase):
 
+	# XXX This is just like a Bastion -- should use that!
+
 	def __init__(self, f):
 		self.f = f
 		for m in self.ok_file_methods:
     
     # The s_* methods are similar but also swap std{in,out,err}
 
+    def make_delegate_files(self):
+        s = self.modules['sys']
+	self.delegate_stdin = FileDelegate(s, 'stdin')
+	self.delegate_stdout = FileDelegate(s, 'stdout')
+	self.delegate_stderr = FileDelegate(s, 'stderr')
+        self.restricted_stdin = FileWrapper(sys.stdin)
+        self.restricted_stdout = FileWrapper(sys.stdout)
+        self.restricted_stderr = FileWrapper(sys.stderr)
+
     def set_files(self):
+	if not hasattr(self, 'save_stdin'):
+	    self.save_files()
+	if not hasattr(self, 'delegate_stdin'):
+	    self.make_delegate_files()
         s = self.modules['sys']
-        s.stdin = FileWrapper(sys.stdin)
-        s.stdout = FileWrapper(sys.stdout)
-        s.stderr = FileWrapper(sys.stderr)
-	sys.stdin = FileDelegate(s, 'stdin')
-	sys.stdout = FileDelegate(s, 'stdout')
-	sys.stderr = FileDelegate(s, 'stderr')
+	s.stdin = self.restricted_stdin
+	s.stdout = self.restricted_stdout
+	s.stderr = self.restricted_stdout
+	sys.stdin = self.delegate_stdin
+	sys.stdout = self.delegate_stdout
+	sys.stderr = self.delegate_stderr
+
+    def reset_files(self):
+	self.restore_files()
+        s = self.modules['sys']
+	self.restricted_stdin = s.stdin
+	self.restricted_stdout = s.stdout
+	self.restricted_stdout = s.stderr
+	
 
     def save_files(self):
         self.save_stdin = sys.stdin
         self.save_stdout = sys.stdout
         self.save_stderr = sys.stderr
 
-    def restore_files(files):
-	sys.stdin = self.save_sydin
+    def restore_files(self):
+	sys.stdin = self.save_stdin
 	sys.stdout = self.save_stdout
 	sys.stderr = self.save_stderr
     
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.