Commits

Miki Tebeka committed 755a56a

Added next method and version bump

  • Participants
  • Parent commits 7c1932f

Comments (0)

Files changed (3)

File fastavro/__init__.py

 '''
 
 __all__ = [ 'iter_avro', 'reader']
-__version__ = '0.6.6'
+__version__ = '0.6.7'
 
 
 try:

File fastavro/_reader.c

-/* Generated by Cython 0.16 on Wed May 23 16:56:59 2012 */
+/* Generated by Cython 0.16 on Fri Jul 13 17:53:07 2012 */
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
 
 static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
 
+#define __Pyx_PyIter_Next(obj) __Pyx_PyIter_Next2(obj, NULL);
+static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject *, PyObject *); /*proto*/
+
 static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
 static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
 
 static PyObject *__pyx_pf_8fastavro_7_reader_34_iter_avro(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_fo, PyObject *__pyx_v_header, PyObject *__pyx_v_schema); /* proto */
 static PyObject *__pyx_pf_8fastavro_7_reader_9iter_avro___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_fo); /* proto */
 static PyObject *__pyx_pf_8fastavro_7_reader_9iter_avro_2__iter__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8fastavro_7_reader_9iter_avro_4next(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
 static char __pyx_k_8[] = "!f";
 static char __pyx_k_9[] = "!I";
 static char __pyx_k_18[] = "!d";
 static char __pyx_k_28[] = "org.apache.avro.file.Header";
 static char __pyx_k_31[] = "/home/miki/Projects/fastavro/fastavro/_reader.py";
 static char __pyx_k_32[] = "fastavro._reader";
-static char __pyx_k_37[] = "Custom iterator over avro file.\n\n    Example:\n        with open('some-file.avro', 'rb') as fo:\n            avro = iter_avro(fo)\n            schema = avro.schema\n\n            for record in avro:\n                process_record(record)\n    ";
+static char __pyx_k_39[] = "Custom iterator over avro file.\n\n    Example:\n        with open('some-file.avro', 'rb') as fo:\n            avro = iter_avro(fo)\n            schema = avro.schema\n\n            for record in avro:\n                process_record(record)\n    ";
 static char __pyx_k__i[] = "i";
 static char __pyx_k__fo[] = "fo";
 static char __pyx_k__os[] = "os";
 static char __pyx_k__long[] = "long";
 static char __pyx_k__meta[] = "meta";
 static char __pyx_k__name[] = "name";
+static char __pyx_k__next[] = "next";
 static char __pyx_k__null[] = "null";
 static char __pyx_k__pack[] = "pack";
 static char __pyx_k__read[] = "read";
 static PyObject *__pyx_kp_s_28;
 static PyObject *__pyx_kp_s_31;
 static PyObject *__pyx_n_s_32;
-static PyObject *__pyx_kp_s_37;
+static PyObject *__pyx_kp_s_39;
 static PyObject *__pyx_kp_s_8;
 static PyObject *__pyx_kp_s_9;
 static PyObject *__pyx_n_s__BLOCK_READERS;
 static PyObject *__pyx_n_s__map;
 static PyObject *__pyx_n_s__meta;
 static PyObject *__pyx_n_s__name;
+static PyObject *__pyx_n_s__next;
 static PyObject *__pyx_n_s__null;
 static PyObject *__pyx_n_s__null_read_block;
 static PyObject *__pyx_n_s__ord;
 static PyObject *__pyx_k_tuple_29;
 static PyObject *__pyx_k_tuple_33;
 static PyObject *__pyx_k_tuple_35;
+static PyObject *__pyx_k_tuple_37;
 static PyObject *__pyx_k_codeobj_30;
 static PyObject *__pyx_k_codeobj_34;
 static PyObject *__pyx_k_codeobj_36;
+static PyObject *__pyx_k_codeobj_38;
 
 /* "fastavro/_reader.py":42
  * 
  * 
  *     def __iter__(self):             # <<<<<<<<<<<<<<
  *         return self._records
+ * 
  */
 
 static PyObject *__pyx_pf_8fastavro_7_reader_9iter_avro_2__iter__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  * 
  *     def __iter__(self):
  *         return self._records             # <<<<<<<<<<<<<<
+ * 
+ *     def next(self):
  */
   __Pyx_XDECREF(__pyx_r);
   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___records); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   return __pyx_r;
 }
 
+/* Python wrapper */
+static PyObject *__pyx_pw_8fastavro_7_reader_9iter_avro_5next(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
+static PyMethodDef __pyx_mdef_8fastavro_7_reader_9iter_avro_5next = {__Pyx_NAMESTR("next"), (PyCFunction)__pyx_pw_8fastavro_7_reader_9iter_avro_5next, METH_O, __Pyx_DOCSTR(0)};
+static PyObject *__pyx_pw_8fastavro_7_reader_9iter_avro_5next(PyObject *__pyx_self, PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("next (wrapper)", 0);
+  __pyx_self = __pyx_self;
+  __pyx_r = __pyx_pf_8fastavro_7_reader_9iter_avro_4next(__pyx_self, ((PyObject *)__pyx_v_self));
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "fastavro/_reader.py":333
+ *         return self._records
+ * 
+ *     def next(self):             # <<<<<<<<<<<<<<
+ *         return next(self._records)
+ */
+
+static PyObject *__pyx_pf_8fastavro_7_reader_9iter_avro_4next(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_RefNannySetupContext("next", 0);
+
+  /* "fastavro/_reader.py":334
+ * 
+ *     def next(self):
+ *         return next(self._records)             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___records); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyIter_Next(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
+  goto __pyx_L0;
+
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("fastavro._reader.iter_avro.next", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
 static PyObject *__pyx_tp_new_8fastavro_7_reader___pyx_scope_struct___iter_avro(PyTypeObject *t, PyObject *a, PyObject *k) {
   struct __pyx_obj_8fastavro_7_reader___pyx_scope_struct___iter_avro *p;
   PyObject *o = (*t->tp_alloc)(t, 0);
   {&__pyx_kp_s_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 1, 0},
   {&__pyx_kp_s_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 0, 1, 0},
   {&__pyx_n_s_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 0, 1, 1},
-  {&__pyx_kp_s_37, __pyx_k_37, sizeof(__pyx_k_37), 0, 0, 1, 0},
+  {&__pyx_kp_s_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 1, 0},
   {&__pyx_kp_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 0},
   {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0},
   {&__pyx_n_s__BLOCK_READERS, __pyx_k__BLOCK_READERS, sizeof(__pyx_k__BLOCK_READERS), 0, 0, 1, 1},
   {&__pyx_n_s__map, __pyx_k__map, sizeof(__pyx_k__map), 0, 0, 1, 1},
   {&__pyx_n_s__meta, __pyx_k__meta, sizeof(__pyx_k__meta), 0, 0, 1, 1},
   {&__pyx_n_s__name, __pyx_k__name, sizeof(__pyx_k__name), 0, 0, 1, 1},
+  {&__pyx_n_s__next, __pyx_k__next, sizeof(__pyx_k__next), 0, 0, 1, 1},
   {&__pyx_n_s__null, __pyx_k__null, sizeof(__pyx_k__null), 0, 0, 1, 1},
   {&__pyx_n_s__null_read_block, __pyx_k__null_read_block, sizeof(__pyx_k__null_read_block), 0, 0, 1, 1},
   {&__pyx_n_s__ord, __pyx_k__ord, sizeof(__pyx_k__ord), 0, 0, 1, 1},
  * 
  *     def __iter__(self):             # <<<<<<<<<<<<<<
  *         return self._records
+ * 
  */
   __pyx_k_tuple_35 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_35)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_35);
   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__self));
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_35));
   __pyx_k_codeobj_36 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_35, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_31, __pyx_n_s____iter__, 330, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_36)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+  /* "fastavro/_reader.py":333
+ *         return self._records
+ * 
+ *     def next(self):             # <<<<<<<<<<<<<<
+ *         return next(self._records)
+ */
+  __pyx_k_tuple_37 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_37)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_37);
+  __Pyx_INCREF(((PyObject *)__pyx_n_s__self));
+  PyTuple_SET_ITEM(__pyx_k_tuple_37, 0, ((PyObject *)__pyx_n_s__self));
+  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__self));
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_37));
+  __pyx_k_codeobj_38 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_37, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_31, __pyx_n_s__next, 333, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_38)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_RefNannyFinishContext();
   return 0;
   __pyx_L1_error:;
  * 
  *     def __iter__(self):             # <<<<<<<<<<<<<<
  *         return self._records
+ * 
  */
   __pyx_t_8 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8fastavro_7_reader_9iter_avro_3__iter__, 0, NULL, __pyx_n_s_32, ((PyObject *)__pyx_k_codeobj_36)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_8);
   if (PyObject_SetItem(__pyx_t_2, __pyx_n_s____iter__, __pyx_t_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
 
+  /* "fastavro/_reader.py":333
+ *         return self._records
+ * 
+ *     def next(self):             # <<<<<<<<<<<<<<
+ *         return next(self._records)
+ */
+  __pyx_t_8 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8fastavro_7_reader_9iter_avro_5next, 0, NULL, __pyx_n_s_32, ((PyObject *)__pyx_k_codeobj_38)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_8);
+  if (PyObject_SetItem(__pyx_t_2, __pyx_n_s__next, __pyx_t_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
   /* "fastavro/_reader.py":310
  * 
  * 
  *     '''Custom iterator over avro file.
  * 
  */
