Hide keyboard shortcuts

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. 

7 

8"""Generic file reader and related tools""" 

9 

10from abc import ABC, abstractmethod 

11 

12 

13class Reader(ABC): 

14 """Abstract class for reader objects.""" 

15 

16 def __init__(self, source, *args, **kwargs): 

17 """Initialize the Reader object. 

18 

19 This should be called by a subclass in its own __init__ method. 

20 

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 

28 

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() 

34 

35 return None 

36 

37 @abstractmethod 

38 def generate_repr(self): 

39 """Convert the raw contents of the source into the internal representation."""