Python csv.register_dialect() Examples
The following are 30
code examples of csv.register_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: transaction.py From BankCSVtoQif with GNU General Public License v2.0 | 6 votes |
def read_from_file(self, f, messenger): csv.register_dialect( 'bank_csv', self.account_config.get_csv_dialect() ) c = csv.reader(f, 'bank_csv') consume(c, self.account_config.dropped_lines) # ignore first lines transactions = [] for line in c: try: transaction = self.create_from_line(line) transactions.append(transaction) messenger.send_message("parsed: " + transaction.__str__()) except IndexError: messenger.send_message('skipped: %s' % line) continue return transactions
Example #2
Source File: dialect.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_dialect_str(self): data = """\ fruit:vegetable apple:brocolli pear:tomato """ exp = DataFrame({ 'fruit': ['apple', 'pear'], 'vegetable': ['brocolli', 'tomato'] }) csv.register_dialect('mydialect', delimiter=':') with tm.assert_produces_warning(ParserWarning): df = self.read_csv(StringIO(data), dialect='mydialect') tm.assert_frame_equal(df, exp) csv.unregister_dialect('mydialect')
Example #3
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 #4
Source File: dataimport.py From fio-plot with BSD 3-Clause "New" or "Revised" License | 6 votes |
def readLogData(inputfile): """FIO log data is imported as CSV data. The scope is the import of a single file. """ dataset = [] if os.path.exists(inputfile): with open(inputfile) as csv_file: csv.register_dialect('CustomDialect', skipinitialspace=True, strict=True) csv_reader = csv.DictReader( csv_file, dialect='CustomDialect', delimiter=',', fieldnames=['timestamp', 'value', 'rwt', 'blocksize', 'offset']) for item in csv_reader: dataset.append(item) dataset = parse_raw_cvs_data(dataset) return dataset
Example #5
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 #6
Source File: dialect.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def test_dialect_str(self): data = """\ fruit:vegetable apple:brocolli pear:tomato """ exp = DataFrame({ 'fruit': ['apple', 'pear'], 'vegetable': ['brocolli', 'tomato'] }) csv.register_dialect('mydialect', delimiter=':') with tm.assert_produces_warning(ParserWarning): df = self.read_csv(StringIO(data), dialect='mydialect') tm.assert_frame_equal(df, exp) csv.unregister_dialect('mydialect')
Example #7
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 #8
Source File: test_csv.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_dialect_apply(self): class testA(csv.excel): delimiter = "\t" class testB(csv.excel): delimiter = ":" class testC(csv.excel): delimiter = "|" class testUni(csv.excel): delimiter = "\u039B" csv.register_dialect('testC', testC) try: self.compare_dialect_123("1,2,3\r\n") self.compare_dialect_123("1\t2\t3\r\n", testA) self.compare_dialect_123("1:2:3\r\n", dialect=testB()) self.compare_dialect_123("1|2|3\r\n", dialect='testC') self.compare_dialect_123("1;2;3\r\n", dialect=testA, delimiter=';') self.compare_dialect_123("1\u039B2\u039B3\r\n", dialect=testUni) finally: csv.unregister_dialect('testC')
Example #9
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 #10
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 #11
Source File: test_csv.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_dialect_apply(self): class testA(csv.excel): delimiter = "\t" class testB(csv.excel): delimiter = ":" class testC(csv.excel): delimiter = "|" class testUni(csv.excel): delimiter = "\u039B" csv.register_dialect('testC', testC) try: self.compare_dialect_123("1,2,3\r\n") self.compare_dialect_123("1\t2\t3\r\n", testA) self.compare_dialect_123("1:2:3\r\n", dialect=testB()) self.compare_dialect_123("1|2|3\r\n", dialect='testC') self.compare_dialect_123("1;2;3\r\n", dialect=testA, delimiter=';') self.compare_dialect_123("1\u039B2\u039B3\r\n", dialect=testUni) finally: csv.unregister_dialect('testC')
Example #12
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 #13
Source File: test_csv.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_dialect_apply(self): class testA(csv.excel): delimiter = "\t" class testB(csv.excel): delimiter = ":" class testC(csv.excel): delimiter = "|" class testUni(csv.excel): delimiter = "\u039B" csv.register_dialect('testC', testC) try: self.compare_dialect_123("1,2,3\r\n") self.compare_dialect_123("1\t2\t3\r\n", testA) self.compare_dialect_123("1:2:3\r\n", dialect=testB()) self.compare_dialect_123("1|2|3\r\n", dialect='testC') self.compare_dialect_123("1;2;3\r\n", dialect=testA, delimiter=';') self.compare_dialect_123("1\u039B2\u039B3\r\n", dialect=testUni) finally: csv.unregister_dialect('testC')
Example #14
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 #15
Source File: sslutils.py From WordOps with MIT License | 6 votes |
def checkwildcardexist(self, wo_domain_name): """Check if a wildcard certificate exist for a domain""" wo_acme_exec = ("/etc/letsencrypt/acme.sh --config-home " "'/etc/letsencrypt/config'") # export certificates list from acme.sh WOShellExec.cmd_exec( self, "{0} ".format(wo_acme_exec) + "--list --listraw > /var/lib/wo/cert.csv") # define new csv dialect csv.register_dialect('acmeconf', delimiter='|') # open file certfile = open('/var/lib/wo/cert.csv', mode='r', encoding='utf-8') reader = csv.reader(certfile, 'acmeconf') wo_wildcard_domain = ("*.{0}".format(wo_domain_name)) for row in reader: if wo_wildcard_domain == row[2]: if not row[3] == "": return True certfile.close() return False
Example #16
Source File: acme.py From WordOps with MIT License | 6 votes |
def cert_check(self, wo_domain_name): """Check certificate existance with acme.sh and return Boolean""" WOAcme.export_cert(self) # set variable acme_cert acme_cert = False # define new csv dialect csv.register_dialect('acmeconf', delimiter='|') # open file certfile = open('/var/lib/wo/cert.csv', mode='r', encoding='utf-8') reader = csv.reader(certfile, 'acmeconf') for row in reader: # check if domain exist if wo_domain_name == row[0]: # check if cert expiration exist if not row[3] == '': acme_cert = True certfile.close() if acme_cert is True: if os.path.exists( '/etc/letsencrypt/live/{0}/fullchain.pem' .format(wo_domain_name)): return True return False
Example #17
Source File: format_runs.py From trec-car-tools with BSD 3-Clause "New" or "Revised" License | 6 votes |
def to_trec_eval_row(self, alternative_exp_name=None, page_only=False): exp_name_ = alternative_exp_name if alternative_exp_name is not None \ else self.exp_name return [self.query_id, 'Q0', self.paragraph_id, self.rank, self.score, exp_name_] # # csv.register_dialect( # 'trec_eval', # delimiter = ' ', # quotechar = '"', # doublequote = False, # skipinitialspace = False, # lineterminator = '\n', # quoting = csv.QUOTE_NONE) # # # def configure_csv_writer(fileobj): # 'Convenience method to create a csv writer with the trec_eval_dialect' # return csv.writer(fileobj, dialect='trec_eval') #
Example #18
Source File: dialect.py From vnpy_crypto with MIT License | 6 votes |
def test_dialect_str(self): data = """\ fruit:vegetable apple:brocolli pear:tomato """ exp = DataFrame({ 'fruit': ['apple', 'pear'], 'vegetable': ['brocolli', 'tomato'] }) csv.register_dialect('mydialect', delimiter=':') with tm.assert_produces_warning(ParserWarning): df = self.read_csv(StringIO(data), dialect='mydialect') tm.assert_frame_equal(df, exp) csv.unregister_dialect('mydialect')
Example #19
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 #20
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 #21
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 #22
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 #23
Source File: tlds.py From designate with Apache License 2.0 | 5 votes |
def from_file(self, input_file=None, delimiter=None): self._startup() input_file = str(input_file) if input_file is not None else None if not os.path.exists(input_file): raise Exception('TLD Input file Not Found') LOG.info("Importing TLDs from %s", input_file) error_lines = [] tlds_added = 0 with open(input_file) as inf: csv.register_dialect('import-tlds', delimiter=str(delimiter)) reader = csv.DictReader(inf, fieldnames=['name', 'description'], restkey='extra_fields', dialect='import-tlds') for line in reader: # check if there are more than 2 fields if 'extra_fields' in line: error_lines.append("InvalidLine --> " + self._convert_tld_dict_to_str(line)) else: tlds_added += self._validate_and_create_tld(line, error_lines) LOG.info("Number of tlds added: %d", tlds_added) errors = len(error_lines) if errors > 0: LOG.error("Number of errors: %d", errors) # Sorting the errors and printing them so that it is easier to # read the errors LOG.error("Error Lines:\n%s", '\n'.join(sorted(error_lines)))
Example #24
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 #25
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 #26
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 #27
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 #28
Source File: test_valid_csv.py From smartcsv with MIT License | 5 votes |
def test_valid_csv_with_a_custom_dialect(self): """Should be valid if all data is passed""" piped_template = VALID_TEMPLATE_STR.replace(',', '|') csv_data = """ title|category|subcategory|currency|price|url|image_url {iphone_data} {ipad_data} """.format( iphone_data=piped_template.format(**IPHONE_DATA), ipad_data=piped_template.format(**IPAD_DATA), ) csv.register_dialect('pipes', delimiter='|') reader = smartcsv.reader( StringIO(csv_data), dialect='pipes', columns=COLUMNS_1) iphone = next(reader) ipad = next(reader) self.assertRaises(StopIteration, lambda: list(next(reader))) self.assertTrue( isinstance(iphone, dict) and isinstance(ipad, dict)) self.assertModelsEquals(iphone, IPHONE_DATA) self.assertModelsEquals(ipad, IPAD_DATA)
Example #29
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 #30
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)