-  if (PyDict_SetItemString(((PyObject *)__pyx_t_2), "__doc__", ((PyObject *)__pyx_kp_s_37)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItemString(((PyObject *)__pyx_t_2), "__doc__", ((PyObject *)__pyx_kp_s_39)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_t_8 = __Pyx_CreateClass(((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2), __pyx_n_s__iter_avro, __pyx_n_s_32); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_8);
   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__iter_avro, __pyx_t_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     return -1;
 }
 
+static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject* iterator, PyObject* defval) {
+    PyObject* next;
+    if (unlikely(!PyIter_Check(iterator))) {
+        PyErr_Format(PyExc_TypeError,
+            "%.200s object is not an iterator", iterator->ob_type->tp_name);
+        return NULL;
+    }
+    next = (*(Py_TYPE(iterator)->tp_iternext))(iterator);
+    if (likely(next)) {
+        return next;
+    } else if (defval) {
+        if (PyErr_Occurred()) {
+            if(!PyErr_ExceptionMatches(PyExc_StopIteration))
+                return NULL;
+            PyErr_Clear();
+        }
+        Py_INCREF(defval);
+        return defval;
+    } else if (PyErr_Occurred()) {
+        return NULL;
+    } else {
+        PyErr_SetNone(PyExc_StopIteration);
+        return NULL;
+    }
+}
+
 static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) {
     PyThreadState *tstate = PyThreadState_GET();
     *type = tstate->exc_type;

File fastavro/reader.py

 
     def __iter__(self):
         return self._records
+
+    def next(self):
+        return next(self._records)