aboutsummaryrefslogtreecommitdiff
path: root/python/gats.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--python/gats.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/python/gats.py b/python/gats.py
index 22463ab..adf5122 100644
--- a/python/gats.py
+++ b/python/gats.py
@@ -85,6 +85,9 @@ def dump( obj, sOut ):
85 sOut.write( struct.pack('>BI', 1, len(sCore)+5 ) ) 85 sOut.write( struct.pack('>BI', 1, len(sCore)+5 ) )
86 sOut.write( sCore ) 86 sOut.write( sCore )
87 87
88class EndMarker:
89 pass
90
88def _readObj( sIn ): 91def _readObj( sIn ):
89 t = sIn.read( 1 ) 92 t = sIn.read( 1 )
90 if t == 'i': # Integer 93 if t == 'i': # Integer
@@ -100,14 +103,14 @@ def _readObj( sIn ):
100 ret = [] 103 ret = []
101 while True: 104 while True:
102 value = _readObj( sIn ) 105 value = _readObj( sIn )
103 if value is None: 106 if isinstance( value, EndMarker ):
104 return ret 107 return ret
105 ret.append( value ) 108 ret.append( value )
106 elif t == 'd': # Dictionary 109 elif t == 'd': # Dictionary
107 ret = {} 110 ret = {}
108 while True: 111 while True:
109 key = _readObj( sIn ) 112 key = _readObj( sIn )
110 if key is None: 113 if isinstance( key, EndMarker ):
111 return ret 114 return ret
112 if not isinstance( key, str ): 115 if not isinstance( key, str ):
113 raise Exception('Only strings can be used as keys in gats dictionaries') 116 raise Exception('Only strings can be used as keys in gats dictionaries')
@@ -149,7 +152,7 @@ def _readObj( sIn ):
149 elif t == 'n': 152 elif t == 'n':
150 return None 153 return None
151 elif t == 'e': # End marker 154 elif t == 'e': # End marker
152 return None 155 return EndMarker()
153 else: 156 else:
154 raise Exception('Invalid gats type discovered: ' + t) 157 raise Exception('Invalid gats type discovered: ' + t)
155 return 'not implemented yet'; 158 return 'not implemented yet';