[pypy-commit] cffi demo-cleanup: fix the demo
arigo
pypy.commits at gmail.com
Thu Jan 7 10:55:42 EST 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: demo-cleanup
Changeset: r2539:496f6485013e
Date: 2016-01-07 16:47 +0100
http://bitbucket.org/cffi/cffi/changeset/496f6485013e/
Log: fix the demo
diff --git a/demo/fastcsv.py b/demo/fastcsv.py
--- a/demo/fastcsv.py
+++ b/demo/fastcsv.py
@@ -4,9 +4,8 @@
# IN-PROGRESS. See the demo at the end of the file
-dialect2ffi = {}
-
-def _make_ffi_from_dialect(dialect):
+def _make_ffi_from_dialect(dialect_name):
+ dialect = csv.get_dialect(dialect_name)
ffi = cffi.FFI()
@@ -26,7 +25,7 @@
else:
d['is_escape_char'] = '&& 0'
- ffi.set_source('_fastcsv', r'''
+ ffi.set_source('_fastcsv_' + dialect_name, r'''
typedef enum {
START_RECORD, START_FIELD, ESCAPED_CHAR, IN_FIELD,
@@ -237,15 +236,16 @@
}
''' % d)
- return ffi, lib
+ ffi.compile()
-def fastcsv_reader(f, dialect):
- dialect = csv.get_dialect(dialect)
+def fastcsv_reader(f, dialect_name):
try:
- ffi, lib = dialect2ffi[dialect]
- except KeyError:
- ffi, lib = dialect2ffi[dialect] = _make_ffi_from_dialect(dialect)
+ module = __import__('_fastcsv_' + dialect_name)
+ except ImportError:
+ _make_ffi_from_dialect(dialect_name)
+ module = __import__('_fastcsv_' + dialect_name)
+ ffi, lib = module.ffi, module.lib
#
linelen = -1
for line in f:
More information about the pypy-commit
mailing list