|
| 1 | +#!/usr/bin/env python |
| 2 | +############################################################################## |
| 3 | +# |
| 4 | +# diffpy.utils by DANSE Diffraction group |
| 5 | +# Simon J. L. Billinge |
| 6 | +# (c) 2010 The Trustees of Columbia University |
| 7 | +# in the City of New York. All rights reserved. |
| 8 | +# |
| 9 | +# File coded by: |
| 10 | +# |
| 11 | +# See AUTHORS.txt for a list of people who contributed. |
| 12 | +# See LICENSE_DANSE.txt for license information. |
| 13 | +# |
| 14 | +############################################################################## |
| 15 | + |
| 16 | +class UnsupportedTypeError(Exception): |
| 17 | + """For file types not supported by our parsers. |
| 18 | +
|
| 19 | + supported_types -- List of supported types. |
| 20 | + file -- file triggering the error. |
| 21 | + message -- for writing a custom message. |
| 22 | + """ |
| 23 | + |
| 24 | + def __init__(self, file, supported_types=None, message=None): |
| 25 | + if message is None: |
| 26 | + self.message = f"The file {file} is not supported." |
| 27 | + if supported_types is not None: |
| 28 | + self.message += " Supported file types include: " |
| 29 | + for t in supported_types: |
| 30 | + self.message += t + ", " |
| 31 | + self.message = self.message[:-2] + "." |
| 32 | + super().__init__(self.message) |
| 33 | + |
| 34 | + |
| 35 | +class ImproperSizeError(Exception): |
| 36 | + """When the size of an object does not match expectations. |
| 37 | +
|
| 38 | + bad_object -- Object with improper size. |
| 39 | + message -- for writing a custom message. |
| 40 | + """ |
| 41 | + |
| 42 | + def __init__(self, bad_object, message=None): |
| 43 | + if message is None: |
| 44 | + self.message = f"The size of {bad_object} is different than expected." |
| 45 | + super().__init__(self.message) |
0 commit comments