THRIFT-1796 TJSONProtocol is not functional
Patch: Avi Flamholz
diff --git a/lib/py/src/protocol/TJSONProtocol.py b/lib/py/src/protocol/TJSONProtocol.py
index 57872bd..5fb3ec7 100644
--- a/lib/py/src/protocol/TJSONProtocol.py
+++ b/lib/py/src/protocol/TJSONProtocol.py
@@ -56,7 +56,7 @@
   JTYPES[CTYPES[key]] = key
 
 
-class JSONBaseContext():
+class JSONBaseContext(object):
 
   def __init__(self, protocol):
     self.protocol = protocol
@@ -135,6 +135,8 @@
 
   def __init__(self, trans):
     TProtocolBase.__init__(self, trans)
+    self.resetWriteContext()
+    self.resetReadContext()
 
   def resetWriteContext(self):
     self.contextStack = []
@@ -261,7 +263,7 @@
         self.readJSONSyntaxChar(QUOTE)
       try:
         return float(self.readJSONNumericChars())
-      except ValueErro:
+      except ValueError:
         raise TProtocolException(TProtocolException.INVALID_DATA,
                                  "Bad data encounted in numeric data")
 
@@ -312,15 +314,15 @@
 
   def readFieldBegin(self):
     character = self.reader.peek()
-    type = 0
+    ttype = 0
     id = 0
     if character == RBRACE:
-      type = TType.STOP
+      ttype = TType.STOP
     else:
       id = self.readJSONInteger()
       self.readJSONObjectStart()
-      type = JTYPES[self.readJSONString(False)]
-    return (None, type, id)
+      ttype = JTYPES[self.readJSONString(False)]
+    return (None, ttype, id)
 
   def readFieldEnd(self):
     self.readJSONObjectEnd()
@@ -341,7 +343,7 @@
     self.readJSONArrayStart()
     elemType = JTYPES[self.readJSONString(False)]
     size = self.readJSONInteger()
-    return (type, size)
+    return (elemType, size)
   readListBegin = readCollectionBegin
   readSetBegin = readCollectionBegin
 
@@ -386,10 +388,10 @@
   def writeStructEnd(self):
     self.writeJSONObjectEnd()
 
-  def writeFieldBegin(self, name, type, id):
+  def writeFieldBegin(self, name, ttype, id):
     self.writeJSONNumber(id)
     self.writeJSONObjectStart()
-    self.writeJSONString(CTYPES[type])
+    self.writeJSONString(CTYPES[ttype])
 
   def writeFieldEnd(self):
     self.writeJSONObjectEnd()
diff --git a/lib/py/src/protocol/TProtocol.py b/lib/py/src/protocol/TProtocol.py
index 5177229..dc2b095 100644
--- a/lib/py/src/protocol/TProtocol.py
+++ b/lib/py/src/protocol/TProtocol.py
@@ -40,7 +40,7 @@
   def __init__(self, trans):
     self.trans = trans
 
-  def writeMessageBegin(self, name, type, seqid):
+  def writeMessageBegin(self, name, ttype, seqid):
     pass
 
   def writeMessageEnd(self):
@@ -52,7 +52,7 @@
   def writeStructEnd(self):
     pass
 
-  def writeFieldBegin(self, name, type, id):
+  def writeFieldBegin(self, name, ttype, fid):
     pass
 
   def writeFieldEnd(self):
@@ -79,7 +79,7 @@
   def writeSetEnd(self):
     pass
 
-  def writeBool(self, bool):
+  def writeBool(self, bool_val):
     pass
 
   def writeByte(self, byte):
@@ -97,7 +97,7 @@
   def writeDouble(self, dub):
     pass
 
-  def writeString(self, str):
+  def writeString(self, str_val):
     pass
 
   def readMessageBegin(self):
@@ -157,46 +157,46 @@
   def readString(self):
     pass
 
-  def skip(self, type):
-    if type == TType.STOP:
+  def skip(self, ttype):
+    if ttype == TType.STOP:
       return
-    elif type == TType.BOOL:
+    elif ttype == TType.BOOL:
       self.readBool()
-    elif type == TType.BYTE:
+    elif ttype == TType.BYTE:
       self.readByte()
-    elif type == TType.I16:
+    elif ttype == TType.I16:
       self.readI16()
-    elif type == TType.I32:
+    elif ttype == TType.I32:
       self.readI32()
-    elif type == TType.I64:
+    elif ttype == TType.I64:
       self.readI64()
-    elif type == TType.DOUBLE:
+    elif ttype == TType.DOUBLE:
       self.readDouble()
-    elif type == TType.STRING:
+    elif ttype == TType.STRING:
       self.readString()
-    elif type == TType.STRUCT:
+    elif ttype == TType.STRUCT:
       name = self.readStructBegin()
       while True:
-        (name, type, id) = self.readFieldBegin()
-        if type == TType.STOP:
+        (name, ttype, id) = self.readFieldBegin()
+        if ttype == TType.STOP:
           break
-        self.skip(type)
+        self.skip(ttype)
         self.readFieldEnd()
       self.readStructEnd()
-    elif type == TType.MAP:
+    elif ttype == TType.MAP:
       (ktype, vtype, size) = self.readMapBegin()
-      for i in range(size):
+      for i in xrange(size):
         self.skip(ktype)
         self.skip(vtype)
       self.readMapEnd()
-    elif type == TType.SET:
+    elif ttype == TType.SET:
       (etype, size) = self.readSetBegin()
-      for i in range(size):
+      for i in xrange(size):
         self.skip(etype)
       self.readSetEnd()
-    elif type == TType.LIST:
+    elif ttype == TType.LIST:
       (etype, size) = self.readListBegin()
-      for i in range(size):
+      for i in xrange(size):
         self.skip(etype)
       self.readListEnd()