Coverage for cclib/io/filereader.py : 92%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
2#
3# Copyright (c) 2017, the cclib development team
4#
5# This file is part of cclib (http://cclib.github.io) and is distributed under
6# the terms of the BSD 3-Clause License.
8"""Generic file reader and related tools"""
10from abc import ABC, abstractmethod
13class Reader(ABC):
14 """Abstract class for reader objects."""
16 def __init__(self, source, *args, **kwargs):
17 """Initialize the Reader object.
19 This should be called by a subclass in its own __init__ method.
21 Inputs:
22 source - A single filename, stream [TODO], or list of filenames/streams [TODO].
23 """
24 if isinstance(source, str):
25 self.filename = source
26 else:
27 raise ValueError
29 def parse(self):
30 """Read the raw contents of the source into the Reader."""
31 # TODO This cannot currently handle streams.
32 with open(self.filename) as handle:
33 self.filecontents = handle.read()
35 return None
37 @abstractmethod
38 def generate_repr(self):
39 """Convert the raw contents of the source into the internal representation."""