Completed
Pull Request — master (#2609)
by Udayan
02:12
created

Fileproxy   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 9 2
A __hash__() 0 5 1
A __str__() 0 5 1
A __iter__() 0 5 1
1
from coala_utils.decorators import generate_eq
2
3
4
@generate_eq("filename")
5
class Fileproxy:
6
    """
7
    The file proxy is a wrapper object to wrap every file. The file proxy is an
8
    object that contains properties about the file currently processed (such as
9
    the filename). It contains:
10
        * The filename, this is the starting point for every other attribute.
11
        * The content of the file as a string.
12
        * The content of the file, line-splitted.
13
14
    Note: Other properties can be included later as and when required.
15
16
    The equality of the object is checked just based on it's filename.
17
    """
18
19
    def __init__(self, filename):
20
        """
21
        Constructs a new fileproxy object.
22
        :param filename: The name of the file to load.
23
        """
24
        self.filename = filename
25
        with open(self.filename, "r", encoding="utf-8") as filehandle:
26
            self.content = filehandle.read()
27
        self.lines = tuple(self.content.splitlines(True))
28
29
    def __iter__(self):
30
        """
31
        :return: A list of lines of the file to iterate over.
32
        """
33
        return iter(self.lines)
34
35
    def __hash__(self):
36
        """
37
        :return: Only hashes the filename.
38
        """
39
        return hash(self.filename)
40
41
    def __str__(self):
42
        """
43
        :return: A string of contents of the whole file.
44
        """
45
        return self.content
46