1
|
|
|
"""Implements all pydvdid package-specific exceptions. |
2
|
|
|
""" |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
from __future__ import unicode_literals |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class PydvdidException(Exception): |
9
|
|
|
"""Implements a class that represents an exception raised by the pydvdid package. This exception |
10
|
|
|
is never directly raised and is intended to be used in an 'except' block to handle any |
11
|
|
|
exception that originates from the package. |
12
|
|
|
""" |
13
|
|
|
|
14
|
|
|
def __new__(cls, *args, **kwargs): |
15
|
|
|
if cls is PydvdidException: |
16
|
|
|
raise TypeError("PydvdidException may not be directly instantiated.") |
17
|
|
|
|
18
|
|
|
return Exception.__new__(cls, *args, **kwargs) |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
class FileContentReadException(PydvdidException): |
22
|
|
|
"""Implements a class that represents the exception raised when a file's content cannot be |
23
|
|
|
successfully read. |
24
|
|
|
""" |
25
|
|
|
|
26
|
|
|
def __init__(self, expected_size, actual_size): |
27
|
|
|
if actual_size is None: |
28
|
|
|
template = "No bytes are available." |
29
|
|
|
else: |
30
|
|
|
template = "{0} bytes were expected, {1} were read." |
31
|
|
|
|
32
|
|
|
super(FileContentReadException, self).__init__(template.format(expected_size, actual_size)) |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
class FileTimeOutOfRangeException(PydvdidException): |
36
|
|
|
"""Implements a class that represents the exception raised when a file's creation or |
37
|
|
|
modification time is outside the allowable range (i.e. before 1601-01-01 00:00:00 or after |
38
|
|
|
9999-12-31 23:59:59). |
39
|
|
|
""" |
40
|
|
|
|
41
|
|
|
def __init__(self, file_time): |
42
|
|
|
template = "File Time '{0}' is outside of the allowable range." |
43
|
|
|
super(FileTimeOutOfRangeException, self).__init__(template.format(file_time)) |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
class PathDoesNotExistException(PydvdidException): |
47
|
|
|
"""Implements a class that represents the exception raised when a path does not exist. |
48
|
|
|
""" |
49
|
|
|
|
50
|
|
|
def __init__(self, path): |
51
|
|
|
template = "Path '{0}' does not exist." |
52
|
|
|
super(PathDoesNotExistException, self).__init__(template.format(path)) |
53
|
|
|
|