def __rshift__(self, obj): """Implement append-to-file pipeline stage. This behaves as __gt__, but opens the file in append mode. """ if isinstance(obj, PipelineEntry): raise ValueError("Cannot write to existing pipeline entry.") obj = filelike.to_filelike(obj, "a") return self._create(obj, "a")
def __rshift__(self,obj): """Implement append-to-file pipeline stage. This behaves as __gt__, but opens the file in append mode. """ if isinstance(obj,PipelineEntry): raise ValueError("Cannot write to existing pipeline entry.") obj = filelike.to_filelike(obj,"a") return self._create(obj,"a")
def test_tofilelike_read(self): """Test behavior of to_filelike for mode "r-".""" class F: def read(self,sz=-1): return "" f = to_filelike(F(),"r-") self.assertEquals(f.__class__,wrappers.FileWrapper) self.assertEquals(f.read(),"") self.assertRaises(ValueError,to_filelike,F(),"r") self.assertRaises(ValueError,to_filelike,F(),"w-") self.assertRaises(ValueError,to_filelike,F(),"rw")
def test_tofilelike_writeseek(self): """Test behavior of to_filelike for mode "w".""" class F: def write(self,data): pass def seek(self,offset,whence): pass f = to_filelike(F(),"w") self.assertEquals(f.__class__,wrappers.FileWrapper) self.assertRaises(ValueError,to_filelike,F(),"r") self.assertRaises(ValueError,to_filelike,F(),"r-")
def test_tofilelike_write(self): """Test behavior of to_filelike for mode "w-".""" class F: def write(self, data): pass f = to_filelike(F(), "w-") self.assertEquals(f.__class__, wrappers.FileWrapper) self.assertRaises(ValueError, to_filelike, F(), "w") self.assertRaises(ValueError, to_filelike, F(), "r") self.assertRaises(ValueError, to_filelike, F(), "r-") self.assertRaises(ValueError, to_filelike, F(), "rw")
def test_tofilelike_read(self): """Test behavior of to_filelike for mode "r-".""" class F: def read(self, sz=-1): return "" f = to_filelike(F(), "r-") self.assertEquals(f.__class__, wrappers.FileWrapper) self.assertEquals(f.read(), "") self.assertRaises(ValueError, to_filelike, F(), "r") self.assertRaises(ValueError, to_filelike, F(), "w-") self.assertRaises(ValueError, to_filelike, F(), "rw")
def test_tofilelike_readwrite(self): """Test behavior of to_filelike for mode "rw".""" class F: def write(self,data): pass def read(self,sz=-1): return "" def seek(self,offset,whence): pass f = to_filelike(F(),"rw") self.assertEquals(f.__class__,wrappers.FileWrapper) self.assertEquals(f.read(),"")
def __lt__(self, obj): """Implement read-from-file pipeline stage. 'obj' must not be a PipelineEntry, and must be coercable to a file-like object using filelike.to_filelike() with mode "r". A new file-like object will be returned that reads from the opened file-like object. """ if isinstance(obj, PipelineEntry): raise ValueError("Cannot read from existing pipeline entry.") obj = filelike.to_filelike(obj, "r") return self._create(obj, "r")
def __gt__(self,obj): """Implement write-to-file pipeline stage. 'obj' must not be a PipelineEntry, and must be coercable to a file-like object using filelike.to_filelike() with mode "w". A new file-like wrapper will be returned that writes to the given object. """ if isinstance(obj,PipelineEntry): raise ValueError("Cannot write to existing pipeline entry.") obj = filelike.to_filelike(obj,"w") return self._create(obj,"w")
def __gt__(self, obj): """Implement write-to-file pipeline stage. 'obj' must not be a PipelineEntry, and must be coercable to a file-like object using filelike.to_filelike() with mode "w". A new file-like wrapper will be returned that writes to the given object. """ if isinstance(obj, PipelineEntry): raise ValueError("Cannot write to existing pipeline entry.") obj = filelike.to_filelike(obj, "w") return self._create(obj, "w")
def __lt__(self,obj): """Implement read-from-file pipeline stage. 'obj' must not be a PipelineEntry, and must be coercable to a file-like object using filelike.to_filelike() with mode "r". A new file-like object will be returned that reads from the opened file-like object. """ if isinstance(obj,PipelineEntry): raise ValueError("Cannot read from existing pipeline entry.") obj = filelike.to_filelike(obj,"r") return self._create(obj,"r")
def test_tofilelike_readwrite(self): """Test behavior of to_filelike for mode "rw".""" class F: def write(self, data): pass def read(self, sz=-1): return "" def seek(self, offset, whence): pass f = to_filelike(F(), "rw") self.assertEquals(f.__class__, wrappers.FileWrapper) self.assertEquals(f.read(), "")
def __lt__(self, obj): """Implement read-from-file pipeline stage. 'obj' must not be a PipelineEntry, and must be coercable to a file-like object using filelike.to_filelike() with mode "w". A new file-like wrapper will be returned that writes to the given object. """ if isinstance(obj, PipelineEntry): raise ValueError("Cannot read from existing pipeline entry.") obj = filelike.to_filelike(obj, "r") while len(self._stages) > 0: next = self._stages.pop() obj = next._create(obj, "r") return obj
def __lt__(self,obj): """Implement read-from-file pipeline stage. 'obj' must not be a PipelineEntry, and must be coercable to a file-like object using filelike.to_filelike() with mode "w". A new file-like wrapper will be returned that writes to the given object. """ if isinstance(obj,PipelineEntry): raise ValueError("Cannot read from existing pipeline entry.") obj = filelike.to_filelike(obj,"r") while len(self._stages) > 0: next = self._stages.pop() obj = next._create(obj,"r") return obj
def test_tofilelike_string(self): """Test behaviour of to_filelike on strings.""" f = to_filelike("testing") self.assert_(isinstance(f,StringIO)) self.assertEquals(f.read(),"testing")
def test_tofilelike_stringio(self): """Test behaviour of to_filelike on StringIO instances.""" f = to_filelike(StringIO()) self.assert_(isinstance(f,StringIO))
def test_tofilelike_stringio(self): """Test behaviour of to_filelike on StringIO instances.""" f = to_filelike(StringIO()) self.assert_(isinstance(f, StringIO))
def test_tofilelike_string(self): """Test behaviour of to_filelike on strings.""" f = to_filelike("testing") self.assert_(isinstance(f, StringIO)) self.assertEquals(f.read(), "testing")