diff --git a/test/py/TestEof.py b/test/py/TestEof.py
index 6614638..0239fc6 100755
--- a/test/py/TestEof.py
+++ b/test/py/TestEof.py
@@ -28,99 +28,99 @@
 
 class TestEof(unittest.TestCase):
 
-  def make_data(self, pfactory=None):
-    trans = TTransport.TMemoryBuffer()
-    if pfactory:
-      prot = pfactory.getProtocol(trans)
-    else:
-      prot = TBinaryProtocol.TBinaryProtocol(trans)
+    def make_data(self, pfactory=None):
+        trans = TTransport.TMemoryBuffer()
+        if pfactory:
+            prot = pfactory.getProtocol(trans)
+        else:
+            prot = TBinaryProtocol.TBinaryProtocol(trans)
 
-    x = Xtruct()
-    x.string_thing = "Zero"
-    x.byte_thing = 0
+        x = Xtruct()
+        x.string_thing = "Zero"
+        x.byte_thing = 0
 
-    x.write(prot)
+        x.write(prot)
 
-    x = Xtruct()
-    x.string_thing = "One"
-    x.byte_thing = 1
+        x = Xtruct()
+        x.string_thing = "One"
+        x.byte_thing = 1
 
-    x.write(prot)
+        x.write(prot)
 
-    return trans.getvalue()
+        return trans.getvalue()
 
-  def testTransportReadAll(self):
-    """Test that readAll on any type of transport throws an EOFError"""
-    trans = TTransport.TMemoryBuffer(self.make_data())
-    trans.readAll(1)
+    def testTransportReadAll(self):
+        """Test that readAll on any type of transport throws an EOFError"""
+        trans = TTransport.TMemoryBuffer(self.make_data())
+        trans.readAll(1)
 
-    try:
-      trans.readAll(10000)
-    except EOFError:
-      return
+        try:
+            trans.readAll(10000)
+        except EOFError:
+            return
 
-    self.fail("Should have gotten EOFError")
+        self.fail("Should have gotten EOFError")
 
-  def eofTestHelper(self, pfactory):
-    trans = TTransport.TMemoryBuffer(self.make_data(pfactory))
-    prot = pfactory.getProtocol(trans)
+    def eofTestHelper(self, pfactory):
+        trans = TTransport.TMemoryBuffer(self.make_data(pfactory))
+        prot = pfactory.getProtocol(trans)
 
-    x = Xtruct()
-    x.read(prot)
-    self.assertEqual(x.string_thing, "Zero")
-    self.assertEqual(x.byte_thing, 0)
-
-    x = Xtruct()
-    x.read(prot)
-    self.assertEqual(x.string_thing, "One")
-    self.assertEqual(x.byte_thing, 1)
-
-    try:
-      x = Xtruct()
-      x.read(prot)
-    except EOFError:
-      return
-
-    self.fail("Should have gotten EOFError")
-
-  def eofTestHelperStress(self, pfactory):
-    """Teest the ability of TBinaryProtocol to deal with the removal of every byte in the file"""
-    # TODO: we should make sure this covers more of the code paths
-
-    data = self.make_data(pfactory)
-    for i in range(0, len(data) + 1):
-      trans = TTransport.TMemoryBuffer(data[0:i])
-      prot = pfactory.getProtocol(trans)
-      try:
         x = Xtruct()
         x.read(prot)
+        self.assertEqual(x.string_thing, "Zero")
+        self.assertEqual(x.byte_thing, 0)
+
+        x = Xtruct()
         x.read(prot)
-        x.read(prot)
-      except EOFError:
-        continue
-      self.fail("Should have gotten an EOFError")
+        self.assertEqual(x.string_thing, "One")
+        self.assertEqual(x.byte_thing, 1)
 
-  def testBinaryProtocolEof(self):
-    """Test that TBinaryProtocol throws an EOFError when it reaches the end of the stream"""
-    self.eofTestHelper(TBinaryProtocol.TBinaryProtocolFactory())
-    self.eofTestHelperStress(TBinaryProtocol.TBinaryProtocolFactory())
+        try:
+            x = Xtruct()
+            x.read(prot)
+        except EOFError:
+            return
 
-  def testBinaryProtocolAcceleratedEof(self):
-    """Test that TBinaryProtocolAccelerated throws an EOFError when it reaches the end of the stream"""
-    self.eofTestHelper(TBinaryProtocol.TBinaryProtocolAcceleratedFactory())
-    self.eofTestHelperStress(TBinaryProtocol.TBinaryProtocolAcceleratedFactory())
+        self.fail("Should have gotten EOFError")
 
-  def testCompactProtocolEof(self):
-    """Test that TCompactProtocol throws an EOFError when it reaches the end of the stream"""
-    self.eofTestHelper(TCompactProtocol.TCompactProtocolFactory())
-    self.eofTestHelperStress(TCompactProtocol.TCompactProtocolFactory())
+    def eofTestHelperStress(self, pfactory):
+        """Teest the ability of TBinaryProtocol to deal with the removal of every byte in the file"""
+        # TODO: we should make sure this covers more of the code paths
+
+        data = self.make_data(pfactory)
+        for i in range(0, len(data) + 1):
+            trans = TTransport.TMemoryBuffer(data[0:i])
+            prot = pfactory.getProtocol(trans)
+            try:
+                x = Xtruct()
+                x.read(prot)
+                x.read(prot)
+                x.read(prot)
+            except EOFError:
+                continue
+            self.fail("Should have gotten an EOFError")
+
+    def testBinaryProtocolEof(self):
+        """Test that TBinaryProtocol throws an EOFError when it reaches the end of the stream"""
+        self.eofTestHelper(TBinaryProtocol.TBinaryProtocolFactory())
+        self.eofTestHelperStress(TBinaryProtocol.TBinaryProtocolFactory())
+
+    def testBinaryProtocolAcceleratedEof(self):
+        """Test that TBinaryProtocolAccelerated throws an EOFError when it reaches the end of the stream"""
+        self.eofTestHelper(TBinaryProtocol.TBinaryProtocolAcceleratedFactory())
+        self.eofTestHelperStress(TBinaryProtocol.TBinaryProtocolAcceleratedFactory())
+
+    def testCompactProtocolEof(self):
+        """Test that TCompactProtocol throws an EOFError when it reaches the end of the stream"""
+        self.eofTestHelper(TCompactProtocol.TCompactProtocolFactory())
+        self.eofTestHelperStress(TCompactProtocol.TCompactProtocolFactory())
 
 
 def suite():
-  suite = unittest.TestSuite()
-  loader = unittest.TestLoader()
-  suite.addTest(loader.loadTestsFromTestCase(TestEof))
-  return suite
+    suite = unittest.TestSuite()
+    loader = unittest.TestLoader()
+    suite.addTest(loader.loadTestsFromTestCase(TestEof))
+    return suite
 
 if __name__ == "__main__":
-  unittest.main(defaultTest="suite", testRunner=unittest.TextTestRunner(verbosity=2))
+    unittest.main(defaultTest="suite", testRunner=unittest.TextTestRunner(verbosity=2))
