aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-05-29 16:42:39 +0000
committerMike Buland <eichlan@xagasoft.com>2012-05-29 16:42:39 +0000
commit3905f9962bbfb312c3804ff9c7b7d1e0fa203cbc (patch)
tree94ef8fa114a86b61e5182ef051e30476aca020a6
parent6b940f4404ef9b357fd725b7aa7fb24c96680abd (diff)
downloadlibgats-3905f9962bbfb312c3804ff9c7b7d1e0fa203cbc.tar.gz
libgats-3905f9962bbfb312c3804ff9c7b7d1e0fa203cbc.tar.bz2
libgats-3905f9962bbfb312c3804ff9c7b7d1e0fa203cbc.tar.xz
libgats-3905f9962bbfb312c3804ff9c7b7d1e0fa203cbc.zip
Apparently in python bools are ints, but ints aren't bools...this means that
you have to test for bool before int or bools are converted to ints. This is fixed now, bools transfer correctly.
-rw-r--r--python/gats.py12
-rwxr-xr-xpython/test.py13
2 files changed, 11 insertions, 14 deletions
diff --git a/python/gats.py b/python/gats.py
index 760314a..40139a2 100644
--- a/python/gats.py
+++ b/python/gats.py
@@ -153,7 +153,12 @@ def _readObj( sIn ):
153 return 'not implemented yet'; 153 return 'not implemented yet';
154 154
155def _writeObj( obj, sOut ): 155def _writeObj( obj, sOut ):
156 if isinstance( obj, int ): 156 if isinstance( obj, bool ):
157 if obj == True:
158 sOut.write('1')
159 else:
160 sOut.write('0')
161 elif isinstance( obj, int ):
157 sOut.write('i') 162 sOut.write('i')
158 _writePackedInt( obj, sOut ) 163 _writePackedInt( obj, sOut )
159 elif isinstance( obj, str ): 164 elif isinstance( obj, str ):
@@ -171,11 +176,6 @@ def _writeObj( obj, sOut ):
171 _writeObj( key, sOut ) 176 _writeObj( key, sOut )
172 _writeObj( obj[key], sOut ) 177 _writeObj( obj[key], sOut )
173 sOut.write('e') 178 sOut.write('e')
174 elif isinstance( obj, bool ):
175 if obj == True:
176 sOut.write('1')
177 else:
178 sOut.write('0')
179 elif isinstance( obj, float ): 179 elif isinstance( obj, float ):
180 if math.isnan( obj ): 180 if math.isnan( obj ):
181 if math.copysign( 1.0, obj ) < 0.0: 181 if math.copysign( 1.0, obj ) < 0.0:
diff --git a/python/test.py b/python/test.py
index f4e679a..fa9c79a 100755
--- a/python/test.py
+++ b/python/test.py
@@ -2,12 +2,9 @@
2 2
3import gats 3import gats
4 4
5print gats.load( open('test.gats', 'rb') ) 5print isinstance( True, bool )
6print isinstance( True, int )
7print isinstance( 1, bool )
8print isinstance( 1, int )
6 9
7gats.dump( 3.14159, open('out.gats', 'wb') ) 10print gats.loads( gats.dumps( 0 ) )
8
9print gats.loads(
10 gats.dumps(
11 500.12345
12 )
13 )