|
8 | 8 | unregister_dialect, get_dialect, list_dialects, \ |
9 | 9 | QUOTE_MINIMAL, QUOTE_ALL, QUOTE_NONNUMERIC, QUOTE_NONE, \ |
10 | 10 | __doc__ |
| 11 | +from _csv import Dialect as _Dialect |
11 | 12 |
|
12 | 13 | try: |
13 | 14 | from cStringIO import StringIO |
@@ -41,48 +42,14 @@ class Dialect: |
41 | 42 | def __init__(self): |
42 | 43 | if self.__class__ != Dialect: |
43 | 44 | self._valid = True |
44 | | - errors = self._validate() |
45 | | - if errors != []: |
46 | | - raise Error, "Dialect did not validate: %s" % ", ".join(errors) |
| 45 | + self._validate() |
47 | 46 |
|
48 | 47 | def _validate(self): |
49 | | - errors = [] |
50 | | - if not self._valid: |
51 | | - errors.append("can't directly instantiate Dialect class") |
52 | | - |
53 | | - if self.delimiter is None: |
54 | | - errors.append("delimiter character not set") |
55 | | - elif (not isinstance(self.delimiter, str) or |
56 | | - len(self.delimiter) > 1): |
57 | | - errors.append("delimiter must be one-character string") |
58 | | - |
59 | | - if self.quotechar is None: |
60 | | - if self.quoting != QUOTE_NONE: |
61 | | - errors.append("quotechar not set") |
62 | | - elif (not isinstance(self.quotechar, str) or |
63 | | - len(self.quotechar) > 1): |
64 | | - errors.append("quotechar must be one-character string") |
65 | | - |
66 | | - if self.lineterminator is None: |
67 | | - errors.append("lineterminator not set") |
68 | | - elif not isinstance(self.lineterminator, str): |
69 | | - errors.append("lineterminator must be a string") |
70 | | - |
71 | | - if self.doublequote not in (True, False) and self.quoting != QUOTE_NONE: |
72 | | - errors.append("doublequote parameter must be True or False") |
73 | | - |
74 | | - if self.skipinitialspace not in (True, False): |
75 | | - errors.append("skipinitialspace parameter must be True or False") |
76 | | - |
77 | | - if self.quoting is None: |
78 | | - errors.append("quoting parameter not set") |
79 | | - |
80 | | - if self.quoting is QUOTE_NONE: |
81 | | - if (not isinstance(self.escapechar, (unicode, str)) or |
82 | | - len(self.escapechar) > 1): |
83 | | - errors.append("escapechar must be a one-character string or unicode object") |
84 | | - |
85 | | - return errors |
| 48 | + try: |
| 49 | + _Dialect(self) |
| 50 | + except TypeError, e: |
| 51 | + # We do this for compatibility with py2.3 |
| 52 | + raise Error(str(e)) |
86 | 53 |
|
87 | 54 | class excel(Dialect): |
88 | 55 | """Describe the usual properties of Excel-generated CSV files.""" |
|
0 commit comments