Completed
Push — pathconf ( 6b4a1f...acbd18 )
by Felipe A.
30s
created

FilenameTooLongError.__init__()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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