InvalidFilenameError.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 3
rs 10
cc 1
1
2
class OutsideDirectoryBase(Exception):
3
    '''
4
    Exception raised when trying to access to a file outside path defined on
5
    `directory_base` config property.
6
    '''
7
    pass
8
9
10
class OutsideRemovableBase(Exception):
11
    '''
12
    Exception raised when trying to access to a file outside path defined on
13
    `directory_remove` config property.
14
    '''
15
    pass
16
17
18
class InvalidPathError(ValueError):
19
    '''
20
    Exception raised when a path is not valid.
21
22
    :property path: value whose length raised this Exception
23
    '''
24
    code = 'invalid-path'
25
    template = 'Path {0.path!r} is not valid.'
26
27
    def __init__(self, message=None, path=None):
28
        self.path = path
29
        message = self.template.format(self) if message is None else message
30
        super(InvalidPathError, self).__init__(message)
31
32
33
class InvalidFilenameError(InvalidPathError):
34
    '''
35
    Exception raised when a filename is not valid.
36
37
    :property filename: value whose length raised this Exception
38
    '''
39
    code = 'invalid-filename'
40
    template = 'Filename {0.filename!r} is not valid.'
41
42
    def __init__(self, message=None, path=None, filename=None):
43
        self.filename = filename
44
        super(InvalidFilenameError, self).__init__(message, path=path)
45
46
47
class PathTooLongError(InvalidPathError):
48
    '''
49
    Exception raised when maximum filesystem path length is reached.
50
51
    :property limit: value length limit
52
    '''
53
    code = 'invalid-path-length'
54
    template = 'Path {0.path!r} is too long, max length is {0.limit}'
55
56
    def __init__(self, message=None, path=None, limit=0):
57
        self.limit = limit
58
        super(PathTooLongError, self).__init__(message, path=path)
59
60
61
class FilenameTooLongError(InvalidFilenameError):
62
    '''
63
    Exception raised when maximum filesystem filename length is reached.
64
    '''
65
    code = 'invalid-filename-length'
66
    template = 'Filename {0.filename!r} is too long, max length is {0.limit}'
67
68
    def __init__(self, message=None, path=None, filename=None, limit=0):
69
        self.limit = limit
70
        super(FilenameTooLongError, self).__init__(
71
            message, path=path, filename=filename)
72