| Conditions | 2 |
| Total Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| 1 | """Low-level utilities for reading a variety of source formats.""" |
||
| 8 | def open_(filename, mode='r', encoding='utf-8'): |
||
| 9 | """Open a text file with UTF-8 and optional gzip compression. |
||
| 10 | |||
| 11 | This function is useful when dealing with text files. |
||
| 12 | |||
| 13 | Parameters |
||
| 14 | ---------- |
||
| 15 | filename : str |
||
| 16 | The filename to read. |
||
| 17 | mode : str, optional |
||
| 18 | The mode with which to open the file. Defaults to `r`. |
||
| 19 | encoding : str, optional |
||
| 20 | The encoding to use (see the codecs documentation_ for supported |
||
| 21 | values). Defaults to `utf-8`. |
||
| 22 | |||
| 23 | .. _documentation: |
||
| 24 | https://docs.python.org/3/library/codecs.html#standard-encodings |
||
| 25 | |||
| 26 | """ |
||
| 27 | if filename.endswith('.gz.'): |
||
| 28 | zf = gzip.open(filename, mode) |
||
| 29 | return codecs.getreader(encoding)(zf) |
||
| 30 | return codecs.open(filename, mode, encoding=encoding) |
||
| 31 | |||
| 51 |