1
|
|
|
from typing import Dict |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
class UniversalCsvReaderFormatHelper: |
5
|
|
|
""" |
6
|
|
|
A helper class for UniversalCsvReader for setting and correcting the formatting parameters for reading CSV files. |
7
|
|
|
""" |
8
|
|
|
|
9
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
10
|
|
|
def pass1(self, filename: str, formatting_parameters: Dict[str, str]) -> Dict[str, str]: |
11
|
|
|
""" |
12
|
|
|
Returns the formatting parameters for reading the next current CSV file. |
13
|
|
|
|
14
|
|
|
This method is called by UniversalCsvReader before opening the CSV file and before auto-detecting parameters. |
15
|
|
|
|
16
|
|
|
Override this method in your own child class according to your needs. |
17
|
|
|
|
18
|
|
|
:param str filename: The next current file name. |
19
|
|
|
:param dict[str,str] formatting_parameters: The default formatting parameters. Keys are: |
20
|
|
|
- encoding: Use auto for auto-detecting. |
21
|
|
|
- delimiter: Use auto for auto-detecting. |
22
|
|
|
- line_terminator: Use auto for auto-detecting. |
23
|
|
|
- escape_char |
24
|
|
|
- quote_char |
25
|
|
|
""" |
26
|
|
|
return formatting_parameters |
27
|
|
|
|
28
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
29
|
|
|
def pass2(self, filename: str, formatting_parameters1: Dict[str, str], formatting_parameters2: Dict[str, str]) -> \ |
30
|
|
|
Dict[str, str]: |
31
|
|
|
""" |
32
|
|
|
Returns the formatting parameters for reading the next current CSV file. |
33
|
|
|
|
34
|
|
|
This method is called by UniversalCsvReader after auto-detecting parameters. |
35
|
|
|
|
36
|
|
|
Override this method in your own child class according to your needs. |
37
|
|
|
|
38
|
|
|
:param str filename: The next current file name. |
39
|
|
|
:param dict[str,str] formatting_parameters1: The formatting parameters as returned by pass1. |
40
|
|
|
:param dict[str,str] formatting_parameters2: The formatting parameters as returned by pass1 but parameters set |
41
|
|
|
to auto are replaced with the automatically detected values. |
42
|
|
|
""" |
43
|
|
|
return formatting_parameters2 |
44
|
|
|
|
45
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
46
|
|
|
|