Debian Codegraph @

pypy/module/_csv/app_csv.py

raw symbols SCIP
1 import _csv
2
3 class Error(Exception):
4 pass
5
6
7 _dialects = {}
8
9 def register_dialect(name, dialect=None, **kwargs):
10 """Create a mapping from a string name to a dialect class."""
11 if not isinstance(name, str):
12 raise TypeError("dialect name must be a string or unicode")
13
14 dialect = _csv.Dialect(dialect, **kwargs)
15 _dialects[name] = dialect
16
17 def unregister_dialect(name):
18 """Delete the name/dialect mapping associated with a string name."""
19 try:
20 del _dialects[name]
21 except KeyError:
22 raise Error("unknown dialect")
23
24 def get_dialect(name):
25 """Return the dialect instance associated with name."""
26 try:
27 return _dialects[name]
28 except KeyError:
29 raise Error("unknown dialect")
30
31 def list_dialects():
32 """Return a list of all know dialect names."""
33 return list(_dialects)