GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Logger.validate()   B
last analyzed

Complexity

Conditions 5

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
c 1
b 0
f 0
dl 0
loc 17
rs 8.5454
1
class Logger:
2
    def __init__(self, logFile: str):
3
        self._logFile = logFile
4
        self._log = None
5
6
    def __enter__(self):
7
        self.open()
8
        return self
9
10
    def __exit__(self, exc_type, exc_val, exc_tb):
11
        self.close()
12
13
    def open(self):
14
        def validate(logFile: str) -> str:
15
            if '.' in logFile:
16
                name, ext = logFile.split('.', 2)
17
                ext = '.' + ext
18
            else:
19
                name = logFile
20
                ext = ''
21
            num = 0
22
            exists = True
23
            while(exists):
24
                logFile = name + '-' + str(num) + ext
25
                try:
26
                    with open(logFile):
27
                            pass
28
                except IOError:
29
                    return logFile
30
                num += 1
31
32
        if self._log is not None:
33
            self.close()
34
        self._logFile = validate(self._logFile)
35
        self._log = open(self._logFile, 'wb')
36
        self.onOpen()
37
38
    def close(self):
39
        if self._log is not None:
40
            self.beforeClose()
41
            self._log.close()
42
            self.afterClose()
43
44
    def log(self, data: bytes):
45
        self._log.write(self.encodeData(data))
46
47
    def onOpen(self):
48
        pass
49
50
    def beforeClose(self):
51
        pass
52
53
    def afterClose(self):
54
        pass
55
56
    def encodeData(self, data):
57
        return data