1
|
|
|
|
2
|
|
|
|
3
|
|
|
class FileActionsException(Exception): |
4
|
|
|
''' |
5
|
|
|
Base class for file-actions exceptions |
6
|
|
|
''' |
7
|
|
|
code = None |
8
|
|
|
template = 'Unhandled error.' |
9
|
|
|
|
10
|
|
|
def __init__(self, message=None, path=None): |
11
|
|
|
self.path = path |
12
|
|
|
message = self.template.format(self) if message is None else message |
13
|
|
|
super(FileActionsException, self).__init__(message) |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
class InvalidDirnameError(FileActionsException): |
17
|
|
|
''' |
18
|
|
|
Exception raised when a new directory name is invalid. |
19
|
|
|
|
20
|
|
|
:property name: name which raised this Exception |
21
|
|
|
''' |
22
|
|
|
code = 'invalid-dirname' |
23
|
|
|
template = 'Clipboard item {0.name!r} is not valid.' |
24
|
|
|
|
25
|
|
|
def __init__(self, message=None, path=None, name=None): |
26
|
|
|
self.name = name |
27
|
|
|
super(InvalidDirnameError, self).__init__(message, path) |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
class ClipboardException(FileActionsException): |
31
|
|
|
''' |
32
|
|
|
Base class for clipboard exceptions. |
33
|
|
|
|
34
|
|
|
:property path: item path which raised this Exception |
35
|
|
|
:property clipboard: :class Clipboard: instance |
36
|
|
|
''' |
37
|
|
|
code = 'invalid-clipboard' |
38
|
|
|
template = 'Clipboard is invalid.' |
39
|
|
|
|
40
|
|
|
def __init__(self, message=None, path=None, clipboard=None): |
41
|
|
|
self.clipboard = clipboard |
42
|
|
|
super(ClipboardException, self).__init__(message, path) |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
class ItemIssue(tuple): |
46
|
|
|
''' |
47
|
|
|
Item/error issue |
48
|
|
|
''' |
49
|
|
|
@property |
50
|
|
|
def item(self): |
51
|
|
|
return self[0] |
52
|
|
|
|
53
|
|
|
@property |
54
|
|
|
def error(self): |
55
|
|
|
return self[1] |
56
|
|
|
|
57
|
|
|
@property |
58
|
|
|
def code(self): |
59
|
|
|
if isinstance(self.error, OSError): |
60
|
|
|
return 'oserror-%d' % self.error.errno |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
class InvalidClipboardItemsError(ClipboardException): |
64
|
|
|
''' |
65
|
|
|
Exception raised when a clipboard item is not valid. |
66
|
|
|
|
67
|
|
|
:property path: item path which raised this Exception |
68
|
|
|
''' |
69
|
|
|
pair_class = ItemIssue |
70
|
|
|
code = 'invalid-clipboard-items' |
71
|
|
|
template = 'Clipboard has invalid items.' |
72
|
|
|
|
73
|
|
|
def __init__(self, message=None, path=None, clipboard=None, issues=()): |
74
|
|
|
self.issues = list(map(self.pair_class, issues)) |
75
|
|
|
supa = super(InvalidClipboardItemsError, self) |
76
|
|
|
supa.__init__(message, path, clipboard) |
77
|
|
|
|
78
|
|
|
def append(self, item, error): |
79
|
|
|
self.issues.append(self.pair_class(item, error)) |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
class InvalidClipboardModeError(ClipboardException): |
83
|
|
|
''' |
84
|
|
|
Exception raised when a clipboard mode is not valid. |
85
|
|
|
|
86
|
|
|
:property mode: mode which raised this Exception |
87
|
|
|
''' |
88
|
|
|
code = 'invalid-clipboard-mode' |
89
|
|
|
template = 'Clipboard mode {0.path!r} is not valid.' |
90
|
|
|
|
91
|
|
|
def __init__(self, message=None, path=None, clipboard=None, mode=None): |
92
|
|
|
self.mode = mode |
93
|
|
|
supa = super(InvalidClipboardModeError, self) |
94
|
|
|
supa.__init__(message, path, clipboard) |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
class InvalidClipboardSizeError(ClipboardException): |
98
|
|
|
''' |
99
|
|
|
Exception raised when a clipboard size exceeds cookie limit. |
100
|
|
|
|
101
|
|
|
:property max_cookies: maximum allowed size |
102
|
|
|
''' |
103
|
|
|
code = 'invalid-clipboard-size' |
104
|
|
|
template = 'Clipboard has too many items.' |
105
|
|
|
|
106
|
|
|
def __init__(self, message=None, path=None, clipboard=None, max_cookies=0): |
107
|
|
|
self.max_cookies = max_cookies |
108
|
|
|
supa = super(InvalidClipboardSizeError, self) |
109
|
|
|
supa.__init__(message, path, clipboard) |
110
|
|
|
|