| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
class TerraSyncPyException(Exception): |
| 24 |
def __init__(self, message=None, *, mayCapitalizeMsg=True): |
| 25 |
"""Initialize a TerraSyncPyException instance. |
| 26 |
|
| 27 |
Except in cases where 'message' starts with a proper noun or |
| 28 |
something like that, its first character should be given in |
| 29 |
lower case. Automated treatments of this exception may print the |
| 30 |
message with its first character changed to upper case, unless |
| 31 |
'mayCapitalizeMsg' is False. In other words, if the case of the |
| 32 |
first character of 'message' must not be changed under any |
| 33 |
circumstances, set 'mayCapitalizeMsg' to False. |
| 34 |
|
| 35 |
""" |
| 36 |
self.message = message |
| 37 |
self.mayCapitalizeMsg = mayCapitalizeMsg |
| 38 |
|
| 39 |
def __str__(self): |
| 40 |
return self.completeMessage() |
| 41 |
|
| 42 |
def __repr__(self): |
| 43 |
return "{}.{}({!r})".format(__name__, type(self).__name__, self.message) |
| 44 |
|
| 45 |
|
| 46 |
def detail(self): |
| 47 |
return self.message |
| 48 |
|
| 49 |
def completeMessage(self): |
| 50 |
if self.message: |
| 51 |
return "{shortDesc}: {detail}".format( |
| 52 |
shortDesc=self.ExceptionShortDescription, |
| 53 |
detail=self.detail()) |
| 54 |
else: |
| 55 |
return self.ExceptionShortDescription |
| 56 |
|
| 57 |
ExceptionShortDescription = "terrasync.py generic exception" |
| 58 |
|
| 59 |
|
| 60 |
class UserError(TerraSyncPyException): |
| 61 |
"""Exception raised when the program is used in an incorrect way.""" |
| 62 |
ExceptionShortDescription = "User error" |
| 63 |
|
| 64 |
class NetworkError(TerraSyncPyException): |
| 65 |
"""Exception raised when getting a network error even after retrying.""" |
| 66 |
ExceptionShortDescription = "Network error" |
| 67 |
|
| 68 |
class UnsupportedURLScheme(TerraSyncPyException): |
| 69 |
"""Exception raised when asked to handle an unsupported URL scheme.""" |
| 70 |
ExceptionShortDescription = "Unsupported URL scheme" |
| 71 |
|
| 72 |
class RepoDataError(TerraSyncPyException): |
| 73 |
""" |
| 74 |
Exception raised when getting invalid data from the TerraSync repository.""" |
| 75 |
ExceptionShortDescription = "Invalid data from the TerraSync repository" |
| 76 |
|
| 77 |
class InvalidDirIndexFile(RepoDataError): |
| 78 |
"""Exception raised when getting invalid data from a .dirindex file.""" |
| 79 |
ExceptionShortDescription = "Invalid .dirindex file" |