Python csv.get_dialect() Examples
The following are 30
code examples of csv.get_dialect().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
csv
, or try the search function
.
Example #1
Source File: test_csv.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_registry_badargs(self): self.assertRaises(TypeError, csv.list_dialects, None) self.assertRaises(TypeError, csv.get_dialect) self.assertRaises(csv.Error, csv.get_dialect, None) self.assertRaises(csv.Error, csv.get_dialect, "nonesuch") self.assertRaises(TypeError, csv.unregister_dialect) self.assertRaises(csv.Error, csv.unregister_dialect, None) self.assertRaises(csv.Error, csv.unregister_dialect, "nonesuch") self.assertRaises(TypeError, csv.register_dialect, None) self.assertRaises(TypeError, csv.register_dialect, None, None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", 0, 0) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", badargument=None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", quoting=None) self.assertRaises(TypeError, csv.register_dialect, [])
Example #2
Source File: test_csv.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_registry_badargs(self): self.assertRaises(TypeError, csv.list_dialects, None) self.assertRaises(TypeError, csv.get_dialect) self.assertRaises(csv.Error, csv.get_dialect, None) self.assertRaises(csv.Error, csv.get_dialect, "nonesuch") self.assertRaises(TypeError, csv.unregister_dialect) self.assertRaises(csv.Error, csv.unregister_dialect, None) self.assertRaises(csv.Error, csv.unregister_dialect, "nonesuch") self.assertRaises(TypeError, csv.register_dialect, None) self.assertRaises(TypeError, csv.register_dialect, None, None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", 0, 0) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", badargument=None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", quoting=None) self.assertRaises(TypeError, csv.register_dialect, [])
Example #3
Source File: write.py From CleverCSV with MIT License | 6 votes |
def _make_python_dialect(self, dialect, **fmtparams): if isinstance(dialect, str): d = csv.get_dialect(dialect) elif isinstance(dialect, csv.Dialect): d = dialect elif isinstance(dialect, SimpleDialect): d = dialect.to_csv_dialect() # We have to subclass the csv.Dialect props = {k: getattr(d, k) for k in DIALECT_KEYS if hasattr(d, k)} for key, value in fmtparams.items(): props[key] = value # lineterminator must be set if not "lineterminator" in props or props["lineterminator"] is None: props["lineterminator"] = "\n" newdialect = type("dialect", (csv.Dialect,), props) return newdialect
Example #4
Source File: test_csv.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_registry_badargs(self): self.assertRaises(TypeError, csv.list_dialects, None) self.assertRaises(TypeError, csv.get_dialect) self.assertRaises(csv.Error, csv.get_dialect, None) self.assertRaises(csv.Error, csv.get_dialect, "nonesuch") self.assertRaises(TypeError, csv.unregister_dialect) self.assertRaises(csv.Error, csv.unregister_dialect, None) self.assertRaises(csv.Error, csv.unregister_dialect, "nonesuch") self.assertRaises(TypeError, csv.register_dialect, None) self.assertRaises(TypeError, csv.register_dialect, None, None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", 0, 0) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", badargument=None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", quoting=None) self.assertRaises(TypeError, csv.register_dialect, [])
Example #5
Source File: test_csv.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_registry_badargs(self): self.assertRaises(TypeError, csv.list_dialects, None) self.assertRaises(TypeError, csv.get_dialect) self.assertRaises(csv.Error, csv.get_dialect, None) self.assertRaises(csv.Error, csv.get_dialect, "nonesuch") self.assertRaises(TypeError, csv.unregister_dialect) self.assertRaises(csv.Error, csv.unregister_dialect, None) self.assertRaises(csv.Error, csv.unregister_dialect, "nonesuch") self.assertRaises(TypeError, csv.register_dialect, None) self.assertRaises(TypeError, csv.register_dialect, None, None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", 0, 0) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", badargument=None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", quoting=None) self.assertRaises(TypeError, csv.register_dialect, [])
Example #6
Source File: test_csv.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_bad_dialect(self): # Unknown parameter self.assertRaises(TypeError, csv.reader, [], bad_attr = 0) # Bad values self.assertRaises(TypeError, csv.reader, [], delimiter = None) self.assertRaises(TypeError, csv.reader, [], quoting = -1) self.assertRaises(TypeError, csv.reader, [], quoting = 100) # See issue #22995 ## def test_copy(self): ## for name in csv.list_dialects(): ## dialect = csv.get_dialect(name) ## self.assertRaises(TypeError, copy.copy, dialect) ## def test_pickle(self): ## for name in csv.list_dialects(): ## dialect = csv.get_dialect(name) ## for proto in range(pickle.HIGHEST_PROTOCOL + 1): ## self.assertRaises(TypeError, pickle.dumps, dialect, proto)
Example #7
Source File: test_csv.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_registry_badargs(self): self.assertRaises(TypeError, csv.list_dialects, None) self.assertRaises(TypeError, csv.get_dialect) self.assertRaises(csv.Error, csv.get_dialect, None) self.assertRaises(csv.Error, csv.get_dialect, "nonesuch") self.assertRaises(TypeError, csv.unregister_dialect) self.assertRaises(csv.Error, csv.unregister_dialect, None) self.assertRaises(csv.Error, csv.unregister_dialect, "nonesuch") self.assertRaises(TypeError, csv.register_dialect, None) self.assertRaises(TypeError, csv.register_dialect, None, None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", 0, 0) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", badargument=None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", quoting=None) self.assertRaises(TypeError, csv.register_dialect, [])
Example #8
Source File: test_csv.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_registry_badargs(self): self.assertRaises(TypeError, csv.list_dialects, None) self.assertRaises(TypeError, csv.get_dialect) self.assertRaises(csv.Error, csv.get_dialect, None) self.assertRaises(csv.Error, csv.get_dialect, "nonesuch") self.assertRaises(TypeError, csv.unregister_dialect) self.assertRaises(csv.Error, csv.unregister_dialect, None) self.assertRaises(csv.Error, csv.unregister_dialect, "nonesuch") self.assertRaises(TypeError, csv.register_dialect, None) self.assertRaises(TypeError, csv.register_dialect, None, None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", 0, 0) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", badargument=None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", quoting=None) self.assertRaises(TypeError, csv.register_dialect, [])
Example #9
Source File: csv.py From girlfriend with MIT License | 6 votes |
def __call__(self, context): if isinstance(self._object, types.StringTypes): self._object = context[self._object] # get dialect object if isinstance(self._dialect, types.StringTypes): dialect = csv.get_dialect(self._dialect) if self._path.startswith("memory:"): buffer_ = StringIO.StringIO() self._write_object(buffer_, dialect) buffer_.seek(0) context[self._path[len("memory:"):]] = buffer_ else: with open(self._path, "w") as f: self._write_object(f, dialect) return self._path
Example #10
Source File: csv.py From girlfriend with MIT License | 6 votes |
def __call__(self, context): # get Dialect object if isinstance(self._dialect, types.StringTypes): dialect = csv.get_dialect(self._dialect) # get content content = self._content if self._content is None: if self._path.startswith(HTTP_SCHEMA): content = requests.get(self._path).text else: with open(self._path, "r") as f: content = f.read() if isinstance(content, types.StringTypes): content = StringIO.StringIO(content) result = [] csv_reader = csv.reader(content, dialect=dialect) for row in csv_reader: self._handle_record(row, result.append) return self._handle_result(context, result)
Example #11
Source File: test_csv.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_registry_badargs(self): self.assertRaises(TypeError, csv.list_dialects, None) self.assertRaises(TypeError, csv.get_dialect) self.assertRaises(csv.Error, csv.get_dialect, None) self.assertRaises(csv.Error, csv.get_dialect, "nonesuch") self.assertRaises(TypeError, csv.unregister_dialect) self.assertRaises(csv.Error, csv.unregister_dialect, None) self.assertRaises(csv.Error, csv.unregister_dialect, "nonesuch") self.assertRaises(TypeError, csv.register_dialect, None) self.assertRaises(TypeError, csv.register_dialect, None, None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", 0, 0) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", badargument=None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", quoting=None) self.assertRaises(TypeError, csv.register_dialect, [])
Example #12
Source File: test_csv.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_registry_badargs(self): self.assertRaises(TypeError, csv.list_dialects, None) self.assertRaises(TypeError, csv.get_dialect) self.assertRaises(csv.Error, csv.get_dialect, None) self.assertRaises(csv.Error, csv.get_dialect, "nonesuch") self.assertRaises(TypeError, csv.unregister_dialect) self.assertRaises(csv.Error, csv.unregister_dialect, None) self.assertRaises(csv.Error, csv.unregister_dialect, "nonesuch") self.assertRaises(TypeError, csv.register_dialect, None) self.assertRaises(TypeError, csv.register_dialect, None, None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", 0, 0) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", badargument=None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", quoting=None) self.assertRaises(TypeError, csv.register_dialect, [])
Example #13
Source File: test_utils.py From Watson with MIT License | 6 votes |
def test_build_csv_multiple_cols(): lt = os.linesep dm = csv.get_dialect('excel').delimiter data = [ co.OrderedDict([('col1', 'value'), ('col2', 'another value'), ('col3', 'more')]), co.OrderedDict([('col1', 'one value'), ('col2', 'two value'), ('col3', 'three')]) ] result = lt.join([ dm.join(['col1', 'col2', 'col3']), dm.join(['value', 'another value', 'more']), dm.join(['one value', 'two value', 'three']) ]) + lt assert build_csv(data) == result # sorted_groupby
Example #14
Source File: test_csv.py From oss-ftp with MIT License | 6 votes |
def test_registry_badargs(self): self.assertRaises(TypeError, csv.list_dialects, None) self.assertRaises(TypeError, csv.get_dialect) self.assertRaises(csv.Error, csv.get_dialect, None) self.assertRaises(csv.Error, csv.get_dialect, "nonesuch") self.assertRaises(TypeError, csv.unregister_dialect) self.assertRaises(csv.Error, csv.unregister_dialect, None) self.assertRaises(csv.Error, csv.unregister_dialect, "nonesuch") self.assertRaises(TypeError, csv.register_dialect, None) self.assertRaises(TypeError, csv.register_dialect, None, None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", 0, 0) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", badargument=None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", quoting=None) self.assertRaises(TypeError, csv.register_dialect, [])
Example #15
Source File: test_csv.py From BinderFilter with MIT License | 6 votes |
def test_registry_badargs(self): self.assertRaises(TypeError, csv.list_dialects, None) self.assertRaises(TypeError, csv.get_dialect) self.assertRaises(csv.Error, csv.get_dialect, None) self.assertRaises(csv.Error, csv.get_dialect, "nonesuch") self.assertRaises(TypeError, csv.unregister_dialect) self.assertRaises(csv.Error, csv.unregister_dialect, None) self.assertRaises(csv.Error, csv.unregister_dialect, "nonesuch") self.assertRaises(TypeError, csv.register_dialect, None) self.assertRaises(TypeError, csv.register_dialect, None, None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", 0, 0) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", badargument=None) self.assertRaises(TypeError, csv.register_dialect, "nonesuch", quoting=None) self.assertRaises(TypeError, csv.register_dialect, [])
Example #16
Source File: test_csv.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_bad_dialect(self): # Unknown parameter self.assertRaises(TypeError, csv.reader, [], bad_attr = 0) # Bad values self.assertRaises(TypeError, csv.reader, [], delimiter = None) self.assertRaises(TypeError, csv.reader, [], quoting = -1) self.assertRaises(TypeError, csv.reader, [], quoting = 100) # See issue #22995 ## def test_copy(self): ## for name in csv.list_dialects(): ## dialect = csv.get_dialect(name) ## self.assertRaises(TypeError, copy.copy, dialect) ## def test_pickle(self): ## for name in csv.list_dialects(): ## dialect = csv.get_dialect(name) ## for proto in range(pickle.HIGHEST_PROTOCOL + 1): ## self.assertRaises(TypeError, pickle.dumps, dialect, proto)
Example #17
Source File: test_csv.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_register_kwargs(self): name = 'fedcba' csv.register_dialect(name, delimiter=';') self.addCleanup(csv.unregister_dialect, name) self.assertEqual(csv.get_dialect(name).delimiter, ';') self.assertEqual([['X', 'Y', 'Z']], list(csv.reader(['X;Y;Z'], name)))
Example #18
Source File: test_csv.py From BinderFilter with MIT License | 5 votes |
def test_registry(self): class myexceltsv(csv.excel): delimiter = "\t" name = "myexceltsv" expected_dialects = csv.list_dialects() + [name] expected_dialects.sort() csv.register_dialect(name, myexceltsv) self.addCleanup(csv.unregister_dialect, name) self.assertEqual(csv.get_dialect(name).delimiter, '\t') got_dialects = sorted(csv.list_dialects()) self.assertEqual(expected_dialects, got_dialects)
Example #19
Source File: test_csv.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_registry(self): class myexceltsv(csv.excel): delimiter = "\t" name = "myexceltsv" expected_dialects = csv.list_dialects() + [name] expected_dialects.sort() csv.register_dialect(name, myexceltsv) self.addCleanup(csv.unregister_dialect, name) self.assertEqual(csv.get_dialect(name).delimiter, '\t') got_dialects = sorted(csv.list_dialects()) self.assertEqual(expected_dialects, got_dialects)
Example #20
Source File: test_csv.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_register_kwargs(self): name = 'fedcba' csv.register_dialect(name, delimiter=';') self.addCleanup(csv.unregister_dialect, name) self.assertEqual(csv.get_dialect(name).delimiter, ';') self.assertEqual([['X', 'Y', 'Z']], list(csv.reader(['X;Y;Z'], name)))
Example #21
Source File: test_csv.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_registry(self): class myexceltsv(csv.excel): delimiter = "\t" name = "myexceltsv" expected_dialects = csv.list_dialects() + [name] expected_dialects.sort() csv.register_dialect(name, myexceltsv) try: self.failUnless(csv.get_dialect(name).delimiter, '\t') got_dialects = csv.list_dialects() got_dialects.sort() self.assertEqual(expected_dialects, got_dialects) finally: csv.unregister_dialect(name)
Example #22
Source File: test_csv.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_register_kwargs(self): name = 'fedcba' csv.register_dialect(name, delimiter=';') try: self.failUnless(csv.get_dialect(name).delimiter, '\t') self.failUnless(list(csv.reader('X;Y;Z', name)), ['X', 'Y', 'Z']) finally: csv.unregister_dialect(name)
Example #23
Source File: test_csv.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_registry(self): class myexceltsv(csv.excel): delimiter = "\t" name = "myexceltsv" expected_dialects = csv.list_dialects() + [name] expected_dialects.sort() csv.register_dialect(name, myexceltsv) self.addCleanup(csv.unregister_dialect, name) self.assertEqual(csv.get_dialect(name).delimiter, '\t') got_dialects = sorted(csv.list_dialects()) self.assertEqual(expected_dialects, got_dialects)
Example #24
Source File: test_csv.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_registry(self): class myexceltsv(csv.excel): delimiter = "\t" name = "myexceltsv" expected_dialects = csv.list_dialects() + [name] expected_dialects.sort() csv.register_dialect(name, myexceltsv) self.addCleanup(csv.unregister_dialect, name) self.assertEqual(csv.get_dialect(name).delimiter, '\t') got_dialects = sorted(csv.list_dialects()) self.assertEqual(expected_dialects, got_dialects)
Example #25
Source File: test_csv.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_register_kwargs(self): name = 'fedcba' csv.register_dialect(name, delimiter=';') self.addCleanup(csv.unregister_dialect, name) self.assertEqual(csv.get_dialect(name).delimiter, ';') self.assertEqual([['X', 'Y', 'Z']], list(csv.reader(['X;Y;Z'], name)))
Example #26
Source File: read.py From CleverCSV with MIT License | 5 votes |
def _make_simple_dialect(self, dialect, **fmtparams): if isinstance(dialect, str): sd = SimpleDialect.from_csv_dialect(csv.get_dialect(dialect)) elif isinstance(dialect, csv.Dialect): sd = SimpleDialect.from_csv_dialect(dialect) elif isinstance(dialect, SimpleDialect): sd = dialect else: raise ValueError("Unknown dialect type: %r" % dialect) for key, value in fmtparams.items(): if key in ["delimiter", "quotechar", "escapechar", "strict"]: setattr(sd, key, value) sd.validate() return sd
Example #27
Source File: test_csv.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_registry(self): class myexceltsv(csv.excel): delimiter = "\t" name = "myexceltsv" expected_dialects = csv.list_dialects() + [name] expected_dialects.sort() csv.register_dialect(name, myexceltsv) self.addCleanup(csv.unregister_dialect, name) self.assertEqual(csv.get_dialect(name).delimiter, '\t') got_dialects = sorted(csv.list_dialects()) self.assertEqual(expected_dialects, got_dialects)
Example #28
Source File: test_csv.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_registry(self): class myexceltsv(csv.excel): delimiter = "\t" name = "myexceltsv" expected_dialects = csv.list_dialects() + [name] expected_dialects.sort() csv.register_dialect(name, myexceltsv) self.addCleanup(csv.unregister_dialect, name) self.assertEqual(csv.get_dialect(name).delimiter, '\t') got_dialects = sorted(csv.list_dialects()) self.assertEqual(expected_dialects, got_dialects)
Example #29
Source File: test_csv.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_register_kwargs(self): name = 'fedcba' csv.register_dialect(name, delimiter=';') self.addCleanup(csv.unregister_dialect, name) self.assertEqual(csv.get_dialect(name).delimiter, ';') self.assertEqual([['X', 'Y', 'Z']], list(csv.reader(['X;Y;Z'], name)))
Example #30
Source File: test_csv.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_register_kwargs(self): name = 'fedcba' csv.register_dialect(name, delimiter=';') self.addCleanup(csv.unregister_dialect, name) self.assertEqual(csv.get_dialect(name).delimiter, ';') self.assertEqual([['X', 'Y', 'Z']], list(csv.reader(['X;Y;Z'], name)))