Debian Codegraph @

cclib/io/filereader.py

raw
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.
7
8 """Generic file reader and related tools"""
9
10 from abc import ABCMeta, abstractmethod
11 from six import add_metaclass
12
13
14 @add_metaclass(ABCMeta)
15 class Reader:
16 """Abstract class for reader objects."""
17
18 def __init__(self, source, *args, **kwargs):
19 """Initialize the Reader object.
20
21 This should be called by a subclass in its own __init__ method.
22
23 Inputs:
24 source - A single filename, stream [TODO], or list of filenames/streams [TODO].
25 """
26 if isinstance(source, str):
27 self.filename = source
28 else:
29 raise ValueError
30
31 def parse(self):
32 """Read the raw contents of the source into the Reader."""
33 # TODO This cannot currently handle streams.
34 with open(self.filename) as handle:
35 self.filecontents = handle.read()
36
37 return None
38
39 @abstractmethod
40 def generate_repr(self):
41 """Convert the raw contents of the source into the internal representation."""