diff options
-rw-r--r-- | python/gats.py | 9 | ||||
-rwxr-xr-x | python/test.py | 2 |
2 files changed, 7 insertions, 4 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 | ||
88 | class EndMarker: | ||
89 | pass | ||
90 | |||
88 | def _readObj( sIn ): | 91 | def _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'; |
diff --git a/python/test.py b/python/test.py index fa9c79a..a359893 100755 --- a/python/test.py +++ b/python/test.py | |||
@@ -7,4 +7,4 @@ print isinstance( True, int ) | |||
7 | print isinstance( 1, bool ) | 7 | print isinstance( 1, bool ) |
8 | print isinstance( 1, int ) | 8 | print isinstance( 1, int ) |
9 | 9 | ||
10 | print gats.loads( gats.dumps( 0 ) ) | 10 | print gats.loads( gats.dumps( [0, 1, 2, 3, None, {'hi': None, 'bye': 1}] ) ) |