Esempio n. 1
0
 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")
Esempio n. 2
0
 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")
Esempio n. 3
0
 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")
Esempio n. 4
0
 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-")
Esempio n. 5
0
    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")
Esempio n. 6
0
    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")
Esempio n. 7
0
 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(),"")
Esempio n. 8
0
 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")
Esempio n. 9
0
 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")
Esempio n. 10
0
 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")
Esempio n. 11
0
 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")
Esempio n. 12
0
    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(), "")
Esempio n. 13
0
 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
Esempio n. 14
0
 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
Esempio n. 15
0
 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")
Esempio n. 16
0
 def test_tofilelike_stringio(self):
     """Test behaviour of to_filelike on StringIO instances."""
     f = to_filelike(StringIO())
     self.assert_(isinstance(f,StringIO))
Esempio n. 17
0
 def test_tofilelike_stringio(self):
     """Test behaviour of to_filelike on StringIO instances."""
     f = to_filelike(StringIO())
     self.assert_(isinstance(f, StringIO))
Esempio n. 18
0
 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")