Miki Tebeka avatar Miki Tebeka committed 9975194

dump and pep8

Comments (0)

Files changed (3)

fastavro/__init__.py

             process_record(record)
 '''
 
-__all__ = [ 'iter_avro', 'reader']
+__all__ = ['iter_avro', 'reader']
 __version__ = '0.6.8'
 
 
     from io import BytesIO as MemoryIO
     xrange = range
 
-
     def py3_btou(n, encoding=_encoding):
         return n.decode(encoding)
 
-
     def py3_utob(n, encoding=_encoding):
         return bytes(n, encoding)
 
     from cStringIO import StringIO as MemoryIO
     xrange = xrange
 
-
     def py2_btou(n, encoding=_encoding):
         return n
 

fastavro/writer.py

 
 NoneType = type(None)
 
+
 def write_null(fo, datum, schema=None):
     '''null is written as zero bytes'''
     pass
 def write_int(fo, datum, schema=None):
     '''int and long values are written using variable-length, zig-zag coding.
     '''
-    write_long(fo, datum, schema)
-
-
-def write_long(fo, datum, schema=None):
-    '''int and long values are written using variable-length, zig-zag coding.
-    '''
     datum = (datum << 1) ^ (datum >> 63)
     while (datum & ~0x7F) != 0:
         fo.write(chr((datum & 0x7f) | 0x80))
         datum >>= 7
         fo.write(chr(datum))
 
+write_long = write_int
+
 
 def write_float(fo, datum, schema=None):
     '''A float is written as 4 bytes.  The float is converted into a 32-bit
     sync_interval = 1000 * SYNC_SIZE
     io = MemoryIO()
 
+    nblocks = 0
+
+    def dump():
+        # FIXME: Compression
+        write_long(fo, nblocks, schema)
+        fo.write(io.getvalue())
+        fo.write(sync_marker)
+        io.truncate(0)
+        io.seek(0, SEEK_SET)
+
     for record in records:
         write_data(io, record, schema)
+        nblocks += 1
         if io.tell() >= sync_interval:
-            # FIXME: Compression
-            write_long(fo, io.tell(), schema)
-            fo.write(io.getvalue())
-            fo.write(sync_marker)
-            io.truncate(0)
-            io.seek(0, SEEK_SET)
+            dump()
+            nblocks = 0
+
+    if io.tell():
+        dump()
 
     fo.flush()
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.